Skip to content

Commit

Permalink
downsample stretch histogram with UI warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Aug 30, 2023
1 parent 7896cdd commit 5237237
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
29 changes: 27 additions & 2 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class PlotOptions(PluginTemplateMixin):

stretch_hist_zoom_limits = Bool().tag(sync=True)
stretch_hist_nbins = IntHandleEmpty(25).tag(sync=True)
stretch_hist_downsampled = List([0, 0]).tag(sync=True)
stretch_histogram_widget = Unicode().tag(sync=True)

stretch_curve_visible_value = Bool().tag(sync=True)
Expand Down Expand Up @@ -600,7 +601,18 @@ def _update_stretch_histogram(self, msg={}):
y_min = max(y_limits.min(), 0)
y_max = y_limits.max()

sub_data = comp.data[y_min:y_max, x_min:x_max].ravel()
arr = comp.data[y_min:y_max, x_min:x_max]

size = arr.shape[0] * arr.shape[1]
if size > 400**2:
xstep = max(1, round(arr.shape[1] / 400))
ystep = max(1, round(arr.shape[0] / 400))
arr = arr[::ystep, ::xstep]
self.stretch_hist_downsampled = [size, arr.shape[0] * arr.shape[1]]
else:
self.stretch_hist_downsampled = [size, size] # not downsampled

sub_data = arr.ravel()

else:
# spectrum-2d-viewer, for example. We'll assume the viewer
Expand All @@ -614,10 +626,23 @@ def _update_stretch_histogram(self, msg={}):
(y_data >= viewer.state.y_min) &
(y_data <= viewer.state.y_max))

# downsampling not currently implemented for 2d spectrum
self.stretch_hist_downsampled = [0, 0]

sub_data = comp.data[inds].ravel()
else:
# include all data, regardless of zoom limits
sub_data = comp.data.ravel()
arr = comp.data
size = arr.shape[0] * arr.shape[1]
if size > 400**2:
xstep = max(1, round(arr.shape[1] / 400))
ystep = max(1, round(arr.shape[0] / 400))
arr = arr[::ystep, ::xstep]
self.stretch_hist_downsampled = [size, arr.shape[0] * arr.shape[1]]
else:
self.stretch_hist_downsampled = [size, size] # not downsampled

sub_data = arr.ravel()

# filter out nans (or else bqplot will fail)
if np.any(np.isnan(sub_data)):
Expand Down
7 changes: 6 additions & 1 deletion jdaviz/configs/default/plugins/plot_options/plot_options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,12 @@
<!-- NOTE: height defined here should match that in the custom CSS rules
below for the bqplot class -->
</v-row>
<jupyter-widget :widget="stretch_histogram_widget"/>
<v-row v-if="stretch_hist_downsampled[0] > stretch_hist_downsampled[1]">
<v-alert type='info'>
Histogram samples a subset of {{stretch_hist_downsampled[1]}} out of {{stretch_hist_downsampled[0]}} pixels.
</v-alert>
</v-row>
<jupyter-widget :widget="stretch_histogram_widget"/>
</div>

<!-- IMAGE:IMAGE -->
Expand Down

0 comments on commit 5237237

Please # to comment.