P_incoherent.py 1.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from numpy import sum
from numpy.core._multiarray_umath import sqrt, array

from proxtoolbox.proxoperators import P_M, P_Sparsity_real

__all__ = ['P_M_incoherent', 'P_Sparsity_real_incoherent']


class P_M_incoherent(P_M):
    """
    Apply the Fourier-domain modulus constraint to a set of incoherent fields:
    scale the amplitudes such that the combined intensity matches the data
    """
    def __init__(self, experiment):
        super(P_M_incoherent, self).__init__(experiment)
        self.intensity = self.data ** 2
        self.eps = 1e-15

    def eval(self, u, prox_idx=None):
        amplitudes = self.prop.eval(u)  # Propagate to measurement domain
        pred = sum(abs(amplitudes)**2, axis=0)  # Predicted total intensity
        divisor = sqrt(pred + self.eps**2)  #
        scaling = 1 - (pred + 2*self.eps**2) / divisor**3 * (pred / divisor - self.data)
        # scaling = self.data / divisor
        out = array([scaling * u_i for u_i in amplitudes])
        return self.invprop.eval(out)  # Propagate back


class P_Sparsity_real_incoherent(P_Sparsity_real):
    def __init__(self, experiment):
        super(P_Sparsity_real_incoherent, self).__init__(experiment)

    def eval(self, u, prox_idx=None):
        out = array([super(P_Sparsity_real_incoherent, self).eval(u_i) for u_i in u])
        return out