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

generalize handling of composite subsets when determining subset type #2207

Closed

Conversation

kecnry
Copy link
Member

@kecnry kecnry commented May 15, 2023

Description

This pull request consolidates multiple different places in the code where subset type is determined and improves the logic to better handle composite subsets. This fixes the first bug found in #2182 (comment) .

Note that the layer-icon for a spatial subset in cubeviz can sometimes still show spectral until the next subset is created. That bug has a different cause (order of events firing) and is out of scope here.

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

@kecnry kecnry added this to the 3.5 milestone May 15, 2023
@kecnry kecnry force-pushed the fix-composite-highlighting branch from 37b28cd to 8ff2297 Compare May 15, 2023 20:13

def get_subset_type(subset):
"""
Determine the subset type of a subset or layer
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Determine the subset type of a subset or layer
Determine the subset type of a subset or layer.


Parameters
----------
subset : should have ``subset_state`` as an attribute, otherwise will return ``None``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
subset : should have ``subset_state`` as an attribute, otherwise will return ``None``.
subset
Should have ``subset_state`` as an attribute, otherwise will return `None`.

Comment on lines +277 to +278
subset_type : str or None
'spatial', 'spectral', or None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
subset_type : str or None
'spatial', 'spectral', or None
subset_type : { 'spatial', 'spectral', `None`}
Subset type.

Comment on lines +288 to +293
if isinstance(subset.subset_state, RoiSubsetState):
return 'spatial'
elif isinstance(subset.subset_state, RangeSubsetState):
return 'spectral'
else:
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this isn't correct, but the point is you want to break out of the loop as soon as you find a match, right?

Suggested change
if isinstance(subset.subset_state, RoiSubsetState):
return 'spatial'
elif isinstance(subset.subset_state, RangeSubsetState):
return 'spectral'
else:
return None
if isinstance(subset.subset_state, RoiSubsetState):
return 'spatial'
elif isinstance(subset.subset_state, RangeSubsetState):
return 'spectral'
else:
return None

Also, what if what you are looking for is in state2? Can't we use Jesse's tree traversal here?

Comment on lines +282 to +287

while hasattr(subset.subset_state, 'state1'):
# this assumes no mixing between spatial and spectral subsets and just
# taking the first component (down the hierarchical tree) to determine the type
subset = subset.subset_state.state1

Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving this as a note to the future, this might be solved with:

subset = subset.subset_state

while hasattr(subset, 'state1'):
    subset = subset.state1

@javerbukh
Copy link
Contributor

From my testing this seems to be working as expected: composite spatial regions appear in the spectrum viewer and I am able to apply a composite spectral subset to that collapsed data. Was the work left on this to fix the test failure?

@kecnry
Copy link
Member Author

kecnry commented Jun 15, 2023

Yes, this fixed the bug but resulted in other test failures that need to be resolved (or an alternate solution that does not cause test failures).

@kecnry
Copy link
Member Author

kecnry commented Jul 6, 2023

superseded by #2266

@kecnry kecnry closed this Jul 6, 2023
@kecnry kecnry deleted the fix-composite-highlighting branch July 6, 2023 14:18
@javerbukh javerbukh mentioned this pull request Jul 10, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants