Commit 281f5127 authored by Martin Reinecke's avatar Martin Reinecke

get_distance_array() -> get_k_length_array(); get_unique_distances() -> get_unique_k_lengths()

parent f1a42ebc
Pipeline #18301 passed with stage
in 6 minutes and 4 seconds
......@@ -99,7 +99,7 @@ class DirectSmoothingOperator(EndomorphicOperator):
"spaces can be smoothed directly.")
axis = affected_axes[0]
distances = x.domain[spaces[0]].get_distance_array()
distances = x.domain[spaces[0]].get_k_length_array()
if self._log_distances:
distances = np.log(np.maximum(distances, 1e-15))
......
......@@ -24,7 +24,7 @@ class FFTSmoothingOperator(EndomorphicOperator):
self._transformator = FFTOperator(self._domain)
codomain = self._domain[0].get_default_codomain()
self._kernel = codomain.get_distance_array()
self._kernel = codomain.get_k_length_array()
smoother = codomain.get_fft_smoothing_kernel_function(self._sigma)
self._kernel = smoother(self._kernel)
......
......@@ -122,7 +122,7 @@ class LMSpace(Space):
def weight(self):
return 1.
def get_distance_array(self):
def get_k_length_array(self):
lmax = self.lmax
ldist = np.empty((self.dim,), dtype=np.float64)
ldist[0:lmax+1] = np.arange(lmax+1, dtype=np.float64)
......@@ -135,7 +135,7 @@ class LMSpace(Space):
idx += 2*(lmax+1-l)
return ldist
def get_unique_distances(self):
def get_unique_k_lengths(self):
return np.arange(self.lmax+1, dtype=np.float64)
def get_fft_smoothing_kernel_function(self, sigma):
......
......@@ -121,7 +121,7 @@ class PowerSpace(Space):
return None
nbin = None if nbin is None else int(nbin)
logarithmic = bool(logarithmic)
dists = space.get_unique_distances()
dists = space.get_unique_k_lengths()
if len(dists) < 3:
raise ValueError("Space does not have enough unique k lengths")
lbound = 0.5*(dists[0]+dists[1])
......@@ -156,15 +156,15 @@ class PowerSpace(Space):
key = (harmonic_partner, binbounds)
if self._powerIndexCache.get(key) is None:
distance_array = self.harmonic_partner.get_distance_array()
k_length_array = self.harmonic_partner.get_k_length_array()
temp_pindex = self._compute_pindex(
harmonic_partner=self.harmonic_partner,
distance_array=distance_array,
k_length_array=k_length_array,
binbounds=binbounds)
temp_rho = np.bincount(temp_pindex.ravel())
assert not np.any(temp_rho == 0), "empty bins detected"
temp_kindex = np.bincount(temp_pindex.ravel(),
weights=distance_array.ravel()) \
weights=k_length_array.ravel()) \
/ temp_rho
self._powerIndexCache[key] = (binbounds,
temp_pindex,
......@@ -175,11 +175,11 @@ class PowerSpace(Space):
self._powerIndexCache[key]
@staticmethod
def _compute_pindex(harmonic_partner, distance_array, binbounds):
def _compute_pindex(harmonic_partner, k_length_array, binbounds):
if binbounds is None:
tmp = harmonic_partner.get_unique_distances()
tmp = harmonic_partner.get_unique_k_lengths()
binbounds = 0.5*(tmp[:-1]+tmp[1:])
return np.searchsorted(binbounds, distance_array)
return np.searchsorted(binbounds, k_length_array)
# ---Mandatory properties and methods---
......@@ -215,7 +215,7 @@ class PowerSpace(Space):
# MR FIXME: this will probably change to 1 soon
return np.asarray(self.rho, dtype=np.float64)
def get_distance_array(self):
def get_k_length_array(self):
return self.kindex.copy()
def get_fft_smoothing_kernel_function(self, sigma):
......
......@@ -120,17 +120,7 @@ class RGSpace(Space):
def weight(self):
return self._wgt
def get_distance_array(self):
""" Calculates an n-dimensional array with its entries being the
lengths of the vectors from the zero point of the grid.
Returns
-------
numpy.ndarray
An array containing the distances.
"""
def get_k_length_array(self):
if (not self.harmonic):
raise NotImplementedError
res = np.arange(self.shape[0], dtype=np.float64)
......@@ -145,7 +135,7 @@ class RGSpace(Space):
res = np.add.outer(res, tmp)
return np.sqrt(res)
def get_unique_distances(self):
def get_unique_k_lengths(self):
if (not self.harmonic):
raise NotImplementedError
dimensions = len(self.shape)
......@@ -165,7 +155,7 @@ class RGSpace(Space):
tmp[t2] = True
return np.sqrt(np.nonzero(tmp)[0])*self.distances[0]
else: # do it the hard way
tmp = self.get_distance_array().unique() # expensive!
tmp = self.get_k_length_array().unique() # expensive!
tol = 1e-12*tmp[-1]
# remove all points that are closer than tol to their right
# neighbors.
......
......@@ -88,7 +88,7 @@ class Space(DomainObject):
"""
return self.__class__()
def get_distance_array(self):
def get_k_length_array(self):
""" The length of the k vector for every pixel.
This method is only implemented for harmonic spaces.
......@@ -100,7 +100,7 @@ class Space(DomainObject):
"""
raise NotImplementedError
def get_unique_distances(self):
def get_unique_k_lengths(self):
""" Returns an array of floats containing the unique k vector lengths
for this space.
This method is only implemented for harmonic spaces.
......
......@@ -38,7 +38,7 @@ class SpaceInterfaceTests(unittest.TestCase):
attr_expected_type[1]))
@expand(product(generate_harmonic_spaces(), [
['get_distance_array', np.ndarray],
['get_k_length_array', np.ndarray],
['get_fft_smoothing_kernel_function', 2.0, LambdaType],
]))
def test_method_ret_type(self, space, method_expected_type):
......
......@@ -49,7 +49,7 @@ CONSTRUCTOR_CONFIGS = [
]
def _distance_array_helper(index_arr, lmax):
def _k_length_array_helper(index_arr, lmax):
if index_arr <= lmax:
index_half = index_arr
else:
......@@ -64,8 +64,8 @@ def _distance_array_helper(index_arr, lmax):
return index_half - m*(2*lmax + 1 - m)//2
def get_distance_array_configs():
da_0 = [_distance_array_helper(idx, 5) for idx in np.arange(36)]
def get_k_length_array_configs():
da_0 = [_k_length_array_helper(idx, 5) for idx in np.arange(36)]
return [[5, da_0]]
......@@ -92,7 +92,7 @@ class LMSpaceFunctionalityTests(unittest.TestCase):
def test_weight(self):
assert_almost_equal(LMSpace(5).weight(), 1.)
@expand(get_distance_array_configs())
def test_distance_array(self, lmax, expected):
@expand(get_k_length_array_configs())
def test_k_length_array(self, lmax, expected):
l = LMSpace(lmax)
assert_almost_equal(l.get_distance_array(), expected)
assert_almost_equal(l.get_k_length_array(), expected)
......@@ -73,7 +73,7 @@ CONSTRUCTOR_CONFIGS = [
]
def get_distance_array_configs():
def get_k_length_array_configs():
da_0 = np.array([0, 1.0, 1.41421356, 2., 2.23606798, 2.82842712])
return [
[RGSpace((4, 4), harmonic=True), da_0],
......@@ -124,10 +124,10 @@ class PowerSpaceFunctionalityTest(unittest.TestCase):
else:
assert_equal(getattr(p, key), value)
@expand(get_distance_array_configs())
def test_distance_array(self, harmonic_partner, expected):
@expand(get_k_length_array_configs())
def test_k_length_array(self, harmonic_partner, expected):
p = PowerSpace(harmonic_partner=harmonic_partner)
assert_almost_equal(p.get_distance_array(), expected)
assert_almost_equal(p.get_k_length_array(), expected)
def test_weight(self):
p = PowerSpace(harmonic_partner=RGSpace(10,harmonic=True))
......
......@@ -74,7 +74,7 @@ CONSTRUCTOR_CONFIGS = [
]
def get_distance_array_configs():
def get_k_length_array_configs():
# for RGSpace(shape=(4, 4), distances=(0.25,0.25))
cords_0 = np.ogrid[0:4, 0:4]
da_0 = ((cords_0[0] - 4 // 2) * 0.25)**2
......@@ -117,10 +117,10 @@ class RGSpaceFunctionalityTests(unittest.TestCase):
for key, value in expected.items():
assert_equal(getattr(x, key), value)
@expand(get_distance_array_configs())
def test_distance_array(self, shape, distances, expected):
@expand(get_k_length_array_configs())
def test_k_length_array(self, shape, distances, expected):
r = RGSpace(shape=shape, distances=distances, harmonic=True)
assert_almost_equal(r.get_distance_array(), expected)
assert_almost_equal(r.get_k_length_array(), expected)
@expand(get_weight_configs())
def test_weight(self, shape, distances, harmonic, power):
......
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