diff --git a/model_server/accessors.py b/model_server/accessors.py index caec8ddf5085f5b43174e27c1462dddcee2ac350..1bb5b6b4b176397660ead624ae704e8b9808992a 100644 --- a/model_server/accessors.py +++ b/model_server/accessors.py @@ -48,7 +48,7 @@ class GenericImageDataAccessor(ABC): @property def pixel_scale_in_micrometers(self): - return None + return {} @property def dtype(self): @@ -176,15 +176,12 @@ class CziImageFileAccessor(GenericImageFileAccessor): @property def pixel_scale_in_micrometers(self): - meta_sc_str = self.czifile.metadata(raw=False)['ImageDocument']['Metadata']['ImageScaling']['ImagePixelSize'] - meta_mags = self.czifile.metadata(raw=False)['ImageDocument']['Metadata']['ImageScaling']['ScalingComponent'] - sc_xy = list(map( - float, - meta_sc_str.split(',') - )) - assert sc_xy[0] == sc_xy[1] - mags = [float(m['Magnification']) for m in meta_mags] - return sc_xy[0] / np.product(mags) + scale_meta = self.czifile.metadata(raw=False)['ImageDocument']['Metadata']['Scaling']['Items']['Distance'] + sc = {} + for m in scale_meta: + if m['DefaultUnitFormat'].encode() == b'\xc2\xb5m' and m['Id'] in self.shape_dict.keys(): # literal mu-m + sc[m['Id']] = m['Value'] * 1e6 + return sc def write_accessor_data_to_file(fpath: Path, accessor: GenericImageDataAccessor, mkdir=True) -> bool: diff --git a/tests/test_accessors.py b/tests/test_accessors.py index 1a465dfb556086ca9cc3ff88941c09052680d1ac..557970ea691b91b228a43e29993bc4068c8d88db 100644 --- a/tests/test_accessors.py +++ b/tests/test_accessors.py @@ -114,4 +114,5 @@ class TestCziImageFileAccess(unittest.TestCase): def test_read_in_pixel_scale_from_czi(self): cf = CziImageFileAccessor(czifile['path']) - self.assertAlmostEqual(cf.pixel_scale_in_micrometers, czifile['um_per_pixel'], places=3) \ No newline at end of file + pxs = cf.pixel_scale_in_micrometers + self.assertAlmostEqual(pxs['X'], czifile['um_per_pixel'], places=3) \ No newline at end of file