diff --git a/CHANGES.rst b/CHANGES.rst index 7c13c942af..e0469340fc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -111,6 +111,8 @@ Bug Fixes world and pixel (previously containing SkyCoord and pixel location tuples, respectively) are now each two separate columns for world_ra/world_dec and pixel_x/pixel_y, respectively. [#3089] +- Aperture Photometry plugin no longer allows negative counts conversion factor. [#3154] + Cubeviz ^^^^^^^ diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py index 032c9fa2ad..c600ee01c9 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py @@ -80,6 +80,11 @@ def test_cubeviz_aperphot_cube_orig_flux(cubeviz_helper, image_cube_hdu_obj_micr assert_allclose(row["mean"], 36 * flux_unit) assert np.isnan(row["slice_wave"]) + # Invalid counts conversion factor + plg.counts_factor = -1 + plg.vue_do_aper_phot() + assert "invalid counts" in plg.result_failed_msg + def test_cubeviz_aperphot_generated_3d_gaussian_smooth(cubeviz_helper, image_cube_hdu_obj_microns): cubeviz_helper.load_data(image_cube_hdu_obj_microns, data_label="test") diff --git a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py index bf9d63be8e..418bbadfef 100644 --- a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py +++ b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py @@ -637,7 +637,9 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None, include_pixarea_fac = True if img_unit != u.count: try: - ctfac = float(counts_factor if counts_factor is not None else self.counts_factor) # noqa + 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') if not np.allclose(ctfac, 0): diff --git a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue index 0bdf42bbe1..7391f01d86 100644 --- a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue +++ b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue @@ -113,6 +113,7 @@ type="number" hint="Factor to convert data unit to counts, in unit of flux/counts" persistent-hint + :rules="[() => counts_factor>=0 || 'Counts conversion factor cannot be negative.']" > @@ -175,7 +176,7 @@ :results_isolated_to_plugin="true" @click="do_aper_phot" :spinner="spinner" - :disabled="aperture_selected === background_selected || !aperture_selected_validity.is_aperture" + :disabled="aperture_selected === background_selected || !aperture_selected_validity.is_aperture || counts_factor < 0" > Calculate