-
Notifications
You must be signed in to change notification settings - Fork 76
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
BUG: Fix spectrum and spaxel resetting limits; FEAT: Add viewer.get_limits() #3249
Conversation
8cc0474
to
5481e43
Compare
TST: Add regression test that fails on main without this patch. FEAT: Add viewer.get_limits() method for convenience and refactor some code to use it. Also refactor some code to use existing set_limits.
5481e43
to
6f6b8f6
Compare
from regions import RectanglePixelRegion | ||
|
||
|
||
@pytest.mark.filterwarnings('ignore:No observer defined on WCS') |
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 warning no longer exist, so we can remove the ignore.
from regions import RectanglePixelRegion | ||
|
||
|
||
@pytest.mark.filterwarnings('ignore:No observer defined on WCS') | ||
def test_spectrum_at_spaxel(cubeviz_helper, spectrum1d_cube_with_uncerts): | ||
def test_spectrum_at_spaxel_no_alt(cubeviz_helper, spectrum1d_cube_with_uncerts): |
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.
Have to add "_no_alt" to the name, otherwise -k test_spectrum_at_spaxel
selects all the other tests with the same prefix as well.
@@ -47,6 +52,9 @@ def test_spectrum_at_spaxel(cubeviz_helper, spectrum1d_cube_with_uncerts): | |||
{'event': 'mouseleave', 'domain': {'x': x, 'y': y}, 'altKey': False}) | |||
assert flux_viewer.toolbar.active_tool._mark.visible is False | |||
|
|||
# Check that X is still zoomed but Y is reset. | |||
assert_allclose(spectrum_viewer.get_limits(), (4.623e-07, 4.6232e-07, 28, 92)) |
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 main
without this patch, this test would fail as such:
# Check that X is still zoomed but Y is reset.
> assert_allclose(spectrum_viewer.get_limits(), (4.623e-07, 4.6232e-07, 28, 92))
jdaviz/configs/cubeviz/plugins/tests/test_tools.py:56:
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E
E Mismatched elements: 2 / 4 (50%)
E Max absolute difference among violations: 4.00276968e-11
E Max relative difference among violations: 8.65800676e-05
E ACTUAL: array([4.6228e-07, 4.6236e-07, 2.8000e+01, 9.2000e+01])
E DESIRED: array([4.6230e-07, 4.6232e-07, 2.8000e+01, 9.2000e+01])
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 updated the test to also account for Y limits, but you get the idea.
@@ -34,8 +31,7 @@ def activate(self): | |||
self._mark = PluginLine(self._profile_viewer, visible=False) | |||
self._profile_viewer.figure.marks = self._profile_viewer.figure.marks + [self._mark, ] | |||
# Store these so we can revert to previous user-set zoom after preview view | |||
pv_state = self._profile_viewer.state | |||
self._previous_bounds = [pv_state.x_min, pv_state.x_max, pv_state.y_min, pv_state.y_max] | |||
self._previous_bounds = self._profile_viewer.get_limits() |
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 thought about having self._previous_bounds
only keeping Y bounds but then decided not to, in case downstream somehow needs the X bounds too.
@@ -166,6 +166,17 @@ def set_limits(self, x_min=None, x_max=None, y_min=None, y_max=None): | |||
if y_max is not None: | |||
self.state.y_max = y_max | |||
|
|||
def get_limits(self): |
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 find this very convenient, so might as well add it in this PR. Otherwise, I will never get to it.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3249 +/- ##
=======================================
Coverage 88.63% 88.63%
=======================================
Files 125 125
Lines 18779 18784 +5
=======================================
+ Hits 16644 16649 +5
Misses 2135 2135 ☔ View full report in Codecov by Sentry. |
that would fail without patching Y zoom also Also keep Y zoom
73052af
to
d969ca1
Compare
self._profile_viewer.state.remove_callback(k, self.on_limits_change) | ||
super().deactivate() | ||
|
||
def on_limits_change(self, *args): |
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 purposely implement this only for Cubeviz and not its parent class because I have no idea what downstream where is using the parent class and want to keep my scope to fix Cubeviz only.
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.
just two small questions to consider - but don't think they need to block merge. Looks good to me and appreciate the code cleanup (even if it made parsing the diff a bit of a pain 😜 )
finally: | ||
self._is_moving = False |
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.
is it possible to send a limits change in before a mouseleave? I guess maybe from API commands submitted in a still running cell or something (or would those just block events anyways)?
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.
Anything is possible via API, but in practice, will a user actually do that?
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.
if not, then we probably don't have to reset to False
until the mouseleave
event, right?
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.
Better be safe than sorry? It might be in a dirty state because I cannot guarantee otherwise.
because we gotta move it, move it.
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.
LGTM, thanks!
Thanks, all! |
…ng limits; FEAT: Add viewer.get_limits()
…9-on-v4.0.x Backport PR #3249 on branch v4.0.x (BUG: Fix spectrum and spaxel resetting limits; FEAT: Add viewer.get_limits())
…imits() (#3249) * BUG: Fix spectrum and spaxel resetting X limits. TST: Add regression test that fails on main without this patch. FEAT: Add viewer.get_limits() method for convenience and refactor some code to use it. Also refactor some code to use existing set_limits. * Fix cubeviz error and add test that would fail without patching Y zoom also Also keep Y zoom * Move _is_moving because we gotta move it, move it.
Description
BUG: Fix spectrum and spaxel resetting X and Y limits.
TST: Add regression test that fails on main without this patch.
FEAT: Add
viewer.get_limits()
method for convenience and refactor some code to use it. Also refactor some code to use existingviewer.set_limits()
method. Since these are not "public API," there is no need for change log for this part.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.