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

Disallow negative counts conversion factor in Aperture Photometry #3154

Merged
merged 2 commits into from
Aug 16, 2024
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
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
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.')
kecnry marked this conversation as resolved.
Show resolved Hide resolved
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