response_operator.py 1.99 KB
Newer Older
1
import numpy as np
2
3
4
5
6
7
from nifty import Field,\
                  FieldArray
from nifty.operators.linear_operator import LinearOperator
from nifty.operators.smoothing_operator import SmoothingOperator
from nifty.operators.composed_operator import ComposedOperator

8
9
10
11

class ResponseOperator(LinearOperator):

    def __init__(self, domain,
12
                 sigma=[1.], exposure=1., implemented=True,
13
14
15
                 unitary=False):

        self._domain = self._parse_domain(domain)
16
17
18
19
20
21
22
23

        shapes = len(self._domain)*[None]
        shape_target = []
        for ii in xrange(len(shapes)):
            shapes[ii] = self._domain[ii].shape
            shape_target = np.append(shape_target, self._domain[ii].shape)

        self._target = self._parse_domain(FieldArray(shape_target,
24
25
26
27
28
                                      dtype=np.float64))
        self._sigma = sigma
        self._implemented = implemented
        self._unitary = unitary

29
30
31
32
33
34
35
36

        self._kernel = len(self._domain)*[None]

        for ii in xrange(len(self._kernel)):
            self._kernel[ii] = SmoothingOperator(self._domain[ii],
                                        sigma=self._sigma[ii])

        self._composed_kernel = ComposedOperator(self._kernel)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

        self._exposure = exposure

    @property
    def domain(self):
        return self._domain

    @property
    def target(self):
        return self._target

    @property
    def implemented(self):
        return self._implemented

    @property
    def unitary(self):
        return self._unitary

    def _times(self, x, spaces):
57
        res = self._composed_kernel.times(x)
58
        res = self._exposure * res
59
60
61
        # res = res.weight(power=1)
        # removing geometric information
        return Field(self._target, val=res.val)
62
63
64
65

    def _adjoint_times(self, x, spaces):
        # setting correct spaces
        res = x*self._exposure
66
        res = Field(self.domain, val=res.val)
67
        res = res.weight(power=-1)
68
        res = self._composed_kernel.adjoint_times(res, spaces)
69
        return res