From 969b916d53b2600b4bb673fd1dd62dcfad55d649 Mon Sep 17 00:00:00 2001 From: dahlend Date: Mon, 17 Jun 2024 10:07:14 -0700 Subject: [PATCH] Suppress WCS warnings --- CHANGELOG.md | 4 ++++ docs/tutorials/kona.rst | 5 ++++- src/neospy/irsa.py | 7 ++++++- src/neospy/wise.py | 5 ++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e20237b..ff3e9c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Significant rewrite of the SPICE kernel file management, this rewrite is required so that future work can enable writing SPICE kernel files. +### Fixed + +- Astropy WCS warnings are now suppressed. + ### Removed - Removed support for SPK Files of type 3, these should be a trivial change from type 2 diff --git a/docs/tutorials/kona.rst b/docs/tutorials/kona.rst index 98ee0ed..2001757 100644 --- a/docs/tutorials/kona.rst +++ b/docs/tutorials/kona.rst @@ -15,6 +15,7 @@ First we do some setup, including importing many needed packages. import matplotlib.pyplot as plt import numpy as np import datetime + import warnings import astropy from astropy.io import fits @@ -55,7 +56,9 @@ calculated from the corners of the frame. # Build the corner position of the FOV in RA/DEC, and build those into vectors # The WCS will raise a warning because the FITs files produced by WISE use an # old format. - frame_wcs = WCS(frame.header, relax=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore") + frame_wcs = WCS(frame.header) corners = [] dx, dy = frame_wcs.pixel_shape for x, y in zip([0, 0, dx, dx], [0, dy, dy, 0]): diff --git a/src/neospy/irsa.py b/src/neospy/irsa.py index 92cd8b5..2f9eeef 100644 --- a/src/neospy/irsa.py +++ b/src/neospy/irsa.py @@ -5,6 +5,7 @@ import time import logging import numpy as np +import warnings import pandas as pd # type: ignore import matplotlib.pyplot as plt # type: ignore from xml.etree import ElementTree @@ -194,7 +195,11 @@ def plot_fits_image(fit, vmin=-3, vmax=7, cmap="bone_r"): Color map to use for the plot. """ data = np.nan_to_num(fit.data) - wcs = WCS(fit.header, relax=True) + + with warnings.catch_warnings(): + warnings.filterwarnings("ignore") + wcs = WCS(fit.header) + if not plt.get_fignums(): plt.figure(dpi=120, figsize=(6, 6), facecolor="w") ax = plt.subplot(projection=wcs) diff --git a/src/neospy/wise.py b/src/neospy/wise.py index 51dacb6..2c78604 100644 --- a/src/neospy/wise.py +++ b/src/neospy/wise.py @@ -498,7 +498,10 @@ def plot_frames( except OSError: continue data = np.nan_to_num(fit.data) - wcs = WCS(fit.header, relax=True) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore") + wcs = WCS(fit.header) + ax = plt.subplot(2, 2, band, projection=wcs) data_no_bkg = data - np.median(data)