Skip to content

Commit

Permalink
Disallow negative counts conversion factor in Aperture Photometry (#3154
Browse files Browse the repository at this point in the history
)

* Disallow negative counts conversion factor
in not-so-simple-anymore-too-bad aperture photometry plugin.

* Fancier front-end checks.

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>

---------

Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>
  • Loading branch information
pllim and kecnry authored Aug 16, 2024
1 parent 3976983 commit acdc0ca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^

Expand Down
5 changes: 5 additions & 0 deletions jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.']"
>
</v-text-field>
</v-row>
Expand Down Expand Up @@ -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
</plugin-action-button>
Expand Down

0 comments on commit acdc0ca

Please sign in to comment.