There is a maintenance of MPCDF Gitlab on Thursday, April 22st 2020, 9:00 am CEST - Expect some service interruptions during this time

Commit aaa02478 authored by Jait Dixit's avatar Jait Dixit

WIP: Fix smooth_operator and spaces

- Move kernel construction to after transform
- Use d2o.arange for distance_array method in HPSpace and GLSpace
parent 413b6f84
......@@ -59,20 +59,19 @@ class SmoothOperator(EndomorphicOperator):
if spaces is not None and self.sigma != 0:
spaces = utilities.cast_axis_to_tuple(spaces, len(x.domain))
space_obj = x.domain[spaces[0]]
axes = x.domain_axes[spaces[0]]
transform = FFTOperator(space_obj)
transform = FFTOperator(x.domain[spaces[0]])
# transform
smooth_out = transform(smooth_out, spaces=spaces[0])
# create the kernel
space_obj = smooth_out.domain[spaces[0]]
kernel = space_obj.distance_array(
x.val.get_axes_local_distribution_strategy(axes=axes))
kernel = kernel.apply_scalar_function(
space_obj.codomain_smoothing_function(self.sigma,
transform.target))
# transform
smooth_out = transform(smooth_out, spaces=spaces[0])
x.domain[spaces[0]].codomain_smoothing_function(self.sigma))
# local data
local_val = smooth_out.val.get_local_data(copy=False)
......
......@@ -3,7 +3,7 @@ from __future__ import division
import itertools
import numpy as np
from d2o import distributed_data_object, STRATEGIES as DISTRIBUTION_STRATEGIES
from d2o import arange, STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.spaces.space import Space
from nifty.config import about, nifty_configuration as gc,\
......@@ -153,23 +153,22 @@ class GLSpace(Space):
return result_x
def distance_array(self, distribution_strategy):
shape = self.shape[0]
def _distance_array_helper(self, qr_tuple):
numerator = np.sqrt(np.sin(qr_tuple[1])**2 +
(np.sin(qr_tuple[0]) * np.cos(qr_tuple[1]))**2)
denominator = np.cos(qr_tuple[0]) * np.cos(qr_tuple[1])
return np.arctan(numerator / denominator)
dists = distributed_data_object(
global_shape=self.shape,
dtype=np.float128,
def distance_array(self, distribution_strategy):
dists = arange(
start = 0, stop = self.shape[0], dtype=np.float128,
distribution_strategy=distribution_strategy
)
center_lat = np.random.randint(self.nlat)
center_lon = np.random.randint(self.nlon)
for i in range(self.nlat):
for j in range(self.nlon):
dists[i + j] = np.arccos(np.sin(i) * np.sin(center_lat) +
np.cos(i) * np.cos(center_lat) *
np.cos(j - center_lon))
dists = dists.apply_scalar_function(
lambda x: self._distance_array_helper(divmod(int(x), self.nlon))
)
return dists
......
......@@ -35,7 +35,7 @@ from __future__ import division
import numpy as np
from d2o import distributed_data_object, STRATEGIES as DISTRIBUTION_STRATEGIES
from d2o import arange, STRATEGIES as DISTRIBUTION_STRATEGIES
from nifty.config import about
from nifty.spaces.space import Space
from nifty.config import nifty_configuration as gc, \
......@@ -138,19 +138,18 @@ class HPSpace(Space):
-------
dists: distributed_data_object
"""
# HPSpace is always 1-dimensional
shape = self.shape[0]
dists = distributed_data_object(
global_shape=shape,
dtype=np.float128,
dists = arange(
start=0, stop = self.shape[0], dtype=np.float128,
distribution_strategy=distribution_strategy
)
center_vec = hp.pix2vec(self.nside, np.random.randint(shape))
# setting the center to fixed value
center_vec = (1, 0, 0)
for i in range(shape):
dists[i] = np.arccos(np.dot(hp.pix2vec(self.nside, i), center_vec))
dists = dists.apply_scalar_function(
lambda x: np.arccos(np.dot(hp.pix2vec(self.nside, int(x)),
center_vec))
)
return dists
......
......@@ -317,7 +317,7 @@ class RGSpace(Space):
temp[:] = zerocenter
return tuple(temp)
def codomain_smoothing_function(self, sigma, target):
def codomain_smoothing_function(self, sigma):
if sigma is None:
sigma = np.sqrt(2) * np.max(self.distances)
......
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