Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

expanded support of SB/Flux translations #2940

Merged
merged 30 commits into from
Jul 23, 2024

Conversation

gibsongreen
Copy link
Contributor

@gibsongreen gibsongreen commented Jul 8, 2024

Description

This pull request is to address separating flux_or_sb_unit into flux_unit or sb_unit. Four total drop downs are now present in the Unit Conversion plugin (spectral unit, flux or surface brightness, flux unit, surface brightness unit).

Some units that are included in main for surface brightness/flux are incapable of being translated, and fail silently. These units have either been removed, or if one of these flux units is selected, conversion is capable within the same physical type, but translation is disabled until the unit is converted to a unit that is translatable.

Screen.Recording.2024-07-08.at.12.52.58.PM.mov

Change log entry

  • Is a change log needed? If yes, is it added to 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, maintainer
    should 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.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a milestone set? Set this to bugfix milestone if this is a bug fix and needs to be released ASAP; otherwise, set this to the next major release milestone. Bugfix milestone also needs an accompanying backport label.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@gibsongreen gibsongreen added cubeviz plugin Label for plugins common to multiple configurations labels Jul 8, 2024
@gibsongreen gibsongreen added this to the 4.0 milestone Jul 8, 2024
Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Are all the calls to reset_limits still needed (I thought the limits were now being translated correctly)?

@gibsongreen
Copy link
Contributor Author

Are all the calls to reset_limits still needed (I thought the limits were now being translated correctly)?

Translating eV / (Hz s m2) and converting the untranslatable_unitsare two cases I see that still require reset_limits

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 89.94083% with 17 lines in your changes missing coverage. Please review.

Project coverage is 88.78%. Comparing base (22ed4cf) to head (069dbbc).
Report is 144 commits behind head on main.

Files with missing lines Patch % Lines
...specviz/plugins/unit_conversion/unit_conversion.py 90.09% 11 Missing ⚠️
jdaviz/core/marks.py 25.00% 3 Missing ⚠️
jdaviz/core/validunits.py 85.71% 2 Missing ⚠️
...igs/specviz/plugins/line_analysis/line_analysis.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2940      +/-   ##
==========================================
- Coverage   88.78%   88.78%   -0.01%     
==========================================
  Files         111      111              
  Lines       17276    17372      +96     
==========================================
+ Hits        15338    15423      +85     
- Misses       1938     1949      +11     

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

@gibsongreen gibsongreen marked this pull request as ready for review July 17, 2024 19:45
@gibsongreen gibsongreen requested a review from rosteen as a code owner July 17, 2024 19:45
Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Just a few more comments and then I think this can go in and we can iterate as needed to build on top of it. Thanks for working through all of this!

@haticekaratay
Copy link
Contributor

After testing some more, I noticed that if we ever select the ST from the flux units, conversion from ST to any other flux seems to fail.

@gibsongreen
Copy link
Contributor Author

After testing some more, I noticed that if we ever select the ST from the flux units, conversion from ST to any other flux seems to fail.

I can't reproduce this, can you send me the traceback and I can track down where that is coming from

@haticekaratay
Copy link
Contributor

haticekaratay commented Jul 19, 2024

After testing some more, I noticed that if we ever select the ST from the flux units, conversion from ST to any other flux seems to fail.

I can't reproduce this, can you send me the traceback and I can track down where that is coming from

It had to do with my env. I don't see it anymore after re-installing the branch. All good.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Here is technical review. I will do functional review next week once I know what was the conclusion from the 1PM meeting today with Cami w.r.t. UI changes. Thanks!

jdaviz/app.py Outdated Show resolved Hide resolved
jdaviz/configs/imviz/plugins/coords_info/coords_info.py Outdated Show resolved Hide resolved
jdaviz/core/marks.py Outdated Show resolved Hide resolved
jdaviz/core/validunits.py Outdated Show resolved Hide resolved
jdaviz/tests/test_utils.py Outdated Show resolved Hide resolved
jdaviz/tests/test_utils.py Outdated Show resolved Hide resolved
jdaviz/tests/test_utils.py Show resolved Hide resolved
Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Here is the rest of technical review since Kyle says I should unskip some files. 😆

