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

POC: Notebook showing glue unit conversion in Specviz #2022

Closed

Conversation

javerbukh
Copy link
Contributor

Description

This pull request is to add a concept notebook that shows how glue unit conversion can be implemented in Jdaviz.

Fixes #

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.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@github-actions github-actions bot added documentation Explanation of code and concepts specviz labels Feb 22, 2023
@pllim
Copy link
Contributor

pllim commented Feb 22, 2023

Does this supersede #1398 ?

@@ -4,6 +4,7 @@
description='Convert the spectral flux density and spectral axis units.'
:link="'https://jdaviz.readthedocs.io/en/'+vdocs+'/'+config+'/plugins.html#unit-conversion'"
disabled_msg="This plugin is temporarily disabled. Effort to improve it is being tracked at GitHub Issue 1972."
Copy link
Member

Choose a reason for hiding this comment

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

(although we probably won't want to actually merge this until the plugin itself is updated)

Suggested change
disabled_msg="This plugin is temporarily disabled. Effort to improve it is being tracked at GitHub Issue 1972."

@javerbukh
Copy link
Contributor Author

@pllim Yes it does, I will close that PR and link to this one.

" all_units = []\n",
" for unit in unit_list: \n",
" try:\n",
" u.Unit(unit)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to keep calling u.Unit(unit). It has overhead. Save the result if successful and reuse it throughout the rest of the function.

Suggested change
" u.Unit(unit)\n",
" cur_unit = u.Unit(unit)\n",

" # warnings.warn(f\"{unit}: {te}\")\n",
" continue\n",
" if u.Unit(unit) == u.Unit(\"Angstrom\"):\n",
" all_units.append(u.Unit(unit.name))\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get this: So if it is Angstrom, you want the Unit object but if not, then you want the unit string? Then won't your output list have mixed object/str elements? Why do you need such a behavior?

" \n",
" def create_flux_equivalencies_list(self, data, cid, units):\n",
" spec = data.get_object(cls=Spectrum1D)\n",
" equivalencies = u.spectral_density(np.sum(spec.spectral_axis))\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
" equivalencies = u.spectral_density(np.sum(spec.spectral_axis))\n",
" equivalencies = u.spectral_density(spec.spectral_axis)\n",

"from glue.core.units import unit_converter\n",
"\n",
"@unit_converter('custom-jdaviz')\n",
"class UnitConverterWithSpectral:\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is overly complicated but I also don't know how glue set up the unit support. The tests at https://github.com/glue-viz/glue/blob/main/glue/core/tests/test_units.py are minimal and does not tell me much when it comes to equivalencies.

In principle, astropy.units should do the conversion for you out of the box. All we need to do is detect if it is spectral axis or flux:

  • spectral axis: use u.spectral()
  • flux: use u.spectral_densitry(spectral_axis)

There should be no need to hardcode so many things. The Unit Conversion plugin already should limit what the users can choose from, so probably okay to assume the input is well-behaved.

I might be missing something here though. Please help me understand. Thanks!

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 spent about an hour trying to move the code to use something like this and with those changes I was unable to get the data loading into the spectrum viewer at all! I'm definitely still in the learning stages as well with glue unit conversion so it might just be my lack of familiarity. I would welcome you trying to get it working if you can!

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, lemme see. Maybe I will convince my Past Self that I was wrong lol.

Copy link
Contributor

Choose a reason for hiding this comment

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

@javerbukh , does javerbukh#14 work as intended or did I miss the mark? 😬

@kecnry
Copy link
Member

kecnry commented Feb 28, 2023

We're moving future efforts towards the actual development in jdaviz rather than wrapping up the fine details in this notebook.

@kecnry kecnry closed this Feb 28, 2023
@pllim pllim mentioned this pull request Feb 28, 2023
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Explanation of code and concepts specviz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants