Skip to content

Commit 284ba7e

Browse files
author
David Turner
committed
Added a try except to catch missing annular spectra when loading in annular spectra fits in _existing_xga_products in BaseSource. Also SO much commenting for some reason
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent a37caaf commit 284ba7e

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

xga/sources/base.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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/20/26, 9:55 AM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/20/26, 10:14 AM. Copyright (c) The Contributors.
33

44
import contextlib
55
import gc
@@ -1865,9 +1865,23 @@ def parse_spectrum(row: pd.Series, combined_obs: bool):
18651865
ann_lums = {int(an_id): None for an_id in fit_ann_inv_ent['ann_id'].values}
18661866
ann_res = {int(an_id): None for an_id in fit_ann_inv_ent['ann_id'].values}
18671867

1868-
# The passing of 'tel' isn't strictly necessary, as the set-idents should be unique identifiers, but
1869-
# it is a useful visual reminder that we are in the telescope loop
1870-
rel_ann_sp = self.get_annular_spectra(set_id=fit_ann_inv_ent.iloc[0]['set_ident'], telescope=tel)
1868+
# If we trust that XGA has loaded in previously created annular spectra properly, which we
1869+
# must, then it is entirely reasonable to try to retrieve the annular spectra instance with the
1870+
# current fit's spectrum set ID.
1871+
# Hopefully the annular spectrum will be retrieved, but if it isn't present we can catch the
1872+
# error, and move on from trying to load this particular fit result. There are several reasons
1873+
# that the annular spectrum may not have been loaded in, files are missing, damaged, or moved, or
1874+
# the way the source was set up this time means that extra observations are associated - whatever
1875+
# the cause, we need to catch it and move on.
1876+
try:
1877+
# The passing of 'tel' isn't strictly necessary, as the set-idents should be unique identifiers, but
1878+
# it is a useful visual reminder that we are in the telescope loop
1879+
rel_ann_sp = self.get_annular_spectra(set_id=fit_ann_inv_ent.iloc[0]['set_ident'], telescope=tel)
1880+
1881+
# If we can't fetch the spectrum, we catch the error, and move on to the next annular spectrum
1882+
# result to be loaded in.
1883+
except NoProductAvailableError:
1884+
break
18711885

18721886
assign_res = True
18731887
for row_ind, row in fit_ann_inv_ent.iterrows():

0 commit comments

Comments
 (0)