Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Nov 25, 2024
1 parent f98a2b9 commit 26bc6a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,19 @@ def calculate_moment(self, add_data=True):
if n_moment == 0:
if self.moment_zero_unit != self.moment.unit:
spectral_axis_unit = u.Unit(self.spectrum_viewer.state.x_display_unit)
print(f'converting {self.moment} to {self.moment_zero_unit}. spectral_axis_unit = {spectral_axis_unit}')

# if the flux unit is a per-frequency unit but the spectral axis unit
# is a wavelength, or vice versa, we need to convert the spectral axis
# unit that the flux was integrated over so they are compatible for
# unit conversion (e.g., Jy m / sr needs to become Jy Hz / sr, and
# (erg Hz)/(s * cm**2 * AA) needs to become (erg)/(s * cm**2)
desired_freq_unit = spectral_axis_unit if spectral_axis_unit.physical_type=='frequency' else u.Hz
desired_length_unit = spectral_axis_unit if spectral_axis_unit.physical_type=='length' else u.AA
desired_freq_unit = spectral_axis_unit if spectral_axis_unit.physical_type == 'frequency' else u.Hz # noqa E501
desired_length_unit = spectral_axis_unit if spectral_axis_unit.physical_type == 'length' else u.AA # noqa E501
moment_temp = convert_integrated_sb_unit(self.moment,
spectral_axis_unit,
desired_freq_unit,
desired_length_unit)
moment_zero_unit_temp = convert_integrated_sb_unit(1 * u.Unit(self.moment_zero_unit),
moment_zero_unit_temp = convert_integrated_sb_unit(1 * u.Unit(self.moment_zero_unit), # noqa E501
spectral_axis_unit,
desired_freq_unit,
desired_length_unit)
Expand All @@ -353,9 +352,11 @@ def calculate_moment(self, add_data=True):
# for unit conversion, now back to Jy m / sr)
if spectral_axis_unit not in moment.unit.bases:
if spectral_axis_unit.physical_type == 'frequency':
moment *= (1*desired_length_unit).to(desired_freq_unit, u.spectral()) / desired_length_unit
moment *= (1*desired_length_unit).to(desired_freq_unit,

Check warning on line 355 in jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py#L355

Added line #L355 was not covered by tests
u.spectral()) / desired_length_unit
elif spectral_axis_unit.physical_type == 'length':
moment *= (1*desired_freq_unit).to(desired_length_unit, u.spectral()) / desired_freq_unit
moment *= (1*desired_freq_unit).to(desired_length_unit,
u.spectral()) / desired_freq_unit

self.moment = moment

Expand Down
6 changes: 4 additions & 2 deletions jdaviz/core/unit_conversion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,11 @@ def convert_integrated_sb_unit(u1, spectral_axis_unit, desired_freq_unit, desire

if (spectral_axis_unit.physical_type != flux_unit_type):
if flux_unit_type == 'length':
spec_axis_conversion_scale_factor = (1*spectral_axis_unit).to(desired_length_unit, u.spectral())
spec_axis_conversion_scale_factor = (1*spectral_axis_unit).to(desired_length_unit,

Check warning on line 458 in jdaviz/core/unit_conversion_utils.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/core/unit_conversion_utils.py#L458

Added line #L458 was not covered by tests
u.spectral())
elif flux_unit_type == 'frequency':
spec_axis_conversion_scale_factor = (1*spectral_axis_unit).to(desired_freq_unit, u.spectral())
spec_axis_conversion_scale_factor = (1*spectral_axis_unit).to(desired_freq_unit,
u.spectral())
else:
return u1 # units are compatible, return input

Check warning on line 464 in jdaviz/core/unit_conversion_utils.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/core/unit_conversion_utils.py#L464

Added line #L464 was not covered by tests

Expand Down

0 comments on commit 26bc6a9

Please sign in to comment.