Commit aaa02478 authored by Jait Dixit's avatar Jait Dixit
Browse files

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