From 6c00eed5af2d7312bbca6638aa36c99b49dcb6fb Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Wed, 4 Sep 2024 19:24:15 +0000 Subject: [PATCH] Fix styling --- .../zarr/large_image_source_zarr/__init__.py | 26 +++--- test/test_sink.py | 79 ++++++++++--------- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/sources/zarr/large_image_source_zarr/__init__.py b/sources/zarr/large_image_source_zarr/__init__.py index e0c178ec9..621f1db9a 100644 --- a/sources/zarr/large_image_source_zarr/__init__.py +++ b/sources/zarr/large_image_source_zarr/__init__.py @@ -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 {} @@ -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): @@ -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): @@ -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 @@ -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: @@ -819,8 +819,8 @@ def _getAxisInternalMetadata(self, axis_name): unit = self.frameUnits.get(axis_name) if self.frameUnits is not None else None if unit is not None: axis_metadata['unit'] = unit - return axis_metadata - + return axis_metadata + def _writeInternalMetadata(self): self._checkEditable() with self._threadLock and self._processLock: diff --git a/test/test_sink.py b/test/test_sink.py index e28b4b929..e2634d1dd 100644 --- a/test/test_sink.py +++ b/test/test_sink.py @@ -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): @@ -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: @@ -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) @@ -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: