Commit 6218e99b authored by Jait Dixit's avatar Jait Dixit

WIP: LMSpace smoothing

- Cython extension to return the correct l-number for an index
parent 04b1ab8c
......@@ -173,7 +173,10 @@ class GLSpace(Space):
return np.arctan(numerator / denominator)
def get_smoothing_kernel_function(self, sigma):
raise NotImplementedError
if sigma is None:
sigma = np.sqrt(2) * np.pi / self.nlat
return lambda x: np.exp((-0.5 * x**2) / sigma**2)
# ---Added properties and methods---
......
......@@ -186,8 +186,11 @@ class HPSpace(Space):
return dists
def get_smoothing_kernel_function(self, sigma, target):
raise NotImplementedError
def get_smoothing_kernel_function(self, sigma):
if sigma is None:
sigma = np.sqrt(2) * np.pi / self.nlat
return lambda x: np.exp((-0.5 * x**2) / sigma**2)
# ---Added properties and methods---
......
import numpy as np
cimport numpy as np
cpdef _distance_array_helper(np.int_t x, np.ndarray[np.int_t] l,
np.int_t original_size, np.int_t lmax):
cdef np.int size = (lmax + 1) * (lmax + 1)
cdef np.ndarray res = np.zeros([size], dtype=np.float128)
res[0:lmax + 1] = np.arange(lmax + 1)
for i in xrange(original_size - lmax - 1):
res[i * 2 + lmax + 1] = l[i + lmax + 1]
res[i * 2 + lmax + 1] = l[i + lmax + 1]
Please register or sign in to reply
return res[x]
from __future__ import division
import numpy as np
......@@ -9,6 +8,10 @@ from nifty.config import about,\
nifty_configuration as gc,\
dependency_injector as gdi
from lm_helper import _distance_array_helper
from d2o import arange
gl = gdi.get('libsharp_wrapper_gl')
hp = gdi.get('healpy')
......@@ -111,7 +114,19 @@ class LMSpace(Space):
self._mmax = self._parse_mmax(mmax)
def distance_array(self, distribution_strategy):
raise NotImplementedError
dists = arange(
start=0, stop=self.shape[0], dtype=np.float128,
distribution_strategy=distribution_strategy
)
l = hp.Alm.getlm(lmax=self.lmax)[0]
dists = dists.apply_scalar_function(
lambda x: _distance_array_helper(
int(x), l, hp.Alm.getsize(self.lmax), self.lmax
)
)
return dists
def get_smoothing_kernel_function(self, sigma):
if sigma is None:
......
......@@ -37,9 +37,11 @@ setup(name="ift_nifty",
packages=find_packages(),
package_dir={"nifty": "nifty"},
zip_safe=False,
ext_modules=cythonize(
"nifty/operators/fft_operator/transformations/lm_transformation_factory"
".pyx"),
ext_modules=cythonize([
"nifty/operators/fft_operator/transformations/"
"lm_transformation_factory.pyx",
"nifty/spaces/lm_space/lm_helper.pyx"
]),
include_dirs= [numpy.get_include()],
dependency_links=[
'git+https://gitlab.mpcdf.mpg.de/ift/keepers.git#egg=keepers',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment