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

Conversation

3 participants
@registerrier
Contributor

registerrier commented May 18, 2018

This PR adds a make_region_maskmethod to HpxNDMap and WcsNDMap.

@registerrier registerrier added this to To do in Map analysis via automation May 18, 2018

@registerrier registerrier self-assigned this May 18, 2018

@registerrier registerrier added this to the 0.8 milestone May 18, 2018

@registerrier registerrier requested a review from cdeil May 18, 2018

@cdeil

@registerrier - Thanks!

I left some inline comments.

My main comment / question is concerning if / how to do contains for sky regions. I think the discussions in astropy-regions have settled on the understanding that sky regions contains isn't well-defined in general and not supported, one always needs a WCS and then does the contains in pixel coordinates, like this:
http://docs.gammapy.org/dev/_modules/gammapy/image/core.html#SkyImage.region_mask

The exception is circle and polygon regions, for those a spherical contains is well-defined, and those should be implemented in astropy-regions as special classes. But that's not there, so I don't think at the moment we should support it here, which makes we don't support region filtering for HPX at all.

@joleroi @registerrier @woodmd - Thoughts?

Show outdated Hide outdated gammapy/maps/hpx.py
Show outdated Hide outdated gammapy/maps/hpxnd.py
Show outdated Hide outdated gammapy/maps/hpxnd.py
Show outdated Hide outdated gammapy/maps/tests/test_wcsnd.py
Show outdated Hide outdated gammapy/maps/wcs.py

@cdeil cdeil changed the title from Map mask to Add map region mask May 18, 2018

@joleroi

This comment has been minimized.

Show comment
Hide comment
@joleroi

joleroi May 18, 2018

Contributor

I don't think at the moment we should support it here, which makes we don't support region filtering for HPX at all.

Agreed, let's leave this to astropy.regions

Contributor

joleroi commented May 18, 2018

I don't think at the moment we should support it here, which makes we don't support region filtering for HPX at all.

Agreed, let's leave this to astropy.regions

Show outdated Hide outdated gammapy/maps/hpx.py
Show outdated Hide outdated gammapy/maps/hpxnd.py
@registerrier

This comment has been minimized.

Show comment
Hide comment
@registerrier

registerrier May 24, 2018

Contributor

The new commits have:

  • removed the region filtering in map.HpxGeom and its test function
  • changed the name of the method toWcsGeom.get_region_mask_array
  • include the new calling scheme for SkyRegion.contains
  • added a MapCoord.apply_region_mask and its associated test

Merge?

Contributor

registerrier commented May 24, 2018

The new commits have:

  • removed the region filtering in map.HpxGeom and its test function
  • changed the name of the method toWcsGeom.get_region_mask_array
  • include the new calling scheme for SkyRegion.contains
  • added a MapCoord.apply_region_mask and its associated test

Merge?

mask_map : `~gammapy.maps.WcsNDMap`
the mask map
"""
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

This comment has been minimized.

Show comment
Hide comment
@registerrier

registerrier May 25, 2018

Contributor

I realize that there is a serious issue with MapCoord.apply_region_mask. At the moment is uses the simple SkyRegion.contains(skycoord) method which is about to be replaced by SkyRegion.contains(skycoord, wcs).
There is no WCS associated to a MapCoord, so we have to pass one to make the selection.

This is a serious issue with regionsno? A SkyRegion should be a region on the sphere no? Otherwise you end up with different selections depending on the WCS object you pass...

Contributor

registerrier commented May 25, 2018

I realize that there is a serious issue with MapCoord.apply_region_mask. At the moment is uses the simple SkyRegion.contains(skycoord) method which is about to be replaced by SkyRegion.contains(skycoord, wcs).
There is no WCS associated to a MapCoord, so we have to pass one to make the selection.

This is a serious issue with regionsno? A SkyRegion should be a region on the sphere no? Otherwise you end up with different selections depending on the WCS object you pass...

@joleroi

This comment has been minimized.

Show comment
Hide comment
@joleroi

joleroi May 25, 2018

Contributor

This is a serious issue with regionsno? A SkyRegion should be a region on the sphere no? Otherwise you end up with different selections depending on the WCS object you pass...

Yes, to my understanding this is intended for SkyRegion. It is really a region on some kind of sky projection. The plan is to add SphericalSkyRegion later, to cover the use case were people want to put a region on an actual sphere. SphericalSkyRegion will implement circles and polygons. There is some discussion on this in astropy/regions#107

Contributor

joleroi commented May 25, 2018

This is a serious issue with regionsno? A SkyRegion should be a region on the sphere no? Otherwise you end up with different selections depending on the WCS object you pass...

Yes, to my understanding this is intended for SkyRegion. It is really a region on some kind of sky projection. The plan is to add SphericalSkyRegion later, to cover the use case were people want to put a region on an actual sphere. SphericalSkyRegion will implement circles and polygons. There is some discussion on this in astropy/regions#107

@cdeil

@registerrier - I left some more small inline comments.

Do you have time to wrap this up?
(feel free to merge, no more iteration needed with me)

Show outdated Hide outdated gammapy/maps/hpx.py
Show outdated Hide outdated gammapy/maps/hpxnd.py
Show outdated Hide outdated gammapy/maps/tests/test_hpxmap.py
Show outdated Hide outdated gammapy/maps/wcs.py
Show outdated Hide outdated gammapy/maps/wcs.py
Show outdated Hide outdated gammapy/maps/tests/test_wcsnd.py

@registerrier registerrier moved this from To do to In progress in Map analysis Jun 1, 2018

@registerrier

This comment has been minimized.

Show comment
Hide comment
@registerrier

registerrier Jun 1, 2018

Contributor

OK I have made the modifications.
There are some difficulties which I had not foreseen with multi resolution maps. I have added an Exception if one try to use one. This will need to be sorted out later.
I have also removed for the moment the MapCoord region filtering. This might be better handled with a MapMask for instance.

Contributor

registerrier commented Jun 1, 2018

OK I have made the modifications.
There are some difficulties which I had not foreseen with multi resolution maps. I have added an Exception if one try to use one. This will need to be sorted out later.
I have also removed for the moment the MapCoord region filtering. This might be better handled with a MapMask for instance.

@registerrier registerrier merged commit 8ab962f into gammapy:master Jun 3, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

Map analysis automation moved this from In progress to Done Jun 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment