nifty8.sugar module#

PS_field(pspace, function)[source]#

Convenience function sampling a power spectrum

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

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

Returns:

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

Return type:

nifty8.field.Field

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.

Parameters:
  • 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

Returns:

The requested smoothing operator

Return type:

DiagonalOperator

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

Creates a diagonal operator with the given power spectrum.

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

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

  • power_spectrum (callable or nifty8.field.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

  • sampling_dtype (dtype or dict of dtype) – Specifies the dtype of the underlying Gaussian distribution. Gaussian. If sampling_dtype is None, the operator cannot be used as a covariance, i.e. no samples can be drawn. Default: None.

Returns:

An operator that implements the given power spectrum.

Return type:

DiagonalOperator

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

Computes the union of multiple DomainTuples/MultiDomains.

Parameters:

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, verbose=False, domain_dtype=<class 'numpy.float64'>, ntries=1)[source]#

Times the execution time of an operator or an energy.

Parameters:
  • obj (Operator or Energy) – Operator or Energy that shall be profiled.

  • want_metric (bool, optional) – Determine if Operator shall be called with want_metric=True. Only applicable for EnergyOperators. Default: True.

  • verbose (bool, optional) – If True, more profiling information is printed. Default: False.

  • domain_dtype (dtype or dict of dtype)

  • ntries (int) – Number of times the operator shall be called. Default: 1.

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.

Parameters:
  • 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’)

Returns:

The newly created random field

Return type:

nifty8.field.Field or:class:nifty8.mulit_field.MultiField

Notes

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.

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

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

Returns:

The newly created uniform field

Return type:

nifty8.field.Field or:class:nifty8.mulit_field.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.

Parameters:
  • 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.

Parameters:
  • 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

is_fieldlike(obj)[source]#

Checks if object is field-like.

Note

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.

is_likelihood_energy(obj)[source]#

Checks if object behaves like a likelihood energy.

is_linearization(obj)[source]#

Checks if object is linearization-like.

is_operator(obj)[source]#

Checks if object is operator-like.

Note

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)#
makeDomain(domain)[source]#

Convenience function creating DomainTuples/MultiDomains Domainoids.

Parameters:

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

Returns:

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.

Parameters:
  • 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

Returns:

The newly created random field

Return type:

nifty8.field.Field or:class:nifty8.mulit_field.MultiField

makeOp(inp, dom=None, sampling_dtype=None)[source]#

Converts a Field or MultiField to a diagonal operator.

Parameters:
  • inp (None, nifty8.field.Field or nifty8.multi_field.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 inp is a scalar, this is used as the operator’s domain

  • sampling_dtype (dtype or dict of dtypes) – If inp shall represent the diagonal covariance of a Gaussian probabilty distribution, sampling_dtype specifies if it is real or complex Gaussian. If sampling_dtype is None, the operator cannot be used as a covariance, i.e. no samples can be drawn. Default: None.

Notes

No volume factors are applied.

plot_priorsamples(op, n_samples=5, common_colorbar=True, **kwargs)[source]#

Create a number of prior sample plots using Plot

Parameters:
  • op – Operator that mapping from standard Gaussian with covariance 1 to the prior distribution

  • n_samples (int) – Number of prior samples for plotting

Note

Keyword arguments are passed to both Plot.add and Plot.output.

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.

Parameters:
  • field (nifty8.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).

Returns:

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

Return type:

nifty8.field.Field

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)#