nifty7.sugar module#

PS_field(pspace, func)[source]#

Convenience function sampling a power spectrum

  • pspace (PowerSpace) – space at whose k_lengths the power spectrum function is evaluated

  • func (function taking and returning a numpy.ndarray(float)) – the power spectrum function


A field defined on (pspace,) containing the computed function values

Return type:


abs(x, *args, **kwargs)#
absolute(x, *args, **kwargs)#
arctan(x, *args, **kwargs)#
calculate_position(operator, output)[source]#

Finds approximate preimage of an operator for a given output.

clip(x, *args, **kwargs)#
cos(x, *args, **kwargs)#
cosh(x, *args, **kwargs)#
create_harmonic_smoothing_operator(domain, space, sigma)[source]#

Creates an operator which smoothes a subspace of a harmonic domain.

  • domain (DomainTuple) – The total domain and target of the operator

  • space (int) – the index of the subspace on which the operator acts. This must be a harmonic space

  • sigma (float) – The sigma of the Gaussian smoothing kernel


The requested smoothing operator

Return type:


create_power_operator(domain, power_spectrum, space=None)[source]#

Creates a diagonal operator with the given power spectrum.

Constructs a diagonal operator that is defined on the specified domain.

  • domain (Domain, tuple of Domain or DomainTuple) – Domain on which the power operator shall be defined.

  • power_spectrum (callable or Field) – An object that contains the power spectrum as a function of k.

  • space (int) – the domain index on which the power operator will work


An operator that implements the given power spectrum.

Return type:


density_estimator(domain, pad=1.0, cf_fluctuations=None, cf_azm_uniform=None, prefix='')[source]#

Computes the union of multiple DomainTuples/MultiDomains.


domains (list of DomainTuple or MultiDomain) –

  • if DomainTuple, all entries must be equal

  • if MultiDomain, there must not be any conflicting components

exec_time(obj, want_metric=True)[source]#

Times the execution time of an operator or an energy.

exp(x, *args, **kwargs)#
expm1(x, *args, **kwargs)#
exponentiate(x, *args, **kwargs)#
from_random(domain, random_type='normal', dtype=<class 'numpy.float64'>, **kwargs)[source]#

Convenience function creating Fields/MultiFields with random values.

  • domain (Domainoid) – the intended domain of the output field

  • random_type ('pm1', 'normal', or 'uniform') – The random distribution to use.

  • dtype (type) – data type of the output field (e.g. numpy.float64) If the datatype is complex, each real an imaginary part have variance 1.

  • **kwargs (additional parameters for the random distribution) – (‘mean’ and ‘std’ for ‘normal’, ‘low’ and ‘high’ for ‘uniform’)


The newly created random field

Return type:

Field or MultiField


When called with a multi-domain, the individual fields will be drawn in alphabetical order of the multi-domain’s domain keys. As a consequence, renaming these keys may cause the multi-field to be filled with different random numbers, even for the same initial RNG state.

full(domain, val)[source]#

Convenience function creating Fields/MultiFields with uniform values.

  • domain (Domainoid) – the intended domain of the output field

  • val (scalar value) – the uniform value to be placed into all entries of the result


The newly created uniform field

Return type:

Field or MultiField

get_default_codomain(domainoid, space=None)[source]#

For RGSpace, returns the harmonic partner domain. For DomainTuple, returns a copy of the object in which the domain indexed by space is substituted by its harmonic partner domain. In this case, if space is None, it is set to 0 if the DomainTuple contains exactly one domain.

  • domain (RGSpace or DomainTuple) – Domain for which to constuct the default harmonic partner

  • space (int) – Optional index of the subdomain to be replaced by its default codomain. domain[space] must be of class RGSpace.

get_signal_variance(spec, space)[source]#

Computes how much a field with a given power spectrum will vary in space

This is a small helper function that computes the expected variance of a harmonically transformed sample of this power spectrum.

  • spec (method) – a method that takes one k-value and returns the power spectrum at that location

  • space (PowerSpace or any harmonic Domain) – If this function is given a harmonic domain, it creates the naturally binned PowerSpace to that domain. The field, for which the signal variance is then computed, is assumed to have this PowerSpace as naturally binned PowerSpace


Checks if object is field-like.


A simple isinstance(obj, ift.Field) does not give the expected result because users might have implemented another class which behaves field-like but is not an instance of Field. Also note that instances of Linearization behave field-like.


Checks if object behaves like a likelihood energy.


Checks if object is linearization-like.


Checks if object is operator-like.


A simple isinstance(obj, ift.Operator) does not give the expected result because, e.g., Field inherits from Operator.

log(x, *args, **kwargs)#
log10(x, *args, **kwargs)#
log1p(x, *args, **kwargs)#

Convenience function creating DomainTuples/MultiDomains Domainoids.


domain (Domainoid (can be DomainTuple, MultiDomain, dict, Domain or list of Domains)) – the description of the requested (multi-)domain


The newly created domain object

Return type:

DomainTuple or MultiDomain

makeField(domain, arr)[source]#

Convenience function creating Fields/MultiFields from Numpy arrays or dicts of Numpy arrays.

  • domain (Domainoid) – the intended domain of the output field

  • arr (Numpy array if domain corresponds to a DomainTuple,) – dictionary of Numpy arrays if domain corresponds to a MultiDomain


The newly created random field

Return type:

Field or MultiField

makeOp(input, dom=None)[source]#

Converts a Field or MultiField to a diagonal operator.

  • input (None, Field or MultiField) –

    • if None, None is returned.

    • if Field on scalar-domain, a ScalingOperator with the coefficient

      given by the Field is returned.

    • if Field, a DiagonalOperator with the coefficients given by this

      Field is returned.

    • if MultiField, a BlockDiagonalOperator with entries given by this

      MultiField is returned.

  • dom (DomainTuple or MultiDomain) – if input is a scalar, this is used as the operator’s domain


No volume factors are applied.

power(x, *args, **kwargs)#
power_analyze(field, spaces=None, binbounds=None, keep_phase_information=False)[source]#

Computes the power spectrum for a subspace of 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. The resulting field has the same units as the square of the initial field.

  • field (Field) – The field to be analyzed

  • spaces (None or int or tuple of int, optional) – The indices of subdomains for which the power spectrum shall be computed. If None, all subdomains will be converted. (default : None).

  • binbounds (None or array-like, optional) – Inner bounds of the bins (default : None). if binbounds is None : bins are inferred.

  • keep_phase_information (bool, optional) – If False, return a real-valued result containing the power spectrum of field. If True, return a complex-valued result whose real component contains the power spectrum computed from the real part of field, and whose imaginary component contains the power spectrum computed from the imaginary part of field. The absolute value of this result should be identical to the output of power_analyze with keep_phase_information=False. (default : False).


The output object. Its domain is a PowerSpace and it contains the power spectrum of field.

Return type:


reciprocal(x, *args, **kwargs)#
sigmoid(x, *args, **kwargs)#
sign(x, *args, **kwargs)#
sin(x, *args, **kwargs)#
sinc(x, *args, **kwargs)#
single_plot(field, **kwargs)[source]#

Creates a single plot using Plot. Keyword arguments are passed to both Plot.add and Plot.output.

sinh(x, *args, **kwargs)#
softplus(x, *args, **kwargs)#
sqrt(x, *args, **kwargs)#
tan(x, *args, **kwargs)#
tanh(x, *args, **kwargs)#
unitstep(x, *args, **kwargs)#