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

Fix moment calculations #1141

Merged
merged 5 commits into from
May 29, 2024
Merged

Fix moment calculations #1141

merged 5 commits into from
May 29, 2024

Conversation

rosteen
Copy link
Contributor

@rosteen rosteen commented May 24, 2024

This solves a bug that was reported offline by @camipacifici - moment 0 should be in units of flux * spectral axis, being the flux integrated over the spectral range, matching the units of line flux. This PR changes from doing a simple sum of flux for moment 0, to summing flux*dx as in line_flux.

The case for SpectrumCollection is because the spectral_axis of a SpectrumCollection comes out as SpectralCoord, and we need bin_edges from SpectralAxis in each individual member of the collection.

@rosteen rosteen added bug analysis Spectral analysis/measurement tools labels May 24, 2024
@rosteen rosteen added this to the v1.x milestone May 24, 2024
@rosteen rosteen requested review from keflavich, eteq and camipacifici and removed request for keflavich, eteq and nmearl May 24, 2024 18:33
@rosteen rosteen changed the title Fix moment 0 Fix moment 0 calculation May 24, 2024
Copy link

codecov bot commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.83%. Comparing base (28b0cdb) to head (4d6c35f).
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1141   +/-   ##
=======================================
  Coverage   86.82%   86.83%           
=======================================
  Files          63       63           
  Lines        4525     4528    +3     
=======================================
+ Hits         3929     3932    +3     
  Misses        596      596           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rosteen
Copy link
Contributor Author

rosteen commented May 24, 2024

Actually, the higher orders also need a similar correction. The sum should have the terms multiplied by dx in those as well, with the additional spectral unit getting cancelled out by dividing by the (corrected) M0.

@rosteen rosteen marked this pull request as draft May 24, 2024 18:48
@rosteen rosteen changed the title Fix moment 0 calculation Fix moment calculations May 24, 2024
@rosteen rosteen marked this pull request as ready for review May 28, 2024 15:47
@rosteen
Copy link
Contributor Author

rosteen commented May 28, 2024

There's an unrelated deprecation warning in devdeps that I'll address separately.

Copy link

@camipacifici camipacifici left a comment

Choose a reason for hiding this comment

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

It is now correct in the 1D case for flux density and it seems to propagate well in Cubeviz. Thank you!

@rosteen
Copy link
Contributor Author

rosteen commented May 28, 2024

There's an unrelated deprecation warning in devdeps that I'll address separately.

Ah, FWIW this is upstream in GWCS: spacetelescope/gwcs#499.

@rosteen rosteen merged commit d16d91a into astropy:main May 29, 2024
12 of 13 checks passed
@pllim
Copy link
Member

pllim commented May 31, 2024

Looks like this broke tests over at Jdaviz, see spacetelescope/jdaviz#2888 (comment)

@pllim pllim mentioned this pull request Jun 3, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Spectral analysis/measurement tools bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants