diff --git a/sources/zarr/large_image_source_zarr/__init__.py b/sources/zarr/large_image_source_zarr/__init__.py index 58285fd51..3103077d1 100644 --- a/sources/zarr/large_image_source_zarr/__init__.py +++ b/sources/zarr/large_image_source_zarr/__init__.py @@ -507,13 +507,22 @@ def getMetadata(self): all_frame_values = self.frameValues[..., i] split = np.split(all_frame_values, all_frame_values.shape[i], axis=i) values = [a.flat[0] for a in split] - uniform = all(len(np.unique(a)) == 1 for a in split) + uniform = all(len(np.unique( + # convert all values to strings for mixed type comparison with np.unique + (a[np.not_equal(a, None)]).astype(str) + )) == 1 for a in split) + try: + min_val = min(values) + max_val = max(values) + except TypeError: + min_val = None + max_val = None result['Value' + axis.upper()] = dict( values=values, uniform=uniform, units=self.frameUnits.get(axis) if self.frameUnits is not None else None, - min=min(values), - max=max(values), + min=min_val, + max=max_val, datatype=np.array(values).dtype.name, ) for idx in range(self._framecount): @@ -810,7 +819,10 @@ def _getAxisInternalMetadata(self, axis_name): all_frame_values.shape[axis_index], axis=axis_index, ) - uniform = all(len(np.unique(a)) == 1 for a in split) + uniform = all(len(np.unique( + # convert all values to strings for mixed type comparison with np.unique + (a[np.not_equal(a, None)]).astype(str) + )) == 1 for a in split) if uniform: values = [a.flat[0] for a in split] else: diff --git a/test/test_sink.py b/test/test_sink.py index fc146628d..1a3ef8c7d 100644 --- a/test/test_sink.py +++ b/test/test_sink.py @@ -743,3 +743,12 @@ def testFrameValuesEdgeCases(tmp_path): ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=1, z=2, z_value=6.4, c_value='CD4') ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=1, z=1, z_value=3.1, c_value='CD4') ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=0, z=1, z_value=1.1) + + ts = large_image.new() + ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=0, z=0, z_value=1, c_value='DAPI') + ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=0, z=1, z_value=3.2, c_value='DAPI') + ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=0, z=2, z_value=6.3, c_value='DAPI') + ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=1, z=2, z_value=6.4, c_value='CD4') + ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=1, z=1, z_value=3.1, c_value='CD4') + ts.addTile(np.zeros((100, 100, 3)), x=0, y=0, c=0, z=1, z_value=1.1) + assert len(ts.metadata.get('frames', [])) == 6