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

Conversation

shanaxel42
Copy link
Collaborator

Fixes #1214

@shanaxel42 shanaxel42 requested a review from ttung April 29, 2019 20:25
@ttung
Copy link
Collaborator

ttung commented Apr 29, 2019

Why do we still want this since the MaxProject filter exists?

@shanaxel42
Copy link
Collaborator Author

shanaxel42 commented Apr 29, 2019

Why do we still want this since the MaxProject filter exists?

MaxProject just uses Imagestack.max_proj, so it'll have the same issues

@codecov-io
Copy link

codecov-io commented Apr 29, 2019

Codecov Report

Merging #1291 into master will increase coverage by 0.43%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1291      +/-   ##
==========================================
+ Coverage   88.84%   89.28%   +0.43%     
==========================================
  Files         146      147       +1     
  Lines        5246     5542     +296     
==========================================
+ Hits         4661     4948     +287     
- Misses        585      594       +9
Impacted Files Coverage Δ
starfish/core/imagestack/imagestack.py 94.01% <100%> (+0.1%) ⬆️
starfish/core/imagestack/parser/numpy/__init__.py 90.76% <100%> (+7.91%) ⬆️
...ots/_detect_spots/trackpy_local_max_peak_finder.py 90.27% <0%> (-1.39%) ⬇️
starfish/core/pipeline/algorithmbase.py 96.66% <0%> (-1.07%) ⬇️
...ore/intensity_table/intensity_table_coordinates.py 100% <0%> (ø) ⬆️
starfish/core/image/_filter/call_bases.py 97.29% <0%> (ø)
starfish/core/experiment/experiment.py 82.51% <0%> (+0.31%) ⬆️
starfish/core/intensity_table/intensity_table.py 96.92% <0%> (+0.49%) ⬆️
starfish/core/codebook/codebook.py 97.26% <0%> (+0.6%) ⬆️
starfish/core/imagestack/parser/crop.py 93.1% <0%> (+0.79%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30c7680...cbddb91. Read the comment docs.

@ttung
Copy link
Collaborator

ttung commented Apr 29, 2019

MaxProject just uses Imagestack.max_proj, so it'll have the same issues

LOL ok my bad. :)

Copy link
Collaborator

@ttung ttung left a comment

Choose a reason for hiding this comment

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

Kind of curious: if you take a max projection across >1 ZPLANES, what is the correct Z coordinate of the result? I think we should have a rational answer for that, and test for it.

@@ -142,8 +142,8 @@ def get_tile(self, r: int, ch: int, z: int) -> TileData:
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

@shanaxel42
Copy link
Collaborator Author

Kind of curious: if you take a max projection across >1 ZPLANES, what is the correct Z coordinate of the result? I think we should have a rational answer for that, and test for it.

Every zplane has it's own zc value so would't it just be that value?

@neuromusic
Copy link
Collaborator

if you take a max projection across >1 ZPLANES, what is the correct Z coordinate of the result?

the mean of the coordinates of the individual zplanes

@shanaxel42 shanaxel42 requested a review from ttung April 30, 2019 17:11
@ttung
Copy link
Collaborator

ttung commented Apr 30, 2019

Every zplane has it's own zc value so would't it just be that value?

When you max-project along Z, all the zplanes get flattened into one. So which zplane would the zc be obtained from?

the mean of the coordinates of the individual zplanes

Furthermore, if the zplanes are not evenly spaced, then you would need to average all of the individual z coordinates, rather than just take the first and last and average them. :)

Copy link
Collaborator

@ttung ttung left a comment

Choose a reason for hiding this comment

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

There needs to be a test to see if we save the correct coordinate when we flatten across >1 planes.

@shanaxel42
Copy link
Collaborator Author

When you max-project along Z, all the zplanes get flattened into one. So which zplane would the zc be obtained from?

But doesn't this happen by just choosing the max value from whatever dim your max_projecting on? And we've already calculated a value for each z_pane. So in this case we'd choose the max z_plane and then the z_coord is whatever we'd previously calculate for that z_plane?

