1
1
# 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
3
3
4
4
import os
5
5
import pickle
@@ -1519,6 +1519,18 @@ def dist_from_source(reg):
1519
1519
err .args = (err .args [0 ] + "- {o} is the associated ObsID." .format (o = obs_id ), )
1520
1520
raise err
1521
1521
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 :
1522
1534
# Grab all images for the ObsID, instruments across an ObsID have the same WCS (other than in cases
1523
1535
# where they were generated with different resolutions).
1524
1536
# TODO see issue #908, figure out how to support different resolutions of image
@@ -1536,13 +1548,6 @@ def dist_from_source(reg):
1536
1548
w = None
1537
1549
else :
1538
1550
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 ]
1546
1551
1547
1552
if isinstance (ds9_regs [0 ], PixelRegion ):
1548
1553
# 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):
1569
1574
if reg_dict [obs_id ][0 ] is not None :
1570
1575
reg_dict [obs_id ] = np .append (reg_dict [obs_id ], custom_regs )
1571
1576
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 )
1573
1578
else :
1574
1579
reg_dict [obs_id ] = np .array ([None ])
1575
1580
0 commit comments