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

BUG: Fix wrong Subset unit when created in 2D spectrum viewer #3201

Merged
merged 6 commits into from
Oct 1, 2024

Conversation

pllim
Copy link
Contributor

@pllim pllim commented Sep 24, 2024

Description

This pull request is to address wrong Subset unit when it is extracted from Subset created in Specviz2d on the 2D spectrum viewer. Glue itself does not attach unit natively to Subset, so that means Jdaviz made wrong assumptions in the extraction code. Bug ticket blamed it to the Export plugin but the actual bug has nothing to do with the Export plugin, thought the plugin did expose the bug when user extracted Subset that way but you don't need the plugin to reproduce the bug.

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. Bugfix milestone also needs an accompanying backport label.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)? 🐱

@pllim pllim added bug Something isn't working 💤backport-v3.10.x on-merge: backport to v3.10.x labels Sep 24, 2024
@pllim pllim added this to the 3.10.4 milestone Sep 24, 2024
@@ -134,6 +137,25 @@ def test_2d_1d_parser(specviz2d_helper, mos_spectrum2d, spectrum1d):
specviz2d_helper.load_data(spectrum_2d=mos_spectrum2d, spectrum_1d=spectrum1d)
assert specviz2d_helper.app.data_collection.labels == ['Spectrum 2D', 'Spectrum 1D']

spec2d_viewer = specviz2d_helper.app.get_viewer("spectrum-2d-viewer")
assert spec2d_viewer.figure.axes[0].label == "x: pixels" # -0.5, 14.5
spec2d_viewer.apply_roi(XRangeROI(10, 12))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could have used the API from #3104 but since it is not merged yet, I didn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#3104 is now merged but the API is not yet public. Should I keep this as-is or should I use the helper.plugins['Subset Tools']._obj.import_region(...) syntax here?

assert len(subsets) == 2
s1 = subsets["Subset 1"]
s2 = subsets["Subset 2"]
assert s1.lower.unit == s1.upper.unit == u.pix
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 confirmed that this line throws exception on main without this patch, but passes with this patch. Exception on main:

>       assert s1.lower.unit == s1.upper.unit == u.pix
E       assert Unit("Angstrom") == Unit("pix")
E        +  where Unit("Angstrom") = <Quantity 12. Angstrom>.unit
E        +    where <Quantity 12. Angstrom> = Spectral Region, 1 sub-regions:\n  (10.0 Angstrom, 12.0 Angstrom) .upper
E        +  and   Unit("pix") = u.pix

and fixed an ambiguous specviz2d test, maybe
jdaviz/app.py Outdated Show resolved Hide resolved
jdaviz/tests/test_subsets.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 5 lines in your changes missing coverage. Please review.

Project coverage is 88.44%. Comparing base (f880d55) to head (eafb391).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
jdaviz/app.py 66.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3201      +/-   ##
==========================================
- Coverage   88.46%   88.44%   -0.02%     
==========================================
  Files         125      125              
  Lines       18668    18676       +8     
==========================================
+ Hits        16514    16518       +4     
- Misses       2154     2158       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

Seems like it's giving the expected results in my testing, other configs appear to still work. LGTM, thanks.

@pllim
Copy link
Contributor Author

pllim commented Sep 30, 2024

@kecnry , I think I addressed your comment.

viewer = self.get_viewer(self._jdaviz_helper._default_spectrum_viewer_reference_name)
data = viewer.data()
if data and len(data) > 0 and isinstance(data[0], Spectrum1D):
units = data[0].spectral_axis.unit
Copy link
Member

Choose a reason for hiding this comment

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

what does data[0] assume? That that is the full cube extracted spectrum? If that is the assumption, maybe we need to be more explicit and request it by label instead? What if that has been unloaded from the viewer?

I still wish this could be generalized, but I see how its difficult since data in the else is the glue component, but data in the if is a Spectrum1D (or other translated object). Although the else in the else then uses a handler to convert to a Spectrum1D anyways. 🤔

If all we need here are the units of the x-axis of the spectrum viewer... can we just access the display units? Or do we need the native units of the "reference" data?

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 don't know the answers. This block is really for Cubeviz and I am trying to patch Specviz2D. Do I really have to fix Cubeviz too?

Copy link
Member

Choose a reason for hiding this comment

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

Fair, ignore my first line of questions then since those do apply to the old code. But I think if we can have a general block here that applies to cubeviz and specviz2d, that would be easier to maintain than if-statements, right? There is even a TODO comment immediately above suggesting switching to display units - so maybe we can simplify this all down to one line once @gibsongreen enables display units across all configs?

Copy link
Member

Choose a reason for hiding this comment

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

(or maybe it makes sense to get this in like this now and either roll that into @gibsongreen's WIP or as a tech-debt follow-up after that makes it in as well?)

Copy link
Member

Choose a reason for hiding this comment

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

ok, we have decided to revisit this after unit conversion is enabled across all configs and merge the logic as-is until then. 🐱

@pllim pllim removed the 💤backport-v3.10.x on-merge: backport to v3.10.x label Oct 1, 2024
@pllim pllim modified the milestones: 3.10.4, 4.0 Oct 1, 2024
@pllim
Copy link
Contributor Author

pllim commented Oct 1, 2024

Actually I am not going to backport this because it is unlikely the backport will be clean due to unit conversion stuff.

@pllim pllim merged commit 23fec46 into spacetelescope:main Oct 1, 2024
17 of 19 checks passed
@pllim pllim deleted the specviz2d-subset-unit branch October 1, 2024 14:18
@pllim
Copy link
Contributor Author

pllim commented Oct 1, 2024

Thanks, all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working specviz2d
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants