Skip to content

Commit

Permalink
MNT: Compatibility with astropy v7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Dec 31, 2024
1 parent 982bebb commit f5a6eb1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ def moment_zero_unit(self):
if self.spectrum_viewer.state.x_display_unit is not None:
return (
u.Unit(self.app._get_display_unit('sb')) *
self.spectrum_viewer.state.x_display_unit
u.Unit(self.spectrum_viewer.state.x_display_unit)
)
return ''
return u.dimensionless_unscaled

@property
def spectral_unit_selected(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_cubeviz_aperphot_cube_orig_flux(cubeviz_helper, image_cube_hdu_obj_micr
# Invalid counts conversion factor
plg.counts_factor = -1
plg.vue_do_aper_phot()
assert "invalid counts" in plg.result_failed_msg
assert "cannot be negative" in plg.result_failed_msg


def test_cubeviz_aperphot_generated_3d_gaussian_smooth(cubeviz_helper, image_cube_hdu_obj_microns):
Expand Down
17 changes: 10 additions & 7 deletions jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,12 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,
if img_unit != u.count:
try:
ctfac = float(counts_factor if counts_factor is not None else self.counts_factor) # noqa: E501
if ctfac < 0:
raise ValueError('Counts conversion factor cannot be negative.')
except ValueError: # Clearer error message
raise ValueError('Missing or invalid counts conversion factor')
else:
if ctfac < 0:
raise ValueError('Counts conversion factor cannot be negative '
f'but got {ctfac}.')
if not np.allclose(ctfac, 0):
include_counts_fac = True

Expand All @@ -742,11 +744,12 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,
(self.flux_scaling is not None)):

# convert flux_scaling from flux display unit to native flux unit
flux_scaling = flux_conversion_general(self.flux_scaling,
u.Unit(self.flux_scaling_display_unit),
img_unit * self.display_solid_angle_unit,
u.spectral_density(self._cube_wave),
with_unit=False)
flux_scaling = flux_conversion_general(
self.flux_scaling,
u.Unit(self.flux_scaling_display_unit),
img_unit * u.Unit(self.display_solid_angle_unit),
u.spectral_density(self._cube_wave),
with_unit=False)

try:
flux_scale = float(flux_scaling if flux_scaling is not None else self.flux_scaling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def _uncertainty(result):
self.update_results(None)
return
# When flux is equivalent to Jy, lineflux result should be shown in W/m2
if flux_unit.is_equivalent(u.Unit('W/(m2 m)'/solid_angle_in_flux_unit)):
if flux_unit.is_equivalent(u.W / (u.m * u.m * u.m * solid_angle_in_flux_unit)):
final_unit = u.Unit(f'W/(m2 {solid_angle_string})')
else:
final_unit = u.Unit('W/m2')
Expand Down
7 changes: 6 additions & 1 deletion jdaviz/core/unit_conversion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ def flux_conversion_general(values, original_unit, target_unit,
return values
return values * original_unit

if isinstance(original_unit, str):
original_unit = u.Unit(original_unit)

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

View check run for this annotation

Codecov / codecov/patch

jdaviz/core/unit_conversion_utils.py#L306

Added line #L306 was not covered by tests
if isinstance(target_unit, str):
target_unit = u.Unit(target_unit)

solid_angle_in_orig = check_if_unit_is_per_solid_angle(original_unit,
return_unit=True)
solid_angle_in_targ = check_if_unit_is_per_solid_angle(target_unit,
Expand All @@ -315,7 +320,7 @@ def flux_conversion_general(values, original_unit, target_unit,
# the pix2 before conversion and re-apply. if this doesn't work, something else
# is going on (missing equivalency, etc)
if solid_angle_in_orig == solid_angle_in_targ == PIX2:
converted_values = (values * original_unit * PIX2).to(target_unit * PIX2)
converted_values = (values * (original_unit * PIX2)).to(target_unit * PIX2)
converted_values = converted_values / PIX2 # re-apply pix2 unit
else:
try:
Expand Down

0 comments on commit f5a6eb1

Please sign in to comment.