From c4bb23d9b6a666126f178071f0f47fde65caf183 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 13 Apr 2023 13:18:23 -0400 Subject: [PATCH] add use_display_units kwarg to get_spectral_regions --- jdaviz/configs/specviz/helper.py | 9 +++++++-- jdaviz/configs/specviz/tests/test_helper.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/jdaviz/configs/specviz/helper.py b/jdaviz/configs/specviz/helper.py index 7692ec04be..e3cd24495b 100644 --- a/jdaviz/configs/specviz/helper.py +++ b/jdaviz/configs/specviz/helper.py @@ -128,18 +128,23 @@ def get_spectra(self, data_label=None, subset_to_apply=None, apply_slider_redshi return output_spectra - def get_spectral_regions(self): + def get_spectral_regions(self, use_display_units=False): """ A simple wrapper around the app-level call to retrieve only spectral subsets, which are now returned as SpectralRegions by default. + Parameters + ---------- + use_display_units: bool, optional + Whether to convert to the display units defined in the plugin. + Returns ------- spec_regs : dict Mapping from the names of the subsets to the subsets expressed as `specutils.SpectralRegion` objects. """ - return self.app.get_subsets(spectral_only=True) + return self.app.get_subsets(spectral_only=True, use_display_units=use_display_units) def x_limits(self, x_min=None, x_max=None): """Sets the limits of the x-axis diff --git a/jdaviz/configs/specviz/tests/test_helper.py b/jdaviz/configs/specviz/tests/test_helper.py index 2be9d6cb9c..53e8122dbd 100644 --- a/jdaviz/configs/specviz/tests/test_helper.py +++ b/jdaviz/configs/specviz/tests/test_helper.py @@ -294,16 +294,20 @@ def test_get_spectral_regions_unit_conversion(specviz_helper, spectrum1d): # Convert the wavelength axis to micron new_spectral_axis = "um" - spec_viewer.state.x_display_unit = new_spectral_axis - spec_viewer.set_plot_axes() + specviz_helper.plugins['Unit Conversion'].spectral_unit = new_spectral_axis spec_viewer.apply_roi(XRangeROI(0.6, 0.7)) # Retrieve the Subset - subsets = specviz_helper.get_spectral_regions() + subsets = specviz_helper.get_spectral_regions(use_display_units=False) + reg = subsets.get('Subset 1') + assert reg.lower.unit == u.Angstrom + assert reg.upper.unit == u.Angstrom + + subsets = specviz_helper.get_spectral_regions(use_display_units=True) reg = subsets.get('Subset 1') - assert reg.lower.unit == u.micron - assert reg.upper.unit == u.micron + assert reg.lower.unit == u.um + assert reg.upper.unit == u.um # Coordinates info panel should show new unit label_mouseover._viewer_mouse_event(spec_viewer,