-
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
Create import_region method for loading region objects #3104
Create import_region method for loading region objects #3104
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3104 +/- ##
========================================
Coverage 88.45% 88.45%
========================================
Files 124 124
Lines 18389 18649 +260
========================================
+ Hits 16266 16496 +230
- Misses 2123 2153 +30 ☔ View full report in Codecov by Sentry. |
fe49ace
to
cae3fa1
Compare
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.
All the existing tests using apply_roi
should be updated to use this new API too?
Is there any benefit to use locally scoped imports vs importing everything you need at the top of the module?
Other comments as follow.
self._import_spectral_regions(regions, mode) | ||
return |
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.
- Given that you
return
here, all the spatial region imports (if you still want them locally scoped) should happen after this. - You should
return bad_regions
here to be consistent with spatial loader behavior, which means your_import_spectral_regions
should give you backbad_regions
like the spatial one does.
self._import_spectral_regions(regions, mode) | |
return | |
return self._import_spectral_regions(regions, mode) |
self.app.hub.broadcast(SnackbarMessage( | ||
f"Loaded {n_loaded}/{n_reg_in} regions, max_num_regions={max_num_regions}, " | ||
f"bad={n_reg_bad}", color=snack_color, timeout=8000, sender=self.app)) | ||
if return_bad_regions: | ||
return bad_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 behavior should be emulated by the spectral region loader too, to be consistent.
jdaviz/configs/default/plugins/subset_plugin/tests/test_subset_plugin.py
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
def _combination_selected_updated(self, change): | ||
self.app.session.edit_subset_mode.mode = SUBSET_MODES[self.combination_mode.selected] | ||
|
||
def _update_combination_mode(self): |
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 only ever called when linking is changed, but needs to be two-way synced, so that changing the mode in the UI (the glue dropdown) or via internal glue API, is reflected in self.combination_mode
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.
has this been addressed? When changing the combination mode from the UI, I do not see the internal traitlet being updated to match (although changing the combination_mode.selected
does reflect in the UI via _combination_selected_updated
).
And this blocks 4.0? |
This is not listed as required for 4.0. In fact, if we do merge it, we may want to consider postponing exposing the API so that we continue to iterate on the public API during the follow-up efforts. |
I think it is important for the API to have consistent behavior if we want the same thing to handle both spatial and spectral. So if we want to wait till after 4.0 anyway, then maybe this can wait for Jesse to come back? |
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. Should we also change the example notebooks (ImvizExample, CubevizExample, ImvizDitheredExample, imviz_advanced_aper_phot, imviz_color_mpl, imviz_edit_subset_programmatic, cubeviz-cropped) which still have calls to helper.load_regions
?
1557dad
to
288e0f3
Compare
Now that the notebooks are updated, that would make this official public API (we can no longer just defer exposing the API), so do we want to milestone this beyond 4.0? |
I thought we already said this PR is for after 4.0, no? |
127df8d
to
f9ac560
Compare
Thank you for the new updates! Setting |
The first |
Do we understand the cause for this? Maybe it can be a separate effort to fix if it wasn't introduced here, but might make this type of workflow simpler if its supported? |
Sorry, forgot to address this point! You need to do |
ah ok, good to know its only that!. (But note that once exposed to the user API, the |
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 think we're at the point where this has dragged on long enough that it should just go in so we can move on to the follow-up tickets. CI is green, so approving. Thanks for your patience and persistence!
def _combination_selected_updated(self, change): | ||
self.app.session.edit_subset_mode.mode = SUBSET_MODES[self.combination_mode.selected] | ||
|
||
def _update_combination_mode(self): |
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.
has this been addressed? When changing the combination mode from the UI, I do not see the internal traitlet being updated to match (although changing the combination_mode.selected
does reflect in the UI via _combination_selected_updated
).
else: | ||
data = self.app.data_collection[refdata_label] | ||
|
||
# TODO: Make this work for data cube. |
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.
is this a new TODO comment or copied from the previous region import code?
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.
Copied from previous, I'll remove it.
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.
does it work for cubes? If not, let's make sure we have a ticket (but safe to ignore here if this was from moved code)
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.
Seems like this works, although the solution is hacky (per glue-viz/glue-astronomy#75 ), maybe @pllim can clarify on the status. Subset creation works with cubes so I think this is safe to remove but I'll wait for Pey-Lian's answer.
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.
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.
If it works it works 🤷 I don't recall changing the spectrum WCS stuff recently in a way that would affect this.
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.
That issue has been closed by glue-viz/glue-astronomy#75 (comment), and the translator would only use a PaddedSpectrumWCS
if the cube had a 1D WCS, which I assume is not the case here.
combination_mode : list, str, or `None` | ||
The way that regions are created or combined. If a list, then it must be the | ||
same length as regions. If `None`, then it will follow the default glue | ||
functionality for subset creation. |
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.
could/should we restore the original combination mode after this either completes or raises an exception?
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.
My thought would be the combination mode stays the last entry in the list but I am interested to hear what would make the most sense for a user.
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.
ok, let's discuss and decide with the team. Whatever the decision, its probably worth explaining here in the API docs so the users know what to expect. 🐱
@kecnry Waiting to hear from @rosteen on whether the line about checking a cube's wcs is still valid but otherwise I addressed the review comments. I tested changing the edit mode using the UI and API and it seemed to update correctly. Please let me know if you have a workflow I can use to test that behavior. As for the comment on combination_mode reverting to default after |
Screen.Recording.2024-09-23.at.9.42.42.AM.mov |
After digging into this more, this might just be a limitation of how glue handles the mode dropdown vs the actual mode that will be used (when there is no active subset selected, there will be a new created subset regardless of the mode dropdown). If/when we want to expose a UI element in the plugin, we'll definitely need to think about this a little more. I'm not sure if/how we should deal with this for the exposed API though 🤔 |
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.
LGTM now - any remaining items can be iterated as we build on top of this before we make the API exposed as public. Thanks for working through all these iterations!
If we want this merged before @javerbukh gets back, I think we could just accept the few small code suggestions I listed and then merge.
Default is to load everything. If you are providing a large file/list | ||
input for ``region``, it is recommended | ||
|
||
refdata_label : str or `None` |
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 wonder if we could just do data_label
- but we can revise this anytime before making public, so can ignore for now.
try: | ||
raw_regs = Regions.read(region, format=region_format) | ||
except Exception: # nosec | ||
raw_regs = SpectralRegion.read(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.
This is fine for now, but I wonder if there's any way we could predict in advance instead of try/except. As it is now, checking the extension would probably work, but in the future we may have the same extension supported between spectral + spatial, so that isn't a longterm solution.
+1 |
7218aa8
to
7610f50
Compare
Description
This pull request creates an
import_region
method that loads a region object withcombination_mode
.Some todo:
jdaviz/jdaviz/core/helpers.py
Line 651 in dfb4bfa
self.combination_mode
should use theSelect
(SubsetSelect
?) class to be able to take advantage of thechoices
andselected
attributesself.combination_mode
to the subset mode selection in the toolbarFixes #
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.