Commit 8edd9280 authored by William Clarke's avatar William Clarke
Browse files

Minor bug fixes

parent 42f0efe8
......@@ -246,7 +246,7 @@ class MRS(object):
# Helper functions
def check_FID(self,ppmlim=(.2,4.2),repare=False):
def check_FID(self,ppmlim=(.2,4.2),repair=False):
"""
Check if FID needs to be conjugated
by looking at total power within ppmlim range
......@@ -254,7 +254,7 @@ class MRS(object):
Parameters
----------
ppmlim : list
repare : if True applies conjugation to FID
repair : if True applies conjugation to FID
Returns
-------
......@@ -266,7 +266,7 @@ class MRS(object):
Spec2 = np.real(misc.FIDToSpec(np.conj(self.FID)))[first:last]
if np.linalg.norm(misc.detrend(Spec1,deg=4)) < np.linalg.norm(misc.detrend(Spec2,deg=4)):
if repare is False:
if repair is False:
warnings.warn('YOU MAY NEED TO CONJUGATE YOUR FID!!!')
return -1
else:
......@@ -282,7 +282,7 @@ class MRS(object):
self.FID = np.conj(self.FID)
self.Spec = misc.FIDToSpec(self.FID)
def check_Basis(self,ppmlim=(.2,4.2),repare=False):
def check_Basis(self,ppmlim=(.2,4.2),repair=False):
"""
Check if Basis needs to be conjugated
by looking at total power within ppmlim range
......@@ -290,7 +290,7 @@ class MRS(object):
Parameters
----------
ppmlim : list
repare : if True applies conjugation to basis
repair : if True applies conjugation to basis
Returns
-------
......@@ -309,7 +309,7 @@ class MRS(object):
conjOrNot.append(0.0)
if (sum(conjOrNot)/len(conjOrNot))>0.5:
if repare is False:
if repair is False:
warnings.warn('YOU MAY NEED TO CONJUGATE YOUR BASIS!!!')
return -1
else:
......
......@@ -197,7 +197,7 @@ def main():
if args.conjfid:
mrs.conj_FID()
else:
conjugated = mrs.check_FID(repare=True)
conjugated = mrs.check_FID(repair=True)
if args.verbose:
if conjugated == 1:
warnings.warn('FID has been checked and conjugated. Please check!',UserWarning)
......@@ -206,7 +206,7 @@ def main():
if args.conjbasis:
mrs.conj_Basis()
else:
conjugated = mrs.check_Basis(repare=True)
conjugated = mrs.check_Basis(repair=True)
if args.verbose:
if conjugated == 1:
warnings.warn('Basis has been checked and conjugated. Please check!',UserWarning)
......
......@@ -285,13 +285,7 @@ def plot_spectrum(mrs,ppmlim=(0.0,4.5),FID=None,proj='real',c='k'):
return plt.gcf()
def plot_spectra(FIDlist,bandwidth,centralFrequency,ppmlim=(0,4.5),single_FID=None,plot_avg=True):
numPoints = FIDlist[0].size
frequencyAxis = np.linspace(-bandwidth/2,
bandwidth/2,
numPoints)
ppmAxisShift = hz2ppm(centralFrequency,
frequencyAxis,shift=True)
def plot_spectra(MRSList,ppmlim=(0,4.5),single_FID=None,plot_avg=True):
plt.figure(figsize=(10,10))
plt.xlim(ppmlim)
......@@ -303,15 +297,16 @@ def plot_spectra(FIDlist,bandwidth,centralFrequency,ppmlim=(0,4.5),single_FID=No
plt.autoscale(enable=True, axis='y', tight=True)
avg=0
for FID in FIDlist:
data = np.real(FID2Spec(FID))
for mrs in MRSList:
data = np.real(mrs.getSpectrum(ppmlim=ppmlim))
ppmAxisShift = mrs.getAxes(ppmlim=ppmlim)
avg += data
plt.plot(ppmAxisShift,data,color='k',linewidth=.5,linestyle='-')
if single_FID is not None:
data = np.real(FID2Spec(single_FID))
data = np.real(single_FID.getSpectrum(ppmlim=ppmlim))
plt.plot(ppmAxisShift,data,color='r',linewidth=2,linestyle='-')
if plot_avg:
avg /= len(FIDlist)
avg /= len(MRSList)
plt.plot(ppmAxisShift,avg,color='g',linewidth=2,linestyle='-')
autoscale_y(plt.gca(),margin=0.05)
......
......@@ -216,7 +216,7 @@ def getNoiseSDDist(specIn,noiseregionmask):
noiseOnlySpec = specIn[noiseregionmask]
npoints = noiseOnlySpec.size
regionPoints = 100
regionPoints = min(100,int(npoints/10))
def running_std_strides(seq, window=100):
stride = seq.strides[0]
......
......@@ -247,20 +247,17 @@ class FitRes(object):
# Functions to return physically meaningful units from the fitting results
def getConc(self,scaling='raw',metab=None,function='mean'):
if function is None:
dfFunc = lambda m : self.fitResults[m].values
dfFunc = lambda m : self.fitResults[m]
else:
dfFunc = lambda m : self.fitResults[m].apply(function)
dfFunc = lambda m : self.fitResults[m].apply(function).to_numpy()
# Extract concentrations from parameters.
if metab is not None:
if metab not in self.metabs:
raise ValueError(f'{metab} is not a recognised metabolite.')
rawConc = np.asarray(dfFunc(metab))
else:
rawConc = []
for m in self.metabs:
rawConc.append(dfFunc(m))
rawConc = np.asarray(rawConc)
rawConc = dfFunc(metab)
else:
rawConc = dfFunc(self.metabs)
if scaling == 'raw':
return rawConc
......
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