Skip to content

Commit b0ab313

Browse files
author
David Turner
committed
Updated utils, BaseSource, and functions in sourcetools.match to a) support T or True in census file columns (to support censuses originating from different XGA versions), and made sure that blacklist exclude_... columns are converted to booleans.
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent 8381c26 commit b0ab313

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

xga/sources/base.py

Lines changed: 3 additions & 3 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, 12:15 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/21/26, 12:59 PM. Copyright (c) The Contributors.
33

44
import contextlib
55
import gc
@@ -264,9 +264,9 @@ def __init__(self, ra: float, dec: float, redshift: float = None, name: str = No
264264
# Extract the exact row of the current telescope's blacklist that is relevant to the current
265265
# ObsID
266266
bl_row = BLACKLIST[tel][BLACKLIST[tel]['ObsID'] == row['ObsID']].iloc[0]
267-
# Find the instruments that we need to exclude because the 'EXCLUDE_{INST}' column was marked 'T'
267+
# Find the instruments that we need to exclude because the 'EXCLUDE_{INST}' column was marked True
268268
excl_inst = [col.split('_')[-1].lower() for col in BLACKLIST[tel].columns
269-
if 'EXCLUDE' in col and bl_row[col] == 'T']
269+
if 'EXCLUDE' in col and bl_row[col]]
270270
# Add the partially excluded observation to the blacklist, with the excluded instrument
271271
blacklisted_obs[tel][row['ObsID']] = excl_inst
272272

xga/sourcetools/match.py

Lines changed: 3 additions & 3 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/18/26, 4:45 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/21/26, 1:01 PM. Copyright (c) The Contributors.
33
from __future__ import annotations
44

55
import gc
@@ -87,7 +87,7 @@ def _separation_search(ra: float, dec: float, telescope: str, search_rad: float)
8787
# the ObsID shouldn't be returned - firstly we locate the 'exclude_{INST NAME}' columns for this telescope's
8888
# blacklist
8989
excl_col = [col for col in in_bl.columns if 'EXCLUDE' in col]
90-
all_excl = in_bl[np.logical_and.reduce([in_bl[excl] == 'T' for excl in excl_col])]
90+
all_excl = in_bl[np.logical_and.reduce([in_bl[excl] for excl in excl_col])]
9191

9292
# These are the observations that a) match (within our criteria) to the supplied coordinates, and b) have at
9393
# least some usable data.
@@ -410,7 +410,7 @@ def census_match(telescope: Union[str, list] = None, obs_ids: Union[List[str], d
410410
)]['ObsID'])]
411411
# Firstly we locate the 'exclude_{INST NAME}' columns for this telescope's blacklist
412412
excl_col = [col for col in in_bl.columns if 'EXCLUDE' in col]
413-
all_excl = in_bl[np.logical_and.reduce([in_bl[excl] == 'T' for excl in excl_col])]
413+
all_excl = in_bl[np.logical_and.reduce([in_bl[excl] for excl in excl_col])]
414414

415415
# These are the observations that have at least some usable data.
416416
all_incl = rel_census[~rel_census["ObsID"].isin(all_excl["ObsID"])]

xga/utils.py

Lines changed: 6 additions & 2 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/21/26, 11:54 AM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/21/26, 12:59 PM. Copyright (c) The Contributors.
33

44
import importlib.resources
55
import json
@@ -745,7 +745,11 @@ def build_observation_census(tel: str, num_cores: int) -> Tuple[pd.DataFrame, pd
745745

746746
# Adding in columns for the instruments
747747
rel_inst_cols = ["USE_{}".format(inst.upper()) for inst in rel_insts]
748-
obs_lookup[rel_inst_cols] = obs_lookup[rel_inst_cols].apply(lambda x: x == 'T')
748+
obs_lookup[rel_inst_cols] = obs_lookup[rel_inst_cols].apply(lambda x: x.isin(['T', 'True', 't', 'true']))
749+
750+
# Also convert the blacklist columns to boolean
751+
rel_bl_cols = [col for col in blacklist.columns if 'EXCLUDE' in col]
752+
blacklist[rel_bl_cols] = blacklist[rel_bl_cols].apply(lambda x: x.isin(['T', 'True', 't', 'true']))
749753

750754
# Finally we return the census and the blacklist
751755
return obs_lookup, blacklist

0 commit comments

Comments
 (0)