Skip to content

Commit f68498c

Browse files
authored
Merge pull request #1307 from DavidT3/bug/xmmRegionMatchNonFunctional
Bug/xmm region match non functional
2 parents 0d4e895 + 0655dc0 commit f68498c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

xga/sourcetools/match.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 26/07/2024, 10:56. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 14/02/2025, 09:46. Copyright (c) The Contributors
33
import gc
44
import os
55
from copy import deepcopy
@@ -265,7 +265,7 @@ def _in_region(ra: Union[float, List[float], np.ndarray], dec: Union[float, List
265265
# "search.".format(obs_id))
266266

267267
# Reading in the region file using the Regions module
268-
og_ds9_regs = Regions.read(reg_path, format='ds9').regions
268+
og_ds9_regs = np.array(Regions.read(reg_path, format='ds9').regions)
269269

270270
# Bodged declaration, the instrument and energy bounds don't matter - all I need this for is the
271271
# nice way it extracts the WCS information that I need
@@ -601,6 +601,18 @@ def xmm_region_match(src_ra: Union[float, np.ndarray], src_dec: Union[float, np.
601601
raise XGAConfigError("This function requires at least one set of images (PN, MOS1, or MOS2) be referenced in "
602602
"the XGA configuration file.")
603603

604+
# We ensure that the RA and Decs are in arrays, even if there is only one coordinate - also in the case of a
605+
# single coordinate we set the number of cores to one
606+
if type(src_ra) != type(src_dec):
607+
raise TypeError("'src_ra' and 'src_dec' arguments must be the same type; either floats or arrays.")
608+
elif isinstance(src_ra, float):
609+
src_ra = np.array([src_ra])
610+
src_dec = np.array([src_dec])
611+
num_cores = 1
612+
elif isinstance(src_ra, list):
613+
src_ra = np.array(src_ra)
614+
src_dec = np.array(src_dec)
615+
604616
# This runs the simple xmm match and gathers the results.
605617
s_match, s_match_bl = simple_xmm_match(src_ra, src_dec, num_cores=num_cores)
606618
# The initial results are then processed into some more useful formats.
@@ -666,7 +678,8 @@ def error_callback(err):
666678

667679
# If any errors occurred during the matching process, they are all raised here as a grouped exception
668680
if len(search_errors) != 0:
669-
ExceptionGroup("The following exceptions were raised in the multi-threaded region finder", search_errors)
681+
raise ExceptionGroup("The following exceptions were raised in the multi-threaded "
682+
"region finder", search_errors)
670683

671684
# This formats the match and no-match information so that the output is the same length and order as the input
672685
# source lists

0 commit comments

Comments
 (0)