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

HLA-1419: Removal of warnings for photometry_utils.py log of zero of negative number #1956

4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ number of the code change for that issue. These PRs can be viewed at:
3.9.2 (unreleased)
==================

- Ignore warnings in calculation of catalog magnitudes from logarithm of zero or negative number. [1956]

- Replaced deprecated class IntegratedGaussianPRF with CircularGaussianSigmaPRF. [#1950]

- Removed python<3.13 restriction and remove some warnings. [#1936]

- build and test with latest supported version of Python [#1955]
Expand Down
12 changes: 9 additions & 3 deletions drizzlepac/haputils/photometry_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def iraf_style_photometry(phot_apertures, bg_apertures, data, photflam, photplam
if math.isclose(photflam, 0.0, abs_tol=constants.TOLERANCE):
mag_err = mag
else:
mag_err = 1.0857 * flux_error / flux
# ignores warnings from log10 of zeros and negative values
with np.errstate(divide='ignore', invalid='ignore'):
mag_err = 1.0857 * flux_error / flux
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like the flux here is the troublesome variable as there is no log computation. What is the value of mag_err here after the divide by zero?

# Set magnitude errors to infinity if flux is negative
mag_err[np.logical_not(flux>0)]=np.inf

Expand Down Expand Up @@ -235,9 +237,13 @@ def convert_flux_to_abmag(in_flux, photflam, photplam):
f_lambda = in_flux * photflam

# Convert f_lambda to STMAG
stmag = -2.5 * np.log10(f_lambda) - 21.10
# ignores warnings from log10 of zeros and negative values
with np.errstate(divide='ignore', invalid='ignore'):
stmag = -2.5 * np.log10(f_lambda) - 21.10

# Convert STMAG to ABMAG
abmag = stmag - 5.0 * np.log10(photplam) + 18.6921
# ignores warnings from log10 of zeros and negative values
with np.errstate(divide='ignore', invalid='ignore'):
abmag = stmag - 5.0 * np.log10(photplam) + 18.6921
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lines 241 and 246 introduce benign changes which eliminate lots of messages in the logs without changing the current computations. In this sense, the changes are fine. However, the Jira ticket was meant to investigate how these computations can be better handled starting from the routine which calls compute_flux_to_abmag. Should the block of code starting on Line 231 be expanded to encompass handling the flux array? If issues are handled in the initial block of code we never drop down into the log10 computations.

In the test dataset was photplam zero or negative? It is a pivot wavelength, so I am curious.


return abmag
Loading