Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Sep 4, 2024
1 parent 0aa76b4 commit f8198a8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 51 deletions.
24 changes: 12 additions & 12 deletions sources/zarr/large_image_source_zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def _scanZarrArray(self, group, arr, results):
arrays, then total pixels, then channels. 'is_ome' is a boolean.
'series' is a list of the found groups and arrays that match the
best criteria. 'axes', 'axes_values', 'axes_units', and 'channels'
are from the best array. 'associated' is a list of all groups and
arrays that might be associated images. These have to be culled
are from the best array. 'associated' is a list of all groups and
arrays that might be associated images. These have to be culled
for the actual groups used in the series.
"""
attrs = group.attrs.asdict() if group is not None else {}
Expand All @@ -245,11 +245,11 @@ def _scanZarrArray(self, group, arr, results):
axes = {axis['name']: idx for idx, axis in enumerate(
attrs['multiscales'][0]['axes'])}
axes_values = {
axis['name']: axis.get('values')
axis['name']: axis.get('values')
for axis in attrs['multiscales'][0]['axes']
}
axes_units = {
axis['name']: axis.get('unit')
axis['name']: axis.get('unit')
for axis in attrs['multiscales'][0]['axes']
}
if isinstance(attrs['omero'].get('channels'), list):
Expand Down Expand Up @@ -374,7 +374,7 @@ def _readFrameValues(self, found, baseArray):
slicing[axis_index] = i
frame_values[tuple(slicing)] = value
elif isinstance(values, dict):
# non-uniform values are written as dicts
# non-uniform values are written as dicts
# mapping values to index permutations
for value, frame_specs in values.items():
if isinstance(value, str):
Expand All @@ -387,7 +387,7 @@ def _readFrameValues(self, found, baseArray):
slicing[self.frameAxes.index(a)] = i
frame_values[tuple(slicing)] = value
self._frameValues = frame_values

def _validateZarr(self):
"""
Validate that we can read tiles from the zarr parent group in
Expand Down Expand Up @@ -796,13 +796,13 @@ def _getAxisInternalMetadata(self, axis_name):
elif axis_name in ['s', 'c']:
axis_metadata['type'] = 'channel'
if self.frameAxes is not None:
frame_axis_index = self.frameAxes.index(axis_name) if axis_name in self.frameAxes else None
if frame_axis_index is not None and self.frameValues is not None:
all_frame_values = self.frameValues[..., frame_axis_index]
axis_index = self.frameAxes.index(axis_name) if axis_name in self.frameAxes else None
if axis_index is not None and self.frameValues is not None:
all_frame_values = self.frameValues[..., axis_index]
split = np.split(
all_frame_values,
all_frame_values.shape[frame_axis_index],
axis=frame_axis_index,
all_frame_values.shape[axis_index],
axis=axis_index,
)
uniform = all(len(np.unique(a)) == 1 for a in split)
if uniform:
Expand All @@ -820,7 +820,7 @@ def _getAxisInternalMetadata(self, axis_name):
if unit is not None:
axis_metadata['unit'] = unit
return axis_metadata

def _writeInternalMetadata(self):
self._checkEditable()
with self._threadLock and self._processLock:
Expand Down
79 changes: 40 additions & 39 deletions test/test_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def get_expected_metadata(axis_spec, frame_shape):
},
)


def compare_metadata(actual, expected):
assert type(actual) is type(expected)
if isinstance(actual, list):
Expand Down Expand Up @@ -611,23 +612,23 @@ def testFrameValuesSmall(use_add_tile_args, tmp_path):
frame = 0
index = 0
for c, c_value in enumerate(axis_spec['c']['values']):
add_tile_args = dict(c=c, axes=['c', 'y', 'x', 's'])
if use_add_tile_args:
add_tile_args.update(c_value=c_value)
else:
frame_values[c] = [c_value]
random_tile = np.random.random(frame_shape)
sink.addTile(random_tile, 0, 0, **add_tile_args)
expected_metadata['frames'].append(
dict(
Frame=frame,
Index=index,
IndexC=c,
ValueC=c_value,
Channel=f'Band {c + 1}',
),
)
frame += 1
add_tile_args = dict(c=c, axes=['c', 'y', 'x', 's'])
if use_add_tile_args:
add_tile_args.update(c_value=c_value)
else:
frame_values[c] = [c_value]
random_tile = np.random.random(frame_shape)
sink.addTile(random_tile, 0, 0, **add_tile_args)
expected_metadata['frames'].append(
dict(
Frame=frame,
Index=index,
IndexC=c,
ValueC=c_value,
Channel=f'Band {c + 1}',
),
)
frame += 1
index += 1

if not use_add_tile_args:
Expand Down Expand Up @@ -676,7 +677,7 @@ def testFrameValues(use_add_tile_args, tmp_path):
}
frame_values_shape = [
*[len(v['values']) for v in axis_spec.values()],
len(axis_spec)
len(axis_spec),
]
frame_values = np.empty(frame_values_shape, dtype=object)

Expand All @@ -687,27 +688,27 @@ def testFrameValues(use_add_tile_args, tmp_path):
if not axis_spec['t']['uniform']:
t_value += 0.01 * z
for c, c_value in enumerate(axis_spec['c']['values']):
add_tile_args = dict(z=z, t=t, c=c, axes=['z', 't', 'c', 'y', 'x', 's'])
if use_add_tile_args:
add_tile_args.update(z_value=z_value, t_value=t_value, c_value=c_value)
else:
frame_values[z, t, c] = [z_value, t_value, c_value]
random_tile = np.random.random(frame_shape)
sink.addTile(random_tile, 0, 0, **add_tile_args)
expected_metadata['frames'].append(
dict(
Frame=frame,
Index=index,
IndexZ=z,
ValueZ=z_value,
IndexT=t,
ValueT=t_value,
IndexC=c,
ValueC=c_value,
Channel=f'Band {c + 1}',
)
)
frame += 1
add_tile_args = dict(z=z, t=t, c=c, axes=['z', 't', 'c', 'y', 'x', 's'])
if use_add_tile_args:
add_tile_args.update(z_value=z_value, t_value=t_value, c_value=c_value)
else:
frame_values[z, t, c] = [z_value, t_value, c_value]
random_tile = np.random.random(frame_shape)
sink.addTile(random_tile, 0, 0, **add_tile_args)
expected_metadata['frames'].append(
dict(
Frame=frame,
Index=index,
IndexZ=z,
ValueZ=z_value,
IndexT=t,
ValueT=t_value,
IndexC=c,
ValueC=c_value,
Channel=f'Band {c + 1}',
),
)
frame += 1
index += 1

if not use_add_tile_args:
Expand Down

0 comments on commit f8198a8

Please sign in to comment.