response_operator.py 1.86 KB
Newer Older
1
from nifty import Field,\
2
3
4
5
    FieldArray,\
    LinearOperator,\
    SmoothingOperator,\
    ComposedOperator
6
7
8
9
10
import numpy as np

class ResponseOperator(LinearOperator):

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

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

        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,
23
24
25
26
27
                                      dtype=np.float64))
        self._sigma = sigma
        self._implemented = implemented
        self._unitary = unitary

28
29
30
31
32
33
34
35

        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)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

        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):
56
        res = self._composed_kernel.times(x)
57
        res = self._exposure * res
58
59
60
        # res = res.weight(power=1)
        # removing geometric information
        return Field(self._target, val=res.val)
61
62
63
64

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