test_response_operator.py 1.81 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2017 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

19
import unittest
Martin Reinecke's avatar
Martin Reinecke committed
20 21
from numpy.testing import assert_allclose
import nifty2go as ift
22 23 24
from itertools import product
from test.common import expand

Martin Reinecke's avatar
Martin Reinecke committed
25

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

Martin Reinecke's avatar
Martin Reinecke committed
29
    @expand(product(spaces, [0.,  5., 1.], [0., 1., .33]))
30
    def test_property(self, space, sigma, exposure):
Martin Reinecke's avatar
Martin Reinecke committed
31 32
        op = ift.ResponseOperator(space, sigma=[sigma],
                                  exposure=[exposure])
33 34 35
        if op.domain[0] != space:
            raise TypeError

Martin Reinecke's avatar
Martin Reinecke committed
36
    @expand(product(spaces, [0.,  5., 1.], [0., 1., .33]))
37
    def test_times_adjoint_times(self, space, sigma, exposure):
Martin Reinecke's avatar
Martin Reinecke committed
38 39 40 41
        op = ift.ResponseOperator(space, sigma=[sigma],
                                  exposure=[exposure])
        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
42 43
        tt1 = rand2.vdot(op.times(rand1))
        tt2 = rand1.vdot(op.adjoint_times(rand2))
Martin Reinecke's avatar
Martin Reinecke committed
44
        assert_allclose(tt1, tt2)