-
Notifications
You must be signed in to change notification settings - Fork 75
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
convert limits on spectrum y-unit change #3335
Conversation
jdaviz/core/freezable_state.py
Outdated
flux=y_corners * u.Unit(old_unit)) | ||
y_corners_new = flux_conversion(y_corners, old_unit, new_unit, spec) | ||
|
||
#with delay_callback(self, 'y_min', 'y_max'): |
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.
@astrofrog - any idea why including this delay_callback
would result in y_max
being immediately reverted to zero?
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.
weird, I don't see this as an issue anymore locally or in tests - I guess some other change may have affected it 🤷♂️ If anyone does see this happen, please let me know!
jdaviz/core/freezable_state.py
Outdated
spec = Spectrum1D(spectral_axis=x_corners * u.Unit(self.x_display_unit), | ||
flux=y_corners * u.Unit(old_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.
There is a way where we can avoid creating a Spectrum1D object here and just pass the x_corners
as a Quantity object to flux_conversion and have it generate the necessary equivalency to be able to do the conversion:
1b80ede
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.
that feels quite hacky to call that slice
, but I guess maybe its ok since its just internal. Definitely like saving the overhead of creating the spectrum1d object just to pass quantity arrays.
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.
slice
has been now been updated to spectral_axis
and I fixed a bug I introduced in flux_conversion
, just passing the quantity array is now working!
Maybe in test_unit_conversion.py it would be worth adding test coverage to ensure that after a conversion that the minimum y-value of the spectrum is greater than the viewer's minimum y-limit value and the spectrum maximum y-value is less than the viewer y maximum limit. |
jdaviz/utils.py
Outdated
if eqv: | ||
image_data = True | ||
# Needed to convert Flux to Flux for complex conversion/translation of cube image data | ||
eqv += u.spectral_density(spectral_axis) | ||
elif len(values) == len(spectral_axis): | ||
eqv = u.spectral_density(spectral_axis) |
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.
@gibsongreen should there be an else here that raises an exception? Can spectral_axis
be a single value?
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.
I recall trying to avoid throwing exceptions here but in this case it probably makes sense to have it in the nested conditions.
Originally slice was used for a single value, since Quantity objects can be both scalar or array-like generalizing this to check for both would be best.
12c90bd
to
6411bf2
Compare
5a1b45b
to
701ba53
Compare
701ba53
to
b3e3ac3
Compare
3cec14b
to
81f6b97
Compare
152e4a9
to
5e8f298
Compare
5e8f298
to
f657a92
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3335 +/- ##
==========================================
- Coverage 88.80% 88.78% -0.03%
==========================================
Files 125 125
Lines 19137 19187 +50
==========================================
+ Hits 16995 17035 +40
- Misses 2142 2152 +10 ☔ View full report in Codecov by Sentry. |
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 seems reasonable to me - I don't understand why delay_callback
wouldn't work though, I can try and investigate this.
It might be worth adding a test for this with an equivalency that does affect the final limits? |
Yep, tests are coming soon. |
else: | ||
spectral_axis.info.meta = {} | ||
|
||
y_corners_new = flux_conversion(y_corners, old_unit, new_unit, spectral_axis=spectral_axis) # noqa |
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.
will this handle equivalencies needed for surface brightness > surface brightness conversions, that may need pixel scale factor?
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, it should
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.
where does it get that from if there is no spectrum.meta or additional equivalency?
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.
the for-loop directly above this (it does rely on layer.layer.meta
, but that should be set by spectral extraction)
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.
On L74 there is a loop to find the scale factor if it exists, and if so, to attach it to the metadata of the spectral_axis
. Then there is a small modification to flux_conversion
to account for passing the scale factor to spectral_axis
instead of spec
(for the case that spec
nor eqv
is not passed).
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, i see what's happening now!
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.
I tested this out and could not break it with any unit conversion combo! I would add some tests (maybe in test_user_api) to test this against different unit conversions and translations and make sure zoom level stays preserved.
5b59941
to
2e3483c
Compare
7e297dd
to
655cd96
Compare
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.
Added test coverages looks good, I retested with the re-introduction of the delayed-callback and glad to see all behavior is working as expected!
Description
This pull request implements custom logic to convert (instead of resetting) y-limits on a spectrum when the y display unit is changed. This does so by sending all 4 corners through the flux/SB conversion logic and ensuring that those bounds remain in view. As a consequence, multiple unit conversions can result in "zooming out", but never zooming in (i.e. this is not expected to roundtrip, but is supposed to keep any feature in frame).
Change log entry
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, maintainershould 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.
trivial
label.