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

Add masked subset support #2462

Merged
merged 3 commits into from
Sep 18, 2023

Conversation

javerbukh
Copy link
Contributor

@javerbukh javerbukh commented Sep 15, 2023

Description

This pull request is a continuation of #2421, which enables freezing of subsets. This converts them to a MultiMaskSubsetState which in this PR can be returned through app.get_subsets() and is visible in the Subset Plugin. If simplify_subset is set to True and there are MultiMaskSubsetState objects in the Composite subset, they will be ignored so that the Range objects can be combined into a SpectralRegion object.

To get the Freeze button to appear:

plugin = viz.app.get_tray_item_from_name('g-subset-plugin')
plugin.can_freeze = True

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.
  • Add support for MultiMaskSubsetState in get_subsets() and the subset plugin.

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.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@github-actions github-actions bot added documentation Explanation of code and concepts cubeviz specviz mosviz embed Regarding issues with front-end embedding testing imviz specviz2d labels Sep 15, 2023
@javerbukh javerbukh force-pushed the add-masked-subset-support branch from 0856fcb to e5b3cfa Compare September 15, 2023 13:35
@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Patch coverage is 87.03% of modified lines.

Files Changed Coverage
jdaviz/utils.py 76.92%
jdaviz/app.py 91.66%
...igs/default/plugins/subset_plugin/subset_plugin.py 100.00%

📢 Thoughts on this report? Let us know!.

@javerbukh javerbukh marked this pull request as ready for review September 15, 2023 14:32
Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Just a few small comments/suggestions, but this seems to work quite well and is a surprisingly-light weight solution, thanks!!

jdaviz/utils.py Outdated Show resolved Hide resolved
@@ -972,6 +972,8 @@ def get_subsets(self, subset_name=None, spectral_only=False,
subset_region = self._get_range_subset_bounds(subset.subset_state,
simplify_spectral,
use_display_units)
elif isinstance(subset.subset_state, MultiMaskSubsetState):
subset_region = self._get_multi_mask_subset_definition(subset.subset_state)
else:
Copy link
Member

Choose a reason for hiding this comment

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

What else might still fall under this else? Can it return any reasonable default in that case or raise an error instead? I just worry about future cases where nothing getting returned could result in unintentionally missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have a preference between reasonable default and raise error? I lean towards default but I can see the merits of either one.

Copy link
Member

Choose a reason for hiding this comment

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

I think default is probably fine for this case, even if it doesn't contain any information besides the class name or something, that is still more instructive than a missing entry.

@rosteen
Copy link
Collaborator

rosteen commented Sep 18, 2023

Looks pretty good, one question from testing: after freezing my composite subset to a mask, when I use get_subset to retrieve it the result is a list:

imviz.app.get_subsets()['Subset 1']
>>> [{'name': 'MultiMaskSubsetState',
    'glue_state': 'MultiMaskSubsetState',
    'region': 986526,
    'subset_state': <jdaviz.utils.MultiMaskSubsetState at 0x17ba5e6d0>}]

Is there any case where this list would have multiple entries? It seems like there isn't, in which case it would be better to return just the dictionary without the list wrapper around it.

@@ -1068,6 +1071,12 @@ def _get_range_subset_bounds(self, subset_state,
"subset_state": subset_state}]
return spec_region

