11# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2- # Last modified by David J Turner (djturner@umbc.edu) 5/11/26, 9:43 AM . Copyright (c) The Contributors.
2+ # Last modified by David J Turner (djturner@umbc.edu) 5/11/26, 12:14 PM . Copyright (c) The Contributors.
33
44import os
55import warnings
1717
1818from . import BaseProduct , BaseAggregateProduct , BaseProfile1D
1919from ..exceptions import ModelNotAssociatedError , ParameterNotAssociatedError , XGASetIDError , NotAssociatedError , \
20- FailedProductError
20+ FailedProductError , ProductNotUsableError
2121from ..products .profile import ProjectedGasTemperature1D , ProjectedGasMetallicity1D , Generic1D , APECNormalisation1D
2222from ..utils import dict_search
2323
@@ -1786,9 +1786,11 @@ def __init__(self, spectra: List[Spectrum]):
17861786 """
17871787 # Get the unique telescope names associated with the passed spectral components
17881788 all_spec_tels = set ([s .telescope for s in spectra ])
1789+
17891790 # This should happen in the super init I think, but we'll have to do the check here as well for safety
17901791 if len (all_spec_tels ) == 0 :
17911792 raise ValueError ("No spectra have been passed to the AnnularSpectra class." )
1793+
17921794 # Currently we only support one telescope per AnnularSpectra
17931795 elif len (all_spec_tels ) > 1 :
17941796 raise NotImplementedError (f"AnnularSpectra comprised of spectra from multiple telescopes ({ all_spec_tels } ) are not "
@@ -1798,6 +1800,16 @@ def __init__(self, spectra: List[Spectrum]):
17981800 # the telescope name from the first one
17991801 telescope = spectra [0 ].telescope
18001802
1803+ # We need to check that all the passed spectra are usable - it is particularly important for spectra, as
1804+ # they actually need several different files to exist to be usable, so checking the main product
1805+ # path exists (for instance) won't cut it. Besides, why do it again when the Spectrum
1806+ # instances already did.
1807+ not_usable_reasons = {s : s .not_usable_reasons for s in spectra if not s .usable }
1808+ if len (not_usable_reasons ) != 0 :
1809+ not_usable_formatted = "\n " .join ([f"{ os .path .basename (s .path )} : \n { nur } "
1810+ for s , nur in not_usable_reasons .items ()])
1811+ raise ProductNotUsableError (f"Not all component spectra are usable:\n { not_usable_formatted } " )
1812+
18011813 super ().__init__ ([s .path for s in spectra ], 'annular_spectrum' , "combined" , "combined" , telescope = telescope )
18021814
18031815 # There shouldn't be any way this can happen, but it doesn't hurt to check that all of the spectra
0 commit comments