Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generalize subset select component to handle spatial and spectral #1175

Merged
merged 10 commits into from
Mar 28, 2022
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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 @@ -273,6 +274,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
kecnry marked this conversation as resolved.
Show resolved Hide resolved
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from jdaviz.core.events import AddDataMessage, RemoveDataMessage, SnackbarMessage
from jdaviz.core.region_translators import regions2aperture
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 @@ -42,6 +42,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 @@ -65,10 +77,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')]
kecnry marked this conversation as resolved.
Show resolved Hide resolved
self.bg_subset_items = ['Manual'] + self.subset_items
kecnry marked this conversation as resolved.
Show resolved Hide resolved

@observe('data_selected')
def _data_selected_changed(self, event={}):
data_selected = event.get('new', self.data_selected)
Expand Down Expand Up @@ -116,6 +124,9 @@ def _data_selected_changed(self, event={}):
# Auto-populate background, if applicable
self._bg_subset_selected_changed()

# update self._selected_subset with the new self._selected_data
self._subset_selected_changed()

pllim marked this conversation as resolved.
Show resolved Hide resolved
def _get_region_from_subset(self, subset):
for subset_grp in self.app.data_collection.subset_groups:
if subset_grp.label == subset:
Expand All @@ -130,7 +141,7 @@ def _get_region_from_subset(self, subset):
@observe('subset_selected')
def _subset_selected_changed(self, event={}):
subset_selected = event.get('new', self.subset_selected)
if self._selected_data is None:
if self._selected_data is None or subset_selected == '':
self.reset_results()
return

Expand Down
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.']"
kecnry marked this conversation as resolved.
Show resolved Hide resolved
label="Background"
hint="Select subset region for background calculation."
/>

<v-row>
<v-text-field
Expand Down
20 changes: 13 additions & 7 deletions jdaviz/configs/imviz/tests/test_simple_aper_phot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import numpy as np
from astropy import units as u
from astropy.tests.helper import assert_quantity_allclose
Expand All @@ -19,9 +20,11 @@ def test_plugin_wcs_dithered(self):
# Make sure invalid Data/Subset selection does not crash plugin.
phot_plugin.data_selected = 'no_such_data'
assert phot_plugin._selected_data is None
phot_plugin.subset_selected = 'no_such_subset'
assert phot_plugin._selected_subset is None
phot_plugin.bg_subset_selected = 'no_such_subset'
with pytest.raises(ValueError):
# will raise an error and revert to first entry
phot_plugin.subset_selected = 'no_such_subset'
assert phot_plugin.subset_selected == ''
phot_plugin.subset_selected = phot_plugin.subset.labels[0]
assert_allclose(phot_plugin.background_value, 0)
phot_plugin.vue_do_aper_phot()
assert not phot_plugin.result_available
Expand All @@ -32,18 +35,21 @@ def test_plugin_wcs_dithered(self):
assert phot_plugin.current_plot_type == 'Radial Profile' # Software default

phot_plugin.data_selected = 'has_wcs_1[SCI,1]'
phot_plugin.subset_selected = 'no_such_subset'
assert phot_plugin._selected_subset is None
phot_plugin.bg_subset_selected = 'no_such_subset'
phot_plugin.subset_selected = phot_plugin.subset.labels[0]
with pytest.raises(ValueError):
phot_plugin.bg_subset_selected = 'no_such_subset'
assert phot_plugin.bg_subset_selected == 'Manual'
assert_allclose(phot_plugin.background_value, 0)

# Perform photometry on both images using same Subset.
phot_plugin.subset_selected = 'Subset 1'
phot_plugin.vue_do_aper_phot()
phot_plugin.data_selected = 'has_wcs_2[SCI,1]'
phot_plugin.current_plot_type = 'Radial Profile (Raw)'
assert phot_plugin._selected_data is not None
assert phot_plugin._selected_subset is not None
phot_plugin.vue_do_aper_phot()
assert phot_plugin.bg_subset_items == ['Manual', 'Subset 1']
assert phot_plugin.bg_subset.labels == ['Manual', 'Subset 1']
assert_allclose(phot_plugin.background_value, 0)
assert_allclose(phot_plugin.counts_factor, 0)
assert_allclose(phot_plugin.pixel_area, 0)
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 @@ -20,7 +20,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
from jdaviz.core.tools import ICON_DIR

__all__ = ['LineAnalysis']
Expand All @@ -39,11 +39,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 @@ -66,12 +66,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