From 3da9aa22febea93d07840b60359143326c472c63 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 15 Nov 2022 17:03:15 -0500 Subject: [PATCH 01/12] updates for Spectrum1D support in specreduce --- .../spectral_extraction.py | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index 53d16a3a82..a6ce0edec0 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -13,8 +13,7 @@ from jdaviz.core.custom_traitlets import IntHandleEmpty, FloatHandleEmpty from jdaviz.core.marks import PluginLine -from astropy.nddata import NDData, StdDevUncertainty, VarianceUncertainty, UnknownUncertainty -from specutils import Spectrum1D +from astropy.nddata import UnknownUncertainty from specreduce import tracing from specreduce import background from specreduce import extract @@ -644,18 +643,18 @@ def export_trace(self, add_data=False, **kwargs): # being able to load back into the plugin) orig_trace = self.trace_trace.selected_obj if isinstance(orig_trace, tracing.FlatTrace): - trace = tracing.FlatTrace(self.trace_dataset.selected_obj.data, + trace = tracing.FlatTrace(self.trace_dataset.selected_obj, orig_trace.trace_pos+self.trace_offset) else: - trace = tracing.ArrayTrace(self.trace_dataset.selected_obj.data, + trace = tracing.ArrayTrace(self.trace_dataset.selected_obj, self.trace_trace.selected_obj.trace+self.trace_offset) elif self.trace_type_selected == 'Flat': - trace = tracing.FlatTrace(self.trace_dataset.selected_obj.data, + trace = tracing.FlatTrace(self.trace_dataset.selected_obj, self.trace_pixel) elif self.trace_type_selected == 'Auto': - trace = tracing.KosmosTrace(self.trace_dataset.selected_obj.data, + trace = tracing.KosmosTrace(self.trace_dataset.selected_obj, guess=self.trace_pixel, bins=int(self.trace_bins), window=self.trace_window, @@ -674,7 +673,7 @@ def vue_create_trace(self, *args): def _get_bg_trace(self): if self.bg_type_selected == 'Manual': - trace = tracing.FlatTrace(self.trace_dataset.selected_obj.data, + trace = tracing.FlatTrace(self.trace_dataset.selected_obj, self.bg_trace_pixel) elif self.bg_trace_selected == 'From Plugin': trace = self.export_trace(add_data=False) @@ -736,15 +735,15 @@ def export_bg(self, **kwargs): trace = self._get_bg_trace() if self.bg_type_selected == 'Manual': - bg = background.Background(self.bg_dataset.selected_obj.data, + bg = background.Background(self.bg_dataset.selected_obj, [trace], width=self.bg_width) elif self.bg_type_selected == 'OneSided': - bg = background.Background.one_sided(self.bg_dataset.selected_obj.data, + bg = background.Background.one_sided(self.bg_dataset.selected_obj, trace, self.bg_separation, width=self.bg_width) elif self.bg_type_selected == 'TwoSided': - bg = background.Background.two_sided(self.bg_dataset.selected_obj.data, + bg = background.Background.two_sided(self.bg_dataset.selected_obj, trace, self.bg_separation, width=self.bg_width) @@ -763,10 +762,7 @@ def export_bg_img(self, add_data=False, **kwargs): Whether to add the resulting image to the application, according to the options defined in the plugin. """ - bg = self.export_bg(**kwargs) - - bg_spec = Spectrum1D(spectral_axis=self.bg_dataset.selected_obj.spectral_axis, - flux=bg.bkg_image()*self.bg_dataset.selected_obj.flux.unit) + bg_spec = self.export_bg(**kwargs).bkg_image() if add_data: self.bg_add_results.add_results_from_plugin(bg_spec, replace=True) @@ -792,8 +788,7 @@ def export_bg_spectrum(self, add_data=False, **kwargs): Whether to add the resulting spectrum to the application, according to the options defined in the plugin. """ - bg = self.export_bg(**kwargs) - spec = bg.bkg_spectrum() + spec = self.export_bg(**kwargs).bkg_spectrum() if add_data: self.bg_spec_add_results.add_results_from_plugin(spec, replace=False) @@ -813,10 +808,7 @@ def export_bg_sub(self, add_data=False, **kwargs): Whether to add the resulting image to the application, according to the options defined in the plugin. """ - bg = self.export_bg(**kwargs) - - bg_sub_spec = Spectrum1D(spectral_axis=self.bg_dataset.selected_obj.spectral_axis, - flux=bg.sub_image()*self.bg_dataset.selected_obj.flux.unit) + bg_sub_spec = self.export_bg(**kwargs).sub_image() if add_data: self.bg_sub_add_results.add_results_from_plugin(bg_sub_spec, replace=True) @@ -867,13 +859,9 @@ def export_extract(self, **kwargs): inp_sp2d = self._get_ext_input_spectrum() if self.ext_type_selected == 'Boxcar': - ext = extract.BoxcarExtract(inp_sp2d.data, trace, width=self.ext_width) + ext = extract.BoxcarExtract(inp_sp2d, trace, width=self.ext_width) elif self.ext_type_selected == 'Horne': - uncert = inp_sp2d.uncertainty if inp_sp2d.uncertainty is not None else VarianceUncertainty(np.ones_like(inp_sp2d.data)) # noqa - if not hasattr(uncert, 'uncertainty_type'): - uncert = StdDevUncertainty(uncert) - image = NDData(inp_sp2d.data, uncertainty=uncert) - ext = extract.HorneExtract(image, trace) + ext = extract.HorneExtract(inp_sp2d, trace) else: raise NotImplementedError(f"extraction type '{self.ext_type_selected}' not supported") # noqa @@ -892,13 +880,6 @@ def export_extract_spectrum(self, add_data=False, **kwargs): extract = self.export_extract(**kwargs) spectrum = extract.spectrum - # Specreduce returns a spectral axis in pixels, so we'll replace with input spectral_axis - # NOTE: this is currently disabled until proper handling of axes-limit linking between - # the 2D spectrum image (plotted in pixels) and a 1D spectrum (plotted in freq or - # wavelength) is implemented. - - # spectrum = Spectrum1D(spectral_axis=inp_sp2d.spectral_axis, flux=spectrum.flux) - if add_data: self.ext_add_results.add_results_from_plugin(spectrum, replace=False) From f2c0099893562b9667f1b3c3d1d7e4591f19cc14 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 15 Nov 2022 17:06:16 -0500 Subject: [PATCH 02/12] TEMP: force spectrum to plot in pixel-space * revert this commit once glue handles non-linear wavelength scaling --- .../plugins/spectral_extraction/spectral_extraction.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index a6ce0edec0..845a897955 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -14,6 +14,7 @@ from jdaviz.core.marks import PluginLine from astropy.nddata import UnknownUncertainty +from astropy import units from specreduce import tracing from specreduce import background from specreduce import extract @@ -793,6 +794,10 @@ def export_bg_spectrum(self, add_data=False, **kwargs): if add_data: self.bg_spec_add_results.add_results_from_plugin(spec, replace=False) + # TEMPORARY: override spectral axis to be in pixels until properly supporting plotting + # in wavelength/frequency + spec._spectral_axis = np.arange(len(spec.spectral_axis)) * units.pix + return spec def vue_create_bg_spec(self, *args): @@ -880,6 +885,10 @@ def export_extract_spectrum(self, add_data=False, **kwargs): extract = self.export_extract(**kwargs) spectrum = extract.spectrum + # TEMPORARY: override spectral axis to be in pixels until properly supporting plotting + # in wavelength/frequency + spectrum._spectral_axis = np.arange(len(spectrum.spectral_axis)) * units.pix + if add_data: self.ext_add_results.add_results_from_plugin(spectrum, replace=False) From 0313848d6a519dfacb7f4d7c26761ffb102641c4 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 2 Dec 2022 11:58:23 -0500 Subject: [PATCH 03/12] update spectral extraction with new model types --- .../spectral_extraction.py | 32 ++++++++++++------- .../spectral_extraction.vue | 16 +++++++++- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index 845a897955..ca6cfa5aa0 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -13,6 +13,7 @@ from jdaviz.core.custom_traitlets import IntHandleEmpty, FloatHandleEmpty from jdaviz.core.marks import PluginLine +from astropy.modeling import models from astropy.nddata import UnknownUncertainty from astropy import units from specreduce import tracing @@ -21,6 +22,10 @@ __all__ = ['SpectralExtraction'] +_model_cls = {'Spline': models.Spline1D, + 'Polynomial': models.Polynomial1D, + 'Legendre': models.Legendre1D} + @tray_registry('spectral-extraction', label="Spectral Extraction", viewer_requirements=['spectrum', 'spectrum-2d']) @@ -101,6 +106,7 @@ class SpectralExtraction(PluginTemplateMixin): trace_type_selected = Unicode().tag(sync=True) trace_pixel = FloatHandleEmpty(0).tag(sync=True) + trace_order = IntHandleEmpty(3).tag(sync=True) trace_peak_method_items = List().tag(sync=True) trace_peak_method_selected = Unicode().tag(sync=True) @@ -205,7 +211,8 @@ def __init__(self, *args, **kwargs): self.trace_type = SelectPluginComponent(self, items='trace_type_items', selected='trace_type_selected', - manual_options=['Flat', 'Auto']) + manual_options=['Flat', 'Polynomial', + 'Legendre', 'Spline']) self.trace_peak_method = SelectPluginComponent(self, items='trace_peak_method_items', @@ -302,7 +309,8 @@ def __init__(self, *args, **kwargs): @property def user_api(self): return PluginUserApi(self, expose=('interactive_extract', - 'trace_dataset', 'trace_type', 'trace_peak_method', + 'trace_dataset', 'trace_type', + 'trace_order', 'trace_peak_method', 'trace_pixel', 'trace_bins', 'trace_window', 'import_trace', 'export_trace', @@ -407,7 +415,7 @@ def _update_plugin_marks(self, *args): sp1d = self.export_extract_spectrum(add_data=False) except Exception as e: # NOTE: ignore error, but will be raised when clicking ANY of the export buttons - # NOTE: KosmosTrace or manual background are often giving a + # NOTE: AutoTrace or manual background are often giving a # "background regions overlapped" error from specreduce self.ext_specreduce_err = repr(e) self.marks['extract'].clear() @@ -473,7 +481,7 @@ def marks(self): return self._marks @observe('trace_dataset_selected', 'trace_type_selected', - 'trace_trace_selected', 'trace_offset', + 'trace_trace_selected', 'trace_offset', 'trace_order', 'trace_pixel', 'trace_peak_method_selected', 'trace_bins', 'trace_window', 'active_step') def _interaction_in_trace_step(self, event={}): @@ -613,7 +621,7 @@ def import_trace(self, trace): if isinstance(trace, tracing.FlatTrace): self.trace_type_selected = 'Flat' self.trace_pixel = trace.trace_pos - elif isinstance(trace, tracing.KosmosTrace): + elif isinstance(trace, tracing.AutoTrace): self.trace_type_selected = 'Auto' self.trace_pixel = trace.guess self.trace_window = trace.window @@ -654,12 +662,14 @@ def export_trace(self, add_data=False, **kwargs): trace = tracing.FlatTrace(self.trace_dataset.selected_obj, self.trace_pixel) - elif self.trace_type_selected == 'Auto': - trace = tracing.KosmosTrace(self.trace_dataset.selected_obj, - guess=self.trace_pixel, - bins=int(self.trace_bins), - window=self.trace_window, - peak_method=self.trace_peak_method_selected.lower()) + elif self.trace_type_selected in _model_cls: + trace_model = _model_cls[self.trace_type_selected](degree=self.trace_order) + trace = tracing.AutoTrace(self.trace_dataset.selected_obj, + guess=self.trace_pixel, + bins=int(self.trace_bins), + window=self.trace_window, + peak_method=self.trace_peak_method_selected.lower(), + trace_model=trace_model) else: raise NotImplementedError(f"trace_type={self.trace_type_selected} not implemented") diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue index 0305c46723..66a0a2c1fb 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue @@ -75,6 +75,20 @@ > + + + + + - + Date: Fri, 2 Dec 2022 12:48:36 -0500 Subject: [PATCH 04/12] update to make use of FitTrace --- .../spectral_extraction.py | 26 ++++++++++--------- .../spectral_extraction.vue | 9 ++++--- .../tests/test_spectral_extraction.py | 8 +++--- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index ca6cfa5aa0..9a8142165a 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -47,12 +47,12 @@ class SpectralExtraction(PluginTemplateMixin): * ``trace_type`` (:class:`~jdaviz.core.template_mixin.SelectPluginComponent`): controls the type of trace to be generated. * ``trace_peak_method`` (:class:`~jdaviz.core.template_mixin.SelectPluginComponent`): - only applicable if ``trace_type`` is set to ``Auto``. + only applicable if ``trace_type`` is not ``Flat``. * :attr:`trace_pixel` : - pixel of the trace. If ``trace_type`` is set to ``Auto``, then this + pixel of the trace. If ``trace_type`` is not ``Flat``, then this is the "guess" for the automated trace. * :attr:`trace_bins` : - only applicable if ``trace_type`` is set to ``Auto``. + only applicable if ``trace_type`` is not ``Flat``. * :attr:`trace_window` : full width of the trace. * :meth:`import_trace` @@ -415,7 +415,7 @@ def _update_plugin_marks(self, *args): sp1d = self.export_extract_spectrum(add_data=False) except Exception as e: # NOTE: ignore error, but will be raised when clicking ANY of the export buttons - # NOTE: AutoTrace or manual background are often giving a + # NOTE: FitTrace or manual background are often giving a # "background regions overlapped" error from specreduce self.ext_specreduce_err = repr(e) self.marks['extract'].clear() @@ -621,11 +621,13 @@ def import_trace(self, trace): if isinstance(trace, tracing.FlatTrace): self.trace_type_selected = 'Flat' self.trace_pixel = trace.trace_pos - elif isinstance(trace, tracing.AutoTrace): - self.trace_type_selected = 'Auto' + elif isinstance(trace, tracing.FitTrace): + self.trace_type_selected = trace.trace_model.__class__.__name__.strip('1D') self.trace_pixel = trace.guess self.trace_window = trace.window self.trace_bins = trace.bins + if hasattr(trace.trace_model, 'degree'): + self.trace_order = trace.trace_model.degree elif isinstance(trace, tracing.ArrayTrace): # pragma: no cover raise NotImplementedError(f"cannot import ArrayTrace into plugin. Use viz.load_trace instead") # noqa else: # pragma: no cover @@ -664,12 +666,12 @@ def export_trace(self, add_data=False, **kwargs): elif self.trace_type_selected in _model_cls: trace_model = _model_cls[self.trace_type_selected](degree=self.trace_order) - trace = tracing.AutoTrace(self.trace_dataset.selected_obj, - guess=self.trace_pixel, - bins=int(self.trace_bins), - window=self.trace_window, - peak_method=self.trace_peak_method_selected.lower(), - trace_model=trace_model) + trace = tracing.FitTrace(self.trace_dataset.selected_obj, + guess=self.trace_pixel, + bins=int(self.trace_bins), + window=self.trace_window, + peak_method=self.trace_peak_method_selected.lower(), + trace_model=trace_model) else: raise NotImplementedError(f"trace_type={self.trace_type_selected} not implemented") diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue index 66a0a2c1fb..921b4cf55a 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue @@ -95,7 +95,7 @@ type="number" v-model.number="trace_pixel" :rules="[() => trace_pixel!=='' || 'This field is required']" - :hint="trace_type_selected === 'Flat' ? 'Pixel row for flat trace.' : 'Pixel row initial guess for auto trace.'" + :hint="trace_type_selected === 'Flat' ? 'Pixel row for flat trace.' : 'Pixel row initial guess for fitting the trace.'" persistent-hint > @@ -113,19 +113,20 @@ - + - + Date: Fri, 2 Dec 2022 12:47:36 -0500 Subject: [PATCH 05/12] binning toggle --- .../spectral_extraction/spectral_extraction.py | 14 ++++++++++---- .../spectral_extraction/spectral_extraction.vue | 8 +++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index 9a8142165a..c1c8a21d69 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -51,8 +51,11 @@ class SpectralExtraction(PluginTemplateMixin): * :attr:`trace_pixel` : pixel of the trace. If ``trace_type`` is not ``Flat``, then this is the "guess" for the automated trace. + * :attr:`trace_do_binning` : + only applicable if ``trace_type`` is not ``Flat``. Bin the input data when fitting the + trace. * :attr:`trace_bins` : - only applicable if ``trace_type`` is not ``Flat``. + only applicable if ``trace_type`` is not ``Flat`` and ``trace_do_binning``. * :attr:`trace_window` : full width of the trace. * :meth:`import_trace` @@ -111,6 +114,7 @@ class SpectralExtraction(PluginTemplateMixin): trace_peak_method_items = List().tag(sync=True) trace_peak_method_selected = Unicode().tag(sync=True) + trace_do_binning = Bool(True).tag(sync=True) trace_bins = IntHandleEmpty(20).tag(sync=True) trace_window = IntHandleEmpty(0).tag(sync=True) @@ -311,7 +315,8 @@ def user_api(self): return PluginUserApi(self, expose=('interactive_extract', 'trace_dataset', 'trace_type', 'trace_order', 'trace_peak_method', - 'trace_pixel', 'trace_bins', 'trace_window', + 'trace_pixel', + 'trace_do_binning', 'trace_bins', 'trace_window', 'import_trace', 'export_trace', 'bg_dataset', 'bg_type', @@ -483,7 +488,7 @@ def marks(self): @observe('trace_dataset_selected', 'trace_type_selected', 'trace_trace_selected', 'trace_offset', 'trace_order', 'trace_pixel', 'trace_peak_method_selected', - 'trace_bins', 'trace_window', 'active_step') + 'trace_do_binning', 'trace_bins', 'trace_window', 'active_step') def _interaction_in_trace_step(self, event={}): if not self.plugin_opened or not self._do_marks: return @@ -626,6 +631,7 @@ def import_trace(self, trace): self.trace_pixel = trace.guess self.trace_window = trace.window self.trace_bins = trace.bins + self.trace_do_binning = True if hasattr(trace.trace_model, 'degree'): self.trace_order = trace.trace_model.degree elif isinstance(trace, tracing.ArrayTrace): # pragma: no cover @@ -668,7 +674,7 @@ def export_trace(self, add_data=False, **kwargs): trace_model = _model_cls[self.trace_type_selected](degree=self.trace_order) trace = tracing.FitTrace(self.trace_dataset.selected_obj, guess=self.trace_pixel, - bins=int(self.trace_bins), + bins=int(self.trace_bins) if self.trace_do_binning else None, window=self.trace_window, peak_method=self.trace_peak_method_selected.lower(), trace_model=trace_model) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue index 921b4cf55a..87e5113da1 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue @@ -102,11 +102,17 @@ + From b8bd460887d323610f22c22120f47abd6f4e2c74 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 2 Dec 2022 14:23:46 -0500 Subject: [PATCH 06/12] update units in parser test --- jdaviz/configs/specviz2d/tests/test_parsers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdaviz/configs/specviz2d/tests/test_parsers.py b/jdaviz/configs/specviz2d/tests/test_parsers.py index bad8390a57..122a10fa29 100644 --- a/jdaviz/configs/specviz2d/tests/test_parsers.py +++ b/jdaviz/configs/specviz2d/tests/test_parsers.py @@ -25,8 +25,8 @@ def test_2d_parser_jwst(specviz2d_helper): assert dc_1.label == 'Spectrum 1D' assert 'header' not in dc_1.meta - # TODO: Update this when specreduce is fixed. - assert dc_1.get_component('flux').units == 'DN' + # extracted 1D spectrum should have same flux units as 2d spectrum + assert dc_1.get_component('flux').units == dc_0.get_component('flux').units # Also check the coordinates info panel. viewer_2d = specviz2d_helper.app.get_viewer('spectrum-2d-viewer') @@ -66,7 +66,7 @@ def test_2d_parser_no_unit(specviz2d_helper, mos_spectrum2d): dc_1 = specviz2d_helper.app.data_collection[1] assert dc_1.label == 'Spectrum 1D' - assert dc_1.get_component('flux').units == 'DN' + assert dc_1.get_component('flux').units == dc_0.get_component('flux').units # Also check the coordinates info panel. viewer_2d = specviz2d_helper.app.get_viewer('spectrum-2d-viewer') From 72116ed38bbde43805ee3b28c7d52683789ce329 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 2 Dec 2022 15:34:57 -0500 Subject: [PATCH 07/12] order-dependent validation for number of bins --- .../plugins/spectral_extraction/spectral_extraction.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue index 87e5113da1..35474964d2 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue @@ -112,7 +112,7 @@ type="number" v-model.number="trace_bins" :rules="[() => trace_bins!=='' || 'This field is required', - () => trace_bins>=4 || 'Bins must be >= 4']" + () => trace_bins>=Math.max(4, trace_order+1) || 'Bins must be >= '+Math.max(4, trace_order+1)]" hint="Number of bins in the dispersion direction." persistent-hint > From 9e2aedcff9d2516642e18e1f29f3bd6fde5ffb60 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 2 Dec 2022 15:37:19 -0500 Subject: [PATCH 08/12] pin specreduce 1.3 --- CHANGES.rst | 3 +++ setup.cfg | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index c24c865435..578ae64918 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -45,6 +45,9 @@ Specviz Specviz2d ^^^^^^^^^ +- Update to be compatible with changes in specreduce 1.3, including FitTrace + with Polynomial, Spline, and Legendre options. [#1889] + API Changes ----------- diff --git a/setup.cfg b/setup.cfg index 48466ad10c..271b47b7df 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = voila>=0.3.5,<0.4 pyyaml>=5.4.1 specutils>=1.9 - specreduce>=1.2.0,<1.3.0 + specreduce>=1.3.0,<1.4.0 photutils>=1.4 glue-astronomy>=0.5.1 asteval>=0.9.23 From 69574d6c7497dd68b4f3d71bccad50165c708e12 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 8 Dec 2022 13:28:54 -0500 Subject: [PATCH 09/12] re-introduce uncertainty fallbacks for HorneExtract --- .../plugins/spectral_extraction/spectral_extraction.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index c1c8a21d69..b82be475a7 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -14,7 +14,7 @@ from jdaviz.core.marks import PluginLine from astropy.modeling import models -from astropy.nddata import UnknownUncertainty +from astropy.nddata import StdDevUncertainty, VarianceUncertainty, UnknownUncertainty from astropy import units from specreduce import tracing from specreduce import background @@ -884,6 +884,10 @@ def export_extract(self, **kwargs): if self.ext_type_selected == 'Boxcar': ext = extract.BoxcarExtract(inp_sp2d, trace, width=self.ext_width) elif self.ext_type_selected == 'Horne': + if inp_sp2d.uncertainty is None: + inp_sp2d.uncertainty = VarianceUncertainty(np.ones_like(inp_sp2d.data)) + if not hasattr(inp_sp2d.uncertainty, 'uncertainty_type'): + inp_sp2d.uncertainty = StdDevUncertainty(inp_sp2d.uncert) ext = extract.HorneExtract(inp_sp2d, trace) else: raise NotImplementedError(f"extraction type '{self.ext_type_selected}' not supported") # noqa From 4dc4aaead20731bd511e3ab863c97ffb78dfed9c Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 8 Dec 2022 13:44:24 -0500 Subject: [PATCH 10/12] fix minor typo in UI --- .../plugins/spectral_extraction/spectral_extraction.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue index 35474964d2..71bb8b7168 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue @@ -334,7 +334,7 @@ :selected.sync="ext_dataset_selected" :show_if_single_entry="false" label="2D Spectrum" - hint="Select the data used to extract the spectrum. 'From Plugin' uses background-subtraced image defined in Background section above." + hint="Select the data used to extract the spectrum. 'From Plugin' uses background-subtracted image defined in Background section above." /> Date: Tue, 13 Dec 2022 09:48:11 -0500 Subject: [PATCH 11/12] add support for Chebyshev traces --- .../plugins/spectral_extraction/spectral_extraction.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index b82be475a7..30ac4df0bc 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -24,7 +24,8 @@ _model_cls = {'Spline': models.Spline1D, 'Polynomial': models.Polynomial1D, - 'Legendre': models.Legendre1D} + 'Legendre': models.Legendre1D, + 'Chebyshev': models.Chebyshev1D} @tray_registry('spectral-extraction', label="Spectral Extraction", @@ -216,7 +217,8 @@ def __init__(self, *args, **kwargs): items='trace_type_items', selected='trace_type_selected', manual_options=['Flat', 'Polynomial', - 'Legendre', 'Spline']) + 'Legendre', 'Chebyshev', + 'Spline']) self.trace_peak_method = SelectPluginComponent(self, items='trace_peak_method_items', From 8a2c7a6586dea2300c7ea6df2dbf1d987b3739ca Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 13 Dec 2022 09:55:13 -0500 Subject: [PATCH 12/12] add UI warning for slow FitTrace * separate messages shown if binning is disabled or if nbins > 20 --- .../spectral_extraction/spectral_extraction.vue | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue index 71bb8b7168..0a27ef7654 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue @@ -119,6 +119,19 @@ + + + WARNING: Trace fitting may be slow without binning. + + + + + + WARNING: Trace fitting may be slow with a large number of bins. + + + +