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 cube fitting compatibility with unit conversion #3190

Merged
merged 22 commits into from
Sep 20, 2024

Conversation

rosteen
Copy link
Collaborator

@rosteen rosteen commented Sep 11, 2024

Opening as draft since I still need to work on the unit conversion part, but I wanted to see the diff and remind myself what I'd changed so far.

@rosteen rosteen added bug Something isn't working cubeviz plugin Label for plugins common to multiple configurations labels Sep 11, 2024
@rosteen rosteen added this to the 4.0 milestone Sep 11, 2024
@rosteen rosteen changed the title Fix cube fitting with NaNs and unit conversion Fix cube fitting compatibility with unit conversion Sep 13, 2024
@rosteen rosteen marked this pull request as ready for review September 13, 2024 17:32
Copy link
Contributor

@cshanahan1 cshanahan1 left a comment

Choose a reason for hiding this comment

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

Tested this out, I do see the fix that now the component units are always in 'surface brightness' if the cube is surface brightness, and do not change based on what is selected for the spectral y axis, so that's fixed. However, I'm still not getting any results in the table or plotted when I run a cube fit on this loaded data using one of the test fixtures to create a cube:

cube = _create_spectrum1d_cube_with_fluxunit(shape=(25, 25, 4), fluxunit=u.Jy / u.sr, with_uncerts=True)

@rosteen
Copy link
Collaborator Author

rosteen commented Sep 14, 2024

Tested this out, I do see the fix that now the component units are always in 'surface brightness' if the cube is surface brightness, and do not change based on what is selected for the spectral y axis, so that's fixed. However, I'm still not getting any results in the table or plotted when I run a cube fit on this loaded data using one of the test fixtures to create a cube:

cube = _create_spectrum1d_cube_with_fluxunit(shape=(25, 25, 4), fluxunit=u.Jy / u.sr, with_uncerts=True)

Hm, the model fit plots fine with the example notebook data, but now that you mention it I don't see table results. I'll look into it on Monday.

@rosteen
Copy link
Collaborator Author

rosteen commented Sep 16, 2024

Tested this out, I do see the fix that now the component units are always in 'surface brightness' if the cube is surface brightness, and do not change based on what is selected for the spectral y axis, so that's fixed. However, I'm still not getting any results in the table or plotted when I run a cube fit on this loaded data using one of the test fixtures to create a cube:

cube = _create_spectrum1d_cube_with_fluxunit(shape=(25, 25, 4), fluxunit=u.Jy / u.sr, with_uncerts=True)

From a comment in the code: # cube fits are currently unsupported in tables - I think that's out of scope for this. I'll investigate the test fixture not plotting.

@rosteen
Copy link
Collaborator Author

rosteen commented Sep 16, 2024

Screen.Recording.2024-09-16.at.9.46.45.AM.mov

@cshanahan1 hm, I see the model plot fine with that cube (I fit a constant to it). Are you sure you didn't need to go into the data menu and add the model to the viewer? Or did it fail to appear with the Plot in Viewer option toggled on?

I do see an error trying to add a Linear model component, trying to fix that...

@rosteen
Copy link
Collaborator Author

rosteen commented Sep 16, 2024

Note that this merging this PR on top of #3156 resolves the test failures (other than the known axis label failure there).

@cshanahan1
Copy link
Contributor

cshanahan1 commented Sep 16, 2024

still seeing some out of sync units. I loaded a Jy/sr cube, changed the flux unit to MJy, and the model fitting plugin shows Jy as the flux unit. This happened when MJy was set before creating the component for the first time, so I shouldn't have to re-estimate parameters, but even when doing that the incorrect unit remains

EDIT from Ricky: Sorry @cshanahan1 I accidentally edited this reply instead of quoting it, and lost your screenshot/recording. The danger of admin power 😬

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

Attention: Patch coverage is 85.45455% with 8 lines in your changes missing coverage. Please review.

Project coverage is 88.21%. Comparing base (d49e3b5) to head (b33dcc0).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...igs/default/plugins/model_fitting/model_fitting.py 86.79% 7 Missing ⚠️
...figs/default/plugins/model_fitting/initializers.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3190      +/-   ##
==========================================
- Coverage   88.50%   88.21%   -0.29%     
==========================================
  Files         124      124              
  Lines       18448    18487      +39     
==========================================
- Hits        16327    16308      -19     
- Misses       2121     2179      +58     

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

@camipacifici
Copy link
Contributor

Linear fitting to cube or single spectrum does not break anymore!
In this PR, I see the icon to open the model fitting table in a different window, but the link goes to a 404 window.

@rosteen
Copy link
Collaborator Author

rosteen commented Sep 16, 2024

still seeing some out of sync units. I loaded a Jy/sr cube, changed the flux unit to MJy, and the model fitting plugin shows Jy as the flux unit. This happened when MJy was set before creating the component for the first time, so I shouldn't have to re-estimate parameters, but even when doing that the incorrect unit remains

Fixed, toggling the cube fit was triggering the dataset selected logic, which was resetting the units. I removed all the unit setting from there in favor of setting it when the first component is initialized (and whenever user changes units or toggles cube fit).

@cshanahan1
Copy link
Contributor

cshanahan1 commented Sep 16, 2024

I see it now respecting flux unit selection when i change between Jy/MJy, but breaks on erg / (Angstrom s cm2 sr). Is it missing a spectral_density equivalency?

@rosteen
Copy link
Collaborator Author

rosteen commented Sep 16, 2024

I see it now respecting flux unit selection when i change between Jy/MJy, but breaks on erg / (Angstrom s cm2 sr). Is it missing a spectral_density equivalency?

Oh, likely, I think I know where....one sec. Good catch.

@cshanahan1
Copy link
Contributor

Could you add a test that tests cube fitting with unit conversion(s)? Maybe something where you change from Jy > MJy, and Jy > er/s/cm2/A ?

@rosteen
Copy link
Collaborator Author

rosteen commented Sep 19, 2024

@cshanahan1 I added a test, but I won't be able to test changing the unit to erg / (Angstrom s cm2) until the contour bug is fixed.

@cshanahan1
Copy link
Contributor

Tested this one final time and couldn't break it. Talked on slack with ricky about a few points of confusion i had and he cleared those up so I'll approve, looks good!

@@ -930,7 +984,8 @@ def _fit_model_to_cube(self, add_data):
models_to_fit,
self.model_equation,
run_fitter=True,
window=None
window=None,
n_cpu=1 # Remove this after debugging!
Copy link
Contributor

Choose a reason for hiding this comment

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

pssst

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FIxed.

Copy link
Contributor

@gibsongreen gibsongreen left a comment

Choose a reason for hiding this comment

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

Did one last look over and round of testing, all looks good to me and works as I'd expect!

@rosteen rosteen merged commit 91c6ff3 into spacetelescope:main Sep 20, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cubeviz plugin Label for plugins common to multiple configurations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants