-
Notifications
You must be signed in to change notification settings - Fork 74
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 get_subsets when XOR is involved #3124
Conversation
Was hoping we could simply hook into glue-astronomy region translator but it didn't work. Maybe the translator is incomplete. I think we wrote a lot of the stuff focused on 2D image region, not spectral region. from glue.config import subset_state_translator
dc = specviz_helper.app.data_collection
subsets = dc.subset_groups
subset = subsets[0]
handler = subset_state_translator.get_handler_for('astropy-regions')
handler.to_object(subset.subsets[0]) # traceback I feel like the proper solution is to implement a new spectral region translator in glue-astronomy but that is way more "story points" than we have available. |
|
||
specviz_helper.app.session.edit_subset_mode.mode = XorMode | ||
viewer.apply_roi(XRangeROI(6700, 7700)) | ||
viewer.apply_roi(XRangeROI(6100, 7600)) |
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 bug gets triggered when XOR is not exactly the same limits as the other regions (and that is usually the case in practice).
merged_regions.append(last_merged) | ||
else: | ||
merged_regions.append(reg_as_tup[index]) | ||
merged_regions = self.get_subsets(subset_name, spectral_only=True) |
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.
Not sure how controversial this is, but in order to fix the XOR bug, I basically have to move the "merge overlapping regions" calls into get_subsets
when simplify_spectral=True
. Otherwise, if you apply XOR and then another operator like OR, you get overlaps even if you ask for simplify_spectral=True
, because to fix the bug, I have to chop up regions in the XOR operations or it is going to throw out some regions that do not overlap with the XOR limits. Hope this is not too confusing.
return True | ||
return False | ||
|
||
@staticmethod | ||
def _merge_overlapping_spectral_regions_worker(spectral_region): |
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.
Same logic as before but I find operating on SpectralRegion directly less complicated than forcing tuple of floats. Also I need SpectralRegion directly to reuse it somewhere else.
@@ -1304,14 +1309,33 @@ def is_there_overlap_spectral_subset(self, subset_name): | |||
Returns True if the spectral subset with subset_name has overlapping | |||
subregions. | |||
""" | |||
spectral_region = self.get_subsets(subset_name, spectral_only=True) | |||
if not spectral_region or len(spectral_region) < 2: | |||
spectral_region = self.get_subsets(subset_name, simplify_spectral=False, spectral_only=True) |
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.
Because I have to move the "merge overlapping regions" calls into get_subsets
when simplify_spectral=True
, I have to force simplify_spectral=False
here so this check is still correct.
@@ -1135,9 +1140,7 @@ def get_sub_regions(self, subset_state, simplify_spectral=True, | |||
else: | |||
if isinstance(two, list): | |||
two[0]['glue_state'] = "AndNotState" | |||
# Return two first so that we preserve the chronology of how |
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.
Not sure what this comment is about because when you add two SpectralRegion, it automatically reorders by ascending wavelength, so it is never chronological to begin with. That is why this comment is removed.
If this is too controversial, other options:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3124 +/- ##
==========================================
- Coverage 88.81% 88.78% -0.04%
==========================================
Files 112 112
Lines 17427 17446 +19
==========================================
+ Hits 15478 15489 +11
- Misses 1949 1957 +8 ☔ View full report in Codecov by Sentry. |
I was still able to find a bug by doing the following order of spectral subsets (you can use PR #3082 to import the entire dictionary). I would expect a SpectralRegions object with 6 elements but
|
@javerbukh , good catch. I guess I misunderstood how |
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'm so glad there is now at least one other person that understands this code 😄 Great job figuring out this bug, I could not replicate it with very complex composite subsets. Hopefully the second reviewer tries the same with similar results.
"Understand" is a strong word... |
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 looks good to me.
and add more tests. Co-authored-by: Jesse Averbukh <[email protected]>
Co-authored-by: Brett M. Morris <[email protected]>
Description
This pull request is to fix bug found in #2941 (comment)
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.