Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update Cubeviz to work on data with spectral axis last #1174

Merged
merged 24 commits into from
Apr 13, 2022

Conversation

rosteen
Copy link
Collaborator

@rosteen rosteen commented Mar 16, 2022

Description

This implements compatibility with glue-viz/glue-astronomy#68, which stops reordering Cube axes and leaves things the way they are in the specutils.Spectrum1D object. Opening as draft since this is very experimental and still needs work - I've fixed the data loading and slice plugin, but I'm sure a couple other things were broken by this. Mainly I wanted other people to see it if they're curious.

TODO

xref #1190

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.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set? Milestone is only currently required for PRs related to Imviz MVP.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@pllim pllim added the cubeviz label Mar 16, 2022
@rosteen
Copy link
Collaborator Author

rosteen commented Mar 16, 2022

The other motivation for posting this now is to make sure it doesn't conflict too much with #1040 . And it obviously needs rebasing.

@pllim

This comment was marked as resolved.

@@ -119,15 +119,24 @@ def _parse_hdu(app, hdulist, file_name=None):
if hdu.data.dtype in (int, np.uint, np.uint32) or \
any(x in hdu.name.lower() for x in EXT_TYPES['mask']):
app.add_data_to_viewer('mask-viewer', data_label)
viewer = app.get_viewer('mask-viewer')
viewer.state.x_att_world = app.data_collection[data_label].id['Right Ascension']
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work with data with no WCS? I am trying to think how this would fit into #1040 .

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 think I need a case here to fall back on Pixel Axis 0 [z] (or whichever is appropriate) for things with no WCS.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure which axis that would be. I have found that specutils only attempt to swapaxes if it detects a WCS, so for anything without WCS, I needed to transpose. If you look at PR 1040, you will see a lot of array.T happening here and there. 🤪 Do I still need that with this patch?

@rosteen
Copy link
Collaborator Author

rosteen commented Mar 22, 2022

CI won't pass yet because this needs glue-viz/glue-astronomy#68. The tests pass locally on my machine with that installed.

@pllim
Copy link
Contributor

pllim commented Mar 22, 2022

Upstream PR is merged, so theoretically, if you pin glue-astronomy to dev version in setup.cfg, your CI would pass. I also added a TODO section in your original post above because your PR should undo two things added in #1190 . FYI.

@codecov
Copy link

codecov bot commented Mar 22, 2022

Codecov Report

Merging #1174 (8955666) into main (ac42df8) will increase coverage by 1.60%.
The diff coverage is 86.27%.

@@            Coverage Diff             @@
##             main    #1174      +/-   ##
==========================================
+ Coverage   77.93%   79.53%   +1.60%     
==========================================
  Files          90       90              
  Lines        7180     7209      +29     
==========================================
+ Hits         5596     5734     +138     
+ Misses       1584     1475     -109     
Impacted Files Coverage Δ
...igs/default/plugins/model_fitting/model_fitting.py 34.65% <0.00%> (+0.50%) ⬆️
...s/default/plugins/model_fitting/fitting_backend.py 77.90% <66.66%> (ø)
jdaviz/configs/cubeviz/plugins/slice/slice.py 75.86% <90.90%> (-0.33%) ⬇️
jdaviz/configs/cubeviz/helper.py 87.23% <93.33%> (+2.38%) ⬆️
jdaviz/app.py 91.14% <100.00%> (+0.08%) ⬆️
jdaviz/configs/cubeviz/plugins/parsers.py 56.93% <100.00%> (+1.13%) ⬆️
jdaviz/configs/cubeviz/plugins/viewers.py 98.07% <100.00%> (+0.51%) ⬆️
...daviz/configs/default/plugins/collapse/collapse.py 96.07% <100.00%> (ø)
...default/plugins/gaussian_smooth/gaussian_smooth.py 86.48% <100.00%> (+0.18%) ⬆️
... and 5 more

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 317e03d...8955666. Read the comment docs.

@pllim pllim modified the milestones: 2.4, 2.5 Mar 29, 2022
@rosteen rosteen force-pushed the cubeviz-noodling branch 2 times, most recently from 6ec3102 to 6e8250f Compare April 5, 2022 21:18
@rosteen
Copy link
Collaborator Author

rosteen commented Apr 5, 2022

I think this is almost ready for in-depth review. There's one persistent bug that I'm aware of that I haven't fixed yet, where calculating a moment with a viewer selected to auto-plot the results will throw an IncompatibleDataException error from Glue compute_fixed_resolution_buffer and crash the app (note that it works fine if you calculate the moment, then go into the data selection menu for the viewer and change to the moment data there). I need to log off for the day, I wonder if you might have some insight on that @astrofrog? To reproduce, run the CubevizExample notebook and go to the Moment Maps plugin, select a viewer (I recommend Center or Right) and hit Calculate. Reminder that this PR requires dev glue-astronomy.

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 6, 2022

