Skip to content

Commit

Permalink
Don't convert if display unit hasn't been initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Aug 26, 2024
1 parent b641728 commit c8f07ef
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ def _on_dataset_selected_changed(self, event={}):
datasets = self.dataset.selected_dc_item
else:
datasets = [self.dataset.selected_dc_item]

self.is_cube = False
for dataset in datasets:
# This assumes all cubes, or no cubes. If we allow photometry on collapsed cubes
# or images this will need to change.
if dataset.ndim > 2:
self.is_cube = True
break
else:
self.is_cube = False

def _on_display_units_changed(self, event={}):

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

# cubeviz: background_value set in plugin is in display units
# convert temporarily to image units for calculations
if (self.config == 'cubeviz') and (img_unit is not None):
if (self.config == 'cubeviz') and (img_unit is not None) and display_unit != '':
background_value = (background_value * display_unit).to_value(
img_unit, u.spectral_density(self._cube_wave))

Expand All @@ -580,7 +580,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,

# cubeviz: background_value set in plugin is in display units
# convert temporarily to image units for calculations
if (self.config == 'cubeviz') and (img_unit is not None):
if (self.config == 'cubeviz') and (img_unit is not None) and display_unit != '':
background_value = (background_value * display_unit).to_value(
img_unit, u.spectral_density(self._cube_wave))
else:
Expand All @@ -590,7 +590,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,

# cubeviz: computed background median will be in display units,
# convert temporarily back to image units for calculations
if (self.config == 'cubeviz') and (img_unit is not None):
if (self.config == 'cubeviz') and (img_unit is not None) and display_unit != '':
background_value = (background_value * display_unit).to_value(
img_unit, u.spectral_density(self._cube_wave))
try:
Expand Down Expand Up @@ -738,25 +738,26 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,
# 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)
phot_table['background'] = phot_table['background'].to(
display_unit, u.spectral_density(self._cube_wave))

if include_pixarea_fac:
phot_table['sum'] = phot_table['sum'].to(
(display_unit * pixarea_fac).unit, u.spectral_density(self._cube_wave))
else:
phot_table['sum'] = phot_table['sum'].to(
if display_unit != '':
phot_table['background'] = phot_table['background'].to(
display_unit, u.spectral_density(self._cube_wave))
for key in ['min', 'max', 'mean', 'median', 'mode', 'std',
'mad_std', 'biweight_location']:
phot_table[key] = phot_table[key].to(
display_unit, u.spectral_density(self._cube_wave))
for key in ['var', 'biweight_midvariance']:
try:
phot_table[key] = phot_table[key].to(display_unit**2)
# FIXME: Can fail going between per-wave and per-freq
except u.UnitConversionError:
pass

if include_pixarea_fac:
phot_table['sum'] = phot_table['sum'].to(
(display_unit * pixarea_fac).unit, u.spectral_density(self._cube_wave))
else:
phot_table['sum'] = phot_table['sum'].to(
display_unit, u.spectral_density(self._cube_wave))
for key in ['min', 'max', 'mean', 'median', 'mode', 'std',
'mad_std', 'biweight_location']:
phot_table[key] = phot_table[key].to(
display_unit, u.spectral_density(self._cube_wave))
for key in ['var', 'biweight_midvariance']:
try:
phot_table[key] = phot_table[key].to(display_unit**2)
# FIXME: Can fail going between per-wave and per-freq
except u.UnitConversionError:
pass

if add_to_table:
try:
Expand Down Expand Up @@ -1078,6 +1079,7 @@ def calculate_batch_photometry(self, options=[], add_to_table=True, update_plots
update_plots=this_update_plots,
**option)
except Exception as e:
raise
failed_iters.append(i)
if full_exceptions:
exceptions.append(e)
Expand Down

0 comments on commit c8f07ef

Please sign in to comment.