Skip to content

Commit

Permalink
generalize subset select component to handle spatial and spectral
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Mar 17, 2022
1 parent d72c718 commit 1f31e99
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 91 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Other Changes and Additions
- Redshifts imported with a custom line list are now ignored. Redshift must be set app-wide via
viz.set_redshift or the line list plugin. [#1134]

- Subset selection dropdowns in plugins now show synced color indicators. [#1156]
- Subset selection dropdowns in plugins now show synced color indicators. [#1156, #1175]

2.3 (2022-03-01)
================
Expand Down
8 changes: 4 additions & 4 deletions jdaviz/components/plugin_subset_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
:items="items"
v-model="selected"
@change="$emit('update:selected', $event)"
:label="label ? label : 'Spectral Region'"
:hint="hint ? hint : 'Select spectral region.'"
:label="label ? label : 'Subset'"
:hint="hint ? hint : 'Select subset.'"
:rules="rules ? rules : []"
item-text="label"
item-value="label"
Expand All @@ -15,7 +15,7 @@
<template slot="selection" slot-scope="data">
<div class="single-line">
<v-icon v-if="data.item.color" left :color="data.item.color">
mdi-chart-bell-curve
{{ data.item.type=='spectral' ? 'mdi-chart-bell-curve' : 'mdi-chart-scatter-plot' }}
</v-icon>
<span>
{{ data.item.label }}
Expand All @@ -25,7 +25,7 @@
<template slot="item" slot-scope="data">
<div class="single-line">
<v-icon v-if="data.item.color" left :color="data.item.color">
mdi-chart-bell-curve
{{ data.item.type=='spectral' ? 'mdi-chart-bell-curve' : 'mdi-chart-scatter-plot' }}
</v-icon>
<span>
{{ data.item.label }}
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
:selected.sync="spectral_subset_selected"
:has_subregions="spectral_subset_selected_has_subregions"
has_subregions_warning="The selected selected subset has subregions, the entire range will be used, ignoring any gaps."
label="Spectral region"
hint="Spectral region to compute the moment map."
/>

Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/default/plugins/collapse/collapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
:selected.sync="spectral_subset_selected"
:has_subregions="spectral_subset_selected_has_subregions"
has_subregions_warning="The selected selected subset has subregions, the entire range will be used, ignoring any gaps."
label="Spectral region"
hint="Select spectral region to apply the collapse."
/>

Expand Down
5 changes: 5 additions & 0 deletions jdaviz/configs/default/plugins/model_fitting/model_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ModelFitting(PluginTemplateMixin, SpectralSubsetSelectMixin):
available_models = List(list(MODELS.keys())).tag(sync=True)

def __init__(self, *args, **kwargs):
self._spectrum1d = None
super().__init__(*args, **kwargs)

self._units = {}
Expand Down Expand Up @@ -274,6 +275,10 @@ def _selected_data_changed(self, event):
@observe("spectral_subset_selected")
def _on_spectral_subset_selected(self, event):
# If "Entire Spectrum" selected, reset based on bounds of selected data
if self._spectrum1d is None:
# TODO: this should be removed as soon as the data dropdown component is
# created and defaults at init
return
if self.spectral_subset_selected == "Entire Spectrum":
self._window = None
self.spectral_min = self._spectrum1d.spectral_axis[0].value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<plugin-subset-select
:items="spectral_subset_items"
:selected.sync="spectral_subset_selected"
label="Spectral region"
hint="Select spectral region to fit."
/>
</v-form>
Expand Down
18 changes: 13 additions & 5 deletions jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from jdaviz.configs.imviz.helper import layer_is_image_data
from jdaviz.core.events import AddDataMessage, RemoveDataMessage, SnackbarMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import TemplateMixin
from jdaviz.core.template_mixin import TemplateMixin, SubsetSelect

__all__ = ['SimpleAperturePhotometry']

Expand Down Expand Up @@ -41,6 +41,18 @@ class SimpleAperturePhotometry(TemplateMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.subset = SubsetSelect(self,
'subset_items',
'subset_selected',
default_text=None,
allowed_type='spatial')

self.bg_subset = SubsetSelect(self,
'bg_subset_items',
'bg_subset_selected',
default_text='Manual',
allowed_type='spatial')

self.hub.subscribe(self, AddDataMessage, handler=self._on_viewer_data_changed)
self.hub.subscribe(self, RemoveDataMessage, handler=self._on_viewer_data_changed)
self.hub.subscribe(self, SubsetCreateMessage, handler=self._on_viewer_data_changed)
Expand All @@ -64,10 +76,6 @@ def _on_viewer_data_changed(self, msg=None):
self.dc_items = [lyr.label for lyr in self.app.data_collection
if layer_is_image_data(lyr)]

self.subset_items = [lyr.label for lyr in self.app.data_collection.subset_groups
if lyr.label.startswith('Subset')]
self.bg_subset_items = ['Manual'] + self.subset_items

@observe('data_selected')
def _data_selected_changed(self, event={}):
data_selected = event.get('new', self.data_selected)
Expand Down
31 changes: 13 additions & 18 deletions jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@
</v-row>

<div v-if='data_selected'>
<v-row>
<v-select
:items="subset_items"
v-model="subset_selected"
label="Subset"
hint="Select subset region for photometry."
persistent-hint
></v-select>
</v-row>
<plugin-subset-select
:items="subset_items"
:selected.sync="subset_selected"
label="Aperture"
hint="Select aperture region for photometry."
/>

<div v-if="subset_selected">
<v-row>
<v-select
:items="bg_subset_items"
v-model="bg_subset_selected"
label="Subset (background)"
hint="Select subset region for background calculation."
persistent-hint
></v-select>
</v-row>
<plugin-subset-select
:items="bg_subset_items"
:selected.sync="bg_subset_selected"
:rules="[() => bg_subset_selected!==subset_selected || 'Must not match aperture.']"
label="Background"
hint="Select subset region for background calculation."
/>

<v-row>
<v-text-field
Expand Down
26 changes: 15 additions & 11 deletions jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
LineAnalysisContinuumRight,
Shadow)
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import PluginTemplateMixin, SpectralSubsetSelect
from jdaviz.core.template_mixin import PluginTemplateMixin, SubsetSelect

__all__ = ['LineAnalysis']

Expand All @@ -31,11 +31,11 @@ class LineAnalysis(PluginTemplateMixin):
dc_items = List([]).tag(sync=True)
selected_spectrum = Unicode("").tag(sync=True)

spectral_subset_items = List([{"label": "Entire Spectrum", "color": False}]).tag(sync=True)
spectral_subset_selected = Unicode("Entire Spectrum").tag(sync=True)
spectral_subset_items = List().tag(sync=True)
spectral_subset_selected = Unicode().tag(sync=True)

continuum_subset_items = List([{"label": "Surrounding", "color": False}]).tag(sync=True)
continuum_selected = Unicode("Surrounding").tag(sync=True)
continuum_subset_items = List().tag(sync=True)
continuum_selected = Unicode().tag(sync=True)

width = FloatHandleEmpty(3).tag(sync=True)
results_computing = Bool(False).tag(sync=True)
Expand All @@ -50,12 +50,16 @@ def __init__(self, *args, **kwargs):
self._units = {}
self.update_results(None)

self.spectral_subset = SpectralSubsetSelect(self,
'spectral_subset_items',
'spectral_subset_selected')
self.continuum = SpectralSubsetSelect(self,
'continuum_subset_items',
'continuum_selected')
self.spectral_subset = SubsetSelect(self,
'spectral_subset_items',
'spectral_subset_selected',
default_text="Entire Spectrum",
allowed_type='spectral')
self.continuum = SubsetSelect(self,
'continuum_subset_items',
'continuum_selected',
default_text='Surrounding',
allowed_type='spectral')

self.hub.subscribe(self, AddDataMessage,
handler=self._on_viewer_data_changed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<plugin-subset-select
:items="spectral_subset_items"
:selected.sync="spectral_subset_selected"
label="Spectral region"
hint="Select spectral region that defines the line."
/>

Expand All @@ -40,7 +41,8 @@
:items="continuum_subset_items"
:selected.sync="continuum_selected"
:rules="[() => continuum_selected!==spectral_subset_selected || 'Must not match line selection.']"
hint="Select spectral region that defines the line."
label="Continuum"
hint="Select spectral region that defines the continuum."
/>

<v-row v-if="continuum_selected=='Surrounding' && spectral_subset_selected!='Entire Spectrum'">
Expand Down
Loading

0 comments on commit 1f31e99

Please sign in to comment.