diff --git a/nifty/spaces/gl_space/gl_space.py b/nifty/spaces/gl_space/gl_space.py index ae55be33801c85bdbdcebc517b68b21f9141ae81..74d365807e67571d403476f25b977d271821258c 100644 --- a/nifty/spaces/gl_space/gl_space.py +++ b/nifty/spaces/gl_space/gl_space.py @@ -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--- diff --git a/nifty/spaces/hp_space/hp_space.py b/nifty/spaces/hp_space/hp_space.py index e7d895d43decf46a70a58d11ac118681761de31e..7758cec72b47dcbab4d44e21c751a17003d35e6f 100644 --- a/nifty/spaces/hp_space/hp_space.py +++ b/nifty/spaces/hp_space/hp_space.py @@ -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--- diff --git a/nifty/spaces/lm_space/lm_helper.pyx b/nifty/spaces/lm_space/lm_helper.pyx new file mode 100644 index 0000000000000000000000000000000000000000..427593fe46803cf18a2e4dd7b5951c99b330d6c0 --- /dev/null +++ b/nifty/spaces/lm_space/lm_helper.pyx @@ -0,0 +1,15 @@ +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] + + return res[x] diff --git a/nifty/spaces/lm_space/lm_space.py b/nifty/spaces/lm_space/lm_space.py index 774a9044fa9ce573d0a66807fdc94be9dc02cfc7..67cb1f4b2799575fa9278d549abbb9d58bfd2e9c 100644 --- a/nifty/spaces/lm_space/lm_space.py +++ b/nifty/spaces/lm_space/lm_space.py @@ -1,4 +1,3 @@ - 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: diff --git a/setup.py b/setup.py index 79c4f06f176dffbb6712ac4d1f2525598d0b45a0..63a59d6f8a428eac65f0098ec058a870cd42778b 100644 --- a/setup.py +++ b/setup.py @@ -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',