Skip to content

Commit

Permalink
adding limit to pixels shown in subset preview
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Aug 15, 2024
1 parent 972e0a7 commit 99206ff
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
4 changes: 0 additions & 4 deletions jdaviz/configs/rampviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def _set_x_axis(self, msg={}):
ref_data = group_viewer.state.reference_data
group_viewer.state.x_att = ref_data.id["Pixel Axis 0 [z]"]
group_viewer.state.y_att = ref_data.id["Pixel Axis 1 [y]"]

Check warning on line 53 in jdaviz/configs/rampviz/helper.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/helper.py#L50-L53

Added lines #L50 - L53 were not covered by tests
group_viewer.state.reset_limits()

integration_viewer = self.app.get_viewer(self._default_integration_viewer_reference_name)
integration_viewer._initialize_x_axis()

def select_group(self, group_index):
"""
Expand Down
61 changes: 44 additions & 17 deletions jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from astropy.nddata import NDDataArray

from functools import cached_property
from traitlets import Bool, Float, List, Unicode, observe
from traitlets import Bool, Float, List, Unicode, observe, Int
from glue.core.message import (
DataCollectionAddMessage, SubsetUpdateMessage, SubsetDeleteMessage
DataCollectionAddMessage, SubsetCreateMessage, SubsetDeleteMessage, SubsetUpdateMessage
)

from jdaviz.core.events import SnackbarMessage, SliceValueUpdatedMessage
Expand All @@ -26,6 +26,8 @@

__all__ = ['RampExtraction']

rng = np.random.default_rng(seed=42)


@tray_registry(
'ramp-extraction', label="Ramp Extraction", viewer_requirements='profile'
Expand All @@ -50,8 +52,10 @@ class RampExtraction(PluginTemplateMixin, ApertureSubsetSelectMixin,
"""
template_file = __file__, "ramp_extraction.vue"
uses_active_status = Bool(True).tag(sync=True)
show_live_preview = Bool(True).tag(sync=True)
show_live_preview = Bool(False).tag(sync=True)
show_subset_preview = Bool(True).tag(sync=True)
subset_preview_warning = Bool(False).tag(sync=True)
subset_preview_limit = Int(250).tag(sync=True)

active_step = Unicode().tag(sync=True)

Expand Down Expand Up @@ -109,6 +113,9 @@ def __init__(self, *args, **kwargs):
self.session.hub.subscribe(self, DataCollectionAddMessage,

Check warning on line 113 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L113

Added line #L113 was not covered by tests
handler=self._on_data_added)

self.session.hub.subscribe(self, SubsetCreateMessage,

Check warning on line 116 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L116

Added line #L116 was not covered by tests
handler=self._on_subset_update)

self.session.hub.subscribe(self, SubsetUpdateMessage,

Check warning on line 119 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L119

Added line #L119 was not covered by tests
handler=self._on_subset_update)

Expand Down Expand Up @@ -136,37 +143,46 @@ def _on_data_added(self, msg={}):
self.integration_viewer._initialize_x_axis()

Check warning on line 143 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L141-L143

Added lines #L141 - L143 were not covered by tests

def _on_subset_update(self, msg={}):

if not hasattr(self, 'aperture') or not hasattr(self.app._jdaviz_helper, 'cube_cache'):
if not hasattr(self.app._jdaviz_helper, 'cube_cache'):

Check warning on line 146 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L146

Added line #L146 was not covered by tests
# if called before fully initialized
return

Check warning on line 148 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L148

Added line #L148 was not covered by tests

if not self.show_live_preview:
# don't update subset previews if live preview is disabled:
return

subset_lbl = msg.subset.label
color = msg.subset.style.color

subset = self.app.get_subsets(subset_lbl)[0]
region = subset['region']

Check warning on line 153 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L150-L153

Added lines #L150 - L153 were not covered by tests

if region is None:
return

Check warning on line 156 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L155-L156

Added lines #L155 - L156 were not covered by tests

