Skip to content

Commit

Permalink
add use_display_units kwarg to get_spectral_regions
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Apr 13, 2023
1 parent ee12c73 commit c4bb23d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 7 additions & 2 deletions jdaviz/configs/specviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <unit-conversion> 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
Expand Down
14 changes: 9 additions & 5 deletions jdaviz/configs/specviz/tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c4bb23d

Please sign in to comment.