New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map region mask #1421

Merged
merged 7 commits into from Jun 3, 2018

changed to geom.get_region_mask_array and added new calls scheme for …

…region.contains
  • Loading branch information...
registerrier committed May 23, 2018
commit a5c2d44c355e7c3c122dc57bafe932c3e732db54
@@ -381,13 +381,13 @@ def test_coadd_unit():
def test_make_region_mask():
from regions import CircleSkyRegion
geom = WcsGeom.create(npix=(11,11), binsz=2,
geom = WcsGeom.create(npix=(3,3), binsz=2,
proj='CAR', coordsys='GAL')
m = WcsNDMap(geom)
region = CircleSkyRegion(SkyCoord(0, 0, unit='deg', frame='galactic'), 1.0*u.deg)
maskmap = m.make_region_mask(region)
assert np.sum(maskmap.data) == 1

This comment has been minimized.

@cdeil

cdeil May 29, 2018

Member

Suggest to add an assert on the dtype of data. It's bool, no?

@cdeil

cdeil May 29, 2018

Member

Suggest to add an assert on the dtype of data. It's bool, no?

This comment has been minimized.

@registerrier

registerrier Jun 1, 2018

Contributor

Done

@registerrier

registerrier Jun 1, 2018

Contributor

Done

maskmap = m.make_region_mask(region, inside=False)
assert np.sum(maskmap.data) == 120
assert np.sum(maskmap.data) == 8
View
@@ -635,15 +635,20 @@ def solid_angle(self):
return u.Quantity(dx * dy, 'sr')
def get_region_idx(self, region):
"""Return idx of pixels inside region
def get_region_mask_array(self, region):
"""Return mask of pixels inside region in the the form of boolean array
TODO: implement list of region for each axis

This comment has been minimized.

@cdeil

cdeil May 29, 2018

Member

I think in my last comment I suggested to remove this TODO (and also in the code below) and to instead show how to do this via a docs example.

@cdeil

cdeil May 29, 2018

Member

I think in my last comment I suggested to remove this TODO (and also in the code below) and to instead show how to do this via a docs example.

This comment has been minimized.

@registerrier

registerrier Jun 1, 2018

Contributor

Well it is not so easy to do actually. I will add an issue about this.

@registerrier

registerrier Jun 1, 2018

Contributor

Well it is not so easy to do actually. I will add an issue about this.

Parameters
----------
region : `~regions.PixelRegion` or `~regions.SkyRegion` object
A region on the sky could be defined in pixel or sky coordinates.
Return
------
mask_array : `~numpy.ndarray` of booleans
the array of
"""
from regions import PixCoord
@@ -653,7 +658,12 @@ def get_region_idx(self, region):
if isinstance(region, SkyRegion):

This comment has been minimized.

@cdeil

cdeil May 29, 2018

Member

I think this would be simpler and equivalent to how regions works now:

if isinstance(region, SkyRegion):
    region = region.to_pixel(self.wcs)

pix = PixCoord(*self.get_idx())
return region.contains(pix)
@cdeil

cdeil May 29, 2018

Member

I think this would be simpler and equivalent to how regions works now:

if isinstance(region, SkyRegion):
    region = region.to_pixel(self.wcs)

pix = PixCoord(*self.get_idx())
return region.contains(pix)

This comment has been minimized.

@registerrier

registerrier Jun 1, 2018

Contributor

Done

@registerrier

registerrier Jun 1, 2018

Contributor

Done

coords=self.get_coord()
return region.contains(coords.skycoord)
# Test to adapt to various call for region.contains
try:
res = region.contains(coords.skycoord, self.wcs)
except TypeError:
res = region.contains(coords.skycoord)
return res
else:
res = self.get_idx()
pcoords = PixCoord(res[0], res[1])
View
@@ -527,7 +527,7 @@ def make_region_mask(self, region, inside=True):
mask_map : `~gammapy.maps.WcsNDMap`
the mask map
"""
mask = self.geom.get_region_idx(region)
mask = self.geom.get_region_mask_array(region)

This comment has been minimized.

@joleroi

joleroi May 25, 2018

Contributor

Can't you pass inside to geom.get_region_mask_array in order to prevent the duplicated check for if inside in the following lines?

@joleroi

joleroi May 25, 2018

Contributor

Can't you pass inside to geom.get_region_mask_array in order to prevent the duplicated check for if inside in the following lines?

This comment has been minimized.

@registerrier

registerrier May 25, 2018

Contributor

OK.

@registerrier

registerrier May 25, 2018

Contributor

OK.

if inside is False:
np.logical_not(mask,out=mask)
# TODO : update meta table to include something about the region used for mask creation?
ProTip! Use n and p to navigate between commits in a pull request.