-
-
Notifications
You must be signed in to change notification settings - Fork 54
Allow length-1 inputs to NDCube.crop #863
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
Changes from 3 commits
fdc0b7c
5ca9043
a06a277
e67897a
266f8df
45ee5ae
dc3a05e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Enable length-1 inputs to `ndcube.NDCube.crop`, not only scalars. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,10 @@ | |||||||||
| import numpy as np | ||||||||||
|
|
||||||||||
| import astropy.nddata | ||||||||||
| from astropy.wcs.wcsapi import BaseHighLevelWCS, HighLevelWCSWrapper, SlicedLowLevelWCS | ||||||||||
| import astropy.units as u | ||||||||||
| from astropy.coordinates import SkyCoord, SpectralCoord | ||||||||||
| from astropy.time import Time | ||||||||||
| from astropy.wcs.wcsapi import BaseHighLevelWCS, BaseLowLevelWCS, HighLevelWCSWrapper, SlicedLowLevelWCS | ||||||||||
|
|
||||||||||
| from ndcube.utils import wcs as wcs_utils | ||||||||||
|
|
||||||||||
|
|
@@ -138,8 +141,16 @@ | |||||||||
| # Define a list of lists to hold the array indices of the points | ||||||||||
| # where each inner list gives the index of all points for that array axis. | ||||||||||
| combined_points_array_idx = [[]] * wcs.pixel_n_dim | ||||||||||
| high_level_wcs = HighLevelWCSWrapper(wcs) if isinstance(wcs, BaseLowLevelWCS) else wcs | ||||||||||
| wcs = high_level_wcs.low_level_wcs | ||||||||||
| # For each point compute the corresponding array indices. | ||||||||||
| for point in points: | ||||||||||
| # Sanitize input format | ||||||||||
| # Make point a tuple if given as a single high level coord object valid for this WCS. | ||||||||||
| if isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())): | ||||||||||
|
||||||||||
| if isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())): | |
| if not isinstance(point, (tuple, list)) and not wcs.seralized_classes and isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())): |
Outdated
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 isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())): | |
| if not isinstance(point, tuple) and isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())): |
Outdated
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 is unrelated to the tuple thing right?
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.
Yes. Here, we can assume that point is a tuple or list. So this line is about converting length-1 objects to scalar ones.
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.
I'm a little lost why we need to do this, can't we handle multi-dimensional inputs?
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.
why are these coordinates so specific?
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.
I copied them from another test. Can't remember why that test had them so specific