Commit 27b65d45 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

cleanups

parent 2450982f
...@@ -292,7 +292,8 @@ class Field(Loggable, Versionable, object): ...@@ -292,7 +292,8 @@ class Field(Loggable, Versionable, object):
if nbin==None : maximum number of bins is used if nbin==None : maximum number of bins is used
binbounds : array-like *optional* binbounds : array-like *optional*
Inner bounds of the bins (default : None). Inner bounds of the bins (default : None).
if binbounds==None : bins are inferred. Overwrites nbins and log Overrides nbin and logarithmic.
if binbounds==None : bins are inferred.
keep_phase_information : boolean, *optional* keep_phase_information : boolean, *optional*
If False, return a real-valued result containing the power spectrum If False, return a real-valued result containing the power spectrum
of the input Field. of the input Field.
...@@ -401,8 +402,7 @@ class Field(Loggable, Versionable, object): ...@@ -401,8 +402,7 @@ class Field(Loggable, Versionable, object):
power_spectrum = cls._calculate_power_spectrum( power_spectrum = cls._calculate_power_spectrum(
field_val=work_field.val, field_val=work_field.val,
pindex=pindex, pdomain=power_domain,
rho=rho,
axes=work_field.domain_axes[space_index]) axes=work_field.domain_axes[space_index])
# create the result field and put power_spectrum into it # create the result field and put power_spectrum into it
...@@ -419,8 +419,9 @@ class Field(Loggable, Versionable, object): ...@@ -419,8 +419,9 @@ class Field(Loggable, Versionable, object):
return result_field return result_field
@classmethod @classmethod
def _calculate_power_spectrum(cls, field_val, pindex, rho, axes=None): def _calculate_power_spectrum(cls, field_val, pdomain, axes=None):
pindex = pdomain.pindex
if axes is not None: if axes is not None:
pindex = cls._shape_up_pindex( pindex = cls._shape_up_pindex(
pindex=pindex, pindex=pindex,
...@@ -429,6 +430,7 @@ class Field(Loggable, Versionable, object): ...@@ -429,6 +430,7 @@ class Field(Loggable, Versionable, object):
axes=axes) axes=axes)
power_spectrum = pindex.bincount(weights=field_val, power_spectrum = pindex.bincount(weights=field_val,
axis=axes) axis=axes)
rho=pdomain.rho
if axes is not None: if axes is not None:
new_rho_shape = [1, ] * len(power_spectrum.shape) new_rho_shape = [1, ] * len(power_spectrum.shape)
new_rho_shape[axes[0]] = len(rho) new_rho_shape[axes[0]] = len(rho)
......
...@@ -42,7 +42,8 @@ class PowerSpace(Space): ...@@ -42,7 +42,8 @@ class PowerSpace(Space):
if nbin == None, then nbin is set to the length of kindex. if nbin == None, then nbin is set to the length of kindex.
binbounds : {list, array-like} *optional* binbounds : {list, array-like} *optional*
Boundaries between the power spectrum bins. Boundaries between the power spectrum bins.
(If binbounds has n entries, there will be n+1 bins.) (If binbounds has n entries, there will be n+1 bins, the first bin
starting at -inf, the last bin ending at +inf.)
(default : None) (default : None)
if binbounds == None : if binbounds == None :
Calculates the bounds from the kindex while applying the Calculates the bounds from the kindex while applying the
...@@ -253,15 +254,16 @@ class PowerSpace(Space): ...@@ -253,15 +254,16 @@ class PowerSpace(Space):
def _do_binning(self): def _do_binning(self):
""" Computes pindex, kindex and rho according to self._binbounds. """ Computes pindex, kindex and rho according to self._binbounds.
""" """
# prepare the pindex object
self._pindex = distributed_data_object(
global_shape=self._k_array.shape,
dtype=np.int,
distribution_strategy=self._k_array.distribution_strategy)
# if no binning is requested, compute the "natural" binning, i.e. there # if no binning is requested, compute the "natural" binning, i.e. there
# is one bin for every distinct k-vector length # is one bin for every distinct k-vector length
if self._binbounds is None: if self._binbounds is None:
self._kindex = self._k_array.unique() self._kindex = self._k_array.unique()
# prepare the distributed_data_object
self._pindex = distributed_data_object(
global_shape=self._k_array.shape,
dtype=np.int,
distribution_strategy=self._k_array.distribution_strategy)
# store the local pindex data in the global_pindex d2o # store the local pindex data in the global_pindex d2o
self._pindex.set_local_data( self._pindex.set_local_data(
np.searchsorted(self._kindex, self._k_array.get_local_data())) np.searchsorted(self._kindex, self._k_array.get_local_data()))
...@@ -269,10 +271,6 @@ class PowerSpace(Space): ...@@ -269,10 +271,6 @@ class PowerSpace(Space):
# use the provided binbounds # use the provided binbounds
else: else:
self._pindex = distributed_data_object(
global_shape=self._k_array.shape,
dtype=np.int,
distribution_strategy=self._k_array.distribution_strategy)
self._pindex.set_local_data(np.searchsorted( self._pindex.set_local_data(np.searchsorted(
self._binbounds, self._k_array.get_local_data())) self._binbounds, self._k_array.get_local_data()))
self._rho = self._pindex.bincount().get_full_data() self._rho = self._pindex.bincount().get_full_data()
......
Supports Markdown
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