self.app.data_collection[0] and
self.app.config == 'specviz'
):
if check_if_unit_is_per_solid_angle(self.app.data_collection[0].get_object()._unit):
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we confident that get_object() would always return an object with _unit attribute for the first loaded data? What assumption are we making here?

With all the talks about "free-form," are we shooting ourselves in our future foot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is a safer way to attain the units from the data item that keeps us more open to enable free-form in the future .

Copy link
Contributor

Choose a reason for hiding this comment

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

Accessing a hidden _unit (leading underscore usually hints that it is private and should not be used externally). I think you are basically trying to find flux unit, so any reason to not use a more public get_object().flux.unit (since this is limited to specviz so you are getting Spectrum1D back). Where did _unit come from anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it is buried within specutils class mixin. @rosteen , what is the difference between Spectrum1D._unit and Spectrum1D.flux.unit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not from the specutils class mixin as far as I can tell, I suspect it's inherited from a couple layers upstream. I'd just use flux.unit.


yunit = _valid_glue_display_unit(flux_or_sb, self.spectrum_viewer, 'y')
# may need to be updated if translations in other configs going to be supported
if not self.flux_unit.choices and self.app.config == 'cubeviz':
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this check happen much earlier in this method to avoid unnecessary computations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see why it can't happen earlier, let me test it out earlier in the _on_flux_unit_changed and I'll make the change bearing no behavioral change occurs!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do get an AttributeError: 'UnitConversion' object has no attribute 'flux_unit' if I move it further up. I can spend some time seeing if/what I can change the conditional to to have the same behavior.

Copy link
Member

Choose a reason for hiding this comment

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

you can add a if not hasattr(self, 'flux_unit'): return to the top of the method if you'd like. The observe on flux_unit_selected can get triggered when the traitlet is created but before the plugin's init has created the flux_unit object itself, and there's no need to run all this logic at that point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean self.flux_unit.choices changes all the time throughout the logic in this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought I had tried the not hasattr before, but irregardless that seemed to do the trick and it is now at the top of the function. Just running through tests locally now to make sure it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The flux_unit can be created, but the self.flux_unit.choices isn't populated yet causing one of the AttributeErrors, but the actually choices don't change once populated.

@pllim
Copy link
Contributor

pllim commented Jul 22, 2024

In terms of functionality (part 1: cubeviz):

  • What does erg / (s cm2) really mean here in the flux unit drop-down? Don't you only get that after integrating over some wavelength/frequency?
  • Does AB/sr look right? It is in the order of 1E+7 in the example Cubeviz notebook data (see screenshot below). Do people really do science in this unit? Maybe a question for Patrick and Cami.
  • Creating a new spectral subset (after having 2 spatial subset) is noticeably slow. I don't know if it is caused by all the math in this PR or what. I feel like we had seen this before and Jesse had fixed it some time ago but now it's back.
  • As a user, it is unclear to me if the fitted model parameter values are in native data unit or the unit I picked, and if the latter, whether it is "flux" or "surface brightness". I just see a table with raw numbers.
  • Moment Map switching between flux/SB -- Is that a follow-up ticket? Kyle said it is supposed to be always in native data unit, right?
  • Just to confirm, none of these new stuff affect aperture photometry, right, because it already does the PIXAR_SR stuff behind the scenes even before Unit Conversion existed? From the diff, I don't think so but I also have not be following all the other PRs.

@pllim
Copy link
Contributor

pllim commented Jul 23, 2024

In terms of functionality (part 2: otherviz):

  • Skipped Imviz, Mosviz, Specviz2d because they have no unit conversion.
  • specviz has Unit Conversion plugin but no toggle between flux and SB.

@kecnry
Copy link
Member

kecnry commented Jul 23, 2024

Creating a new spectral subset (after having 2 spatial subset) is noticeably slow. I don't know if it is caused by all the math in this PR or what. I feel like we had seen this before and Jesse had fixed it some time ago but now it's back.

Can you check on main and if its there as well, file a tech debt ticket please?

As a user, it is unclear to me if the fitted model parameter values are in native data unit or the unit I picked, and if the latter, whether it is "flux" or "surface brightness". I just see a table with raw numbers.
Moment Map switching between flux/SB -- Is that a follow-up ticket? Kyle said it is supposed to be always in native data unit, right?
Just to confirm, none of these new stuff affect aperture photometry, right, because it already does the PIXAR_SR stuff behind the scenes even before Unit Conversion existed? From the diff, I don't think so but I also have not be following all the other PRs.
Skipped Imviz, Mosviz, Specviz2d because they have no unit conversion.

All of these are separate follow-up tickets already discussed and assigned. For aperture photometry, this will be limited to the results table displaying in the user-preferred units, with no need to convert SB<>flux.

specviz has Unit Conversion plugin but no toggle between flux and SB.

This is by design - afaik, we don't have access to PIXAR_SR in pipeline extracted spectra.

@camipacifici
Copy link
Contributor

This is by design - afaik, we don't have access to PIXAR_SR in pipeline extracted spectra.

The 1D spectra from JWST come with 2 columns for flux, one in surface brightness and one in flux (I do not remember if this depends of the source being defined as point or extended). So technically, specviz has all the information to display one or the other. I will double check what it is actually loading...I do not remember anymore.

@pllim
Copy link
Contributor

pllim commented Jul 23, 2024

@camipacifici
Copy link
Contributor

That's what I thought, thank you!
As a follow up, maybe we should give the user the choice to load flux or surface brightness. They should both be available in each x1d file. What do you think?

@rosteen
Copy link
Collaborator

rosteen commented Jul 23, 2024

There was already a request in specutils to make the choice at load time in Spectrum1D.read() rather than assuming based on point source vs extended, I could prioritize making that change if we also want to use it here.

@kecnry
Copy link
Member

kecnry commented Jul 23, 2024

If we load both into glue (when loading from a file), we could easily swap out the columns... but we'll still need to handle detecting when we can and cannot do that. Perhaps an idea for future expansion?

@gibsongreen gibsongreen changed the title SB/Flux conversion across all configs expanded support of SB/Flux translations Jul 23, 2024
@pllim
Copy link
Contributor

pllim commented Jul 23, 2024

Can you check on main and if its there as well, file a tech debt ticket please?

Performance seems normal on main.

@kecnry
Copy link
Member

kecnry commented Jul 23, 2024

Can you give steps to reproduce? Is this only after changing the display units? That could be something to report upstream in glue if the units of the subset need to be mapped to the viewer or something.

@pllim
Copy link
Contributor

pllim commented Jul 23, 2024

Can you give steps to reproduce?

  1. Starts Cubeviz example notebook. Load the data.
  2. In Unit Conversion plugin, change to Surface Brightness.
  3. Draw circle region around star. Draw rectangle region on a background area. See 3 spectra in spectrum viewer when you reset its zoom.
  4. Draw one spectral region over the spectra. The lag is a heartbeat. Slower than normal but only if you are paying attention.
  5. Draw second spectral region somewhere else. The lag is now half a sec before things are finalized.

If no one else sees this, then never mind.

@kecnry
Copy link
Member

kecnry commented Jul 23, 2024

I can't reproduce anything significant. Do you see the same thing on main when switching from wavelength to frequency for the spectral axis? If so, I think we can say this PR isn't to blame and investigate separately.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

LGTM. Since Cami already has performance as a broad goal at some point, we can defer the lag I saw.

@pllim pllim merged commit 143cd8d into spacetelescope:main Jul 23, 2024
16 of 19 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cubeviz plugin Label for plugins common to multiple configurations specviz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants