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

Implement Superpixel on NDCube #450

Merged
merged 120 commits into from
Mar 1, 2023
Merged

Conversation

DanRyanIrish
Copy link
Member

@DanRyanIrish DanRyanIrish commented Jul 29, 2021

Description

This PR implements a superpixel method on NDCube (now renamed rebin) that downsamples the grid by a factor that is an integer fraction of the cube's length in the relevant dimension. It enables the user to provide the function that dictates how the value in the superpixel is derived from its constituent pixels. To support this, an interpolate method has been introduced to ExtraCoords.

For reviewing purposes, the core pieces of this PR are NDCube.rebin and ExtraCoords.interpolate.

This PR depends on #449

To Do

  • Discuss/decide how to handle uncertainty
  • Handle ExtraCoords
  • Handle SkyCoord ExtraCoord
  • Add tests
  • Add changelog for ExtraCoord.interpolate
  • Test error propagation
  • Generalise SkyCoord interpolation as suggested in conversation thread.
  • Use numpy.interp to remove scipy dependency
  • Rename superpixel to rebin
  • Propagate uncertainties to max and min versions. If multiple pixels with max/min value, preserve the larger uncertainty
  • Add and standard deviation version. Drop uncertainty
  • Write tests for min/max versions
  • Resolve near-name conflict with astropy NDArithmeticMixin kwarg propagate_uncertainties which has a different behaviour.
  • Implement extra_coords interpolate on TableCoordinate objects
  • Add resample method to ExtraCoords leveraging TableCoord interpolate
  • Replace use of ExtraCoords.interpolate with ExtraCoords.resample in this PR and bugfix ExtraCoords.resample
  • Delete ExtraCoords.interpolate
  • Change use_masked_values to operation_ignores_mask

@pep8speaks
Copy link

pep8speaks commented Jul 29, 2021

Hello @DanRyanIrish! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers!

Comment last updated at 2021-11-18 14:23:40 UTC

@DanRyanIrish DanRyanIrish marked this pull request as draft July 29, 2021 14:42
@DanRyanIrish DanRyanIrish changed the title Draft: Implement Superpixel on NDCube Implement Superpixel on NDCube Jul 29, 2021
@DanRyanIrish DanRyanIrish added this to the 2.1 milestone Jul 29, 2021
ndcube/extra_coords/extra_coords.py Outdated Show resolved Hide resolved
ndcube/extra_coords/extra_coords.py Outdated Show resolved Hide resolved
ndcube/extra_coords/extra_coords.py Outdated Show resolved Hide resolved
ndcube/ndcube.py Outdated Show resolved Hide resolved
ndcube/extra_coords/extra_coords.py Outdated Show resolved Hide resolved
@DanRyanIrish
Copy link
Member Author

@Cadair: The oldestdeps tests are failing due to a DeprecationWarning being raised. @nabobalis have tried to make this ignored but against all insistence from us, the warning is still raised? Any ideas how to fix this? If not, the only options may be to merge with this failing or bump the oldest deps.

tox.ini Show resolved Hide resolved
@DanRyanIrish
Copy link
Member Author

@Cadair : Thanks to some help from Nabil, this PR is ready for another review. I plan to add a couple more tests to check correct errors are raised and bump up the coverage. Apart from that though, this PR could be merged.

Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

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

Looking great!

I have left a bunch of mostly minor comments. I will admit I haven't gone through and understood the depths of all the code, but it looks good.

It seems the coverage 🤖 isn't very happy, don't suppose you have the time to cover some of the edge / error cases with tests?

haha just noticed your comment about doing that.

changelog/450.feature.2.rst Outdated Show resolved Hide resolved
ndcube/extra_coords/extra_coords.py Outdated Show resolved Hide resolved
ndcube/extra_coords/extra_coords.py Outdated Show resolved Hide resolved
ndcube/extra_coords/extra_coords.py Show resolved Hide resolved
ndcube/extra_coords/table_coord.py Outdated Show resolved Hide resolved
ndcube/ndcube.py Show resolved Hide resolved
Comment on lines +1125 to +1126
if isinstance(new_data, ARRAY_MASK_MAP[np.ndarray]):
new_data = new_data.data
Copy link
Member

Choose a reason for hiding this comment

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

This still weirds me out. It feels like we have special cased dask and numpy here, where numpy does this but dask dosen't. What if cupy adds a masked array where we need to do this. It all makes me uncomfortable.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. But since numpy and dask masked arrays have different APIs, the alternative I see is to force everything into numpy masked arrays which is a worse idea.

ndcube/ndcube.py Outdated Show resolved Hide resolved
ndcube/ndcube.py Outdated Show resolved Hide resolved
# Execute rebin.
cube = ndcube_2d_dask
bin_shape = (4, 2)
output = cube.rebin(bin_shape, propagate_uncertainties=True)
Copy link
Member

Choose a reason for hiding this comment

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

hmm, I would have to confirm that, but probably.

@DanRyanIrish
Copy link
Member Author

@Cadair I think this is ready for a final review.

@property
@abc.abstractproperty
def is_empty(self):
"""Return True if no extra coords present, else return False."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""Return True if no extra coords present, else return False."""
"""
Return True if no extra coords present, else return False.
"""

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.

4 participants