-
Notifications
You must be signed in to change notification settings - Fork 81
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
Imviz region setter/getter #630
Conversation
d469380
to
90c4c26
Compare
c7fe641
to
bf2efc6
Compare
My hot-take here:
I'd say this should be addressed eventually but doesn't need to be in this PR - i.e., it would be nice to be able to load a region, fiddle with it, and then do something with it, but it is not critical as long as I can just draw a new one by hand over the top of it and get that one instead
I think that's a feature not a bug! More sersiously, I have a hazy memory of debating with someone about this, and if it turns out they convinced me, I think it's OK to have to explicitly name the region. That said, I would also advocate for the behavior I'm asking for in #622 - that is, the no-argument version gives a dictionary or something with all the regions. That might be a trivial fix somewhere higher up in the helper class heirarchy?
It would be nice to fix this if possible, but... as per #622 (comment) I think it's not critical that we get a round-trip as long as the interactively drawn apertures still give back a valid region object.
Also, "not great but not critical" IMHO, as long as it works for interactive regions. |
Oh, and for all of those that I was saying "not critical", I think we should definitely make issues for them and try to fix them, but they don't have to block this PR nor stop closing of #622. |
# Range selection on a profile is currently not supported in | ||
# the glue translation machinery for astropy regions, so we | ||
# have to do it manually. Only data that is 2d is supported, | ||
# therefore, if the data is already 2d, simply use as is. | ||
if value.data.ndim == 2: | ||
region = value.data.get_selection_definition( | ||
format='astropy-regions') | ||
subset_id=key, format='astropy-regions') |
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 is to fix a real bug that affects even interactive regions.
data = self.app.data_collection[ | ||
self.app.data_collection.labels.index(data_label)] |
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.
@astrofrog , is there any reason not to call data_collection
directly? I don't see any unintended consequences but you know better.
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.
Note to self: I wonder if linking problem can be deferred if I use the "reference image" and take away data_label
option...
mask = np.zeros((10, 10), dtype=np.bool_) | ||
mask[0, 0] = True | ||
self.imviz.load_static_regions({'my_mask': mask}, data_label) | ||
self.verify_region_loaded('my_mask') |
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.
Note for future self: Since Subset is global, I think it is actually loaded 4 times here (twice for each parametrize
call). But since the region name is the same, the second parametrize
call probably overwrote the first one. But that is probably okay for testing because we just want to check nothing crashed.
Codecov Report
@@ Coverage Diff @@
## main #630 +/- ##
==========================================
+ Coverage 59.60% 59.94% +0.34%
==========================================
Files 65 65
Lines 4005 4034 +29
==========================================
+ Hits 2387 2418 +31
+ Misses 1618 1616 -2
Continue to review full report at Codecov.
|
e5119f8
to
a906548
Compare
The linking stuff added in #611 is messing up the regions stuff here. I am not sure how to make the notebook play nice with linked data. Need @astrofrog to chime in here. The biggest problem is masked subset creation chokes when the second image is too small. I get The smaller problem is when you uncheck/recheck the boxes so linked images show properly for blinking, the second image is displayed. Which means all the cells that execute on Perhaps the linking problem needs to be solved before we can proceed here. |
if hasattr(region, 'to_pixel'): | ||
# TODO: GWCS not yet supported, see | ||
# https://github.com/astropy/photutils/issues/1219 | ||
# https://github.com/astropy/regions/issues/374 |
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 part of the code needs updating when new release of regions
with GWCS support is done, see astropy/regions#374 (comment) .
Too many conflicts now. Work continues on #721. |
Fix #622
Notes to self:
TODO
regions
0.5 is released with support for GWCS, see Sky region does not understand GWCS astropy/regions#374 (comment)photutils
is released with support for GWCS, see Sky aperture does not understand GWCS astropy/photutils#1219 (comment)Proof of concept
my_aper
andmy_aper_sky
are fromphotutils
aperture objects, from pixel and sky, respectively.my_reg
andmy_reg_sky
are fromregions
objects, from pixel and sky, respectively.my_mask
is from Numpy boolean array.Subset 6
andSubset 7
are from manually drawn shapes.(I don't know what is the extra small red dot in the left image is. I swear it wasn't there when I took the screenshot!)
Problem 1: Cannot move region (out of scope? yes)
Once they are loaded, they cannot be moved around. However, I also noticed this behavior with manually drawn region, so maybe fixing this is out of scope.
With manually drawn region, you can only move it right after drawn. If you click on a different button and come back to it, you can no longer move it.
Problem 2: When multiple regions exist, get_regions() breaks (fixed)
This is fixed for interactive regions. Because we don't have to roundtrip anymore, this does not affect
regions
regions.Older notes
Workflow 1: Run the notebook cell to load
my_aper
. Run the notebook cell to loadmy_reg
. Run the notebook cell that callsimviz.get_regions()
.Workflow 2: Run the notebook cell to load
my_aper
. Manually draw another region. Run the notebook cell that callsimviz.get_regions()
.Traceback would look similar to this:
Problem 3: When only one region is loaded, get_regions() still breaks (won't fix)
Because we dropped the roundtripping requirement, this is no longer an issue. I am reserving "Subset N" label for interactive regions, thus in this way, I can know which one was done interactively, and which programmatically, and get around this problem.
Older notes
Workflow 1: Run the notebook cell to load
my_aper
. Run the notebook cell that callsimviz.get_regions()
.Workflow 2: Run the notebook cell to load
my_reg
. Run the notebook cell that callsimviz.get_regions()
.Question: How do you even translate an arbitrary mask back to
regions
? Is it possible to attach meta data toSubset
for round-tripping? See glue-viz/glue-astronomy#30Traceback would look similar to this:
Problem 4: Delete button for regions is broken (fixed)
Seems to work fine now, except for existing bug already reported to #642.
Older notes
Workflow: Load
my_aper
andmy_reg
. Manually draw another region. Pick your favorite and click on the associated trashcan button. See the region selection menu acting weird.In the dev version without this patch, deletion kinda works, except for #642.