Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing coordinate issues with max_proj #1291

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion starfish/core/imagestack/imagestack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ def max_proj(self, *dims: Axes) -> "ImageStack":
max_projection = self._data.max([dim.value for dim in dims])
max_projection = max_projection.expand_dims(tuple(dim.value for dim in dims))
max_projection = max_projection.transpose(*self.xarray.dims)
max_proj_stack = self.from_numpy(max_projection.values)
max_proj_stack = self.from_numpy(max_projection.values, coordinates=self.xarray.coords)
return max_proj_stack

def _squeezed_numpy(self, *dims: Axes):
Expand Down
15 changes: 2 additions & 13 deletions starfish/core/imagestack/parser/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ def get_tile(self, r: int, ch: int, z: int) -> TileData:
pos_ch = self.index_labels[Axes.CH].index(ch)
pos_z = self.index_labels[Axes.ZPLANE].index(z)

selectors: Mapping[str, Any] = {
Axes.ROUND.value: r,
Axes.CH.value: ch,
Axes.ZPLANE.value: z,
}

coordinates: MutableMapping[Coordinates, Tuple[Number, Number]] = dict()

if self.coordinates is not None:
Expand All @@ -136,14 +130,9 @@ def get_tile(self, r: int, ch: int, z: int) -> TileData:
(Coordinates.Y, PhysicalCoordinateTypes.Y_MIN, PhysicalCoordinateTypes.Y_MAX),
(Coordinates.Z, PhysicalCoordinateTypes.Z_MIN, PhysicalCoordinateTypes.Z_MAX),
):
min_selectors = dict(selectors)
min_selectors[PHYSICAL_COORDINATE_DIMENSION] = min_selector_value.value
max_selectors = dict(selectors)
max_selectors[PHYSICAL_COORDINATE_DIMENSION] = max_selector_value.value

coordinates[coordinate_type] = (
self.coordinates.loc[min_selectors].item(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you get rid of L139-L142 now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yea good call

self.coordinates.loc[max_selectors].item())
float(self.coordinates[coordinate_type][0]),
float(self.coordinates[coordinate_type][-1]))
else:
# fake coordinates!
coordinates[Coordinates.X] = (0.0, 0.001)
Expand Down
10 changes: 10 additions & 0 deletions starfish/core/imagestack/test/test_max_proj.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np

from starfish import data
from starfish.core.types import Axes
from ..imagestack import ImageStack

Expand All @@ -11,3 +12,12 @@ def test_max_projection_preserves_dtype():

max_projection = image.max_proj(Axes.CH, Axes.ROUND, Axes.ZPLANE)
assert max_projection.xarray.dtype == original_dtype


def test_max_projection_preserves_coordinates():
e = data.ISS(use_test_data=True)
nuclei = e.fov().get_image('nuclei')
nuclei_proj = nuclei.max_proj(Axes.ROUND, Axes.CH, Axes.ZPLANE)
# Since this data already has only 1 round, 1 ch, 1 zplane
# let's just assert that the max_proj operation didn't change anything
assert nuclei.xarray.equals(nuclei_proj.xarray)