Skip to content

Commit

Permalink
Handle exclusive regions correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jzuhone committed Apr 23, 2024
1 parent 30c34f4 commit e1c5ac4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions soxs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,21 @@ def _region_filter(hdu, region, format="ds9", exclude=False):
pixcoords = PixCoord(hdu.data["X"], hdu.data["Y"])
if isinstance(region, Region):
region = [region]
evt_mask = False
evt_mask = np.zeros(hdu.data["ENERGY"].size, dtype="bool")
for r in region:
include_this = bool(r.meta.get("include", True))
if isinstance(r, PixelRegion):
evt_mask |= r.contains(pixcoords)
this_mask = r.contains(pixcoords)
elif isinstance(r, SkyRegion):
w = wcs_from_header(hdu.header)
skycoords = pixcoords.to_sky(w, origin=1)
evt_mask |= r.contains(skycoords, w)
this_mask = r.contains(skycoords, w)
else:
raise NotImplementedError
if include_this:
evt_mask |= this_mask
else:
evt_mask &= this_mask
if exclude:
evt_mask = ~evt_mask
return evt_mask
Expand Down

0 comments on commit e1c5ac4

Please sign in to comment.