Skip to content

Commit

Permalink
fix var names in aper phot, remove specutils version check (spacetele…
Browse files Browse the repository at this point in the history
…scope#3187)

* fix var names in aper phot, remove specutils version check

* change log

* indentation
  • Loading branch information
cshanahan1 authored Sep 9, 2024
1 parent deaab79 commit 88ff8da
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ New Features
------------

- Added flux/surface brightness translation and surface brightness
unit conversion in Cubeviz and Specviz. [#2781, #2940, #3088, #3111, #3113, #3129, #3139, #3149, #3155, #3178, #3185]
unit conversion in Cubeviz and Specviz. [#2781, #2940, #3088, #3111, #3113, #3129,
#3139, #3149, #3155, #3178, #3185, #3187]

- Plugin tray is now open by default. [#2892]

Expand Down
5 changes: 1 addition & 4 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,7 @@ def calculate_moment(self, add_data=True):

# convert unit string to u.Unit so moment map data can be converted
spectral_y_display_unit = u.Unit(flux_sb_unit)
if SPECUTILS_LT_1_15_1:
moment_new_unit = spectral_y_display_unit
else:
moment_new_unit = spectral_y_display_unit * self.spectrum_viewer.state.x_display_unit # noqa: E501
moment_new_unit = spectral_y_display_unit * self.spectrum_viewer.state.x_display_unit # noqa: E501
self.moment = self.moment.to(moment_new_unit)

# Reattach the WCS so we can load the result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_cubeviz_aperphot_unit_conversion(cubeviz_helper, spectrum1d_cube_custom
# check that initial units are synced between plugins
assert uc.flux_unit.selected == 'MJy'
assert uc.angle_unit.selected == 'sr'
assert ap.display_spectral_y_unit == 'MJy / sr'
assert ap.display_unit == 'MJy / sr'
assert ap.flux_scaling_display_unit == 'MJy'

# and defaults for inputs are in the correct unit
Expand Down
46 changes: 25 additions & 21 deletions jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class SimpleAperturePhotometry(PluginTemplateMixin, ApertureSubsetSelectMixin,
# Cubeviz only
cube_slice = Unicode("").tag(sync=True)
is_cube = Bool(False).tag(sync=True)
display_spectral_y_unit = Unicode("").tag(sync=True)

# surface brightness display unit
display_unit = Unicode("").tag(sync=True)

# flux scaling display unit will always be flux, not sb
flux_scaling_display_unit = Unicode("").tag(sync=True)

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -173,7 +177,7 @@ def _on_display_units_changed(self, event={}):
if self.config == 'cubeviz':

# get previously selected display units
prev_display_spectral_y_unit = self.display_spectral_y_unit
prev_display_unit = self.display_unit
prev_flux_scale_unit = self.flux_scaling_display_unit

# update display unit traitlets to new selection
Expand All @@ -182,13 +186,13 @@ def _on_display_units_changed(self, event={}):
# convert the previous background and flux scaling values to new unit so
# re-calculating photometry with the current selections will produce
# the previous output with the new unit.
if prev_display_spectral_y_unit != '':
if prev_display_unit != '':

# convert background to new unit
if self.background_value is not None:

prev_unit = u.Unit(prev_display_spectral_y_unit)
new_unit = u.Unit(self.display_spectral_y_unit)
prev_unit = u.Unit(prev_display_unit)
new_unit = u.Unit(self.display_unit)

bg = self.background_value * prev_unit
self.background_value = bg.to_value(
Expand All @@ -206,14 +210,14 @@ def _on_display_units_changed(self, event={}):
def _set_display_unit_of_selected_dataset(self):

"""
Set the display_spectral_y_unit and flux_scaling_display_unit traitlets,
Set the display_unit and flux_scaling_display_unit traitlets,
which depend on if the selected data set is flux or surface brightness,
and the corresponding global display unit for either flux or
surface brightness.
"""

if not self.dataset_selected or not self.aperture_selected:
self.display_spectral_y_unit = ''
self.display_unit = ''
self.flux_scaling_display_unit = ''
return

Expand All @@ -225,13 +229,13 @@ def _set_display_unit_of_selected_dataset(self):
# if data is something-per-solid-angle, its a SB unit and we should
# use the selected global display unit for SB
if check_if_unit_is_per_solid_angle(comp.units):
spectral_y_type = 'sb'
display_unit_type = 'sb'
else:
spectral_y_type = 'flux'
display_unit_type = 'flux'

disp_unit = self.app._get_display_unit(spectral_y_type)
disp_unit = self.app._get_display_unit(display_unit_type)

self.display_spectral_y_unit = disp_unit
self.display_unit = disp_unit

# now get display unit for flux_scaling_display_unit. this unit will always
# be in flux, but it will not be derived from the global flux display unit
Expand All @@ -240,7 +244,7 @@ def _set_display_unit_of_selected_dataset(self):
self.flux_scaling_display_unit = fs_unit.to_string()

else:
self.display_spectral_y_unit = ''
self.display_unit = ''
self.flux_scaling_display_unit = ''

def _get_defaults_from_metadata(self, dataset=None):
Expand All @@ -263,8 +267,8 @@ def _get_defaults_from_metadata(self, dataset=None):
mjy2abmag = 0.003631

# if display unit is different, translate
if (self.config == 'cubeviz') and (self.display_spectral_y_unit != ''):
disp_unit = u.Unit(self.display_spectral_y_unit)
if (self.config == 'cubeviz') and (self.display_unit != ''):
disp_unit = u.Unit(self.display_unit)
mjy2abmag = (mjy2abmag * u.Unit("MJy/sr")).to_value(disp_unit)

if 'photometry' in meta and 'pixelarea_arcsecsq' in meta['photometry']:
Expand Down Expand Up @@ -349,7 +353,7 @@ def _dataset_selected_changed(self, event={}):

# get correct display unit for newly selected dataset
if self.config == 'cubeviz':
# set display_spectral_y_unit and flux_scaling_display_unit
# set display_unit and flux_scaling_display_unit
self._set_display_unit_of_selected_dataset()

# auto-populate background, if applicable.
Expand Down Expand Up @@ -449,9 +453,9 @@ def _calc_background_median(self, reg, data=None):

# convert to display unit, if necessary (cubeviz only)

if (self.config == 'cubeviz') and (self.display_spectral_y_unit != '') and comp.units:
if (self.config == 'cubeviz') and (self.display_unit != '') and comp.units:
bg_md = (bg_md * u.Unit(comp.units)).to_value(
u.Unit(self.display_spectral_y_unit), u.spectral_density(self._cube_wave))
u.Unit(self.display_unit), u.spectral_density(self._cube_wave))

return bg_md

Expand Down Expand Up @@ -554,7 +558,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,
img_unit = None

if self.config == 'cubeviz':
display_unit = u.Unit(self.display_spectral_y_unit)
display_unit = u.Unit(self.display_unit)

if background is not None and background not in self.background.choices: # pragma: no cover
raise ValueError(f"background must be one of {self.background.choices}")
Expand Down Expand Up @@ -734,7 +738,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,
phot_table.add_column(slice_val, name="slice_wave", index=29)

if comp.units: # convert phot. results from image unit to display unit
display_unit = u.Unit(self.display_spectral_y_unit)
display_unit = u.Unit(self.display_unit)
# convert units of certain columns in aperture phot. output table
# to reflect display units (i.e if data units are MJy / sr, but
# Jy / sr is selected in Unit Conversion plugin)
Expand Down Expand Up @@ -775,8 +779,8 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,
if update_plots:

# for cubeviz unit conversion display units
if self.display_spectral_y_unit != '':
plot_display_unit = self.display_spectral_y_unit
if self.display_unit != '':
plot_display_unit = self.display_unit
else:
plot_display_unit = None

Expand Down

0 comments on commit 88ff8da

Please sign in to comment.