-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add more flux units for SB conv #3389
base: main
Are you sure you want to change the base?
Conversation
cb7f5d6
to
0e16917
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.
If the unrelated changes bother you, I can revert them. Just happened to come across them while trying to make sense of the test failure.
and | ||
(((solid_angle_in_orig) and (not solid_angle_in_targ)) or | ||
((not solid_angle_in_orig) and (solid_angle_in_targ)))): | ||
if (((spec and ('_pixel_scale_factor' in spec.meta)) or |
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.
Too many parenthesis so I removed some. No functional change.
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.
From what was discussed at tag up, I'll mention @cshanahan1 has a ticket that consolidates the flux_conversion here, and flux_conversion_general function so there will be some refactoring down the line
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.
So, should I revert?
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 don't think so, just wanted to mention it here. The plan is to remove one of the two functions (I'm not sure which), none of the changes are major conflicts here and it may just get removed entirely so I'm good with keeping the changes here for now.
CI failures are unrelated. They also fail on |
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.
Tested this on a bunch of cubes, behavior is now fixed and match expected behavior from recent discussions. I think this can be marked as trivial but up to you, I'll tag @cshanahan1 here again just so she knows about the non-functional changes to flux_converision
Thanks for the review! Sure, I marked it as trivial but I cannot merge until the DQ failure is fixed (#3390) unless admin overrides the branch protection. |
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.
'Indirect_units' seem to be for flux units that can't be directly translated to surface brightness when a cube is in Jy because they require both a custom equivalency and u.spectral_density. However, if a cube is in erg/s/cm2/A then wouldn't the 'indirect_units' list be comprised of Jy/MJy/uJy etc instead? There should be two sets of 'indirect_units' since that will change based on what the unit in question is, and if it needs u.spectral? If we have all surface brightness units in this list of units (as this PR introduces) then that kind of makes it unnecessary to define these translations as 'indirect' since they may not be. I also don't quite understand why only PIX2 SB units were added here, don't we pass PIXAR_SR to this flux conversion function (or look for it in meta)? It doesn't make sense that the existing units can either be per PIX2 or Sr but not these new units just added
I am doing some work to try to use the flux_conversion_general function for all unit conversions so I think if this fixes a pressing issue its fine since I will refactor this anyway. Could you make sure to add a test case so I can make sure that this works with my refactor?
Fix test and some indentations
0e16917
to
ad55fcd
Compare
What should I be testing? There is not traceback or warning or anything. Just visually things look off in the spectrum viewer. But when I access |
@cshanahan1 those are all good questions. I think the unit conversion stuff got too complicated. I was simply looking for the least intrusive way to fix the reported issue while resisting the urge to refactor everything. |
p.s. All the callback and async stuff not helping either. |
p.p.s. Speaking of async, this also bothered me a bit, the fact that a method is purposely called twice when it does not really have to be this way but it is a battle for another day.
|
I'm not familiar with the ticket that spawned this PR, but writing a test that loads a cube in these units and does a translation and tests the viewer marks or limits to make sure the unit conversion was done seems reasonable? |
How do I extract the correct marks? |
You could also add a test to test_spec_sb_flux_conversion() that just tests the flux conversion function I'm confused why cts was added, this cant be translated to any other flux unit, and it should be 'directly' convertible between flux and SB using one of the equivalencies we define |
Gilbert has a special JWST cube from Cami with that unit and it was mentioned in the ticket. Which equivalencies is that? I thought the indirect unit stuff was it. Adding it there did fix the bug for counts, as Gilbert tested. |
_eqv_pixar_sr and _eqv_flux_to_sb_pixel. 'indirect' means they need one of these and u.spectral for conversion, which can't be combined. Another thought - this PR fixes spectral axis translation for whatever dataset was broken, but won't fix plugin unit conversion since that goes through flux_conversion_general. My ticket to consolidate these will address that, but we should make sure to revisit this case in that PR Sorry this is all so confusing, hopefully this will be simplified soon |
Yeah I am not sure why I tried to add this test as you requested but it fails even with this patch, so as you suspected, whatever logic route this workflow is taking does not go through the way you wanted it to. If you really don't like this patch, we can just close this PR without merge, I will unassign myself and then you can see if your refactor would automatically fix it later. 🤷♀️ def test_spec_sb_flux_conversion_no_pixscale():
# Actual spectrum content does not matter, just the meta is used here.
spec = Spectrum1D(flux=[1, 1, 1] * u.Jy, spectral_axis=[1, 2, 3] * u.um)
# values != 2
values = [10, 20, 30]
# conversions with eq pixels
assert_allclose(flux_conversion(values, u.Jy / PIX2, u.Jy, spec), [10, 20, 30])
assert_allclose(flux_conversion(values, u.Jy, u.Jy / PIX2, spec), [10, 20, 30])
assert_allclose(flux_conversion(values, u.ct / PIX2, u.ct, spec), [10, 20, 30])
assert_allclose(flux_conversion(values, u.ct, u.ct / PIX2, spec), [10, 20, 30])
# complex translation Jy / PIX2 -> erg / (Angstrom s cm2 PIX2)
targ = [2.99792458e-12, 1.49896229e-12, 9.99308193e-13]
assert_allclose(flux_conversion(values, u.Jy / PIX2, u.erg / (u.Angstrom * u.s * u.cm**2 * PIX2), spec), targ) # noqa: E501
# complex translation erg / (Angstrom s cm2 PIX2) -> Jy / PIX2
targ = [3.33564095e+13, 2.66851276e+14, 9.00623057e+14]
assert_allclose(flux_conversion(values, u.erg / (u.Angstrom * u.s * u.cm**2 * PIX2), u.Jy / PIX2, spec), targ) # noqa: E501
spectral_values = spec.spectral_axis
spec_unit = u.MJy
eqv = u.spectral_density(spectral_values)
# test spectrum when target unit in untranslatable unit list
target_values = [5.03411657e-05, 2.01364663e-04, 4.53070491e-04]
expected_units = u.ph / (u.Hz * u.s * u.cm**2)
returned_values, return_units, unit_flag = _indirect_conversion(
values=values, orig_units=u.MJy,
targ_units=u.ph / (u.s * u.cm**2 * u.Hz * PIX2),
eqv=eqv,
spec_unit=spec_unit,
indirect_needs_spec_axis=None
)
assert_allclose(returned_values, target_values)
assert return_units == expected_units
assert unit_flag == 'orig' |
Going from erg/s/cm2/A to erg/s/cm2/A/PIX2 and then converting again to Jy/PIX2 would require the spectral density equivalencies and the custom equivalencies, so the indirect conversion doesn’t only apply to the Jy/similar units. The context of the ticket is for counts cubes and manga cubes both of which will be in PIX2, so the PIXAR_SR keyword wouldn’t apply in either of these cases. I don’t think we would need 2 separate indirect units lists here, the logic for the indirect conversion is only going to get hit when the original and target units can’t be directly converted, otherwise it just returns. |
As Clare requested, I change this back to draft for now as her refactor would remove the patched function entirely. Gilbert is looking into how to access the marks for test. |
Description
This pull request is to address broken spectrum viewer for MANGA cube when Surface Brightness is selected and user wants to change flux units.
I threw in a fix for the reporting "counts cube" but not sure how to test that because that detail was not given in JIRA.
Change log entry
CHANGES.rst
? If you want to avoid merge conflicts,list the proposed change log here for review and add to
CHANGES.rst
before merge. If no, maintainershould add a
no-changelog-entry-needed
label.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.