Commit 2d3f070c authored by Reimar H Leike's avatar Reimar H Leike
Browse files

changed LogRGSpace.get_k_length_array to something sensible. Slope operator...

changed LogRGSpace.get_k_length_array to something sensible. Slope operator and AMplitude model are now getting the structure of the space from the space
parent 598158ec
......@@ -78,23 +78,23 @@ class LogRGSpace(StructuredDomain):
self._t_0, True)
def get_k_length_array(self):
# FIXME This is simply wrong! Definitely not the final version.
ib = dobj.ibegin_from_shape(self._shape)
res = np.arange(self.local_shape[0], dtype=np.float64) + ib[0]
res = np.minimum(res, self.shape[0]-res)*self.bindistances[0]
if len(self.shape) == 1:
return Field.from_local_data(self, res)
res *= res
for i in range(1, len(self.shape)):
tmp = np.arange(self.local_shape[i], dtype=np.float64) + ib[i]
tmp = np.minimum(tmp, self.shape[i]-tmp)*self.bindistances[i]
tmp *= tmp
res = np.add.outer(res, tmp)
return Field.from_local_data(self, np.sqrt(res))
def get_expk_length_array(self):
# FIXME This is a hack! Only for plotting. Seems not to be the final version.
out = exp(self.get_k_length_array()).to_global_data_rw()
out[1:] = out[:-1]
out[0] = 0
return Field.from_global_data(self, out)
if not self.harmonic:
raise NotImplementedError
ks = self.get_k_array()
return Field.from_global_data(self, np.linalg.norm(ks, axis=0))
def get_k_array(self):
ndim = len(self.shape)
k_array = np.zeros((ndim,) + self.shape)
dist = self.bindistances
for i in range(ndim):
ks = np.zeros(self.shape[i])
ks[1:] = np.minimum(self.shape[i] - 1 - np.arange(self.shape[i]-1), np.arange(self.shape[i]-1)) * dist[i]
if self.harmonic:
ks[0] = np.nan
else:
ks[0] = -np.inf
ks[1:] += self.t_0[i]
k_array[i] += ks.reshape((1,)*i + (self.shape[i],) + (1,)*(ndim-i-1))
return k_array
......@@ -48,12 +48,7 @@ def create_cepstrum_amplitude_field(domain, cepstrum):
dist = domain.bindistances
shape = domain.shape
# Prepare q_array
q_array = np.zeros((dim,) + shape)
for i in range(dim):
ks = np.zeros(shape[i])
ks[1:] = np.minimum(shape[i] - 1 - np.arange(shape[i]-1), np.arange(shape[i]-1)) * dist[i]
q_array[i] += ks.reshape((1,)*i + (shape[i],) + (1,)*(dim-i-1))
q_array = domain.get_k_array()
# Fill cepstrum field (all non-zero modes)
no_zero_modes = (slice(1, None),) * dim
......
......@@ -60,13 +60,7 @@ class SlopeOperator(LinearOperator):
raise ValueError("Slope Operator only works for ndim == 1")
# Prepare pos
self.pos = np.zeros((self.ndim,) + self.target[0].shape)
shape = self.target.shape
dist = self.target[0].bindistances
for i in range(self.ndim):
ks = np.zeros(shape[i])
ks[1:] = np.minimum(shape[i] - 1 - np.arange(shape[i]-1), np.arange(shape[i]-1)) * dist[i]
self.pos[i] += ks.reshape((1,)*i + (shape[i],) + (1,)*(self.ndim-i-1))
self.pos = self.target[0].get_k_array()-self.target[0].t_0[0]
......
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