Skip to content

Commit a9b5fd3

Browse files
committed
Suppress NaN warnings with context manager.
1 parent feedc15 commit a9b5fd3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/hats/inspection/visualize_catalog.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ def get_fov_moc_from_wcs(wcs: WCS) -> MOC | None:
236236
y_px = np.append(y_px, y[1:, 0][::-1])
237237

238238
# Disable the output of warnings when encoutering NaNs.
239-
warnings.filterwarnings("ignore")
240-
# Inverse projection from pixel coordinate space to the world coordinate space
241-
viewport = pixel_to_skycoord(x_px, y_px, wcs)
242-
# If one coordinate is a NaN we exit the function and do not go further
243-
ra_deg, dec_deg = viewport.icrs.ra.deg, viewport.icrs.dec.deg
244-
warnings.filterwarnings("default")
239+
with warnings.catch_warnings():
240+
warnings.simplefilter("ignore")
241+
# Inverse projection from pixel coordinate space to the world coordinate space
242+
viewport = pixel_to_skycoord(x_px, y_px, wcs)
243+
# If one coordinate is a NaN we exit the function and do not go further
244+
ra_deg, dec_deg = viewport.icrs.ra.deg, viewport.icrs.dec.deg
245245

246246
if np.isnan(ra_deg).any() or np.isnan(dec_deg).any():
247247
return None

0 commit comments

Comments
 (0)