Skip to content

Commit

Permalink
Update continuum, moment maps, and spectral extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
javerbukh committed Mar 19, 2024
1 parent 70a27fd commit 9257b59
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ def get_aperture(self):
# Retrieve flux cube and create an array to represent the cone mask
flux_cube = self._app._jdaviz_helper._loaded_flux_cube.get_object(cls=Spectrum1D,
statistic=None)
# TODO: Replace with code for retrieving display_unit in cubeviz when it is available
display_unit = flux_cube.spectral_axis.unit
display_unit = astropy.units.Unit(self.app._get_display_unit('spectral'))

# Center is reverse coordinates
center = (self.aperture.selected_spatial_region.center.y,
Expand All @@ -367,7 +366,7 @@ def get_aperture(self):
f'Spectral axis unit physical type is {display_unit.physical_type}, '
'must be length for cone aperture')

fac = flux_cube.spectral_axis.value / self.reference_wavelength
fac = flux_cube.spectral_axis.to(display_unit).value / self.reference_wavelength

# TODO: Use flux_cube.spectral_axis.to_value(display_unit) when we have unit conversion.
if isinstance(aperture, CircularAperture):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ def _on_spectral_unit_changed(self, *args):
xunit = _valid_glue_display_unit(self.spectral_unit.selected, self.spectrum_viewer, 'x')
if self.spectrum_viewer.state.x_display_unit != xunit:
self.spectrum_viewer.state.x_display_unit = xunit
self.hub.broadcast(GlobalDisplayUnitChanged('spectral',
self.spectral_unit.selected,
sender=self))
self.hub.broadcast(GlobalDisplayUnitChanged('spectral',
self.spectral_unit.selected,
sender=self))

@observe('flux_unit_selected')
def _on_flux_unit_changed(self, *args):
yunit = _valid_glue_display_unit(self.flux_unit.selected, self.spectrum_viewer, 'y')
if self.spectrum_viewer.state.y_display_unit != yunit:
self.spectrum_viewer.state.y_display_unit = yunit
self.hub.broadcast(GlobalDisplayUnitChanged('flux',
self.flux_unit.selected,
sender=self))
self.hub.broadcast(GlobalDisplayUnitChanged('flux',
self.flux_unit.selected,
sender=self))
3 changes: 2 additions & 1 deletion jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ def _handle_display_units(data, use_display_units):
u.spectral()),
flux=data.flux.to(flux_unit,
u.spectral_density(data.spectral_axis)),
uncertainty=new_uncert)
uncertainty=new_uncert,
mask=data.mask)
else: # pragma: nocover
raise NotImplementedError(f"converting {data.__class__.__name__} to display units is not supported") # noqa
return data
Expand Down
5 changes: 3 additions & 2 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,8 @@ def _get_continuum(self, dataset, spatial_subset, spectral_subset, update_marks=
if spatial_subset == 'per-pixel':
if self.app.config != 'cubeviz':
raise ValueError("per-pixel only supported for cubeviz")
full_spectrum = self.dataset.selected_obj
full_spectrum = self.app._jdaviz_helper.get_data(self.dataset.selected,
use_display_units=True)
else:
full_spectrum = dataset.selected_spectrum_for_spatial_subset(spatial_subset.selected if spatial_subset is not None else None, # noqa
use_display_units=True)
Expand Down Expand Up @@ -2533,7 +2534,7 @@ def _get_continuum(self, dataset, spatial_subset, spectral_subset, update_marks=
continuum_mask = ~self._specviz_helper.get_data(
dataset.selected,
spectral_subset=self.continuum_subset_selected,
use_display_units=False).mask
use_display_units=True).mask
spectral_axis_nanmasked = spectral_axis.value.copy()
spectral_axis_nanmasked[~continuum_mask] = np.nan
if not update_marks:
Expand Down

0 comments on commit 9257b59

Please sign in to comment.