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

Spectrum1D translator update for NDCube version #36

Merged
merged 5 commits into from
Aug 27, 2021

Conversation

rosteen
Copy link
Contributor

@rosteen rosteen commented Jul 9, 2021

This updates the Spectrum1D translator to handle 3D Spectrum1D objects, currently applicable to the dev version of specutils which subclasses Spectrum1D off of NDCube. I also tested with the current releases of specutils and jdaviz and this doesn't break back-compatibility, so it should be fine to merge it now.

This also supersedes #29 .

@codecov
Copy link

codecov bot commented Jul 9, 2021

Codecov Report

Merging #36 (7e2cc09) into master (4c5e6e7) will decrease coverage by 1.62%.
The diff coverage is 68.51%.

❗ Current head 7e2cc09 differs from pull request most recent head 7a01dbf. Consider uploading reports for the commit 7a01dbf to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master      #36      +/-   ##
==========================================
- Coverage   96.40%   94.77%   -1.63%     
==========================================
  Files          15       15              
  Lines        1002     1034      +32     
==========================================
+ Hits          966      980      +14     
- Misses         36       54      +18     
Impacted Files Coverage Δ
...lue_astronomy/translators/tests/test_spectrum1d.py 89.43% <63.63%> (-10.57%) ⬇️
glue_astronomy/translators/spectrum1d.py 91.66% <76.19%> (-5.56%) ⬇️

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 4c5e6e7...7a01dbf. Read the comment docs.

@rosteen
Copy link
Contributor Author

rosteen commented Jul 9, 2021

@javerbukh it would be great if you could test this out with your jdaviz branch for spacetelescope/jdaviz#547. Actually, now that I think about it, I think I made a few minor changes to your PR - I'll open a PR to your fork with those.

Edit: see javerbukh/jdaviz#7

@javerbukh
Copy link
Contributor

Are you able to load data with this branch and jdaviz#547 + your additions?

@rosteen
Copy link
Contributor Author

rosteen commented Jul 12, 2021

I am. You also need the dev version of specutils (which in turn installs a dev version of ndcube). Order of installation also might matter, make sure you install the jdaviz code first to make sure it doesn't try to upgrade the version of glue-jupyter or specutils.

@javerbukh
Copy link
Contributor

Ah, gotcha.

@javerbukh
Copy link
Contributor

Ok, data loads! It looks off but was the priority that it loaded?
Screen Shot 2021-07-12 at 2 54 08 PM

@rosteen
Copy link
Contributor Author

rosteen commented Jul 12, 2021

Excellent. What about the data looks off? The only problem I noticed initially was that the slider is broken (which isn't a glue-astronomy problem).

If you could also check that the data round-trips correctly by pulling it back out into the notebook, that would probably be sufficient for this PR.

@javerbukh
Copy link
Contributor

javerbukh commented Jul 12, 2021

@rosteen
Copy link
Contributor Author

rosteen commented Jul 12, 2021

Ah, right, they probably are. Could you install specutils from astropy/specutils#822 and see if that fixes the RA/Dec swap?

Lots of dev versions/PRs to get this all working nicely at the moment, unfortunately.

@javerbukh
Copy link
Contributor

That works! I'll have to update the jdaviz PR to have the slider use the correct axis.

@rosteen
Copy link
Contributor Author

rosteen commented Jul 16, 2021

@astrofrog @eteq I can't tag reviewers here, would one of you take a look at this and approve/merge if it looks good to you (or comment if it doesn't)? I believe the non-codecov test failures are due to failed tox invocations, not something due to this PR.

Of course now that I mention codecov...I should add a test of round tripping a 3d Spectrum1D. I'll see if I have time for that today.

@rosteen rosteen force-pushed the spec1d-translator-update branch from 0278e6e to 7e2cc09 Compare July 22, 2021 15:24
@rosteen
Copy link
Contributor Author

rosteen commented Jul 22, 2021

Codecov is angry because the added tests don't run right now, since they require NDCube 2.0.

@rosteen rosteen force-pushed the spec1d-translator-update branch from 7e2cc09 to 48a4fbe Compare July 22, 2021 15:46
@pllim
Copy link
Contributor

pllim commented Aug 17, 2021

Can we merge?

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

Looks good in general, just a couple of requests

# Glue expects spectral axis first for cubes (opposite of specutils).
# Swap the spectral axis to first here. to_object doesn't need this because
# Spectrum1D does it automatically on initialization.
if len(obj.flux.shape) == 3:
Copy link
Member

Choose a reason for hiding this comment

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

What about cases where the data has 2 dimensions? (for example a 2D spectrum)

CHANGES.rst Outdated
0.1 (2020-09-17)
----------------

- Initial release
Copy link
Member

Choose a reason for hiding this comment

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

Could you rebase so as not to include this commit? You'll then need to add a 0.3 section and a changelog entry.

else:
# Don't use the dummy GWCS created by Spectrum1D initialized with spectral_axis
if isinstance(obj.wcs, GWCS):
data = Data(coords=SpectralCoordinates(obj.spectral_axis))
Copy link
Member

Choose a reason for hiding this comment

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

We don't really need this anymore, Data coords can be a GWCS as far as I know.

data['flux'] = obj.flux
data.get_component('flux').units = str(obj.unit)

# Glue expects spectral axis first for cubes (opposite of specutils).
Copy link
Member

Choose a reason for hiding this comment

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

In addition to the above comments it would be good to clarify here whether you mean for the WCS or Numpy array. The data array and WCS will have axes in opposite order - spectral cubes read with plain Astropy FITS and WCS or with SpectralCube are often stored in spectral,dec,ra for the Numpy data array and ra,dec,spectral for the WCS.

Glue can handle any axis order as long as x_att and y_att are set correctly but it would indeed be good to make sure SpectralCube and Spectrum1D return a similar glue data object.

@astrofrog
Copy link
Member

I have rebased this and will merge and address my comments in a follow-up PR (I need to make further changes to this to support 2D Spectrum1D instances.

@astrofrog astrofrog force-pushed the spec1d-translator-update branch from 48a4fbe to 7a01dbf Compare August 27, 2021 12:51
@astrofrog
Copy link
Member

The test failure with dev dependencies is related as I think it's a recent change in specutils but I will merge and address in a separate PR.

@astrofrog astrofrog merged commit 03e439a into glue-viz:master Aug 27, 2021
@pllim
Copy link
Contributor

pllim commented Aug 30, 2021

@astrofrog , I think this causing failure in jdaviz dev job, see spacetelescope/jdaviz#821 .

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