From dbe14cfcdc8654ec8b1628b343b1bff7edc35cc1 Mon Sep 17 00:00:00 2001 From: James Tocknell Date: Tue, 6 Feb 2024 16:09:01 +1100 Subject: [PATCH] Minor changes to DC loaders for future surveys This makes it easier to use a fallback header and access the last spectra from a wrapper loader. These changes are to support loading some of the IFS surveys (such as SAMI) that Data Central hosts. --- specutils/io/default_loaders/dc_common.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/specutils/io/default_loaders/dc_common.py b/specutils/io/default_loaders/dc_common.py index 4315ed4b2..f5b6fe8d1 100644 --- a/specutils/io/default_loaders/dc_common.py +++ b/specutils/io/default_loaders/dc_common.py @@ -306,7 +306,12 @@ def add_single_spectra_to_map( return None if valid_wcs or not spec_wcs_info: - wcs = WCS(header) + try: + wcs = WCS(header) + except (ValueError, KeyError): + if fallback_header is None: + raise + wcs = WCS(fallback_header) if drop_wcs_axes is not None: if isinstance(drop_wcs_axes, Callable): wcs = drop_wcs_axes(wcs) @@ -352,9 +357,7 @@ def add_single_spectra_to_map( spectrum.uncertainty = UNCERTAINTY_MAP[purpose](aligned_flux) spectrum.meta["uncertainty_header"] = header - # We never actually want to return something, this just flags it to pylint - # that we know we're breaking out of the function when skip is selected - return None + return spectrum def get_purpose(