-
Notifications
You must be signed in to change notification settings - Fork 153
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
Conversation
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.
How do you pass in equivalencies?
How do you ensure flux conversion would be correct, especially in non-linear flux units?
As mentioned in glue-viz/glue-jupyter#311 I am planning on making the unit conversion pluggable/swappable. More soon! |
When you have coded it, I am gonna throw in some magnitudes to make your life interesting, maybe. 😉 |
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 |
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.
Do you just wanna use intersphinx here?
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.
Fixed
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:: |
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, this is a way to bypass built-in astropy equivalencies? 👀
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.
Yes
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 |
2ff1c2b
to
7696e13
Compare
… unit conversion classes
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
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! |
.. 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). |
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.
This breaks backward compatibility -- See failures in https://github.com/spacetelescope/jdaviz/actions/runs/4053913069/jobs/6975103932
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.
Thanks, will have a think if there is a way we can avoid breaking backward compatibility
axis_values = converter.to_unit(self.viewer_state.reference_data, | ||
self.viewer_state.x_att, axis_values, | ||
self.viewer_state.x_display_unit) |
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.
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.
This adds initial support for unit conversion in the profile viewer, as a test case that is also useful for jdaviz.
Remaining TODOs: