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

Suppress warnings about NaNs in input data from TweakRegStep #8308

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
11 changes: 10 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,23 @@ residual_fringe
- Fix a bug with 1d residual fringe zeroing out negative fluxes instead of
ignoring them. [#8261]

source_catalog
--------------

- Suppress warnings from ``photutils.background.Background2D`` regarding
NaNs in the input data. [#8308]

tweakreg
--------

- Update ``sregion`` after WCS corrections are applied. [#8158]

- Added option to choose IRAFStarFinder and segmentation.SourceFinder
- Add option to choose IRAFStarFinder and segmentation.SourceFinder
instead of DAOStarFinder and exposed star finder parameters. [#8203]

- Suppress warnings from ``photutils.background.Background2D`` regarding
NaNs in the input data. [#8308]


1.13.4 (2024-01-25)
===================
Expand Down
40 changes: 22 additions & 18 deletions jwst/source_catalog/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,26 @@ def _background2d(self):
bkg_estimator = MedianBackground()
filter_size = (3, 3)

try:
bkg = Background2D(self.data, self.box_size,
filter_size=filter_size,
coverage_mask=self.coverage_mask,
sigma_clip=sigma_clip,
bkg_estimator=bkg_estimator)
except ValueError:
# use the entire unmasked array
bkg = Background2D(self.data, self.data.shape,
filter_size=filter_size,
coverage_mask=self.coverage_mask,
sigma_clip=sigma_clip,
bkg_estimator=bkg_estimator,
exclude_percentile=100.)
log.info('Background could not be estimated in meshes. '
'Using the entire unmasked array for background '
f'estimation: bkg_boxsize={self.data.shape}.')
# All data have NaNs. Suppress warnings about them.
with warnings.catch_warnings():
warnings.filterwarnings(action="ignore", category=AstropyUserWarning)
try:
bkg = Background2D(self.data, self.box_size,
filter_size=filter_size,
coverage_mask=self.coverage_mask,
sigma_clip=sigma_clip,
bkg_estimator=bkg_estimator)
except ValueError:
# use the entire unmasked array
bkg = Background2D(self.data, self.data.shape,
filter_size=filter_size,
coverage_mask=self.coverage_mask,
sigma_clip=sigma_clip,
bkg_estimator=bkg_estimator,
exclude_percentile=100.)
log.info('Background could not be estimated in meshes. '
'Using the entire unmasked array for background '
f'estimation: bkg_boxsize={self.data.shape}.')

return bkg

Expand Down Expand Up @@ -150,8 +153,9 @@ def convolve_data(data, kernel_fwhm, mask=None):
"""
kernel = make_kernel(kernel_fwhm)

# All data have NaNs. Supress warnings about them.
with warnings.catch_warnings():
warnings.simplefilter('ignore', AstropyUserWarning)
warnings.filterwarnings(action="ignore", category=AstropyUserWarning)
return convolve(data, kernel, mask=mask, normalize_kernel=True)


Expand Down
2 changes: 1 addition & 1 deletion jwst/tweakreg/tweakreg_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def make_tweakreg_catalog(model, snr_threshold, bkg_boxsize=400, starfinder='dao
else:
raise ValueError(f"Unknown starfinder type: {starfinder}")

# Mask the non-imaging area (e.g. MIRI)
# Mask the non-imaging area, e.g. reference pixels and MIRI non-science area
coverage_mask = ((dqflags.pixel['NON_SCIENCE'] +
dqflags.pixel['DO_NOT_USE']) &
model.dq).astype(bool)
Expand Down