Skip to content

Commit

Permalink
simplify array creation in example, and remove incorrect translation
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Mar 11, 2024
1 parent c4c1cd7 commit a63fef5
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,22 @@ store_chunks = (1, 2, 2, 2)

# simulate a multiscale pyramid
shapes = (10,) * ndim, (5,) * ndim
arrays = []
scales = []
translations = []
paths = []
arrays = [np.zeros(s) for s in shapes]

# define the base scaling and translation
scale_base = [1.0, 2.0, 2.0, 2.0]
trans_base = [0.0, 0.0, 0.0, 0.0]
# arrays will be named s0, s1, etc
paths = [f's{idx}' for idx in range(len(shapes))]

for idx, s in enumerate(shapes):
arrays.append(np.zeros(s))
# power of 2 downsampling per-axis for each image
scales.append(np.multiply(2 ** idx, scale_base))
# downsampling-induced translation per-axis for each image
translations.append(
np.multiply(scale_base, 2 ** (idx - 1)),
)

if idx > 0:
translations[-1] += np.sum(translations[:-1], axis=0)
# regular 2x downsampling
scales = [
[1.0, 2.0, 2.0, 2.0],
[2.0, 4.0, 4.0, 4.0],
]

# name the arrays s0, s1, s2
paths.append(f's{idx}')
# translation introduced by 2x downsampling
translations = [
[0.0, 0.0, 0.0, 0.0],
[0.5, 1.0, 1.0, 1.0]
]

# this is now a complete model of the Zarr group
group_model = Group.from_arrays(
Expand Down Expand Up @@ -174,7 +167,7 @@ print(group_model.model_dump())
{'type': 'scale', 'scale': [1.0, 2.0, 2.0, 2.0]},
{
'type': 'translation',
'translation': [0.5, 1.0, 1.0, 1.0],
'translation': [0.0, 0.0, 0.0, 0.0],
},
),
},
Expand All @@ -184,7 +177,7 @@ print(group_model.model_dump())
{'type': 'scale', 'scale': [2.0, 4.0, 4.0, 4.0]},
{
'type': 'translation',
'translation': [1.5, 3.0, 3.0, 3.0],
'translation': [0.5, 1.0, 1.0, 1.0],
},
),
},
Expand Down Expand Up @@ -261,14 +254,14 @@ print(stored_group.attrs.asdict())
'path': 's0',
'coordinateTransformations': (
{'type': 'scale', 'scale': [1.0, 2.0, 2.0, 2.0]},
{'type': 'translation', 'translation': [0.5, 1.0, 1.0, 1.0]},
{'type': 'translation', 'translation': [0.0, 0.0, 0.0, 0.0]},
),
},
{
'path': 's1',
'coordinateTransformations': (
{'type': 'scale', 'scale': [2.0, 4.0, 4.0, 4.0]},
{'type': 'translation', 'translation': [1.5, 3.0, 3.0, 3.0]},
{'type': 'translation', 'translation': [0.5, 1.0, 1.0, 1.0]},
),
},
],
Expand Down

0 comments on commit a63fef5

Please sign in to comment.