-
Notifications
You must be signed in to change notification settings - Fork 76
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
Perform corrections to Line Analysis Flux Results #1564
Conversation
Codecov ReportBase: 86.28% // Head: 86.39% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1564 +/- ##
==========================================
+ Coverage 86.28% 86.39% +0.11%
==========================================
Files 94 94
Lines 9366 9431 +65
==========================================
+ Hits 8081 8148 +67
+ Misses 1285 1283 -2
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. |
JWST spectra have two relevant keywords: JWST spectra will be in either:
So, the bottom line is, do not multiply by pixel solid angle in this PR. This should be handled elsewhere. |
The thing this PR should do is calculate the line flux in units like W/m^2/sr (for inputs like MJy/sr) |
One small edge case concerning when the Line Analysis units return in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does user-facing documentation also need updating?
Is this tested anywhere?
@pllim Yup, tests are incoming! |
This PR has a conflict. I think that is why CI is stuck. Please rebase. Thanks! |
7649ea7
to
7d1acc2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few initial comments - I'll take another look once tests are implemented.
If this is the expected behavior, should this logic live in specutils instead of custom jwst logic in jdaviz? Then we can just keep things simple in jdaviz, call specutils directly, and users won't be confused by a discrepancy between jdaviz and native specutils calls? 🤷
else: | ||
# If PIXAR_SR wasn't provided, keep the steradian unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this else
also catches cases where the viewer collapse function is something other than min/max/sum, right? Is that expected behavior for the user or would that be confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path here is super confusing (see #1564 (comment)), so let me try to explain it and let's see if it makes sense, or if I confused myself 😅
If the Flux units are in surface brightness (e.g. has the steradians in it), but PIXAR_SR
was not provided, the units should ALWAYS be in W/(m2 sr). It doesn't matter what the collapse function is. The conversion to W/m2 ONLY happens when PIXAR_SR
exists, AND the function is either min, max, or sum.
To directly answer your question, if the function is mean/median and the flux is in surface brightness, then the units SHOULD NOT be converted to W/m2, instead SHOULD keep the steradian. Likewise, if the collapse function is min/max/sum and PIXAR_SR
was NOT provided, then likewise the units should keep the steradian.
How'd I do?
c7d97a6
to
e26f220
Compare
Converting to draft while I handle test failures (my local testing env broke :/) |
Ok, new update/scope change from @PatrickOgle. I'll try to summarize here, but please correct me if I get something wrong! So the root of the min/max/sum multiplying by What this means is the logic in jdaviz/jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py Lines 354 to 363 in c2a1126
As a result, I've moved this PR back into draft until I can make those changes. Will mark it ready once I make those changes/update tests. In addition, the integration of Hz is a candidate to be moved up to |
I think #1564 (comment) makes sense. But let me make sure I understand: Are you saying that the real fix is in specutils but for now we need to workaround it in our own collapse method? Is there an upstream issue about this in specutils? |
@pllim There are two "upstream" fixes that should be considered for this PR's next steps:
|
Just talking about glue-core , the collapse function is at https://github.com/glue-viz/glue/blob/f8c1e9646e7252aa13f5f58c4838cb9b670875d3/glue/utils/array.py#L431 and looks like data has shed unit at that point. I don't see why glue should care about astronomy-specific computations so deep down the engine. Unless Tom R has a better idea, I think we need to keep track of these units somewhere in the Cubeviz parser logic but I got lost in the code. This is the only place we are calling Lines 835 to 840 in c2a9b82
This triggers the spectrum collapse somehow but where is the actual code? I cannot find it. Does it magically triggers jdaviz/jdaviz/configs/cubeviz/plugins/parsers.py Lines 192 to 193 in 9d7bc4a
I see this but I think it only targets wavelength unit, not flux:
|
I might have tracked down the collapse code to here: jdaviz/jdaviz/configs/default/plugins/plot_options/plot_options.py Lines 140 to 141 in 9d7bc4a
and here: Yeah, not sure how to ask it to handle unit there. That code is fully generalized to handle any given attribute in Data. Maybe all we need to do is to change this line to show correct collapsed unit on the axis:
|
4b1ab3c
to
01f60bc
Compare
jdaviz/configs/specviz/plugins/line_analysis/tests/test_lineflux.py
Outdated
Show resolved
Hide resolved
Here is the full test suite, including the mixed units and 1/sr: def gauss_with_unity_area(x, mean, sigma): Unit-flux gaussian in frequency space freq = np.arange(1, 2, 0.001)*u.Hz Unit-flux gaussian in wavelength space lam = np.arange(1,2, 0.001)*u.m Unit-flux gaussian in wavelength space, mixed units, per steradian lam_a = np.arange(1,2, 0.001)*u.Angstrom Display Spectrum 1 D in Specviz from jdaviz import Specviz Then open Line Analysis Plugin to get Flux = 1 W/m^2/[sr] in all 5 cases. |
Happy to give a final review once the above unit tests are in place. |
@PatrickOgle Ok done! |
Co-authored-by: Kyle Conroy <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gives the correct answer for unit area Gaussian in wavelength, frequency space, and mixed units.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me now, thanks (assuming CI will pass)!
Does the "upstream fix required" label still apply? Do we need a ticket to consider whether to move this logic to specutils as a follow-up or did we decide it doesn't belong there at all?
temp_result = raw_result.to(final_unit) | ||
if getattr(raw_result, 'uncertainty', None) is not None: | ||
temp_result.uncertainty = raw_result.uncertainty.to(final_unit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hopefully this will be improved upstream some day... but does the trick for now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created astropy/specutils#980 in specutils to make sure we don't forget to discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my comment on these lines was referring to the fact that .uncertainty
(or any arbitrary attribute added to a quantity) isn't supported by astropy and so is stripped from the quantity object when calling .to
(see astropy/specutils#961 for some related discussion).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh right. Sorry my comment was meant as a direct response to your general review. Sorry, poor placement
Thanks for the eyes @pllim @kecnry @PatrickOgle! I appreciate everyone's patience as we hammered this PR through its multiple iterations! |
Description
This PR performs corrections to the Line Analysis as requested by @PatrickOgle to get the base units of the Line Flux to Watts/meter^2.
One remaining task is to multiply with the pixel area if provided. I'm not sure how that is represented in the header, so I feel like more guidance is needed to get that working. Even better if an example dataset can be provided with PIXAR_SR is set. Some obvious ones to start with:
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.
trivial
label.CHANGES.rst
?