Ejemplo n.º 1
0
 def interpFunc(time, deriv=False):
     if deriv is False:
         basis = nagini.rSplineBasis(time, knots)
         interp = np.dot(basis, coefs)
         return interp
     else:
         basis, basisD = nagini.rSplineBasis(time, knots, dot=True)
         interp = np.dot(basis, coefs)
         deriv = np.dot(basisD, coefs)
         return interp, deriv
Ejemplo n.º 2
0
petData = nagini.reshape4d(pet.get_data())
maskData = mask.get_data().flatten()

#Mask pet data
petMasked = petData[maskData == 1, :]

#Get PET time vetor
petTime = info[:, 1]

#Caculate whole-brain timecourse
petMean = np.mean(petMasked, axis=0)

#Get spline knots and basis
petKnots = nagini.knotLoc(petTime, args.nKnots[0])
petKnots[0] = 10
petBasis = nagini.rSplineBasis(petTime, petKnots)

#Fit spline to whole brain
X, _, _, _ = np.linalg.lstsq(petBasis, petMean)

#Get spline predictions
timePred = np.linspace(0, petTime[-1], 1000)
predBasis, predDeriv = nagini.rSplineBasis(timePred, petKnots, dot=True)
petPred = np.dot(predBasis, X)
petPredD = np.dot(predDeriv, X)

#Get timepoints for SUVR window
startTime = timePred[np.where(petPredD > 10)[0][0]]
endTime = startTime + args.window[0]
suvrTime = np.linspace(startTime, endTime, 100)
Ejemplo n.º 3
0
        return interpFunc

    #Apply wrapper function
    aifFunc = wrapFunc(aifFit[0], aifFit[1], aifFit[2], aifFit[3], aifFit[4],
                       aifFit[5], aifScale)

else:

    #Get basis for AIF spline
    if args.nKnots is None:
        nKnots = aifC.shape[0]
    else:
        nKnots = args.nKnots[0]
    aifKnots = nagini.knotLoc(aifTime, nKnots, bounds=[5, 95])
    aifBasis = nagini.rSplineBasis(aifTime, aifKnots)

    #Use scikit learn to do a initial bayesian ridge fit
    bModel = linear_model.BayesianRidge(fit_intercept=True)
    initFit = bModel.fit(aifBasis[:, 1::], aifC)
    initCoefs = np.concatenate((initFit.intercept_[np.newaxis], initFit.coef_))

    #Compute absolute studentized residuals
    initFitted = np.dot(aifBasis, initCoefs)
    initResid = aifC - initFitted
    initHat = np.diag(
        aifBasis.dot(np.linalg.inv(aifBasis.T.dot(aifBasis)).dot(aifBasis.T)))
    initVar = 1.0 / (aifC.shape[0] - aifBasis.shape[1]) * np.sum(
        np.power(initResid, 2))
    initStudent = np.abs(initResid / np.sqrt(initVar * (1 - initHat)))
Ejemplo n.º 4
0
else:
	#Decay correct DCV file to start frame
	if args.decay == 1:
		aifC *= np.exp(np.log(2)/122.24*info[0,0])
	#Remove decay correction for DCV file
	else:
		aifC /= np.exp(np.log(2)/122.24*aifTime)

#Get basis for AIF spline
if args.nKnots is None:
	nKnots = aifC.shape[0]
else:
	nKnots = args.nKnots[0]
aifKnots = nagini.knotLoc(aifTime,nKnots,bounds=[5,95])
aifBasis = nagini.rSplineBasis(aifTime,aifKnots)

#Use scikit learn to do a bayesian style ridge regression for spline fit
bModel = linear_model.BayesianRidge(fit_intercept=True)
bFit = bModel.fit(aifBasis[:,1::],aifC)
aifCoefs = np.concatenate((bFit.intercept_[np.newaxis],bFit.coef_))
aifSpline = np.dot(aifBasis,aifCoefs)

#Get interpolation times as start to end of pet scan with aif sampling rate
sampTime = np.min(np.diff(aifTime))
interpTime = np.arange(np.floor(startTime[0]),np.ceil(endTime[-1]+sampTime),sampTime)

#Make sure we stay within boundaries of pet timing
if interpTime[-1] > np.ceil(endTime[-1]):
	interpTime = interpTime[:-1]
Ejemplo n.º 5
0
#Get image data
petData = nagini.reshape4d(pet.get_data())
maskData = mask.get_data().flatten()

#Mask pet data
petMasked = petData[maskData==1,:]

#Get PET time vetor
petTime = info[:,1]

#Caculate whole-brain timecourse
petMean = np.mean(petMasked,axis=0)

#Get spline knots and basis
petKnots = nagini.knotLoc(petTime,args.nKnots[0]); petKnots[0] = 10
petBasis = nagini.rSplineBasis(petTime,petKnots)

#Fit spline to whole brain
X,_,_,_ = np.linalg.lstsq(petBasis,petMean)

#Get spline predictions
timePred = np.linspace(0,petTime[-1],1000)
predBasis,predDeriv = nagini.rSplineBasis(timePred,petKnots,dot=True)
petPred = np.dot(predBasis,X); petPredD = np.dot(predDeriv,X)

#Get timepoints for SUVR window
startTime = timePred[np.where(petPredD>10)[0][0]]
endTime = startTime + args.window[0]
suvrTime = np.linspace(startTime,endTime,100)

#Get new basis
Ejemplo n.º 6
0
    aifC *= np.exp(np.log(2) / 122.24 * info[0, 0]) * np.exp(
        np.log(2) / 122.24 * aifTime)

else:
    #Decay correct to PET start
    aifC *= np.exp(np.log(2) / 122.24 * info[0, 0])

#Set number of knots
if args.nKnots is None:
    nKnots = aifTime.shape[0]
else:
    nKnots = args.nKnots[0]

#Calculate spline basis
aifKnots = nagini.knotLoc(aifTime, nKnots, bounds=[5, 95])
aifBasis = nagini.rSplineBasis(aifTime, aifKnots)

#Use scikit learn to do a bayesian style ARD regression for fit
bModel = linear_model.ARDRegression(fit_intercept=True)
bFit = bModel.fit(aifBasis[:, 1::], aifC)
aifCoefs = np.concatenate((bFit.intercept_[np.newaxis], bFit.coef_))

#Get basis for interpolating integral of spline at CBV time
pBasis, pBasisI = nagini.rSplineBasis(cbvTime, aifKnots, dDot=True)

#Get integral of input function from start to end of CBV frame
aifInteg = np.dot(pBasisI, aifCoefs)
aifSum = aifInteg[1] - aifInteg[0]

#Get whole-brain pet value
wbPet = np.mean(petMasked)