@ttung
Copy link
Collaborator

ttung commented Apr 30, 2019

For each pixel, you could be sourcing the value from a different z plane. However, we only store a coordinate value per plane, and so when you flatten to one, you have to store only one z coordinate.

@kevinyamauchi
Copy link
Collaborator

@shanaxel42, what is the status of this PR? I am trying to add other types of projection (e.g., sum across axes) in #1342 and I was hoping to integrate the changes here for transferring physical coordinates.

@shanaxel42
Copy link
Collaborator Author

@shanaxel42, what is the status of this PR? I am trying to add other types of projection (e.g., sum across axes) in #1342 and I was hoping to integrate the changes here for transferring physical coordinates.

Hey! Sorry this one kinda fell off my radar, I'll get it merged today!

@kevinyamauchi
Copy link
Collaborator

Awesome! Thanks!

@@ -299,7 +300,7 @@ def from_numpy(
cls,
array: np.ndarray,
index_labels: Optional[Mapping[Axes, Sequence[int]]]=None,
coordinates: Optional[xr.DataArray]=None,
coordinates: Optional[DataArrayCoordinates]=None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

parameter docs not updated below.

starfish/core/imagestack/imagestack.py Show resolved Hide resolved
float(self.coordinates[coordinate_type][0]),
float(self.coordinates[coordinate_type][-1]))
# For the z coordinate, take the average.
average_z_coord = np.average(self.coordinates[Coordinates.Z])
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you pass this a full 5D tensor (i.e., where z has many layers) into from_numpy, this will mess up your z coordinates.

@shanaxel42 shanaxel42 requested a review from ttung May 14, 2019 14:05
@@ -310,7 +311,7 @@ def from_numpy(
index_labels : Optional[Mapping[Axes, Sequence[int]]]
Mapping from axes (r, ch, z) to their labels. If this is not provided, then the axes
will be labeled from 0..(n-1), where n=the size of the axes.
coordinates : Optional[xr.DataArray]
coordinates : Optional[DataArrayCoordinates]
DataArray indexed by r, ch, z, with xmin, xmax, ymin, ymax, zmin, zmax as columns. If
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be updated as well, presumably.

Copy link
Collaborator

Choose a reason for hiding this comment

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

contract is here. actually it's not even up to date. :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea this is def not true anymore. it should just be DataArrayCoordinates object

physical_coords = self.xarray.coords
if Axes.ZPLANE in dims:
# if we max proj by z, take average coord
physical_coords[Coordinates.Z].values[0] = \
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't calculate the average twice.

also, the physical_coords[Coordinates.Z] is the wrong size! It should be size = 2, according to the contract for from_numpy (min, max).

furthermore, the size of the coords for X/Y is also wrong. It's currently the size of the X/Y, and presumably it ought to also be 2.

average_z_coordinate = np.average((self.xarray.coords[Coordinates.Z])
physical_coords[Coordinates.Z] = xr.DataArray(...)

Furthermore, if one max projects across another dimension where we assign coordinates (like x or y), we would presumably need to do the same thing. Alternatively, we could explicitly disallow max projecting across x or y, but if we want to do that, we should clear it with Deep/Ambrose/Kevin/Brian.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no min/max contract in from_numpy, it takes the first and last values from the array. So they can be any size

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But I can do that here if you think that's cleaner

@shanaxel42 shanaxel42 requested a review from ttung May 14, 2019 19:10
ttung pushed a commit that referenced this pull request May 23, 2019
This is based on top of #1352 and #1291.  The most likely path for this to get merged is for #1352 (and its supporting PRs) to land, rebase #1291 on top of master, and merging this all in.
@ttung
Copy link
Collaborator

ttung commented May 24, 2019

Going to close this as it landed with #1353

@ttung ttung closed this May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

max_proj does weird things to physical coordinates
5 participants