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)
Esempio n. 2
0
def testZeroPadder(space, factor, dtype, central):
    dom = (ift.RGSpace(10), ift.UnstructuredDomain(13), ift.RGSpace(7, 12),
           ift.HPSpace(4))
    newshape = [int(factor * l) for l in dom[space].shape]
    _check_repr(ift.FieldZeroPadder(dom, newshape, space, central))
Esempio n. 3
0
def testSymmetrizingOperator(space, dtype):
    dom = (ift.LogRGSpace(10, [2.], [1.]), ift.UnstructuredDomain(13),
           ift.LogRGSpace((5, 27), [1., 2.7], [0., 4.]), ift.HPSpace(4))
    _check_repr(ift.SymmetrizingOperator(dom, space))
Esempio n. 4
0
def testContractionOperator(spaces, wgt, dtype):
    dom = (ift.RGSpace(10), ift.RGSpace(13), ift.GLSpace(5), ift.HPSpace(4))
    _check_repr(ift.ContractionOperator(dom, spaces, wgt))
Esempio n. 5
0
import pytest

import nifty5 as ift

from ..common import list2fixture

_h_RG_spaces = [
    ift.RGSpace(7, distances=0.2, harmonic=True),
    ift.RGSpace((12, 46), distances=(.2, .3), harmonic=True)
]
_h_spaces = _h_RG_spaces + [ift.LMSpace(17)]
_p_RG_spaces = [
    ift.RGSpace(19, distances=0.7),
    ift.RGSpace((1, 2, 3, 6), distances=(0.2, 0.25, 0.34, .8))
]
_p_spaces = _p_RG_spaces + [ift.HPSpace(17), ift.GLSpace(8, 13)]
_pow_spaces = [ift.PowerSpace(ift.RGSpace((17, 38), harmonic=True))]

pmp = pytest.mark.parametrize
dtype = list2fixture([np.float64, np.complex128])


def _check_repr(op):
    op.__repr__()


@pmp('sp', _p_RG_spaces)
def testLOSResponse(sp, dtype):
    starts = np.random.randn(len(sp.shape), 10)
    ends = np.random.randn(len(sp.shape), 10)
    sigma_low = 1e-4 * np.random.randn(10)
Esempio n. 6
0
#
# Copyright(C) 2013-2019 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.

from numpy.testing import assert_allclose, assert_equal

import nifty5 as ift

from ..common import list2fixture

space1 = list2fixture([
    ift.RGSpace(4),
    ift.PowerSpace(ift.RGSpace((4, 4), harmonic=True)),
    ift.LMSpace(5),
    ift.HPSpace(4),
    ift.GLSpace(4)
])
space2 = space1


def test_times_adjoint_times(space1, space2):
    cspace = (space1, space2)
    diag1 = ift.Field.from_random('normal', domain=space1)
    diag2 = ift.Field.from_random('normal', domain=space2)
    op1 = ift.DiagonalOperator(diag1, cspace, spaces=(0, ))
    op2 = ift.DiagonalOperator(diag2, cspace, spaces=(1, ))

    op = op2(op1)

    rand1 = ift.Field.from_random('normal', domain=(space1, space2))
    if len(sys.argv) == 2:
        mode = int(sys.argv[1])
    else:
        mode = 1

    if mode == 0:
        # One-dimensional regular grid
        position_space = ift.RGSpace([1024])
        mask = np.ones(position_space.shape)
    elif mode == 1:
        # Two-dimensional regular grid with checkerboard mask
        position_space = ift.RGSpace([128, 128])
        mask = make_checkerboard_mask(position_space)
    else:
        # Sphere with half of its pixels randomly masked
        position_space = ift.HPSpace(128)
        mask = make_random_mask()

    # Specify harmonic space corresponding to signal
    harmonic_space = position_space.get_default_codomain()

    # Harmonic transform from harmonic space to position space
    HT = ift.HarmonicTransformOperator(harmonic_space, target=position_space)

    # Set prior correlation covariance with a power spectrum leading to
    # homogeneous and isotropic statistics
    def power_spectrum(k):
        return 100. / (20. + k**3)

    # 1D spectral space on which the power spectrum is defined
    power_space = ift.PowerSpace(harmonic_space)
Esempio n. 8
0
    conv_delta = conv_op(delta)

    # Plot results
    plot = ift.Plot()
    plot.add(signal, title='Signal')
    plot.add(conv_signal, title='Signal Convolved')
    plot.add(cac_signal, title='Signal, Conv, Adj-Conv')
    plot.add(conv_delta, title='Kernel')
    plot.output()


# Healpix test
nside = 64
npix = 12 * nside * nside

domain = ift.HPSpace(nside)

# Define test signal (some point sources)
signal_vals = np.zeros(npix, dtype=np.float64)
for i in range(0, npix, npix // 12 + 27):
    signal_vals[i] = 500.

signal = ift.from_global_data(domain, signal_vals)

delta_vals = np.zeros(npix, dtype=np.float64)
delta_vals[0] = 1.0
delta = ift.from_global_data(domain, delta_vals)


# Define kernel function
def func(theta):
Esempio n. 9
0
def testZeroPadder(space, factor, dtype, central):
    dom = (ift.RGSpace(10), ift.UnstructuredDomain(13), ift.RGSpace(7, 12),
           ift.HPSpace(4))
    newshape = [int(factor * l) for l in dom[space].shape]
    op = ift.FieldZeroPadder(dom, newshape, space, central)
    ift.extra.consistency_check(op, dtype, dtype)
Esempio n. 10
0
def testSymmetrizingOperator(space, dtype):
    dom = (ift.LogRGSpace(10, [2.], [1.]), ift.UnstructuredDomain(13),
           ift.LogRGSpace((5, 27), [1., 2.7], [0., 4.]), ift.HPSpace(4))
    op = ift.SymmetrizingOperator(dom, space)
    ift.extra.consistency_check(op, dtype, dtype)
Esempio n. 11
0
def testContractionOperator(spaces, wgt, dtype):
    dom = (ift.RGSpace(10), ift.RGSpace(13), ift.GLSpace(5), ift.HPSpace(4))
    op = ift.ContractionOperator(dom, spaces, wgt)
    ift.extra.consistency_check(op, dtype, dtype)
Esempio n. 12
0
# Copyright(C) 2013-2019 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.

from unittest import SkipTest

import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_equal

import nifty5 as ift

pmp = pytest.mark.parametrize
IC = ift.GradientNormController(tol_abs_gradnorm=1e-5, iteration_limit=1000)

spaces = [ift.RGSpace([1024], distances=0.123), ift.HPSpace(32)]

minimizers = [
    'ift.VL_BFGS(IC)',
    'ift.NonlinearCG(IC, "Polak-Ribiere")',
    # 'ift.NonlinearCG(IC, "Hestenes-Stiefel"),
    'ift.NonlinearCG(IC, "Fletcher-Reeves")',
    'ift.NonlinearCG(IC, "5.49")',
    'ift.L_BFGS_B(ftol=1e-10, gtol=1e-5, maxiter=1000)',
    'ift.L_BFGS(IC)',
    'ift.NewtonCG(IC)'
]

newton_minimizers = ['ift.RelaxedNewton(IC)']
quadratic_only_minimizers = [
    'ift.ConjugateGradient(IC)',