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 an issue with providing astropy Units to calc_datacube #639

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

mperrin
Copy link
Collaborator

@mperrin mperrin commented Sep 27, 2024

This fixes an issue I found with the calc_datacube function, which currently errors if provided wavelengths as astropy Quantities:

>>> import numpy as np, webbpsf, astropy.units as u

>>> nrs = webbpsf.NIRSpec()
>>> nrs.calc_datacube(wavelengths=np.array([1,2,3])*u.micron)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

[... long trace of error text from Astropy trying to write a Quantity into a FITS header]

This fix makes sure the wavelength is converted to a plain float in units of meters before being saved as a header keyword.

No change is needed in calc_psf which already works correctly with units. This fix is just needed for calc_datacube which somehow slipped through the cracks for this.

@mperrin mperrin self-assigned this Sep 27, 2024
Copy link
Collaborator

@obi-wan76 obi-wan76 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, I ran the example in the PR without any error.

@mperrin
Copy link
Collaborator Author

mperrin commented Sep 30, 2024

(accidentally pushed a commit to this branch that wasn't intended; I force-pushed to remove it and go back to just the intended commits. I'm going to let the CI run again, and then merge)

@mperrin mperrin merged commit 4780261 into spacetelescope:develop Oct 1, 2024
14 checks passed
@mperrin mperrin deleted the datacube_units_fix branch October 1, 2024 21:09
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.

2 participants