# glue region has transposed coords relative to cached cube:
region_mask = region.to_mask().to_image(self.cube.shape[:-1]).astype(bool).T
cube_subset = self.cube[region_mask] # shape: (N pixels extracted, M groups)

Check warning on line 160 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L159-L160

Added lines #L159 - L160 were not covered by tests

mark = [
n_pixels_in_extraction = cube_subset.shape[0]

Check warning on line 162 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L162

Added line #L162 was not covered by tests

if n_pixels_in_extraction < self.subset_preview_limit:
self.subset_preview_warning = False
select_from_cube_subset = Ellipsis

Check warning on line 166 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L164-L166

Added lines #L164 - L166 were not covered by tests
else:
self.subset_preview_warning = True
select_from_cube_subset = rng.integers(

Check warning on line 169 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L168-L169

Added lines #L168 - L169 were not covered by tests
0, n_pixels_in_extraction, size=self.subset_preview_limit
)

marks = [

Check warning on line 173 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L173

Added line #L173 was not covered by tests
PluginLine(
self.integration_viewer, x=np.arange(cube_subset.shape[1]), y=y,
stroke_width=1, colors=[color], opacities=[0.25], label=subset_lbl,
visible=False
visible=self._subset_preview_visible and subset_lbl == self.aperture.selected
)
for y in cube_subset
for y in cube_subset[select_from_cube_subset]
]

self.integration_viewer.figure.marks = [

Check warning on line 182 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L182

Added line #L182 was not covered by tests
mark for mark in self.integration_viewer.figure.marks
if getattr(mark, 'label', None) != subset_lbl
] + mark
] + marks

def _on_subset_delete(self, msg={}):
subset_lbl = msg.subset.label
Expand All @@ -182,12 +198,23 @@ def _update_subset_previews(self, msg={}):
if not hasattr(self.app._jdaviz_helper, '_default_integration_viewer_reference_name'):
return

Check warning on line 199 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L198-L199

Added lines #L198 - L199 were not covered by tests

visible = self.show_subset_preview and (self.is_active or self.keep_active)
redraw_limits = False
for mark in self.integration_viewer.figure.marks:
if isinstance(mark, PluginLine) and mark.label is not None:
mark.visible = visible and self.aperture.selected == mark.label
new_visibility = (

Check warning on line 204 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L201-L204

Added lines #L201 - L204 were not covered by tests
self._subset_preview_visible and
self.aperture.selected == mark.label
)
if mark.visible != new_visibility:
mark.visible = new_visibility
redraw_limits = True

Check warning on line 210 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L208-L210

Added lines #L208 - L210 were not covered by tests

self.integration_viewer.reset_limits()
if redraw_limits:
self.integration_viewer.reset_limits()

Check warning on line 213 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L212-L213

Added lines #L212 - L213 were not covered by tests

@property
def _subset_preview_visible(self):
return self.show_subset_preview and self.is_active

Check warning on line 217 in jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/rampviz/plugins/ramp_extraction/ramp_extraction.py#L217

Added line #L217 was not covered by tests

@property
def user_api(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<v-row>
<v-switch
v-model="show_live_preview"
label="Show live-extraction"
label="Show live ramp extraction"
hint="Whether to compute/show extraction when making changes to input parameters. Disable if live-preview becomes laggy."
persistent-hint
></v-switch>
Expand Down Expand Up @@ -47,7 +47,10 @@
label="Spatial aperture"
:hint="'Select a spatial region to extract its '+resulting_product_name+'.'"
/>

<v-alert v-if="subset_preview_warning" type='warning' style="margin-left: -12px; margin-right: -12px">
For subsets with >{{subset_preview_limit}} pixels, subset ramp previews will be shown
for {{subset_preview_limit}} randomly drawn pixels from within the subset.
</v-alert>
</div>

<div @mouseover="() => active_step='extract'">
Expand Down

0 comments on commit 99206ff

Please sign in to comment.