Skip to content

Commit

Permalink
JP-3148: Trap source catalog errors in tweakreg (spacetelescope#7507)
Browse files Browse the repository at this point in the history
* JP-3148: Trap source catalog errors in tweakreg

* add change log entry

* Incorporate Mihai's suggestions

* update change log
  • Loading branch information
hbushouse authored Mar 29, 2023
1 parent 81084e0 commit 80eaaf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
7 changes: 5 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ ramp_fitting
- Update ramp fitting to calculate separate readnoise variance for processing
``undersampling_correction`` output [#7484]


resample
--------

Expand Down Expand Up @@ -138,15 +137,16 @@ straylight

- Fix bug with straylight zeroing out NaNs in input rate images, as these
are now deliberately set as such [#7455]
- Move ``jwst.datamodels`` out of ``jwst`` into ``stdatamodels.jwst.datamodels``. [#7439]

scripts
-------

- Added a script ``adjust_wcs.py`` to apply additional user-provided rotations
and scale corrections to an imaging WCS of a calibrated image. [#7430]

- Update ``minimum_deps`` script to use ``importlib_metadata`` and ``packaging``
instead of ``pkg_resources``. [#7457]

- Offload ``minimum_deps`` script to ``minimum_dependencies`` package [#7463]

transforms
Expand All @@ -167,6 +167,9 @@ tweakreg
- Fixed a bug due to which alignment may be aborted due to corrections
being "too large" yet compatible with step parameters. [#7494]

- Added a trap for failures in source catalog construction, which now returns
an empty catalog for the image on which the error occurred. [#7507]

undersampling_correction
------------------------

Expand Down
19 changes: 15 additions & 4 deletions jwst/tweakreg/tweakreg_catalog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from astropy.table import Table
import numpy as np
from photutils.detection import DAOStarFinder
Expand All @@ -6,6 +8,9 @@

from ..source_catalog.detection import JWSTBackground

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


def make_tweakreg_catalog(model, kernel_fwhm, snr_threshold, sharplo=0.2,
sharphi=1.0, roundlo=-1.0, roundhi=1.0,
Expand Down Expand Up @@ -73,10 +78,17 @@ def make_tweakreg_catalog(model, kernel_fwhm, snr_threshold, sharplo=0.2,
dqflags.pixel['DO_NOT_USE']) &
model.dq).astype(bool)

bkg = JWSTBackground(model.data, box_size=bkg_boxsize,
coverage_mask=coverage_mask)
columns = ['id', 'xcentroid', 'ycentroid', 'flux']
try:
bkg = JWSTBackground(model.data, box_size=bkg_boxsize,
coverage_mask=coverage_mask)
threshold_img = bkg.background + (snr_threshold * bkg.background_rms)
except ValueError as e:
log.warning(f"Error determining sky background: {e.args[0]}")
# return an empty catalog
catalog = Table(names=columns, dtype=(int, float, float, float))
return catalog

threshold_img = bkg.background + (snr_threshold * bkg.background_rms)
threshold = np.median(threshold_img) # DAOStarFinder requires float

daofind = DAOStarFinder(fwhm=kernel_fwhm, threshold=threshold,
Expand All @@ -85,7 +97,6 @@ def make_tweakreg_catalog(model, kernel_fwhm, snr_threshold, sharplo=0.2,
peakmax=peakmax)
sources = daofind(model.data, mask=coverage_mask)

columns = ['id', 'xcentroid', 'ycentroid', 'flux']
if sources:
catalog = sources[columns]
else:
Expand Down

0 comments on commit 80eaaf7

Please sign in to comment.