Commit 5b259cc2 authored by Theo Steininger's avatar Theo Steininger
Browse files

small update

parent 223f71e3
...@@ -36,41 +36,40 @@ from nifty.random import Random ...@@ -36,41 +36,40 @@ from nifty.random import Random
class Field(Loggable, Versionable, object): class Field(Loggable, Versionable, object):
""" Combines D2O-objects with meta-information NIFTY needs for computations. """ The discrete representation of a continuous field over multiple spaces.
In NIFTY, Fields are used to store dataarrays and carry all the needed In NIFTY, Fields are used to store data arrays and carry all the needed
metainformation (i.e. the domain) for operators to be able to work on them. metainformation (i.e. the domain) for operators to be able to work on them.
In addition Field has functions to analyse the power spectrum of it's In addition Field has methods to work with power-spectra.
content or create a random field of it.
Parameters Parameters
---------- ----------
domain : DomainObject domain : DomainObject
One of the space types NIFTY supports. RGSpace, GLSpace, HPSpace, One of the space types NIFTY supports. RGSpace, GLSpace, HPSpace,
LMSpace or PowerSpace. It might also be a FieldArray, which is LMSpace or PowerSpace. It might also be a FieldArray, which is
an unstructured domain. an unstructured domain.
val : scalar, numpy.ndarray, distributed_data_object, Field val : scalar, numpy.ndarray, distributed_data_object, Field
The values the array should contain after init. A scalar input will The values the array should contain after init. A scalar input will
fill the whole array with this scalar. If an array is provided the fill the whole array with this scalar. If an array is provided the
array's dimensions must match the domain's. array's dimensions must match the domain's.
dtype : type dtype : type
A numpy.type. Most common are int, float and complex. A numpy.type. Most common are int, float and complex.
distribution_strategy: optional[{'fftw', 'equal', 'not', 'freeform'}] distribution_strategy: optional[{'fftw', 'equal', 'not', 'freeform'}]
Specifies which distributor will be created and used. Specifies which distributor will be created and used.
'fftw' uses the distribution strategy of pyfftw, 'fftw' uses the distribution strategy of pyfftw,
'equal' tries to distribute the data as uniform as possible 'equal' tries to distribute the data as uniform as possible
'not' does not distribute the data at all 'not' does not distribute the data at all
'freeform' distribute the data according to the given local data/shape 'freeform' distribute the data according to the given local data/shape
copy: boolean copy: boolean
Attributes Attributes
---------- ----------
val : distributed_data_object val : distributed_data_object
domain : DomainObject domain : DomainObject
See Parameters. See Parameters.
domain_axes : tuple of tuples domain_axes : tuple of tuples
...@@ -78,8 +77,8 @@ class Field(Loggable, Versionable, object): ...@@ -78,8 +77,8 @@ class Field(Loggable, Versionable, object):
dtype : type dtype : type
Contains the datatype stored in the Field. Contains the datatype stored in the Field.
distribution_strategy : string distribution_strategy : string
Name of the used distribution_strategy. Name of the used distribution_strategy.
Raise Raise
----- -----
TypeError TypeError
...@@ -87,7 +86,7 @@ class Field(Loggable, Versionable, object): ...@@ -87,7 +86,7 @@ class Field(Loggable, Versionable, object):
*the given domain contains something that is not a DomainObject *the given domain contains something that is not a DomainObject
instance instance
*val is an array that has a different dimension than the domain *val is an array that has a different dimension than the domain
Examples Examples
-------- --------
>>> a = Field(RGSpace([4,5]),val=2) >>> a = Field(RGSpace([4,5]),val=2)
...@@ -99,7 +98,7 @@ class Field(Loggable, Versionable, object): ...@@ -99,7 +98,7 @@ class Field(Loggable, Versionable, object):
[2, 2, 2, 2, 2]]) [2, 2, 2, 2, 2]])
>>> a.dtype >>> a.dtype
dtype('int64') dtype('int64')
See Also See Also
-------- --------
distributed_data_object distributed_data_object
...@@ -169,15 +168,15 @@ class Field(Loggable, Versionable, object): ...@@ -169,15 +168,15 @@ class Field(Loggable, Versionable, object):
Normal input is a domain/ tuple of domains. Normal input is a domain/ tuple of domains.
start : int start : int
Sets the integer number for the first axis Sets the integer number for the first axis
Returns Returns
------- -------
out : tuple out : tuple
Incremental numeration of all axes. Incremental numeration of all axes.
Note Note
---- ----
The 'spaces' keyword is used in operators in order to carry out The 'spaces' keyword is used in operators in order to carry out
operations only on a certain subspace if the domain of the Field is operations only on a certain subspace if the domain of the Field is
a product space. a product space.
...@@ -202,7 +201,7 @@ class Field(Loggable, Versionable, object): ...@@ -202,7 +201,7 @@ class Field(Loggable, Versionable, object):
val : list of arrays val : list of arrays
If the dtype is None, Fields tries to infere the datatype from the If the dtype is None, Fields tries to infere the datatype from the
values given to it at initialization. values given to it at initialization.
Returns Returns
------- -------
out : np.dtype out : np.dtype
...@@ -247,20 +246,20 @@ class Field(Loggable, Versionable, object): ...@@ -247,20 +246,20 @@ class Field(Loggable, Versionable, object):
Parameters Parameters
---------- ----------
cls : class cls : class
random_type : String random_type : String
'pm1', 'normal', 'uniform' are the supported arguments for this 'pm1', 'normal', 'uniform' are the supported arguments for this
method. method.
domain : DomainObject domain : DomainObject
The domain of the output random field The domain of the output random field
dtype : type dtype : type
The datatype of the output random field The datatype of the output random field
distribution_strategy : all supported distribution strategies distribution_strategy : all supported distribution strategies
The distribution strategy of the output random field The distribution strategy of the output random field
Returns Returns
------- -------
out : Field out : Field
...@@ -319,8 +318,8 @@ class Field(Loggable, Versionable, object): ...@@ -319,8 +318,8 @@ class Field(Loggable, Versionable, object):
def power_analyze(self, spaces=None, log=False, nbin=None, binbounds=None, def power_analyze(self, spaces=None, log=False, nbin=None, binbounds=None,
real_signal=True): real_signal=True):
""" Computes the powerspectrum of the Field """ Computes the powerspectrum of the Field
Creates a PowerSpace with the given attributes and computes the Creates a PowerSpace with the given attributes and computes the
power spectrum as a field over this PowerSpace. power spectrum as a field over this PowerSpace.
It's important to note that this can only be done if the subspace to It's important to note that this can only be done if the subspace to
be analyzed is in harmonic space. be analyzed is in harmonic space.
...@@ -331,16 +330,16 @@ class Field(Loggable, Versionable, object): ...@@ -331,16 +330,16 @@ class Field(Loggable, Versionable, object):
The subspace which you want to have the powerspectrum of. The subspace which you want to have the powerspectrum of.
{default : None} {default : None}
if spaces==None : Tries to synthesize for the whole domain if spaces==None : Tries to synthesize for the whole domain
log : boolean, *optional* log : boolean, *optional*
True if the output PowerSpace should have log binning. True if the output PowerSpace should have log binning.
{default : False} {default : False}
nbin : int, None, *optional* nbin : int, None, *optional*
The number of bins the resulting PowerSpace shall have. The number of bins the resulting PowerSpace shall have.
{default : None} {default : None}
if nbin==None : maximum number of bins is used if nbin==None : maximum number of bins is used
binbounds : array-like, None, *optional* binbounds : array-like, None, *optional*
Inner bounds of the bins, if specifield Inner bounds of the bins, if specifield
{default : None} {default : None}
...@@ -357,10 +356,10 @@ class Field(Loggable, Versionable, object): ...@@ -357,10 +356,10 @@ class Field(Loggable, Versionable, object):
*len(spaces) is either 0 or >1 *len(spaces) is either 0 or >1
*len(domain) is not 1 with spaces=None *len(domain) is not 1 with spaces=None
*the analyzed space is not harmonic *the analyzed space is not harmonic
Returns Returns
------- -------
out : Field out : Field
The output object. It's domain is a PowerSpace and it contains The output object. It's domain is a PowerSpace and it contains
the power spectrum of 'self's field. the power spectrum of 'self's field.
...@@ -505,26 +504,26 @@ class Field(Loggable, Versionable, object): ...@@ -505,26 +504,26 @@ class Field(Loggable, Versionable, object):
def power_synthesize(self, spaces=None, real_power=True, real_signal=True, def power_synthesize(self, spaces=None, real_power=True, real_signal=True,
mean=None, std=None): mean=None, std=None):
"""Yields a random field in harmonic space with this power spectrum. """Yields a random field in harmonic space with this power spectrum.
This method draws a Gaussian random field in the harmic partner domain. This method draws a Gaussian random field in the harmic partner domain.
The drawn field has this field as its power spectrum. The drawn field has this field as its power spectrum.
Notes Notes
----- -----
For this the domain must be a PowerSpace. For this the domain must be a PowerSpace.
Parameters Parameters
---------- ----------
spaces : {tuple, int, None} *optional* spaces : {tuple, int, None} *optional*
Specifies the subspace in which the power will be synthesized in Specifies the subspace in which the power will be synthesized in
case of a product space. case of a product space.
{default : None} {default : None}
if spaces==None : Tries to synthesize for the whole domain if spaces==None : Tries to synthesize for the whole domain
real_power : boolean *optional* real_power : boolean *optional*
Determines whether the power spectrum is real or complex Determines whether the power spectrum is real or complex
{default : True} {default : True}
real_signal : boolean *optional* real_signal : boolean *optional*
True will result in a purely real signal-space field. True will result in a purely real signal-space field.
This means that the created field is symmetric wrt. the origin This means that the created field is symmetric wrt. the origin
...@@ -535,11 +534,11 @@ class Field(Loggable, Versionable, object): ...@@ -535,11 +534,11 @@ class Field(Loggable, Versionable, object):
{default : None} {default : None}
if mean==None : mean will be set to 0 if mean==None : mean will be set to 0
std : float *optional* std : float *optional*
The standard deviation of the noise field the powerspectrum will be The standard deviation of the noise field the powerspectrum will be
multiplied on. multiplied on.
{default : None} {default : None}
if std==None : std will be set to 1 if std==None : std will be set to 1
Returns Returns
------- -------
out : Field out : Field
...@@ -664,12 +663,12 @@ class Field(Loggable, Versionable, object): ...@@ -664,12 +663,12 @@ class Field(Loggable, Versionable, object):
Parameters Parameters
---------- ----------
new_val : number, numpy.array, distributed_data_object, new_val : number, numpy.array, distributed_data_object,
Field, None, *optional* Field, None, *optional*
The values to be stored in the field. The values to be stored in the field.
{default : None} {default : None}
if new_val==None : sets the values to 0. if new_val==None : sets the values to 0.
copy : boolean, *optional* copy : boolean, *optional*
True if this field holds a copy of new_val, False if True if this field holds a copy of new_val, False if
it holds the same object it holds the same object
...@@ -691,9 +690,9 @@ class Field(Loggable, Versionable, object): ...@@ -691,9 +690,9 @@ class Field(Loggable, Versionable, object):
Parameters Parameters
---------- ----------
copy : boolean copy : boolean
True makes the method retrun a COPY of the Field's underlying True makes the method retrun a COPY of the Field's underlying
distributed_data_object. distributed_data_object.
Returns Returns
------- -------
out : distributed_data_object out : distributed_data_object
...@@ -715,7 +714,7 @@ class Field(Loggable, Versionable, object): ...@@ -715,7 +714,7 @@ class Field(Loggable, Versionable, object):
@property @property
def val(self): def val(self):
""" Retruns actual distributed_data_object associated with this Field. """ Retruns actual distributed_data_object associated with this Field.
Returns Returns
------- -------
out : distributed_data_object out : distributed_data_object
...@@ -731,7 +730,7 @@ class Field(Loggable, Versionable, object): ...@@ -731,7 +730,7 @@ class Field(Loggable, Versionable, object):
@val.setter @val.setter
def val(self, new_val): def val(self, new_val):
""" Sets the values in the d2o of the Field. """ Sets the values in the d2o of the Field.
Parameters Parameters
---------- ----------
new_val : number, numpy.array, distributed_data_object, Field new_val : number, numpy.array, distributed_data_object, Field
...@@ -748,9 +747,9 @@ class Field(Loggable, Versionable, object): ...@@ -748,9 +747,9 @@ class Field(Loggable, Versionable, object):
@property @property
def shape(self): def shape(self):
""" Returns the shape of the Field/ it's domain. """ Returns the shape of the Field/ it's domain.
All axes lengths written down seperately in a tuple. All axes lengths written down seperately in a tuple.
Returns Returns
------- -------
out : tuple out : tuple
...@@ -773,9 +772,9 @@ class Field(Loggable, Versionable, object): ...@@ -773,9 +772,9 @@ class Field(Loggable, Versionable, object):
@property @property
def dim(self): def dim(self):
""" Returns the dimension of the Field/it's domain. """ Returns the dimension of the Field/it's domain.
Multiplies all values from shape. Multiplies all values from shape.
Returns Returns
------- -------
out : int out : int
...@@ -811,16 +810,16 @@ class Field(Loggable, Versionable, object): ...@@ -811,16 +810,16 @@ class Field(Loggable, Versionable, object):
def cast(self, x=None, dtype=None): def cast(self, x=None, dtype=None):
""" Transforms x to a d2o with the same shape as the domain of 'self' """ Transforms x to a d2o with the same shape as the domain of 'self'
Parameters Parameters
---------- ----------
x : number, d2o, Field, array_like x : number, d2o, Field, array_like
The input that shall be casted on a d2o of the same shape like the The input that shall be casted on a d2o of the same shape like the
domain. domain.
dtype : type dtype : type
The datatype the output shall have. The datatype the output shall have.
Returns Returns
------- -------
out : distributed_data_object out : distributed_data_object
...@@ -866,7 +865,7 @@ class Field(Loggable, Versionable, object): ...@@ -866,7 +865,7 @@ class Field(Loggable, Versionable, object):
def copy(self, domain=None, dtype=None, distribution_strategy=None): def copy(self, domain=None, dtype=None, distribution_strategy=None):
""" Returns a full copy of the Field. """ Returns a full copy of the Field.
If no keyword arguments are given, the returned object will be an If no keyword arguments are given, the returned object will be an
identical copy of the original Field. By explicit specification one is identical copy of the original Field. By explicit specification one is
able to define the domain, the dtype and the distribution_strategy of able to define the domain, the dtype and the distribution_strategy of
...@@ -876,13 +875,13 @@ class Field(Loggable, Versionable, object): ...@@ -876,13 +875,13 @@ class Field(Loggable, Versionable, object):
---------- ----------
domain : DomainObject domain : DomainObject
The new domain the Field shall have. The new domain the Field shall have.
dtype : type dtype : type
The new dtype the Field shall have. The new dtype the Field shall have.
distribution_strategy : all supported distribution strategies distribution_strategy : all supported distribution strategies
The new distribution strategy the Field shall have. The new distribution strategy the Field shall have.
Returns Returns
------- -------
out : Field out : Field
...@@ -906,20 +905,20 @@ class Field(Loggable, Versionable, object): ...@@ -906,20 +905,20 @@ class Field(Loggable, Versionable, object):
If no keyword arguments are given, the returned object will be an If no keyword arguments are given, the returned object will be an
identical copy of the original Field containing random data. By identical copy of the original Field containing random data. By
explicit specification one is able to define the domain, the dtype and explicit specification one is able to define the domain, the dtype and
the distribution_strategy of the returned Field. the distribution_strategy of the returned Field.
Parameters Parameters
---------- ----------
domain : DomainObject domain : DomainObject
The new domain the Field shall have. The new domain the Field shall have.
dtype : type dtype : type
The new dtype the Field shall have. The new dtype the Field shall have.
distribution_strategy : all supported distribution strategies distribution_strategy : all supported distribution strategies
The distribution strategy the new Field should have. The distribution strategy the new Field should have.
Returns Returns
------- -------
out : Field out : Field
...@@ -984,13 +983,13 @@ class Field(Loggable, Versionable, object): ...@@ -984,13 +983,13 @@ class Field(Loggable, Versionable, object):
Here one can set the power to which the dimension is taken before Here one can set the power to which the dimension is taken before
division. power=2 will make the method devide every entry in 'self' division. power=2 will make the method devide every entry in 'self'
by the square of the dimension. by the square of the dimension.
inplace : boolean inplace : boolean
For True the values in 'self' will be changed to the weighted ones. For True the values in 'self' will be changed to the weighted ones.
spaces : int spaces : int
Determines on what subspace the operation takes place. Determines on what subspace the operation takes place.
Returns Returns
------- -------
out : Field out : Field
...@@ -1020,27 +1019,27 @@ class Field(Loggable, Versionable, object): ...@@ -1020,27 +1019,27 @@ class Field(Loggable, Versionable, object):
def dot(self, x=None, spaces=None, bare=False): def dot(self, x=None, spaces=None, bare=False):
""" Computes the dot product of 'self' with x. """ Computes the dot product of 'self' with x.
For a 1D Field this is the scalar product. For a 1D Field this is the scalar product.
Parameters Parameters
---------- ----------
x : Field x : Field
Must have the same shape as 'self' Must have the same shape as 'self'
spaces : int spaces : int
bare : boolean bare : boolean
bare=True operation will compute the sum over the pointwise product bare=True operation will compute the sum over the pointwise product
of 'self' and x. of 'self' and x.
With bare=False this number will be devided by the dimension of the With bare=False this number will be devided by the dimension of the
space over which the dotproduct is comupted. space over which the dotproduct is comupted.
Returns Returns
------- -------
out : float, complex out : float, complex
""" """
if not isinstance(x, Field): if not isinstance(x, Field):
raise ValueError("The dot-partner must be an instance of " + raise ValueError("The dot-partner must be an instance of " +
...@@ -1089,12 +1088,12 @@ class Field(Loggable, Versionable, object): ...@@ -1089,12 +1088,12 @@ class Field(Loggable, Versionable, object):
def conjugate(self, inplace=False): def conjugate(self, inplace=False):
""" Retruns the complex conjugate of the field. """ Retruns the complex conjugate of the field.
Parameters Parameters
---------- ----------
inplace : boolean inplace : boolean
Decides whether self or a copied version of self shall be used Decides whether self or a copied version of self shall be used
Returns Returns
------- -------
cc : field cc : field
...@@ -1427,18 +1426,18 @@ class Field(Loggable, Versionable, object): ...@@ -1427,18 +1426,18 @@ class Field(Loggable, Versionable, object):
def __repr__(self): def __repr__(self):
""" Is called by jsut typing the instance's name. """ Is called by jsut typing the instance's name.
""" """
return "<nifty_core.field>" return "<nifty_core.field>"
def __str__(self): def __str__(self):
""" Is called by the print command. """ Is called by the print command.
Retruns Retruns
------- -------
out : A sting with usefull information about the stored values and out : A sting with usefull information about the stored values and
properties of 'self' properties of 'self'
""" """
minmax = [self.min(), self.max()] minmax = [self.min(), self.max()]
mean = self.mean() mean = self.mean()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!