added data property of PSFKernel and a copy flag for .apply() method
@@ -164,6 +164,11 @@ class PSFKernel(object):
def __init__(self, psf_kernel_map):
self._psf_kernel_map = psf_kernel_map
+ @property
+ def data(self):
+ """Access the PSFKernel numpy array"""
+ return self._psfkernel_map.data
+
@property
def psf_kernel_map(self):
return self._psf_kernel_map
@@ -256,7 +261,7 @@ class PSFKernel(object):
"""Write the Map object which contains the PSF kernel to file."""
self.psf_kernel_map.write(*args, **kwargs)
- def apply(self, map):
+ def apply(self, map, copy=True):
"""Apply the kernel to an input Map.
Parameters
@@ -264,14 +269,19 @@ class PSFKernel(object):
map : `~gammapy.maps.WcsNDMap`
the model map to be convolved with the PSFKernel.
It should have the same MapGeom than the current PSFKernel.
-
+ copy : bool
+ If set to True returns new map otherwise performs in-place convolution
Returns
-------
convolved_map : `~gammapy.maps.Map`
the convolved map
"""
# TODO : check that the MapGeom are consistent
+ if copy:
convolved_map = Map.from_geom(geom=map.geom, unit=map.unit, meta=map.meta)
+ else:
+ convolved_map = map
+
for img, idx in map.iter_by_image():
convolved_map.data[idx] = convolve_fft(img, self.psf_kernel_map.data[idx])
return convolved_map
