From df51b0ded6c2c2f987a1cda51d82e218ede314f5 Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Fri, 26 Apr 2024 12:44:38 -0400 Subject: [PATCH] Better default TPF stretch --- CHANGES.rst | 2 +- lcviz/parsers.py | 6 ++++++ lcviz/plugins/plot_options/plot_options.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index a8541cb2..0805c9d6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ 0.4.0 (unreleased) ------------------ -* Support loading, viewing, and slicing through TPF data cubes. [#82] +* Support loading, viewing, and slicing through TPF data cubes. [#82, #117] * Default data labels no longer include flux-origin, but do include quarter/campaign/sector. [#111] diff --git a/lcviz/parsers.py b/lcviz/parsers.py index 6b1799ed..4c32b875 100644 --- a/lcviz/parsers.py +++ b/lcviz/parsers.py @@ -4,6 +4,7 @@ import lightkurve from lcviz.viewers import PhaseScatterView, TimeScatterView +from lcviz.plugins.plot_options import PlotOptions __all__ = ["light_curve_parser"] @@ -75,6 +76,11 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw vid='image', name='image') app.add_data_to_viewer('image', new_data_label) + # set TPF viewer's stretch to custom defaults: + plot_options_plugin = PlotOptions(app=app) + if plot_options_plugin is not None: + plot_options_plugin._default_tpf_stretch() + else: if show_in_viewer: for viewer_id, viewer in app._viewer_store.items(): diff --git a/lcviz/plugins/plot_options/plot_options.py b/lcviz/plugins/plot_options/plot_options.py index b0dcb028..2fbfe387 100644 --- a/lcviz/plugins/plot_options/plot_options.py +++ b/lcviz/plugins/plot_options/plot_options.py @@ -1,3 +1,5 @@ +import numpy as np + from jdaviz.configs.default.plugins import PlotOptions from jdaviz.core.registries import tray_registry @@ -31,6 +33,20 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.docs_link = f"https://lcviz.readthedocs.io/en/{self.vdocs}/plugins.html#plot-options" + def _default_tpf_stretch( + self, vmin_percentile=5, vmax_percentile=99, tpf_viewer_reference='image' + ): + viewer = self.app.get_viewer(tpf_viewer_reference) + image = viewer.layers[0].get_image_data() + vmin, vmax = np.nanpercentile( + image, [vmin_percentile, vmax_percentile] + ) + + self.viewer_selected = tpf_viewer_reference + self.stretch_function_value = 'log' + self.stretch_vmin_value = vmin + self.stretch_vmax_value = vmax + @property def user_api(self): api = super().user_api