Skip to content

Commit

Permalink
bugfix/invert-lif-scales (#288)
Browse files Browse the repository at this point in the history
* Invert LIF scale sizes

* Apply scale changes to tests
  • Loading branch information
Jackson Maxfield Brown authored Aug 9, 2021
1 parent 3b71939 commit c9e2af9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 9 additions & 0 deletions aicsimageio/readers/lif_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ def _get_coords_and_physical_px_sizes(
# Unpack short info scales
scale_x, scale_y, scale_z, scale_t = image_short_info["scale"]

# Scales from readlif are returned as px/µm
# We want to return as µm/px
scale_x = 1 / scale_x if scale_x is not None else None
scale_y = 1 / scale_y if scale_y is not None else None
scale_z = 1 / scale_z if scale_z is not None else None

# Handle Spatial Dimensions
if scale_z is not None:
coords[DimensionNames.SpatialZ] = Reader._generate_coord_array(
Expand Down Expand Up @@ -596,6 +602,9 @@ def _construct_mosaic_xarray(self, data: types.ArrayLike) -> xr.DataArray:

# Add expanded Y and X coords
scale_x, scale_y, _, _ = selected_scene.info["scale"]
scale_x = 1 / scale_x if scale_x is not None else None
scale_y = 1 / scale_y if scale_y is not None else None

if scale_y is not None:
coords[DimensionNames.SpatialY] = Reader._generate_coord_array(
0, stitched.shape[-2], scale_y
Expand Down
14 changes: 7 additions & 7 deletions aicsimageio/tests/readers/test_lif_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
np.uint16,
dimensions.DEFAULT_DIMENSION_ORDER,
["Gray--TL-BF--EMP_BF", "Green--FLUO--GFP"],
(None, 3.076923076923077, 3.076923076923077),
(None, 0.32499999999999996, 0.32499999999999996),
),
(
"s_1_t_4_c_2_z_1.lif",
Expand All @@ -47,7 +47,7 @@
np.uint16,
dimensions.DEFAULT_DIMENSION_ORDER,
["Gray--TL-PH--EMP_BF", "Green--FLUO--GFP"],
(None, 2.9485556406398508, 2.9485556406398508),
(None, 0.33914910277324634, 0.33914910277324634),
),
(
"tiled.lif",
Expand All @@ -57,7 +57,7 @@
np.uint8,
dimensions.DEFAULT_DIMENSION_ORDER_WITH_MOSAIC_TILES,
["Gray", "Red", "Green", "Cyan"],
(None, 4.984719055966396, 4.984719055966396),
(None, 0.20061311154598827, 0.20061311154598827),
),
pytest.param(
"example.txt",
Expand Down Expand Up @@ -306,10 +306,10 @@ def test_lif_reader_mosaic_tile_inspection(
[
(
"tiled.lif",
np.arange(0, 2552.176156654795, 4.984719055966396),
np.arange(0, 2552.176156654795, 4.984719055966396),
np.arange(0, 28024.09053264308, 4.984719055966396),
np.arange(0, 38212.85628303839, 4.984719055966396),
np.arange(0, 102.71391311154599, 0.20061311154598827),
np.arange(0, 102.71391311154599, 0.20061311154598827),
np.arange(0, 1127.846913111546, 0.20061311154598827),
np.arange(0, 1537.900113111546, 0.20061311154598827),
),
],
)
Expand Down
4 changes: 2 additions & 2 deletions aicsimageio/tests/test_aics_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
np.uint16,
dimensions.DEFAULT_DIMENSION_ORDER,
["Gray--TL-PH--EMP_BF", "Green--FLUO--GFP"],
(None, 2.9485556406398508, 2.9485556406398508),
(None, 0.33914910277324634, 0.33914910277324634),
ET.Element,
),
(
Expand All @@ -179,7 +179,7 @@
np.uint8,
dimensions.DEFAULT_DIMENSION_ORDER,
["Gray", "Red", "Green", "Cyan"],
(None, 4.984719055966396, 4.984719055966396),
(None, 0.20061311154598827, 0.20061311154598827),
ET.Element,
),
#######################################################################
Expand Down

0 comments on commit c9e2af9

Please sign in to comment.