diff --git a/docs/specviz2d/plugins.rst b/docs/specviz2d/plugins.rst index cf1cfec10f..75e00a8faa 100644 --- a/docs/specviz2d/plugins.rst +++ b/docs/specviz2d/plugins.rst @@ -94,9 +94,11 @@ The background step of the plugin allows for creating background and background- images via `specreduce.background `_. Once you interact with any of the inputs in the background step or hover over that area -of the plugin, the live visualization will change to show the center (dotted line) and edges -(solid lines) of the background region(s). Choose between creating the background -around the trace defined in the Trace section, or around a "Manual" flat trace. +of the plugin, the live visualization in the 2d spectrum viewer will change to show the center +(dotted line) and edges (solid lines) of the background region(s). The 1D representation of the +background will also be visualized in the 1D spectrum viewer (dotted line). + +Choose between creating the background around the trace defined in the Trace section, or around a "Manual" flat trace. To visualize the resulting background or background-subtracted image, click on the respective panel, and choose a label for the new data entry. The exported images will now appear in the data dropdown @@ -108,7 +110,10 @@ To export and access the specreduce Background object defined in the plugin, cal bg = sp_ext.export_bg() -To access the background image or background-subtracted image as a :class:`~specutils.Spectrum1D` object, call :meth:`~jdaviz.configs.specviz2d.plugins.spectral_extraction.spectral_extraction.SpectralExtraction.export_bg_img` or :meth:`~jdaviz.configs.specviz2d.plugins.spectral_extraction.spectral_extraction.SpectralExtraction.export_bg_img`, respectively. +To access the background image, background spectrum, or background-subtracted image as a :class:`~specutils.Spectrum1D` object, +call :meth:`~jdaviz.configs.specviz2d.plugins.spectral_extraction.spectral_extraction.SpectralExtraction.export_bg_img`, +:meth:`~jdaviz.configs.specviz2d.plugins.spectral_extraction.spectral_extraction.SpectralExtraction.export_bg_spectrum`, +or :meth:`~jdaviz.configs.specviz2d.plugins.spectral_extraction.spectral_extraction.SpectralExtraction.export_bg_sub`, respectively. To import the parameters from a specreduce Background object into the plugin, whether it's new or was exported and modified in the notebook, call :meth:`~jdaviz.configs.specviz2d.plugins.spectral_extraction.spectral_extraction.SpectralExtraction.import_bg`:: diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py index 19aa9c529b..e43dbb14a7 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py @@ -80,6 +80,14 @@ class SpectralExtraction(PluginTemplateMixin): bg_add_to_viewer_items = List().tag(sync=True) bg_add_to_viewer_selected = Unicode().tag(sync=True) + bg_spec_results_label = Unicode().tag(sync=True) + bg_spec_results_label_default = Unicode().tag(sync=True) + bg_spec_results_label_auto = Bool(True).tag(sync=True) + bg_spec_results_label_invalid_msg = Unicode('').tag(sync=True) + bg_spec_results_label_overwrite = Bool().tag(sync=True) + bg_spec_add_to_viewer_items = List().tag(sync=True) + bg_spec_add_to_viewer_selected = Unicode().tag(sync=True) + bg_sub_results_label = Unicode().tag(sync=True) bg_sub_results_label_default = Unicode().tag(sync=True) bg_sub_results_label_auto = Bool(True).tag(sync=True) @@ -175,6 +183,16 @@ def __init__(self, *args, **kwargs): self.bg_add_results.viewer.filters = ['is_spectrum_2d_viewer'] self.bg_results_label_default = 'background' + self.bg_spec_add_results = AddResults(self, 'bg_spec_results_label', + 'bg_spec_results_label_default', + 'bg_spec_results_label_auto', + 'bg_spec_results_label_invalid_msg', + 'bg_spec_results_label_overwrite', + 'bg_spec_add_to_viewer_items', + 'bg_spec_add_to_viewer_selected') + self.bg_spec_add_results.viewer.filters = ['is_spectrum_viewer'] + self.bg_spec_results_label_default = 'background-spectrum' + self.bg_sub_add_results = AddResults(self, 'bg_sub_results_label', 'bg_sub_results_label_default', 'bg_sub_results_label_auto', @@ -312,7 +330,7 @@ def _update_plugin_marks(self, *args): 'bg': ['trace', 'bg1_center', 'bg1_lower', 'bg1_upper', 'bg2_center', 'bg2_lower', 'bg2_upper', - 'extract'], + 'bg_spec', 'extract'], 'ext': ['trace', 'ext_upper', 'ext_lower', 'extract']} @@ -353,11 +371,12 @@ def marks(self): # NOTE: += won't trigger the figure to notice new marks viewer2d.figure.marks = viewer2d.figure.marks + list(self._marks.values()) - mark1d = PluginLine(viewer1d, visible=self.plugin_opened) - self._marks['extract'] = mark1d + self._marks['extract'] = PluginLine(viewer1d, visible=self.plugin_opened) + self._marks['bg_spec'] = PluginLine(viewer1d, visible=self.plugin_opened, line_style='dotted') # noqa # NOTE: += won't trigger the figure to notice new marks - viewer1d.figure.marks = viewer1d.figure.marks + [mark1d] + viewer1d.figure.marks = viewer1d.figure.marks + [self._marks['extract'], + self._marks['bg_spec']] return self._marks @@ -397,7 +416,7 @@ def _interaction_in_bg_step(self, event={}): except Exception: # NOTE: ignore error, but will be raised when clicking ANY of the export buttons for mark in ['trace', 'bg1_center', 'bg1_lower', 'bg1_upper', - 'bg2_center', 'bg2_lower', 'bg2_upper']: + 'bg2_center', 'bg2_lower', 'bg2_upper', 'bg_spec']: self.marks[mark].clear() else: xs = range(len(trace.trace)) @@ -430,6 +449,13 @@ def _interaction_in_bg_step(self, event={}): for mark in ['bg2_center', 'bg2_lower', 'bg2_upper']: self.marks[mark].clear() + try: + spec = self.export_bg_spectrum() + except Exception: + self.marks['bg_spec'].clear() + else: + self.marks['bg_spec'].update_xy(spec.spectral_axis, spec.flux) + self.active_step = 'bg' self._update_plugin_marks() @@ -664,6 +690,28 @@ def vue_create_bg_img(self, *args): color='error', sender=self) ) + def export_bg_spectrum(self, add_data=False, **kwargs): + """ + Create a background 1D spectrum from the input parameters defined in the plugin. + + Parameters + ---------- + add_data : bool + 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() + + if add_data: + # TODO: implement new add_results + self.bg_spec_add_results.add_results_from_plugin(spec, replace=False) + + return spec + + def vue_create_bg_spec(self, *args): + self.export_bg_spectrum(add_data=True) + def export_bg_sub(self, add_data=False, **kwargs): """ Create a background-subtracted 2D spectrum from the input parameters defined in the plugin. diff --git a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue index 0b8f558078..f56c657809 100644 --- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue +++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.vue @@ -227,7 +227,7 @@ - Export Background + Export Background Image - Export Subtracted + Export Background Spectrum + + + + + + + + + + + + Export Background-Subtracted Image