Dear Gitlab Users, for our upcoming upgrade to Gitlab v14, Gitlab will be unavailable on Thursday, 05.08.2021 from 5:00 pm to approximately 7:00 pm. Note that with v14, certain breaking changes will be introduced (https://about.gitlab.com/blog/2021/06/04/gitlab-moving-to-14-breaking-changes/).

Commit 9be2c164 authored by jansen31's avatar jansen31
Browse files

flat bg by RMS

parent 126c549a
......@@ -146,9 +146,9 @@ class P_nondispersive_sparse_ksparse(P_nondispersive_sparse):
def extra_constraint(self, profiles):
"""Apply sparsity, k-space sparsity and then orthonormality"""
profiles[:self.n_states] = self.p_sr.eval(profiles[:self.n_states]) # Sparse real
for ii in range(self.n_states):
profiles[ii] = self.p_ksparse.eval(profiles[ii])
profiles[:self.n_states] = self.p_sr.eval(profiles[:self.n_states]) # Sparse real
return profiles
......@@ -177,9 +177,9 @@ class P_nondispersive_sparse_ksparse_ortho(P_nondispersive_sparse_ortho):
def extra_constraint(self, profiles):
"""Apply sparsity, k-space sparsity and then orthonormality"""
profiles[:self.n_states] = self.p_sr.eval(profiles[:self.n_states]) # Sparse real
for ii in range(self.n_states):
profiles[ii] = self.p_ksparse.eval(profiles[ii])
profiles[:self.n_states] = self.p_sr.eval(profiles[:self.n_states]) # Sparse real
profiles[:2] = self.p_ortho.eval(profiles[:2]) # Orthonormality
return profiles
......@@ -278,8 +278,8 @@ class PFlatBackground(PMomentumMicroscope):
def __init__(self, experiment):
super(PFlatBackground, self).__init__(experiment)
self.nonnegativity = True
self.minval = 0.1 # TODO: remove hard-coding
self.maxval = 15
self.minval = 1e-10
self.maxval = 1e10
def eval(self, u, prox_idx=None):
assert not any(isnan(u)), "NaNs detected in iterate u"
......@@ -310,11 +310,11 @@ class PFlatBackground(PMomentumMicroscope):
if self.nonnegativity:
bg = where(bg.real > 0, bg.real, 0)
# av_value = median(bg[bg != 0])
vals = bg[bg != 0]
if len(vals) != 0:
# av_value = sqrt(mean(vals) ** 2)
av_value = mean(vals)
av_value = sqrt(mean(vals) ** 2) # By RMS
# av_value = mean(vals) # By mean
# av_value = median(bg[bg != 0]) # By median
else:
av_value = self.minval # TODO: need better approach here, perhaps data-driven?
av_value = min([max([av_value, self.minval]), self.maxval])
......@@ -375,5 +375,13 @@ class PMomentumSparse(PMomentumMicroscope):
def eval(self, u):
kspace = self.prop.eval(u)
constrained = self.p_sparse.eval(kspace)
return self.invprop.eval(constrained)
if self.tolerance == 0:
return self.invprop.eval(constrained)
else:
norm = sum(abs(u)**2)
rel_diff = sum(abs(constrained-u)**2)/norm
if rel_diff > self.tolerance:
return constrained
else:
return u
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment