Skip to content

Commit

Permalink
stretch histogram vmin/vmax dynamic step size (spacetelescope#2388)
Browse files Browse the repository at this point in the history
* stretch histogram vmin/vmax dynamic step size
  • Loading branch information
kecnry authored Aug 23, 2023
1 parent 5575b64 commit eef4f64
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Imviz

- The stretch histogram within plot options can now be popped-out into its own window. [#2314]

- vmin/vmax step size in the plot options plugin is now dynamic based on the full range of the
image. [#2388]

- Footprints plugin for plotting overlays of instrument footprints in the image viewer. [#2341]

Mosviz
Expand Down
8 changes: 8 additions & 0 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class PlotOptions(PluginTemplateMixin):
stretch_preset_value = Any().tag(sync=True) # glue will pass either a float or string
stretch_preset_sync = Dict().tag(sync=True)

stretch_vstep = Float(0.1).tag(sync=True) # dynamic based on full range from image

stretch_vmin_value = Float().tag(sync=True)
stretch_vmin_sync = Dict().tag(sync=True)

Expand Down Expand Up @@ -621,6 +623,12 @@ def _update_stretch_histogram(self, msg={}):
if len(sub_data) > 0:
hist_lims = interval.get_limits(sub_data)
hist_mark.min, hist_mark.max = hist_lims
# set the stepsize for vmin/vmax to be approximately 1% of the range of the
# histogram (within the percentile interval), rounded to 1-2 significant digits
# to avoid random step sizes. This logic is somewhat arbitrary and can be safely
# modified or eventually exposed to the user if that would be useful.
stretch_vstep = (hist_lims[1] - hist_lims[0]) / 100.
self.stretch_vstep = np.round(stretch_vstep, decimals=-int(np.log10(stretch_vstep))+1) # noqa
hist_mark.bins = self.stretch_hist_nbins
# in case only the sample has changed but its length has not,
# we'll force the traitlet to trigger a change
Expand Down
18 changes: 16 additions & 2 deletions jdaviz/configs/default/plugins/plot_options/plot_options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,25 @@
</glue-state-sync-wrapper>

<glue-state-sync-wrapper :sync="stretch_vmin_sync" :multiselect="multiselect" @unmix-state="unmix_state('stretch_vmin')">
<glue-float-field label="Stretch VMin" :value.sync="stretch_vmin_value" />
<v-text-field
ref="stretch_vmin"
type="number"
label="Stretch VMin"
v-model.number="stretch_vmin_value"
type="number"
:step="stretch_vstep"
></v-text-field>
</glue-state-sync-wrapper>

<glue-state-sync-wrapper :sync="stretch_vmax_sync" :multiselect="multiselect" @unmix-state="unmix_state('stretch_vmax')">
<glue-float-field label="Stretch VMax" :value.sync="stretch_vmax_value" />
<v-text-field
ref="stretch_vmax"
type="number"
label="Stretch VMax"
v-model.number="stretch_vmax_value"
type="number"
:step="stretch_vstep"
></v-text-field>
</glue-state-sync-wrapper>

<div v-if="stretch_function_sync.in_subscribed_states">
Expand Down

0 comments on commit eef4f64

Please sign in to comment.