Ejemplo n.º 1
0
def test_gaussian_energy(space, nonlinearity, noise, seed):
    np.random.seed(seed)
    dim = len(space.shape)
    hspace = space.get_default_codomain()
    ht = ift.HarmonicTransformOperator(hspace, target=space)
    binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
    pspace = ift.PowerSpace(hspace, binbounds=binbounds)
    Dist = ift.PowerDistributor(target=hspace, power_space=pspace)
    xi0 = ift.Field.from_random(domain=hspace, random_type='normal')

    def pspec(k):
        return 1 / (1 + k**2)**dim

    pspec = ift.PS_field(pspace, pspec)
    A = Dist(ift.sqrt(pspec))
    N = ift.ScalingOperator(noise, space)
    n = N.draw_sample()
    R = ift.ScalingOperator(10., space)

    def d_model():
        if nonlinearity == "":
            return R(ht(ift.makeOp(A)))
        else:
            tmp = ht(ift.makeOp(A))
            nonlin = getattr(tmp, nonlinearity)()
            return R(nonlin)

    d = d_model()(xi0) + n

    if noise == 1:
        N = None

    energy = ift.GaussianEnergy(d, N)(d_model())
    ift.extra.check_jacobian_consistency(energy, xi0, ntries=10, tol=5e-8)
def test_normalisation(space, tp):
    tol = 10*_get_rtol(tp)
    cospace = space.get_default_codomain()
    fft = ift.HarmonicTransformOperator(space, cospace)
    inp = ift.Field.from_random(
        domain=space, random_type='normal', std=1, mean=2, dtype=tp)
    out = fft.times(inp)
    zero_idx = tuple([0]*len(space.shape))
    assert_allclose(
        inp.to_global_data()[zero_idx], out.integrate(), rtol=tol, atol=tol)
def test_dotsht2(lm, tp):
    tol = 10*_get_rtol(tp)
    a = ift.LMSpace(lmax=lm)
    b = ift.HPSpace(nside=lm//2)
    fft = ift.HarmonicTransformOperator(domain=a, target=b)
    inp = ift.Field.from_random(
        domain=a, random_type='normal', std=1, mean=0, dtype=tp)
    out = fft.times(inp)
    v1 = np.sqrt(out.vdot(out))
    v2 = np.sqrt(inp.vdot(fft.adjoint_times(out)))
    assert_allclose(v1, v2, rtol=tol, atol=tol)
Ejemplo n.º 4
0
#
# Copyright(C) 2013-2019 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.

import numpy as np

import nifty5 as ift
from helpers import plot_WF, power_plot, generate_mysterious_data

np.random.seed(42)

position_space = ift.RGSpace(256)
harmonic_space = position_space.get_default_codomain()

HT = ift.HarmonicTransformOperator(harmonic_space, target=position_space)

power_space = ift.PowerSpace(harmonic_space)

# Set up an amplitude operator for the field
# We want to set up a model for the amplitude spectrum with some magic numbers
dct = {
    'target': power_space,
    'n_pix': 64,  # 64 spectral bins
    # Spectral smoothness (affects Gaussian process part)
    'a': 10,  # relatively high variance of spectral curvature
    'k0': .2,  # quefrency mode below which cepstrum flattens
    # Power-law part of spectrum:
    'sm': -4,  # preferred power-law slope
    'sv': .6,  # low variance of power-law slope
    'im':  -6,  # y-intercept mean, in-/decrease for more/less contrast
Ejemplo n.º 5
0
def testHarmonic(sp, dtype):
    _check_repr(ift.HarmonicTransformOperator(sp))
Ejemplo n.º 6
0
def testHarmonic(sp, dtype):
    op = ift.HarmonicTransformOperator(sp)
    ift.extra.consistency_check(op, dtype, dtype)
Ejemplo n.º 7
0

if __name__ == '__main__':
    np.random.seed(420)

    # Choose between random line-of-sight response (mode=0) and radial lines
    # of sight (mode=1)
    if len(sys.argv) == 2:
        mode = int(sys.argv[1])
    else:
        mode = 0
    filename = "getting_started_3_mode_{}_".format(mode) + "{}.png"

    position_space = ift.RGSpace([128, 128])
    harmonic_space = position_space.get_default_codomain()
    ht = ift.HarmonicTransformOperator(harmonic_space, position_space)
    power_space = ift.PowerSpace(harmonic_space)

    # Set up an amplitude operator for the field
    dct = {
        'target': power_space,
        'n_pix': 64,  # 64 spectral bins

        # Spectral smoothness (affects Gaussian process part)
        'a': 3,  # relatively high variance of spectral curbvature
        'k0': .4,  # quefrency mode below which cepstrum flattens

        # Power-law part of spectrum:
        'sm': -5,  # preferred power-law slope
        'sv': .5,  # low variance of power-law slope
        'im':  0,  # y-intercept mean, in-/decrease for more/less contrast