Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Compatibility with astropy v7.1 #3375

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 '
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message was swallowed by the ironic message that was supposed to make things clearer. I took it out of except block.

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 @@
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 @@
# 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
Loading