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

Added ability to convert units in profile viewer #2296

Merged
merged 18 commits into from
Jan 30, 2023

Conversation

astrofrog
Copy link
Member

@astrofrog astrofrog commented Apr 28, 2022

This adds initial support for unit conversion in the profile viewer, as a test case that is also useful for jdaviz.

Remaining TODOs:

  • Make sure this works properly with glue-jupyter
  • Add documentation about pluggable conversion classes
  • Add tests

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.

How do you pass in equivalencies?

How do you ensure flux conversion would be correct, especially in non-linear flux units?

@astrofrog
Copy link
Member Author

astrofrog commented May 3, 2022

As mentioned in glue-viz/glue-jupyter#311 I am planning on making the unit conversion pluggable/swappable. More soon!

@pllim
Copy link
Contributor

pllim commented May 3, 2022

When you have coded it, I am gonna throw in some magnitudes to make your life interesting, maybe. 😉

doc/customizing_guide/units.rst Outdated Show resolved Hide resolved
the ability to select units for the x and y axes is only available in the profile viewer.

Data components can be assigned units as a string (or `None` to indicate no known units).
By default, glue uses `astropy.units <https://docs.astropy.org/en/stable/units/index.html>`_ package
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you just wanna use intersphinx here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

doc/customizing_guide/units.rst Outdated Show resolved Hide resolved
to theb carry out unit conversions based on these units. However, it is possible to customize the
unit conversion machinery, either to use a different unit transformation machinery, or to specify
e.g. equivalencies in the astropy unit conversion. To customize the unit conversion behavior, you
will need to define a unit converter as shown below::
Copy link
Contributor

Choose a reason for hiding this comment

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

So, this is a way to bypass built-in astropy equivalencies? 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

@pllim
Copy link
Contributor

pllim commented May 13, 2022

p.s. I think at its current state, this PR broke Specviz parser. I had this installed and was doing something else and it crashed. The error went away when I uninstalled this branch and reinstalled glue-core 1.3.0

@astrofrog astrofrog force-pushed the units branch 2 times, most recently from 2ff1c2b to 7696e13 Compare January 17, 2023 10:20
@astrofrog astrofrog changed the title Initial work on unit support Added ability to convert units in profile viewer Jan 24, 2023
@astrofrog astrofrog marked this pull request as ready for review January 24, 2023 11:42
@astrofrog astrofrog requested a review from dhomeier January 24, 2023 11:43
@astrofrog
Copy link
Member Author

I will go ahead and merge this, but @dhomeier feel free to take a look at this anyway if you have time and let me know if you spot anything that needs fixing!

@astrofrog astrofrog merged commit 54b4cc8 into glue-viz:main Jan 30, 2023
.. note:: Support for automatic unit conversion in glue is experimental - at the moment
the ability to select units for the x and y axes is only available in the profile viewer.

Data components can be assigned units as a string (or `None` to indicate no known units).
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks backward compatibility -- See failures in https://github.com/spacetelescope/jdaviz/actions/runs/4053913069/jobs/6975103932

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, will have a think if there is a way we can avoid breaking backward compatibility

Comment on lines +406 to +408
axis_values = converter.to_unit(self.viewer_state.reference_data,
self.viewer_state.x_att, axis_values,
self.viewer_state.x_display_unit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Something does not look quite right here. Why does this use reference data but the next line use input data? I tried changing this but I cannot make it work.

I am seeing over at spacetelescope/jdaviz#2048 that when I add a second spectrum with GHz (first spectrum is loaded in micron and plot is showing micron), the second data plots GHz values as if they are micron without any conversion.

The inputs to custom Jdaviz converter registers as such:

# Signature: to_unit(self, data, cid, values, original_units, target_units)

data = Jy_um  # But I am loading mJy_GHz
cid = World 0
values = [142758.31333333 123202.38       108358.71975904  96707.24451613   87318.19165049  79590.9180531   73120.11170732  67622.35894737   62893.52265734  58782.83490196]
original_units = um  # This is wrong, should be GHz
target_units = um

It is also very confusing that the custom converter takes one more arg than what is really used over here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants