-
Notifications
You must be signed in to change notification settings - Fork 68
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
Conversation
Why do we still want this since the |
|
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
LOL ok my bad. :) |
There was a problem hiding this 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(), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yea good call
Every zplane has it's own zc value so would't it just be that value? |
the mean of the coordinates of the individual zplanes |
When you max-project along Z, all the zplanes get flattened into one. So which zplane would the zc be obtained from?
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. :) |
There was a problem hiding this 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.
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? |
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. |
@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! |
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, |
There was a problem hiding this comment.
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.
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]) |
There was a problem hiding this comment.
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.
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :/
There was a problem hiding this comment.
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] = \ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Going to close this as it landed with #1353 |
Fixes #1214