Skip to content

Commit

Permalink
WIP: exclude spatial subsets from legend/plot options
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Oct 17, 2024
1 parent f6a3eab commit 28a4cff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lcviz/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from traitlets import observe
from jdaviz.configs.default.plugins import PlotOptions
from jdaviz.core.registries import tray_registry
from jdaviz.utils import get_subset_type

from lcviz.viewers import CubeView

__all__ = ['PlotOptions']

Expand Down Expand Up @@ -37,6 +40,17 @@ def __init__(self, *args, **kwargs):
def _update_docs_link(self, *args):
self.docs_link = f"https://lcviz.readthedocs.io/en/{self.vdocs}/plugins.html#plot-options"

def not_spatial_subset_in_scatter_viewer(lyr):
# note: have to check the classname instead of isinstance to avoid circular import
if np.any([isinstance(viewer, CubeView)
for viewer in self.layer.viewer_objs]):
return True
# at this point, NO selected viewers are TPF Cube viewers,
# so we want to exclude spatial subsets
return get_subset_type(lyr) != 'spatial'

self.layer.add_filter(not_spatial_subset_in_scatter_viewer)

def _default_tpf_stretch(
self, vmin_percentile=5, vmax_percentile=99, tpf_viewer_reference='image'
):
Expand Down
14 changes: 14 additions & 0 deletions lcviz/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ def _apply_layer_defaults(self, layer_state):
layer_state.size = 5
layer_state.points_mode = 'markers'

def _layer_included_in_legend(self, layer, subset_type):
print("***", layer.layer.label, subset_type)
if subset_type == 'spatial':
# do not show spatial subsets in time or phase viewers
return False
return super()._layer_included_in_legend(layer, subset_type)

def set_plot_axes(self):
# set which components should be plotted
dc = self.jdaviz_app.data_collection
Expand Down Expand Up @@ -361,6 +368,13 @@ def _on_layers_update(self, layers=None):
if hasattr(layer, 'attribute') and layer.attribute != flux_comp:
layer.attribute = flux_comp

def _layer_included_in_legend(self, layer, subset_type):
print("***", layer.layer.label, subset_type)
if subset_type == 'spectral': # NOTE: spectral here means xrange (i.e. not spatial)
# ONLY show spatial subsets in image/cube viewer
return False
return super()._layer_included_in_legend(layer, subset_type)

def data(self, cls=None):
# TODO: generalize upstream in jdaviz.
# This method is generalized from
Expand Down

0 comments on commit 28a4cff

Please sign in to comment.