Skip to content

Commit 9d0f484

Browse files
authored
Merge pull request #1355 from DavidT3/bug/custRegNotInArray
Bug/cust reg not in array
2 parents b820a76 + 3773c3c commit 9d0f484

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

xga/sources/base.py

Lines changed: 14 additions & 9 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/03/2025, 18:04. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 06/06/2025, 11:29. Copyright (c) The Contributors
33

44
import os
55
import pickle
@@ -1519,6 +1519,18 @@ def dist_from_source(reg):
15191519
err.args = (err.args[0] + "- {o} is the associated ObsID.".format(o=obs_id), )
15201520
raise err
15211521

1522+
# Apparently can happen that there are no regions in a region file, so if that is the case
1523+
# then I just set the ds9_regs to [None] because I know the rest of the code can deal with that.
1524+
# It can't deal with an empty list
1525+
if len(ds9_regs) == 0:
1526+
ds9_regs = [None]
1527+
else:
1528+
ds9_regs = [None]
1529+
1530+
# If either of these are fulfilled then we MUST have a WCS - even though custom regions are always
1531+
# in RA-DEC, the regions module requires a passed wcs to be able to use 'contains' - will have to
1532+
# change all this at some point
1533+
if ds9_regs[0] is not None or len(custom_regs) != 0:
15221534
# Grab all images for the ObsID, instruments across an ObsID have the same WCS (other than in cases
15231535
# where they were generated with different resolutions).
15241536
# TODO see issue #908, figure out how to support different resolutions of image
@@ -1536,13 +1548,6 @@ def dist_from_source(reg):
15361548
w = None
15371549
else:
15381550
w = ims[0].radec_wcs
1539-
# Apparently can happen that there are no regions in a region file, so if that is the case
1540-
# then I just set the ds9_regs to [None] because I know the rest of the code can deal with that.
1541-
# It can't deal with an empty list
1542-
if len(ds9_regs) == 0:
1543-
ds9_regs = [None]
1544-
else:
1545-
ds9_regs = [None]
15461551

15471552
if isinstance(ds9_regs[0], PixelRegion):
15481553
# If regions exist in pixel coordinates, we need an image WCS to convert them to RA-DEC, so we need
@@ -1569,7 +1574,7 @@ def dist_from_source(reg):
15691574
if reg_dict[obs_id][0] is not None:
15701575
reg_dict[obs_id] = np.append(reg_dict[obs_id], custom_regs)
15711576
elif reg_dict[obs_id][0] is None and len(custom_regs) != 0:
1572-
reg_dict[obs_id] = custom_regs
1577+
reg_dict[obs_id] = np.array(custom_regs)
15731578
else:
15741579
reg_dict[obs_id] = np.array([None])
15751580

0 commit comments

Comments
 (0)