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

JP-3444: update tso photometry to use ApertureStats #8672

Merged
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
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ stpipe
added a `query_step_status()` function to use as an alternative to checking
`self.skip`. [#8600]

tso_photometry
--------------

- Replaced photutils.aperture do_photometry with photutils.ApertureStats to remove NaNs
when performing TSO photometry for non SUB64 WLP8 pupil data. For SUB64 WLP8 changed
summing data in the aperture to use np.nansum to ignore NaNs. [#8672]

tweakreg
--------

Expand Down
12 changes: 12 additions & 0 deletions docs/jwst/tso_photometry/description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ the times will be computed from the exposure start time, the integration time,
and the number of integrations. In either case, the times are
Modified Julian Date, time scale UTC.

If NaNs exist in the source or background annulus, they are masked out and the value
returned is the sum over the real-valued data.
This is different from the convention for photometry in standard imaging mode:
in that case, a NaN value is returned if it is present in any of the pixels in
the source aperture. In the imaging case, the mostly likely cause of NaN pixels
in the aperture is NaN-valued central pixels for a saturated source in an image
with many sources. For TSO data, it is more likely that single pixels are affected
in a given integration and science analysis will be focused on variability of one source.
If NaNs are present, the absolute flux will be underestimated, but the relative values may still
be useful.


The output table contains these fields:

- MJD
Expand Down
27 changes: 15 additions & 12 deletions jwst/tso_photometry/tso_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from astropy.table import QTable
from astropy.time import Time, TimeDelta
import astropy.units as u
from photutils.aperture import CircularAperture, CircularAnnulus
from photutils.aperture import CircularAperture, CircularAnnulus, ApertureStats

from stdatamodels.jwst.datamodels import CubeModel

Expand Down Expand Up @@ -79,25 +79,28 @@ def tso_aperture_photometry(datamodel, xcenter, ycenter, radius, radius_inner,
'subarray. No background subtraction was performed.')

for i in np.arange(nimg):
aperture_sum.append(np.sum(datamodel.data[i, :, :]))
aperture_sum.append(np.nansum(datamodel.data[i, :, :]))
aperture_sum_err.append(
np.sqrt(np.sum(datamodel.err[i, :, :]**2)))
np.sqrt(np.nansum(datamodel.err[i, :, :]**2)))
else:
info = ('Photometry measured in a circular aperture of r={0} '
'pixels. Background calculated as the mean in a '
'circular annulus with r_inner={1} pixels and '
'r_outer={2} pixels.'.format(radius, radius_inner,
radius_outer))
for i in np.arange(nimg):
aper_sum, aper_sum_err = phot_aper.do_photometry(
datamodel.data[i, :, :], error=datamodel.err[i, :, :])
ann_sum, ann_sum_err = bkg_aper.do_photometry(
datamodel.data[i, :, :], error=datamodel.err[i, :, :])

aperture_sum.append(aper_sum[0])
aperture_sum_err.append(aper_sum_err[0])
annulus_sum.append(ann_sum[0])
annulus_sum_err.append(ann_sum_err[0])
aperstats = ApertureStats(datamodel.data[i, :, :],
phot_aper,
error=datamodel.err[i, :, :])

annstats = ApertureStats(datamodel.data[i, :, :],
bkg_aper,
error=datamodel.err[i, :, :])

aperture_sum.append(aperstats.sum)
aperture_sum_err.append(aperstats.sum_err)
annulus_sum.append(annstats.sum)
annulus_sum_err.append(annstats.sum_err)

aperture_sum = np.array(aperture_sum)
aperture_sum_err = np.array(aperture_sum_err)
Expand Down
Loading