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

Adding support for uncertainty extraction to NDDataArray #86

Merged
merged 6 commits into from
Mar 2, 2023

Conversation

bmorris3
Copy link
Contributor

In #81, I added translators for objects in astropy.nddata. In this PR, I add support for extracting uncertainties from glue Data objects and translating them into the uncertainty attr in NDDataArray objects. This was missing in the previous PR, but should have been there.

@pllim

This comment was marked as resolved.

Update glue_astronomy/translators/nddata.py

Co-authored-by: P. L. Lim <[email protected]>

Update glue_astronomy/translators/nddata.py

Co-authored-by: P. L. Lim <[email protected]>
@bmorris3 bmorris3 force-pushed the better-nddata-support branch from 0795261 to b735190 Compare February 27, 2023 21:02
@codecov
Copy link

codecov bot commented Feb 27, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.34 🎉

Comparison is base (63d9e0c) 96.99% compared to head (5469ccb) 97.33%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   96.99%   97.33%   +0.34%     
==========================================
  Files          17       18       +1     
  Lines        1296     1351      +55     
==========================================
+ Hits         1257     1315      +58     
+ Misses         39       36       -3     
Impacted Files Coverage Δ
glue_astronomy/translators/nddata.py 95.37% <100.00%> (+2.81%) ⬆️
glue_astronomy/translators/tests/test_nddata.py 98.56% <100.00%> (+0.14%) ⬆️
glue_astronomy/tests/test_spectral_coordinates.py 100.00% <0.00%> (ø)
glue_astronomy/spectral_coordinates.py 100.00% <0.00%> (+6.66%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dhomeier
Copy link
Contributor

Looks good for StdDevUncertainty. I admit I don't know exactly to what extent glue Data objects support other uncertainty types, but Specutils1DHandler processes and stores the types and units to retrieve the appropriate type:

if attribute_label == 'uncertainty':
values = UNCERT_REF[
data.meta.get('uncertainty_type', 'std')](values)

It would be good to cover this consistently, and perhaps add test cases for VarianceUncertainty and InverseVariance.
Then at some point we should probably see how the Spectrum1D translator can reuse the NDData functionality, but that need not be part of this PR.

@bmorris3
Copy link
Contributor Author

@dhomeier I agree this would be great! For now, the relevant collapse functions I wrote for jdaviz via astropy in NDDataArray only support variance-like uncertainties, so this PR is a good first step (astropy/astropy#14175).

@dhomeier
Copy link
Contributor

I see. Would it make sense to have to_data convert other types with represent_as(StdDevUncertainty) then? That's probably a bit double-sided, as other applications may have use for the original forms, even if jdaviz does not a this point.
But otherwise I think it should check for the correct type on input, as the present implementation would e.g. silently interpret an InverseVariance as StdDevUncertainty and return it as such.

@bmorris3
Copy link
Contributor Author

bmorris3 commented Mar 1, 2023

Good idea @dhomeier! Implemented in 91d8dbc.

Copy link
Contributor

@dhomeier dhomeier left a comment

Choose a reason for hiding this comment

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

Great, thank! I'd still add the tests for the other input types.

glue_astronomy/translators/tests/test_nddata.py Outdated Show resolved Hide resolved
@dhomeier
Copy link
Contributor

dhomeier commented Mar 1, 2023

Will need imports for the other uncertainties; also we may have to compare to spec.uncertainty instead of uncertainty since the former should have the correct units set (not sure if represent_as will transform it correctly otherwise).

@bmorris3
Copy link
Contributor Author

bmorris3 commented Mar 1, 2023

@dhomeier Done and passing 💯

@bmorris3
Copy link
Contributor Author

bmorris3 commented Mar 1, 2023

@dhomeier Would you consider this a bugfix, for soon release? We will use it downstream in spacetelescope/jdaviz#2039.

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 to me!

@astrofrog astrofrog merged commit f7b389c into glue-viz:main Mar 2, 2023
@astrofrog astrofrog added the enhancement New feature or request label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants