test_response_operator.py 1.11 KB
Newer Older
1
import unittest
Martin Reinecke's avatar
Martin Reinecke committed
2
3
from numpy.testing import assert_allclose
import nifty2go as ift
4
5
6
from itertools import product
from test.common import expand

Martin Reinecke's avatar
Martin Reinecke committed
7

8
class ResponseOperator_Tests(unittest.TestCase):
Martin Reinecke's avatar
Martin Reinecke committed
9
    spaces = [ift.RGSpace(128), ift.GLSpace(nlat=37)]
10

Martin Reinecke's avatar
Martin Reinecke committed
11
    @expand(product(spaces, [0.,  5., 1.], [0., 1., .33]))
Martin Reinecke's avatar
Martin Reinecke committed
12
    def test_property(self, space, sigma, sensitivity):
Martin Reinecke's avatar
Martin Reinecke committed
13
        op = ift.ResponseOperator(space, sigma=[sigma],
Martin Reinecke's avatar
Martin Reinecke committed
14
                                  sensitivity=[sensitivity])
15
16
17
        if op.domain[0] != space:
            raise TypeError

Martin Reinecke's avatar
Martin Reinecke committed
18
    @expand(product(spaces, [0.,  5., 1.], [0., 1., .33]))
Martin Reinecke's avatar
Martin Reinecke committed
19
    def test_times_adjoint_times(self, space, sigma, sensitivity):
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
20
        if not isinstance(space, ift.RGSpace):  # no smoothing supported
21
            sigma = 0.
Martin Reinecke's avatar
Martin Reinecke committed
22
        op = ift.ResponseOperator(space, sigma=[sigma],
Martin Reinecke's avatar
Martin Reinecke committed
23
                                  sensitivity=[sensitivity])
Martin Reinecke's avatar
Martin Reinecke committed
24
25
        rand1 = ift.Field.from_random('normal', domain=space)
        rand2 = ift.Field.from_random('normal', domain=op.target[0])
Martin Reinecke's avatar
Martin Reinecke committed
26
27
        tt1 = rand2.vdot(op.times(rand1))
        tt2 = rand1.vdot(op.adjoint_times(rand2))
Martin Reinecke's avatar
Martin Reinecke committed
28
        assert_allclose(tt1, tt2)