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

Clean up binary mask #1622

Merged
merged 1 commit into from
Nov 13, 2019
Merged

Clean up binary mask #1622

merged 1 commit into from
Nov 13, 2019

Conversation

ttung
Copy link
Collaborator

@ttung ttung commented Oct 18, 2019

  1. Use typed axes/coordinates when possible.
  2. Have _get_axes_names return axes/coordinates in the order they are expected in the numpy arrays.
  3. Improve how we render the mask names.

Test plan: pytest starfish/core/binary_mask/test

@ttung ttung requested a review from shanaxel42 October 18, 2019 22:15
@codecov-io
Copy link

codecov-io commented Oct 18, 2019

Codecov Report

Merging #1622 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1622      +/-   ##
==========================================
- Coverage   90.09%   90.09%   -0.01%     
==========================================
  Files         234      234              
  Lines        8764     8761       -3     
==========================================
- Hits         7896     7893       -3     
  Misses        868      868
Impacted Files Coverage Δ
starfish/core/binary_mask/util.py 90.9% <100%> (-1.95%) ⬇️
starfish/core/binary_mask/expand.py 100% <100%> (ø) ⬆️
starfish/core/binary_mask/binary_mask.py 93.2% <100%> (ø) ⬆️
starfish/test/full_pipelines/api/test_iss_api.py 100% <100%> (ø) ⬆️
starfish/core/binary_mask/test/test_binary_mask.py 100% <100%> (ø) ⬆️

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 6674d9b...b8bfd88. Read the comment docs.

@ttung ttung removed the request for review from shanaxel42 October 19, 2019 00:38
@ttung ttung force-pushed the tonytung-binary-mask-cleanup branch 2 times, most recently from e231f98 to 69253ca Compare October 24, 2019 17:45
@ttung ttung force-pushed the tonytung-binary-mask-cleanup branch from 69253ca to b0301db Compare October 28, 2019 17:26
@ttung ttung force-pushed the tonytung-binary-mask-cleanup branch 3 times, most recently from 88e5b1a to 8512135 Compare October 30, 2019 20:41
@ttung ttung requested a review from shanaxel42 November 7, 2019 01:12
1. Use typed axes/coordinates when possible.
2. Have `_get_axes_names` return axes/coordinates in the order they are expected in the numpy arrays.
3. Improve how we render the mask names.

Test plan: `pytest starfish/core/binary_mask/test`
@ttung ttung force-pushed the tonytung-binary-mask-cleanup branch from 8512135 to b8bfd88 Compare November 7, 2019 22:49

Returns
-------
masks : BinaryMaskCollection
Masks generated from the label image.
"""
props = regionprops(label_image)
len_max_label = len(str(len(props) - 1))
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is there the extra str conversion here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was tripped up by this too. Let's say we have 100 regions. len(props) - 1 gets you 99 as an int. Then str(99) gives you "99". Then len("99") gives you 2.



def fill_from_mask(
mask: xr.DataArray,
fill_value: int,
result_array: np.ndarray,
axes_order: Sequence[Union[str, Axes]] = AXES_ORDER,
axes_order: Sequence[Union[str, Axes]] = (Axes.ZPLANE, Axes.Y, Axes.X),
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not use your get_axes_order helper method here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That basically happens in #1628

@ttung ttung merged commit fdf8962 into master Nov 13, 2019
@ttung ttung deleted the tonytung-binary-mask-cleanup branch November 13, 2019 06:42
ttung pushed a commit that referenced this pull request Nov 13, 2019
LabelImage requires all the pixel coordinate and physical coordinate values along each axis, so to facilitate the easy conversion to and from BinaryMaskCollection and LabelImage, we need to change the data model for BinaryMaskCollection.

Previously, BinaryMaskCollection stored a series of xarrays for each of the masks.  This does not guarantee that the pixel/physical coordinates for every position along each axis.  Furthermore, it duplicates a lot of data.

This new approach stores the coordinates as independent arrays, and then stores each mask as a naked np.ndarray with offsets.  Conversions to and from LabelImage is pretty straightforward.  Returning each mask as an xarray (to maintain compatibility with the existing API) requires generating an xarray on the fly, but is not terribly expensive.

Writing to disk is now through a versioned interface similar to what was done for slicedimage.

Test plan: Updated tests to reflect the API changes.
Part of #1497
Depends on #1619, #1622
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.

3 participants