-
Notifications
You must be signed in to change notification settings - Fork 80
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
batch_load contextmanager and optimize data visibility interactions #1742
Conversation
jdaviz/app.py
Outdated
# Sets the plot axes labels to be the units of the most recently | ||
# active data. | ||
if len(viewer_data_labels) > 0 and self._jdaviz_helper._in_batch_load == 0: | ||
active_data = self.data_collection[viewer_data_labels[0]] | ||
if (hasattr(active_data, "_preferred_translation") | ||
and active_data._preferred_translation is not None): | ||
self._set_plot_axes_labels(viewer_id) | ||
|
||
self._update_selected_data_items(viewer_id, selected_items) | ||
if self.config == 'imviz': | ||
viewer.on_limits_change() # Trigger compass redraw |
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 had to modify this logic slightly to get it to work in the new method. Is the assumption of using the first data layer label valid here? It seems this logic was originally implemented in #191.
Apparently not because it seems to break the axes labeling in Specviz... I'll investigate and fix that before marking this for review.
4f451ff
to
f33de66
Compare
components = [str(comp) for comp in msg.data.main_components] | ||
if "ra" in components or "Lon" in components: | ||
# linking currently removes any markers, so we want to skip | ||
# linking immediately after new markers are added (see imviz.helper.link_image_data). | ||
# Eventually we'll probably want to support linking WITH markers, at which point this | ||
# if-statement should be removed. | ||
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.
this is a temporary workaround to mimic the previous behavior where markers handle linking themselves within add_markers and are removed when future calls are made to linking. Follow-up effort to remove this filed as #1749.
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.
@pllim - if you have suggestions for a better way to detect if msg.data
(which should be the new data collection entry object) is a markers entry as opposed to an image, let me know!
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 probably ok for now, especially given we'll revisit this in the future.
3b18088
to
1c887ab
Compare
clear_other_data=False): | ||
visible=True, clear_other_data=False): |
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.
should we instead have visible
at the end of kwargs? This is in app
, so shouldn't be considered as API-breaking, but if anywhere else relies on the positional order of clear_other_data
, this could cause problems.
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.
As you stated, it is safer to put visible
at the end. Is there a reason why it cannot be after clear_other_data
?
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 just think that it intuitively makes sense to be in this order (visible
seems more directly tied to the other inputs and action of the method, whereas clear_other_data
is more loosely connected and probably less-often to be used). But if API breaking concerns warrants switching the order, I can do that.
Codecov ReportBase: 87.79% // Head: 87.81% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1742 +/- ##
==========================================
+ Coverage 87.79% 87.81% +0.02%
==========================================
Files 95 95
Lines 10149 10167 +18
==========================================
+ Hits 8910 8928 +18
Misses 1239 1239
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
if data_label in self.data_collection.labels: | ||
warnings.warn(f"Overwriting existing data entry with label '{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.
related: #1709
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 even possible since this is returned by data_label = self.return_unique_name(data_label)
above?
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.
Yes, this is needed to mimic the previous behavior in the test_case_that_breaks_return_label
test introduced in #1672
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.
moves the responsibility of data-linking in Imviz from load_data to the plugin - so that new data that are added will respect the user set linking options and not revert to "pixels". (NOTE: do we need a fallback for the case where the plugin isn't loaded?)
Is this statement still true? If so, it is a concern because someone might have a image viewer config without that plugin loaded, especially given now Brett Morris has made the config so flexible.
if data_label in self.data_collection.labels: | ||
warnings.warn(f"Overwriting existing data entry with label '{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.
Is this even possible since this is returned by data_label = self.return_unique_name(data_label)
above?
clear_other_data=False): | ||
visible=True, clear_other_data=False): |
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.
As you stated, it is safer to put visible
at the end. Is there a reason why it cannot be after clear_other_data
?
f'`load_data` method or similar.') | ||
raise ValueError( | ||
f"No data item found with label '{data_label}'. Label must be one " | ||
"of:\n\t" + "\n\t".join(dc_labels)) |
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.
"of:\n\t" + "\n\t".join(dc_labels)) | |
f"of:\n\t{'\n\t'.join(dc_labels)}") |
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 reverted this since it wasn't introduced here (only moved) and your suggestion failed code style checks.
Since they all seem related, I think one PR is fine.
Is there any performance improvement to do this? Even so, can be a follow-up PR?
I don't think so. What if we change our mind and want other viz to use it in the future? We don't want to be moving code back and forth.
Can be deferred as future PR. Loading list of files as comma-separated string is already supported (did you try jdaviz/jdaviz/configs/imviz/helper.py Line 129 in ea91330
|
That was kind of my concern as well.... although the new flexible config would arguably work better with this setup since the old logic was in the Imviz helper (not the viewers) and so would need to be reproduced manually by the user (or the helper would need to be subclassed). Here, loading the plugin is now sufficient to apply image linking in any viewer. But if we want to support the use-case of the Imviz helper without the linking plugin, then I can add some logic to check that and just fallback on pixel linking in the helper. |
Maybe safer to wait for upstream. Even if this doesn't "introduce" per-se, looks like it is making the warning more common? |
ok, I'll move to draft for now and we can make a decision once we get an ETA on the glue-jupyter release timing. Thanks for the reviews everyone! |
Trying this out in the
|
@pllim - yes those are the changed behaviors I noticed as well. I agree that the expected behavior probably would be to always have all the slices enabled, by default, although I am honestly not sure why the changes here would revert that behavior in the last case (although I didn't dig too deeply into the code logic since I wasn't sure the expected behavior or if that was an officially supported use-case). |
In Imviz, I don't think a user would ever want to load something and not have it blink-able. 🤔
It is also curious that in |
cd74915
to
3ce9a81
Compare
@pllim - I think I have fixed the cases in the concept notebook (by delaying the loading into viewer for any new label that results from a call to |
@kecnry , I can confirm that your updated PR fixed all 3 use cases of loading slices into Imviz in the concept notebook. For fun, I tried to load more frames from the GIF into Imviz (66 slices!) by changing |
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 don't grok all the diff but seems to work for Imviz. Baby Shark is happy.
* plugin listens for new data added to DataCollection, if within batch_load, linking is skipped. * plugin also listens to exiting batch load and forces data to re-link to the plugin settings.
* add_markers has its own linking logic and calls to linking will currently erase any existing markers. Until that logic is changed/fixed, we want to skip linking immediately after adding markers to avoid them being removed as soon as they're added.
Co-authored-by: P. L. Lim <[email protected]>
* to get performance updates from minimizing unnecessary messages/events
RTD failure is just because the build started before the pip release of glue-jupyter was available (but I can re-force push to force a rebuild if anyone thinks necessary - it was passing before bumping glue-jupyter though) |
I restarted RTD build. FYI 🤞 |
|
||
[data] = [x for x in self.data_collection if x.label == data_label] | ||
color_cycler = ColorCycler() | ||
viewer.add_data(data, percentile=95, color=color_cycler()) |
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.
To do/fix soon: this implementation always produce the first color in the cycler, for all data. I'll take a look!
Blocked by
Description
This pull request
helper.batch_load
contextmanager (currently only used in Imviz)load_data
to the plugin - so that new data that are added will respect the user set linking options and not revert to "pixels". (NOTE: do we need a fallback for the case where the plugin isn't loaded?)imviz.load_data(do_link=False)
with a deprecation warning suggesting using the contextmanager instead.app.set_data_visibility(viewer_reference, data_label, visible=True, replace=False)
and updates tests that used the oldvue_data_item_visibility
(see skip viewer.add_data if already in viewer #1724 (comment))These were all quite tied together (writing deferred loading into viewer required a change in the API for the data menu), but could possibly be split into separate PRs if anyone thinks that would be useful. From a user-perspective, the change here is in how to defer linking and load multiple images into Imviz and the improved performance of toggling layers in the data menu.
Example use:
The performance gains are primarily found with an increasing number of images. For example, loading 5 layers of the Carina data set into Imviz in a loop took ~10s previously. Repeating those same 5 layers took another ~20s. With this PR, those same 5 layers take ~5-7s and does not increase significantly with repeated calls (although the visualization if the viewer is displayed will start to scale with the number of layers). The performance gains by setting WCS linking in advance of loading are even more significant. Note that most of the speed ups were not actually cause by delaying the linking (in the pixel-linking case, at least) but rather by the changes to the logic in the data menu (and by #1724).
Open questions:
app.auto_link
logic be migrated to use this internally?imviz.load_data(files, ...)
(wherefiles
is a list of filenames or objects) that makes use of this internally?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.