Skip to content
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

adds gauss-bessel kernel #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion cygrid/cygrid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ __all__ = ['Cygrid', 'WcsGrid', 'SlGrid', 'ShapeError']


from .kernels cimport (
gaussian_1d_kernel, gaussian_2d_kernel, tapered_sinc_1d_kernel
gaussian_1d_kernel, gaussian_2d_kernel, tapered_sinc_1d_kernel,
gauss_bessel_kernel
)
from .hphashtab cimport HpxHashTable
from .helpers cimport (
Expand Down Expand Up @@ -424,6 +425,10 @@ cdef class Cygrid(object):
'1D tapered-sinc kernel', 3, <bint> False,
# ('kernel_sigma', 'param_a', 'param_b')
),
'gaussbessel': (
'1D Gauss-Bessel kernel', 3, <bint> False,
# ('kernel_sigma', 'param_a', 'param_b')
),
}

try:
Expand Down Expand Up @@ -456,6 +461,8 @@ cdef class Cygrid(object):
self.kernel_func_ptr = gaussian_2d_kernel
elif kernel_type_u == 'tapered_sinc':
self.kernel_func_ptr = tapered_sinc_1d_kernel
elif kernel_type_u == 'gaussbessel':
self.kernel_func_ptr = gauss_bessel_kernel

self.kernel_set = <bint> True
self.kernel_params_arr = kernel_params_arr
Expand Down
4 changes: 4 additions & 0 deletions cygrid/kernels.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ from numpy cimport (
int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
uint32_t, uint64_t, float32_t, float64_t
)
cimport scipy.special.cython_special as csc


cdef:
Expand All @@ -50,4 +51,7 @@ cdef:
double tapered_sinc_1d_kernel(
double distance, double bearing, double[::1] kernel_params
) nogil
double gauss_bessel_kernel(
double distance, double bearing, double[::1] kernel_params
) nogil

37 changes: 37 additions & 0 deletions cygrid/kernels.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,40 @@ cdef double tapered_sinc_1d_kernel(
arg = PI * distance / kernel_params[0]

return sinc(arg / kernel_params[2]) * exp(-(arg / kernel_params[1]) ** 2)


cdef double gauss_bessel_kernel(
double distance, double bearing, double[::1] kernel_params
) nogil:
'''
Gaussian tapered Bessel kernel following the definition
of Mangum et al. 2007 A&A 474 679M.

Parameters
----------
distance : double
Radial distance/separation
bearing : double
unused - this is only in the call signature to allow function pointers
kernel_params : double[::1]
mem-view on kernel-parameters array
must contain:
kernel_params[0] : A third of the Half Power Beam Width
kernel_params[1] : 2.52
kernel_params[2] : 1.55

Returns
-------
Kernel weight : double
'''

cdef:
double arg, Earg, gauss, bessel

arg = PI * fabs(distance) / kernel_params[0] / kernel_params[2]
bessel = csc.j1(arg) / arg

Earg = distance * distance / kernel_params[0] / kernel_params[0] / kernel_params[1] / kernel_params[1] / 2.0
gauss = exp(-Earg)

return gauss * bessel
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ requires = [
"numpy==1.23.4; python_version=='3.11'",
# "oldest-supported-numpy",
"extension-helpers",
"scipy"
]
build-backend = "setuptools.build_meta"

Expand Down