def _get_multi_mask_subset_definition(self, subset_state):
return [{"name": subset_state.__class__.__name__,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, you're explicitly wrapping the dict in a list here. What was the reason for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for this is that MultiMask could be one region of many in a composite subset. To return all that information, we use a list of dictionaries which contain information on those subregions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh, I missed (or forgot) that get_subsets() always returns a list of dictionaries now, even the subset is a single region. As long as it's consistent, carry on nothing to see here 😄

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 is this kind of subset supposed to work when "reparenting" becomes a thing? Or when Brett's rotation work gets merged?

Or is this never going to be enabled for Imviz?

@javerbukh
Copy link
Contributor Author

@pllim Good question, this use case is more for LCViz so it will not be enabled for Imviz, at least not this iteration.

@rosteen
Copy link
Collaborator

rosteen commented Sep 18, 2023

@pllim Good question, this use case is more for LCViz so it will not be enabled for Imviz, at least not this iteration.

I did test this in Imviz and it worked, but I haven't thought through any implications/interactions due to the things @pllim brought up. I think adding this to the conversion through WCS links for reparenting should be easy, not sure about rotation. I think I'm comfortable merging given my current ongoing work.

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

LGTM - feel free to add the change log and merge whenever ready!

kecnry and others added 2 commits September 18, 2023 16:07
fix event handling for choosing config from launcher

filepath fallback when object from config-detection fails to load

fix: support for notebook 7 (spacetelescope#2420)

Notebook 7 requires a different way to detect if the app runs in
a notebook context.

Fix explanation in markdown cell.

DOC: Footprints plugin API docs (spacetelescope#2426)

* build footprints API docs

* add code snippet in plugin docs

* fix syntax in API docs

---------

Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>

prevent overwriting user-API methods (spacetelescope#2425)

fix default color for overlay when traitlet set by user

* for the FIRST overlay, the user could have set the color traitlet before the internal overlay object is created (which occurs as soon as the plugin is first shown).  In that case, we want to respect the user choice of color.

similar fixes for any other traitlet when plugin inactive

regression test

change log entry

fix API import of single region and overwriting existing entry

* along with regression testing

TST: Also pull in scikit-image dev
to get rid of incompatibility with numpy

Use new "true circle" tool from glue-jupyter (spacetelescope#2332)

* Use truecircle tool
from glue-viz/glue-jupyter#376

* MNT: Bump glue-jupyter minversion
that can use this new tool

* Add change log

* Fix line too long

* Fix change log verbiage

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>

---------

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>

Enable multiselect in subset plugin for recentering (spacetelescope#2430)

* Enable multiselect in subset plugin for recentering

* Fix bug with default text

* Remove unused import

* Fix bug in aperature photometry

* Address review comments

* Remove commented out code

* Add initial tests

* Fix bug when exiting multiselect and switching subsets

* Add documentation and update CHANGES file

* Remove print statement

* Add comment about recentering taking multiple iterations to docs

* fix chip styling in subset dropdown

* only set selected_has_subregions if exists

* only show multiselect toggle in imviz

* Apply suggestions from code review

Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>

---------

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>

Debug standalone build (spacetelescope#2441)

* Log jdaviz output for debugging

* Run workflow on debugging branch

* See if collecting data from jupyter-client will fix this, otherwise might need to downgrade

* Remove debugging stuff

MNT: Bump actions/checkout to v4

Enable workflow_dispatch for standalone

because it cannot be enabled outside of main apparently

[ci skip] [rtd skip]

EXP: Update workflow versions

Fix Mosviz slit overlay (spacetelescope#2434)

* Fix Mosviz slit overlay
by using polygon instead of forcing a rectangle without angle info.

Co-authored-by: Camilla Pacifici <camilla.pacifici@gmail.com>

* Off by one error in predicted PR num

---------

Co-authored-by: Camilla Pacifici <camilla.pacifici@gmail.com>

API access (hidden) to disable cubeviz movie UI (spacetelescope#2440)

* (hidden) API access to disable cubeviz movie UI
* default movie_enabled based on new app-setting server_is_remote
* test coverage

TST: Ignore ASDF warning about gwcs-1.0.0 schema
because gwcs dev and/or asdf-wcs-schemas 0.2.0 triggers the warning because the schema is no longer supported.
@javerbukh javerbukh force-pushed the add-masked-subset-support branch from 93698c5 to 578c22d Compare September 18, 2023 20:08
@javerbukh javerbukh added the skip-changelog-checks changelog bot directive label Sep 18, 2023
CHANGES.rst Outdated Show resolved Hide resolved
Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>
@javerbukh javerbukh removed the skip-changelog-checks changelog bot directive label Sep 18, 2023
@javerbukh javerbukh added this to the 3.7 milestone Sep 18, 2023
@javerbukh javerbukh merged commit d1f24ee into spacetelescope:main Sep 18, 2023
13 of 15 checks passed
@javerbukh javerbukh deleted the add-masked-subset-support branch September 19, 2023 00:19
bmorris3 pushed a commit to bmorris3/jdaviz that referenced this pull request Sep 22, 2023
* Integrate MultiMaskSubsetState into get_subsets and subset_plugin

---------

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cubeviz documentation Explanation of code and concepts embed Regarding issues with front-end embedding imviz mosviz specviz specviz2d testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants