The Field class – …

class nifty.Field(domain=None, val=None, dtype=None, distribution_strategy=None, copy=False)[source]

Bases: keepers.logging.loggable.Loggable, keepers.versioning.versionable.Versionable, object

The discrete representation of a continuous field over multiple spaces.

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. In addition Field has methods to work with power-spectra.

Parameters:

domain : DomainObject

One of the space types NIFTY supports. RGSpace, GLSpace, HPSpace, LMSpace or PowerSpace. It might also be a FieldArray, which is an unstructured domain.

val : scalar, numpy.ndarray, distributed_data_object, Field

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 array’s dimensions must match the domain’s.

dtype : type

A numpy.type. Most common are int, float and complex.

distribution_strategy: optional[{‘fftw’, ‘equal’, ‘not’, ‘freeform’}]

Specifies which distributor will be created and used. ‘fftw’ uses the distribution strategy of pyfftw, ‘equal’ tries to distribute the data as uniform as possible ‘not’ does not distribute the data at all ‘freeform’ distribute the data according to the given local data/shape

copy: boolean

See also

distributed_data_object

Examples

>>> a = Field(RGSpace([4,5]),val=2)
>>> a.val
<distributed_data_object>
array([[2, 2, 2, 2, 2],
       [2, 2, 2, 2, 2],
       [2, 2, 2, 2, 2],
       [2, 2, 2, 2, 2]])
>>> a.dtype
dtype('int64')

Attributes

val Returns the distributed_data_object associated with this Field.
domain (DomainObject) See Parameters.
domain_axes (tuple of tuples) Enumerates the axes of the Field
dtype (type) Contains the datatype stored in the Field.
distribution_strategy (string) Name of the used distribution_strategy.

Methods

all([spaces])
any([spaces])
cast([x, dtype]) Transforms x to a d2o with the correct dtype and shape.
conjugate([inplace]) Retruns the complex conjugate of the field.
copy([domain, dtype, distribution_strategy]) Returns a full copy of the Field.
copy_empty([domain, dtype, …]) Returns an empty copy of the Field.
dot([x, spaces, bare]) Computes the volume-factor-aware dot product of ‘self’ with x.
from_random(random_type[, domain, dtype, …]) Draws a random field with the given parameters.
get_val([copy]) Returns the distributed_data_object associated with this Field.
max([spaces])
mean([spaces])
min([spaces])
nanmax([spaces])
nanmin([spaces])
norm([q]) Computes the Lq-norm of the field values.
power_analyze([spaces, logarithmic, nbin, …]) Computes the powerspectrum for a subspace of the Field.
power_synthesize([spaces, real_power, …]) Converts a power spectrum into a random field realization.
prod([spaces])
set_val([new_val, copy]) Sets the fields distributed_data_object.
std([spaces])
sum([spaces])
var([spaces])
weight([power, inplace, spaces]) Weights the pixels of self with their invidual pixel-volume.

Methods

cast(x=None, dtype=None)[source]

Transforms x to a d2o with the correct dtype and shape.

Parameters:

x : scalar, d2o, Field, array_like

The input that shall be casted on a d2o of the same shape like the domain.

dtype : type

The datatype the output shall have. This can be used to override the fields dtype.

Returns:

out : distributed_data_object

The output object.

See also

_actual_cast

conjugate(inplace=False)[source]

Retruns the complex conjugate of the field.

Parameters:

inplace : boolean

Decides whether the conjugation should be performed inplace.

Returns:

cc : field

The complex conjugated field.

copy(domain=None, dtype=None, distribution_strategy=None)[source]

Returns a full copy of the Field.

If no keyword arguments are given, the returned object will be an identical copy of the original Field. By explicit specification one is able to define the domain, the dtype and the distribution_strategy of the returned Field.

Parameters:

domain : DomainObject

The new domain the Field shall have.

dtype : type

The new dtype the Field shall have.

distribution_strategy : all supported distribution strategies

The new distribution strategy the Field shall have.

Returns:

out : Field

The output object. An identical copy of ‘self’.

See also

copy_empty

copy_empty(domain=None, dtype=None, distribution_strategy=None)[source]

Returns an empty copy of the Field.

If no keyword arguments are given, the returned object will be an identical copy of the original Field. The memory for the data array is only allocated but not actively set to any value (c.f. numpy.ndarray.copy_empty). By explicit specification one is able to change the domain, the dtype and the distribution_strategy of the returned Field.

Parameters:

domain : DomainObject

The new domain the Field shall have.

dtype : type

The new dtype the Field shall have.

distribution_strategy : string, all supported distribution strategies

The distribution strategy the new Field should have.

Returns:

out : Field

The output object.

See also

copy

dot(x=None, spaces=None, bare=False)[source]

Computes the volume-factor-aware dot product of ‘self’ with x.

Parameters:

x : Field

The domain of x must contain self.domain

spaces : tuple of ints

If the domain of self and x are not the same, spaces specfies the mapping.

bare : boolean

If true, no volume factors will be included in the computation.

Returns:

out : float, complex

classmethod from_random(random_type, domain=None, dtype=None, distribution_strategy=None, **kwargs)[source]

Draws a random field with the given parameters.

Parameters:

cls : class

random_type : String

‘pm1’, ‘normal’, ‘uniform’ are the supported arguments for this method.

domain : DomainObject

The domain of the output random field

dtype : type

The datatype of the output random field

distribution_strategy : all supported distribution strategies

The distribution strategy of the output random field

Returns:

out : Field

The output object.

See also

power_synthesise

get_val(copy=False)[source]

Returns the distributed_data_object associated with this Field.

Parameters:

copy : boolean

If true, a copy of the Field’s underlying distributed_data_object is returned.

Returns:

out : distributed_data_object

See also

val

norm(q=2)[source]

Computes the Lq-norm of the field values.

Parameters:

q : scalar

Parameter q of the Lq-norm (default: 2).

Returns:

norm : scalar

The Lq-norm of the field values.

power_analyze(spaces=None, logarithmic=False, nbin=None, binbounds=None, decompose_power=True)[source]

Computes the powerspectrum for a subspace of the Field.

Creates a PowerSpace for the space addressed by spaces with the given binning and computes the power spectrum as a Field over this PowerSpace. This can only be done if the subspace to be analyzed is a harmonic space.

Parameters:

spaces : int optional

The subspace for which the powerspectrum shall be computed (default : None). if spaces==None : Tries to synthesize for the whole domain

logarithmic : boolean optional

True if the output PowerSpace should use logarithmic binning. {default : False}

nbin : int optional

The number of bins the resulting PowerSpace shall have (default : None). if nbin==None : maximum number of bins is used

binbounds : array-like optional

Inner bounds of the bins (default : None). if binbounds==None : bins are inferred. Overwrites nbins and log

decompose_power : boolean, optional

Whether the analysed signal-space Field is intrinsically real or complex and if the power spectrum shall therefore be computed for the real and the imaginary part of the Field separately (default : True).

Returns:

out : Field

The output object. It’s domain is a PowerSpace and it contains the power spectrum of ‘self’s field.

power_synthesize(spaces=None, real_power=True, real_signal=True, mean=None, std=None)[source]

Converts a power spectrum into a random field realization.

This method draws a Gaussian random field in the harmic partner domain of a PowerSpace.

Parameters:

spaces : {tuple, int, None} optional

Specifies the subspace containing all the PowerSpaces which should be converted (default : None). if spaces==None : Tries to convert the whole domain.

real_power : boolean optional

Determines whether the power spectrum is treated as intrinsically real or complex (default : True).

real_signal : boolean optional

True will result in a purely real signal-space field (default : True).

mean : float optional

The mean of the Gaussian noise field which is used for the Field synthetization (default : None). if mean==None : mean will be set to 0

std : float optional

The standard deviation of the Gaussian noise field which is used for the Field synthetization (default : None). {default : None} if std==None : std will be set to 1

Returns:

out : Field

The output object. A random field created with the power spectrum stored in the spaces in self.

See also

power_analyze

Notes

For this the spaces specified by spaces must be a PowerSpaces.

set_val(new_val=None, copy=False)[source]

Sets the fields distributed_data_object.

Parameters:

new_val : scalar, array-like, Field, None optional

The values to be stored in the field. {default : None}

copy : boolean, optional

If False, Field tries to not copy the input data but use it directly. {default : False}

See Also

——–

val

weight(power=1, inplace=False, spaces=None)[source]

Weights the pixels of self with their invidual pixel-volume.

Parameters:

power : number

The pixels get weighted with the volume-factor**power.

inplace : boolean

If True, self will be weighted and returned. Otherwise, a copy is made.

spaces : tuple of ints

Determines on which subspace the operation takes place.

Returns:

out : Field

The weighted field.

dim

Returns the total number of pixel-dimensions the field has.

Effectively, all values from shape are multiplied.

Returns:

out : int

The dimension of the Field.

See also

shape

dof

Returns the total number of degrees of freedom the Field has. For real Fields this is equal to self.dim. For complex Fields it is 2*`self.dim`.

shape

Returns the total shape of the Field’s data array.

Returns:

out : tuple

The output object. The tuple contains the dimansions of the spaces in domain.

See also

dim

total_volume

Returns the total volume of all spaces in the domain.

val

Returns the distributed_data_object associated with this Field.

Returns:out : distributed_data_object

See also

get_val