I fixed the above error with a small change to app.py to clear existing data in a viewer first before selecting the new data, rather than doing both in one step.

@pllim
Copy link
Contributor

pllim commented Apr 6, 2022

We need to pin to glue-astronomy dev with this PR, right?

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 6, 2022

We need to pin to glue-astronomy dev with this PR, right?

Yes, the setup.cfg file here has it pinned.

@astrofrog
Copy link
Collaborator

@rosteen - did you fix the issue you asked me about above or should I still investigate?

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 6, 2022

@rosteen - did you fix the issue you asked me about above or should I still investigate?

I did figure out a fix, no need to investigate.

# Make sure that the x_att is correct on data load
ref_data = self.state.reference_data
if ref_data and ref_data.ndim == 3:
for att_name in ["Right Ascension", "RA"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better way to detect world vs pixel? I feel like hardcoding RA might box us in to only certain world coordinate frames.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Digging into Glue and looking at what the other options that might occur here are, it seems like Galactic Longitude/Latitude are probably the only others we might need to worry about (I don't want to mess with supporting solar people and their crazy helioprojective things right now 😆). I don't know if people would want lat or lon on the x-axis, I'll ask the POs.

viewer = self.app.get_viewer("spectrum-viewer")
ref_data = viewer.state.reference_data
if ref_data and ref_data.ndim == 3:
for att_name in ["Wave", "Wavelength", "Freq", "Frequency"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do people make cubes in wave number, etc? How do these map to supported CTYPE and how many of those we need to actually support?

https://github.com/astropy/astropy/blob/43ee5806e9c6f7d58c12c1cb9287b3c61abe489d/astropy/wcs/wcsapi/fitswcs.py#L88

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looking at the glue-astronomy translator, it seems like the other likely options are Wavenumber, Velocity and Energy. I'll add those.

@javerbukh
Copy link
Contributor

I can get more specific about how to reproduce:

  1. Run cubeviz example notebook
  2. Create a spatial subset and a spectral subset
  3. Create a model that is a first order polynomial
  4. Fit model, show in middle viewer, and apply to cube
  5. Open line analysis and get traceback

Cubeviz still runs but the line analysis plugin hangs.

@javerbukh
Copy link
Contributor

Looks like everything works great other than the error I mentioned and the spectrum viewer not automatically reseting limits. If the former originates outside the PR and the latter will work after merge/rebase, I'm ready to approve this.

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 12, 2022

I'm investigating the cube fitting, it is a problem with this PR and I should have a fix soon (I hope). This also led me to notice that the fit to the spectrum isn't getting properly plotted in the spectrum viewer either, so I'm trying to figure that out as well. Good catch.

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 12, 2022

@javerbukh I think that the last bug in the model fitting is also present on main, could you confirm that I'm not crazy? Basically if you fit the whole cube with a spectral subset selected, the results comes back with all zero values. Very not great, but not due to these changes as far as I can tell.

@javerbukh
Copy link
Contributor

This is what I see on main. I do not see the same error as I saw on this branch.
Screen Shot 2022-04-12 at 12 23 29 PM

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 12, 2022

What does this give you?

fit = viz.app.data_collection["Model [Cube] 1"]
fit['flux'].max()

@javerbukh
Copy link
Contributor

0.0

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 12, 2022

See #1245 for the followup on the Cubeviz fitting bug.

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Everything seems to work now, and it'll definitely be good to get this change in and behind us!

@javerbukh
Copy link
Contributor

When I press Apply to Cube in model fitting I do not see any indication that jdaviz is working on it (loading bar or the spinning thing).

@rosteen
Copy link
Collaborator Author

rosteen commented Apr 13, 2022

When I press Apply to Cube in model fitting I do not see any indication that jdaviz is working on it (loading bar or the spinning thing).

This is also present on main. I think it happens when a previous snackbar message is still up when the "Apply to Cube" button is clicked. If you wait/clear all the other snackbar messages first it appears. I'll make an issue for this.

Edit: See #1246

Copy link
Contributor

@javerbukh javerbukh left a comment

Choose a reason for hiding this comment

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

Sounds good, thanks for opening the ticket!

@rosteen rosteen merged commit d1a6ea1 into spacetelescope:main Apr 13, 2022
@rosteen rosteen deleted the cubeviz-noodling branch April 13, 2022 14:50
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants