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

TST: Fix CI in v4.1.x branch #3376

Merged
merged 2 commits into from
Jan 3, 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 '
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
32 changes: 16 additions & 16 deletions jdaviz/configs/imviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,29 +420,29 @@ def test_parse_hst_drz(self, imviz_helper):
assert_allclose(sky.dec.deg, 10.802045612042956, rtol=1e-3)
data_unit = u.electron / u.s
assert_quantity_allclose(tbl[0]['background'], 0.0014 * data_unit)
assert_quantity_allclose(tbl[0]['sum'], 115.944737 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['sum'], 112.712406 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['sum_aper_area'], 2583.959958 * PIX2, rtol=1e-3)
assert_array_equal(tbl[0]['pixarea_tot'], None)
assert_array_equal(tbl[0]['aperture_sum_counts'], None)
assert_array_equal(tbl[0]['aperture_sum_counts_err'], None)
assert_array_equal(tbl[0]['counts_fac'], None)
assert_array_equal(tbl[0]['aperture_sum_mag'], None)
assert_array_equal(tbl[0]['flux_scaling'], None)
assert_quantity_allclose(tbl[0]['min'], -0.042749 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['max'], 1.588676 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['mean'], 0.04495 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['median'], 0.021585 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['mode'], -0.025143 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['std'], 0.102367 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['mad_std'], 0.023415 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['var'], 0.010479 * (data_unit * data_unit), rtol=1e-3)
assert_quantity_allclose(tbl[0]['biweight_location'], 0.021173 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['biweight_midvariance'], 0.00062 * (data_unit * data_unit), rtol=1e-3) # noqa
assert_quantity_allclose(tbl[0]['fwhm'], 21.538407 * u.pix, rtol=1e-3)
assert_quantity_allclose(tbl[0]['semimajor_sigma'], 10.04406 * u.pix, rtol=1e-3)
assert_quantity_allclose(tbl[0]['semiminor_sigma'], 8.150735 * u.pix, rtol=1e-3)
assert_quantity_allclose(tbl[0]['orientation'], 79.605418 * u.deg, rtol=1e-3)
assert_quantity_allclose(tbl[0]['eccentricity'], 0.584355, rtol=1e-3)
assert_quantity_allclose(tbl[0]['min'], -0.02422 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['max'], 1.577081 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['mean'], 0.043684 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['median'], 0.02129 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['mode'], -0.023497 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['std'], 0.09908 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['mad_std'], 0.023219 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['var'], 0.009817 * (data_unit * data_unit), rtol=1e-3)
assert_quantity_allclose(tbl[0]['biweight_location'], 0.020978 * data_unit, rtol=1e-3)
assert_quantity_allclose(tbl[0]['biweight_midvariance'], 0.000606 * (data_unit * data_unit), rtol=1e-3) # noqa
assert_quantity_allclose(tbl[0]['fwhm'], 21.230628 * u.pix, rtol=1e-3)
assert_quantity_allclose(tbl[0]['semimajor_sigma'], 9.712415 * u.pix, rtol=1e-3)
assert_quantity_allclose(tbl[0]['semiminor_sigma'], 8.260686 * u.pix, rtol=1e-3)
assert_quantity_allclose(tbl[0]['orientation'], 80.054019 * u.deg, rtol=1e-3)
assert_quantity_allclose(tbl[0]['eccentricity'], 0.525929, rtol=1e-3)

# Request specific extension (name only), use given label
imviz_helper.load_data(filename, ext='CTX', data_label='jclj01010_drz',
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)):
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, why this swap here? there are many cases of creating units from strings that aren't changed (or possible to change, i think). is this preferred when possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't comb through the whole package but I change it when I see it in the diff. There is no reason to incur extra overhead of string parsing if you already know what you want.

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