P_incoherent.py 1.62 KB
 jansen31 committed Nov 03, 2020 1 ``````from numpy import sum, where `````` jansen31 committed Nov 02, 2020 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 ``````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): `````` jansen31 committed Nov 03, 2020 30 31 32 `````` """ Apply a sparsity constraint to the combined intensity of a set of incoherent iterates """ `````` jansen31 committed Nov 02, 2020 33 34 35 36 `````` def __init__(self, experiment): super(P_Sparsity_real_incoherent, self).__init__(experiment) def eval(self, u, prox_idx=None): `````` jansen31 committed Nov 03, 2020 37 38 39 40 41 `````` u_real = u.real density = sum(abs(u_real)**2, axis=0) sparse = super(P_Sparsity_real_incoherent, self).eval(density) out = array([where(sparse != 0, u_i, 0) for u_i in u_real]) # out = array([super(P_Sparsity_real_incoherent, self).eval(u_i) for u_i in u]) `````` jansen31 committed Nov 02, 2020 42 `` return out``