def FitNormed(Time, Amp, LifeTime, Offset, ScatterAmp, Start=0, End=len(AvgIRF)): IRF = AvgIRF[Start:End] return Convolve(IRF, Exp(Time, Amp, LifeTime)) + Convolve( IRF, Exp(Time + 12.5, Amp, LifeTime)) + Offset + IRF * ScatterAmp
def FitNormed(Data, Time, StartTime, LifeTime, BackgroundAmp, BackgroundPos, SignalAmp, Offset, L2, A2, BufferPos, BufferAmp, Start=0, End=len(Time)): #Decay = r_[zeros(len(Time)),Exp(Time, 1.0, LifeTime)] #EXP1 = Exp(Time, 1.0, LifeTime) EXP1 = Exp(Time, 1.0, LifeTime) + Exp(Time + 12.5, 1.0, LifeTime) #EXP2 = Exp(Time, 1.0, L2)+Exp(Time+12.5, 1.0, L2) #Decay = r_[zeros(len(Time)),SignalAmp*EXP1+A2*EXP2] Decay = r_[zeros(len(Time)), EXP1] LongTime = r_[-Time[::-1], Time] #IRFIV = norm.pdf(LongTime,StartTime,Width) IRFIV = IRFI(LongTime - StartTime) IRFIV = IRFIV / sum(IRFIV) Convolved = RawConvolveFFT(Decay, IRFIV, len(Time)) #CenteredIRF = r_[zeros(len(Time)), Scatter[Start:End]] #CenteredIRF = roll(CenteredIRF,len(Time)-argmax(CenteredIRF)) #CenteredIRF = CenteredIRF/sum(CenteredIRF) #Convolved = RawConvolveFFT(Decay, CenteredIRF, len(Time)) BGIV = CurrentBackgroundI(Time - BackgroundPos) BGIV = BGIV / max(BGIV) BIV = BI(Time - BufferPos) * BufferAmp SignalR = SignalAmp * Convolved #BackgroundAmp = 1.0-max(SignalR[Start:End]) BackgroundAmp = abs(1.0 - (SignalR + BIV)[argmax(BGIV)] - Offset) BackgroundR = BGIV * BackgroundAmp Result = SignalR + BackgroundR + Offset + BIV #return Result/max(Result) return Result, SignalR, BackgroundR
def FitNormed(Data, Time, Amp, ScatterAmp, Offset, Roll=0, Start=0, End=len(AvgIRF)): LifeTime = 4.1 TempIRF = roll(AvgIRF, int(Roll))[Start:End] #IRF = r_[TempIRF[:int(0.15*len(TempIRF))],zeros(len(TempIRF)-int(0.15*len(TempIRF)))] IRF = TempIRF / sum(TempIRF) #Scatter = roll(TempIRF,(argmax(Data)-argmax(TempIRF))) Scatter = TempIRF Scatter = Scatter / max(Scatter) Convolved = Convolve(IRF, Exp(Time, 1.0, LifeTime)) + Convolve( IRF, Exp(Time + 12.5, 1.0, LifeTime)) #Convolved = Exp(Time, 1.0, LifeTime) + Exp(Time+12.5, 1.0, LifeTime) #Convolved = Convolve(IRF, Exp(Time, 1.0, LifeTime)) #Convolved = Exp(Time, 1.0, LifeTime) #return Convolved + Scatter*ScatterAmp + Offset return Amp * Convolved / max(Convolved) + Scatter * ScatterAmp + Offset
Width = FWHM / 2.0 * (2.0 * log(2.0))**0.5 LongTime = r_[-Time[::-1], Time] IRF = norm.pdf(LongTime, Time[0], Width) IRF = IRF / max(IRF) Testing['Gauss'] = IRF print "\nPlotting: Aligned Data:" Plots.append( ForkDisplay(LongTime, Testing, Title="Convolution Testing", YAxis="Intensity (Counts)")) Decay = r_[zeros(len(Time)), Exp(Time, 1.0, 4.1) + Exp(Time + 12.5, 1.0, 4.1)] import matplotlib.pylab as plt plt.plot(Time, RawConvolveFFT(Testing['Gauss'], Decay, len(Time))) plt.plot(Time, RawConvolveFFT(Testing['Raw'], Decay, len(Time))) plt.show() # from time import time # # CurrentTime = time() # Testing['FFT'] = ConvolveFFT(NormIRF, Decay) # Testing['FFT'] = Testing['FFT']/max(Testing['FFT']) # print "FFT (Time) :%s" % (time() - CurrentTime) # print Testing['FFT'] # # Testing = Testing.AddCol("GFFT") # CurrentTime = time() # Testing['GFFT'] = GConvolveFFT(Decay, Time, 5.0, 0.04)
AlignedIRF = roll(AlignedIRF, len(Time) - argmax(AlignedIRF)) IRFZero = AlignedIRF[argmax(LongTime > 2.5)] AlignedIRF0 = AlignedIRF - IRFZero AlignedIRF0[AlignedIRF0 < 0.0] = 0.0 AlignedIRF0[LongTime > 2.5] = 0.0 FWHM = 0.060 Width = FWHM / (2.0 * (2.0 * log(2.0))**0.5) StartTime = 0.004 GIRF = norm.pdf(LongTime, StartTime, Width) GIRF = exp(-(LongTime - StartTime)**2.0 / (2.0 * Width**2.0)) / sqrt(2.0 * pi) GIRF = GIRF / sum(GIRF) Decay = r_[zeros(len(Time)), Exp(Time, 1.0, 4.1)] Convolved = RawConvolveFFT(Decay, AlignedIRF, None) Convolved0 = RawConvolveFFT(Decay, AlignedIRF0, None) GConvolved = RawConvolveFFT(Decay, GIRF, None) TimeOffset = 0.0 IRFI = InterpolatedUnivariateSpline(LongTime, AlignedIRF) IRFIV = IRFI(LongTime - TimeOffset) IRFIV = IRFIV / sum(IRFIV) IRFIVConv = RawConvolveFFT(Decay, IRFIV, None) Plotting = ChannelizedArray(len(LongTime), 1, 'float64') Plotting.ChangeColName("Channel_1", "Convolved") Plotting['Convolved'] = roll(Convolved / max(Convolved), 4095)