-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add Sky Regions to get_subsets() #2496
Conversation
Also need:
|
@pllim @javerbukh i was going to add some documentation for this and i noticed the 'get_interactive_regions' function is how getting subsets back is advertised in the documentation. i think i should probably add a to_sky flag there as well, although that doesn't call 'get_subsets' (not sure why?) so i would need to put some logic in there too. thoughts on this? do we not advertise get_subsets but rather this function? |
There is a conflict now. Please rebase. Thanks!
I think @kecnry created a tech debt ticket on |
in that case, i will hold off on adding user documentation for this until that is decided. |
6d1a207
to
215ccef
Compare
CHANGES.rst
Outdated
@@ -9,9 +9,13 @@ Cubeviz | |||
|
|||
- Add circular annulus subset to toolbar. [#2438] | |||
|
|||
- Expose sky regions in get_subsets. [#2496] |
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.
Expose how? A user needs to know enough to use it.
jdaviz/app.py
Outdated
sky_subset_region = None | ||
override_wcs = None # only for cubeviz, where gwcs is missing spatial info | ||
skip_sky_region = False | ||
if to_sky: | ||
wcs = subset_state.xatt.parent.coords | ||
if self.config == 'cubeviz': | ||
parent_data = subset_state.attributes[0].parent | ||
override_wcs = parent_data.meta["_orig_spatial_wcs"] | ||
if override_wcs is None: | ||
# if cubeviz and theres no spatial wcs, we have to skip computing sky region | ||
skip_sky_region = True | ||
else: | ||
if wcs is None: | ||
skip_sky_region = True # also need to skip if in imviz and theres no WCS |
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 think this can be simplified (but please confirm that it actually works because other code below might also need changing to go with this):
sky_subset_region = None | |
override_wcs = None # only for cubeviz, where gwcs is missing spatial info | |
skip_sky_region = False | |
if to_sky: | |
wcs = subset_state.xatt.parent.coords | |
if self.config == 'cubeviz': | |
parent_data = subset_state.attributes[0].parent | |
override_wcs = parent_data.meta["_orig_spatial_wcs"] | |
if override_wcs is None: | |
# if cubeviz and theres no spatial wcs, we have to skip computing sky region | |
skip_sky_region = True | |
else: | |
if wcs is None: | |
skip_sky_region = True # also need to skip if in imviz and theres no WCS | |
if to_sky and self.config == 'cubeviz': | |
parent_data = subset_state.xatt.parent # Can you not use xatt in Cubeviz like in glue-astronomy? Not sure. | |
if "_orig_spec" in parent_data.meta: | |
to_sky = parent_data.meta["_orig_spec"].wcs | |
else: | |
to_sky = parent_data.coords |
The point here is that you only need to hack around when it is Cubeviz and when the data has the "_orig_spec" hack. Otherwise, let existing backend handle things. Unless there is another use case that also needs hacking?
jdaviz/app.py
Outdated
roi_as_sky_region = None | ||
if to_sky and not skip_sky_region: | ||
roi_as_sky_region = roi_subset_state_to_region(subset_state, | ||
to_sky=True, | ||
override_wcs=override_wcs) |
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.
Now that I think about this more, there is no point in calling roi_subset_state_to_region
again. I overlooked the fact that you actually want to keep both pixel and sky regions. Once you have the pixel region, you only need one more step to convert it to sky region; you don't need glue-astronomy here.
roi_as_sky_region = None | |
if to_sky and not skip_sky_region: | |
roi_as_sky_region = roi_subset_state_to_region(subset_state, | |
to_sky=True, | |
override_wcs=override_wcs) | |
if to_sky: | |
roi_as_sky_region = roi_as_region.to_sky(to_sky) | |
else: | |
roi_as_sky_region = None |
|
||
# store original WCS in metadata. this is a hacky workaround for converting subsets | ||
# to sky regions, where the parent data of the subset might have dropped spatial WCS info | ||
metadata['_orig_spatial_wcs'] = wcs.celestial |
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 don't know how I feel about introducing yet one more hidden meta key to hack around Cubeviz WCS stuff. Why not use the existing "_orig_spec"? Does doing that introduce too big a performance penalty? This comment applies to all other similar occurrences.
metadata['_orig_spatial_wcs'] = wcs.celestial | |
metadata['_orig_spec'] = sc |
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.
we only sometimes need the full sc (only when theres a unit mismatch), but (for now) we always need the wcs (just the celestial component too) so i decided to always store that since its inexpensive. it will also be easier to refactor (rather than putting a check in if sc is not stored, then store wcs, then unpacking it later and doing the same check for sc)
I suggested changes to glue-viz/glue-astronomy#96 . If those are accepted, this PR needs to adapt. |
Timeout is from:
https://stsci.box.com/shared/static/d5k9z5j05dgfv6ljgie483w21kmpevni.fits Maybe Box is thinking we're spamming it. It still available. |
Codecov ReportAttention:
... and 1 file with indirect coverage changes 📢 Thoughts on this report? Let us know!. |
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 definitely nice to have, good work! My only thought is that the sky region could be given automatically (without having to set include_sky_region
to True
), but I could see that causing performance issues so maybe we shelve that idea for a future date.
There is a change log conflict now. Can you please rebase? Thanks! |
17ebb44
to
6fe09b7
Compare
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.
Very close! Some minor comments. Thanks!
If you run out of time, lemme know. Will be happy to help you wrap this up.
@@ -404,7 +444,9 @@ def _parse_ndarray(app, file_obj, data_label=None, data_type=None, | |||
|
|||
if not hasattr(flux, 'unit'): | |||
flux = flux << u.count | |||
s3d = Spectrum1D(flux=flux) | |||
|
|||
meta = standardize_metadata({'_orig_spatial_wcs': 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.
I am not sure if standardize_metadata
is needed for simple cases like this but I guess some consistency does not hurt.
jdaviz/tests/test_subsets.py
Outdated
wcs = spectral_cube_wcs.celestial | ||
data = NDData(np.ones((128, 128)) * u.nJy, wcs=wcs) |
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.
wcs = spectral_cube_wcs.celestial | |
data = NDData(np.ones((128, 128)) * u.nJy, wcs=wcs) | |
data = NDData(np.ones((128, 128)) * u.nJy, wcs=imviz_2d_wcs) |
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.
You might have to update the results below.
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.
same as my explanation above. i'll put a comment in the test to explain why im using the cube wcs here.
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.
Thanks!
* adding sky regions to get_subsets * final review comments * code style
Updateglue-astronomy
pin inpyproject.toml
after the PR above is merged and released.Description
Adds API to export sky regions for spatial subsets, as part of get_subsets(). If 'export_sky_region'=True, both a pixel and a sky region will be returned from get_subsets.
JDAT 3498
Requires glue-viz/glue-astronomy#96Change log entry
CHANGES.rst
? If you want to avoid merge conflicts,list the proposed change log here for review and add to
CHANGES.rst
before merge. If no, maintainershould add a
no-changelog-entry-needed
label.Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
trivial
label.