-
Notifications
You must be signed in to change notification settings - Fork 186
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
Implement PSFKernelMap #3689
base: main
Are you sure you want to change the base?
Implement PSFKernelMap #3689
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3689 +/- ##
========================================
Coverage 93.76% 93.76%
========================================
Files 162 162
Lines 19512 19630 +118
========================================
+ Hits 18295 18406 +111
- Misses 1217 1224 +7
Continue to review full report at Codecov.
|
I feel like I wasn't very creative when making the tests... Please let me know if you can think of something a better than what I implemented! |
I made the I also realised I could construct the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @LauraOlivera .
This is a really useful addition. With the coming of non-isotropic PSF, this type of PSFMap
will be needed.
I have the following concerns:
- I don't think this class represents a map of kernels but simply a map of non-isotropic PSF. kernel implies a geometry and a projection (and contain a pdf per bin and not per sr). This cannot be described by the
lon
andlat
axes. So this is really a generalizedPSFMap
. It could even possibly inherit from it and theget_psf_kernel
should follow more closely the implementation ofPSFMap.get_psf_kernel
. - A priori, the stored PSF is in physical coordinates. I assume it should be the same frame as the
IRFMap
geom, right? This would need to be documented somewhere.
LONLAT_AXIS_DEFAULT = MapAxis.from_bounds(-1, 1, nbin=11, unit='deg') | ||
|
||
if not all([psf_lon_axis, psf_lat_axis]): | ||
psf_lon_axis = LONLAT_AXIS_DEFAULT.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably better not to change the name attribute directly. You can rather set it during the copy
:
LONLAT_AXIS_DEFAULT.copy(name="psf_lon")
sigma : `~astropy.coordinates.Angle` | ||
Gaussian width. | ||
geom : `Geom` | ||
Image geometry. By default an allsky geometry is created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the exposure be argument as well?
|
||
geom_exposure = geom.squash(axis_name='psf_lon').squash(axis_name='psf_lat') | ||
exposure_map = Map.from_geom( | ||
geom=geom_exposure, unit="m2 s", data=1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is default exposure 0 not more appropriate?
sigma : `~astropy.coordinates.Angle` | ||
Gaussian width. | ||
geom : `Geom` | ||
Image geometry. By default an allsky geometry is created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe specify the dimension of the default geometry?
|
||
|
||
@classmethod | ||
def from_geom(cls, geom): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is really an extension of the PSFMap
this probably should follow the logic of the PSFMap.from_geom
and create an empty Map
. In the long run, if we have anisotropic PSF stored as IRFs we will have to use this class in MapDataset.create
else: | ||
geom_center = geom.center_skydir | ||
|
||
kernel_geom = WcsGeom.create(skydir=geom_center, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the projection to use? Is the default "CAR"
OK in general?
Maybe don't allow for empty geom?
|
||
kernel_data = self.psf_kernel_map.to_region_nd_map(region=position) | ||
|
||
width = 2*np.max(np.abs([kernel_data.geom.axes['psf_lon'].edges.min().to_value('deg'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume that the geometry with is defined from the input geom
no?
|
||
position = self._get_nearest_valid_position(position) | ||
|
||
kernel_data = self.psf_kernel_map.to_region_nd_map(region=position) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't one compute the lon
and lat
of each pixel in the input geom
and then evaluate the IRFMap
at the given coords?
|
||
return cls.from_gauss(energy_axis_true, psf_lon_axis, psf_lat_axis, sigma=0.1 * u.deg, geom=geom.to_image()) | ||
|
||
def get_psf_kernel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect this method to follow much more closely PSFMap.get_psf_kernel
except that the map evaluation is performed with lon
and lat
separation from the center of the target geometry
@@ -327,3 +327,49 @@ def gauss_convolve(self, sigma, norm=1): | |||
norms.append(self.norms[ii] * norm) | |||
|
|||
return MultiGauss2D(sigmas, norms) | |||
|
|||
class AsymmetricGauss2DPDF: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might prove useful to add a rotation angle no?
@registerrier Your description would imply that the On the other hand this makes the |
@registerrier Following your understanding of the asymmetric PSF map, we would maybe not need any |
Just taking the thought a bit further, maybe it still make sense to have both, a class PSFMap(IRFMap):
"""Implements all common functionality, should be N-dimensional"""
def to_psf_kernel_map(self, geom_kernels):
"""Compute PSFKernelMap"""
return PSFKernelMap(..., geom_kernels)
# This corresponds to our current PSFMap
class RadiallySymmetricPSFMap(PSFMap):
""""""
required_axes = ["rad", "energy_true"]
# This is what Régis thought Laura implemented
class NonRadiallySymmetricPSFMap(PSFMap):
""""""
required_axes = ["psf_lon", "psf_lat", "energy_true"]
# This is what I thought Laura implemented
class PSFKernelMap(IRFMap):
"""Contains precomputed PSFKernel"""
def __init__(map, exposure, geom_kernels):
pass But I'm just brain-storming for now... The difference between the |
@LauraOlivera your seems to be updated from the main... |
This pull request addresses issue #3681 to implement a
PSFKernelMap
.So far, I have created the object and implemented a
from_gauss()
method to easily create Gaussian kernel maps. Since one of the uses of this implementation are asymmetric PSF kernels, I added anAsymmetricGauss2DPDF
togammapy.utils.gauss
to easily create asymmetric Gaussian kernels.I marked the PR as draft because I still have a bunch to do. An incomplete list below:
from_geom
methodget_psf_kernel()
?Things that will need to be done in a follow-up PR:
PSFKernelMap
andPSFKernel.psf_kernel_map