Commit 3b31c7e2 authored by William Clarke's avatar William Clarke
Browse files

Slight reworking of rescaling. Makes fitting more robust.

parent a9fa0d04
......@@ -246,6 +246,23 @@ class MRS(object):
# Helper functions
def processForFitting(self,ppmlim=(.2,4.2),):
""" Apply rescaling and run the conjugation checks"""
self.check_FID(ppmlim=ppmlim,repair=True)
self.check_Basis(ppmlim=ppmlim,repair=True)
self.rescaleForFitting()
def rescaleForFitting(self,scale=100):
""" Apply rescaling across data, basis and H20"""
scaledFID,scaling = misc.rescale_FID(self.FID,scale=scale)
self.set_FID(scaledFID)
if self.H2O is not None:
self.H2O *= scaling
if self.basis is not None:
self.basis,_ = misc.rescale_FID(self.basis,scale=scale)
def check_FID(self,ppmlim=(.2,4.2),repair=False):
"""
Check if FID needs to be conjugated
......
......@@ -160,16 +160,8 @@ def main():
FID,dataheader = mrs_io.read_FID(args.data)
basis, names, basisheader = mrs_io.read_basis(args.basis)
# Rescale FID and basis to have nice range
if not args.no_rescale:
FID = misc.rescale_FID(FID,scale=100)
basis = misc.rescale_FID(basis,scale=100)
if args.h2o is not None:
H2O,_ = mrs_io.read_FID(args.h2o)
if not args.no_rescale:
H2O = misc.rescale_FID(H2O,scale=100)
else:
H2O = None
......@@ -221,6 +213,10 @@ def main():
if conjugated == 1:
warnings.warn('Basis has been checked and conjugated. Please check!',UserWarning)
# Rescale FID, H2O and basis to have nice range
if not args.no_rescale:
mrs.rescaleForFitting()
# Do phase correction
if args.phase_correct:
if args.verbose:
......
......@@ -398,6 +398,7 @@ def fit_FSLModel(mrs,
verbose=False,
monitor=True,
args=args)
results.optim_out = res_vb
# de-log
if model.lower()=='lorentzian':
......
......@@ -434,7 +434,7 @@ def rescale_FID(x,scale=100):
else:
factor = np.linalg.norm(np.mean(y,axis=1),axis=0)
y = y / factor * scale
return y
return y,1/factor * scale
def create_peak(mrs,ppm,gamma=0,sigma=0):
......
Supports Markdown
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