安装两个不同幅度的模型

时间:2017-08-21 19:56:47

标签: python pandas models

我正在尝试进行两次Fraunhofer发布的扫描。请帮助我理解我的代码中的一个片段,使其运行得更好,因为它改变了拟合,但我不知道为什么!这是我的具体意思:

if MaxIndexup>MaxIndexdown: FitDataup = TempData.loc[TempData["Field (Oe)"] <= MaxIndexup]  

当它运行时,会放入一堆文件,其中包含大量与手头问题无关的数据。这是如何识别(几乎)高斯分布的峰值,然后你如何拟合它以使叶片更好地工作(如果你理解弗劳恩霍夫衍射图案给出的波瓣)。我的代码工作正常,我只是想/需要了解更多,以便如何更好地解析和拟合数据:

from os import walk
import numpy as np
import pandas as pd
import re
import math
from scipy import stats
import scipy.special as sp
from lmfit import Model

#create function that computes the Fruanhofer diffraction pattern: reference--> https://en.wikipedia.org/wiki/Fraunhofer_diffraction; also see the Guassian section
def Fraunup(x, Imaxup, Lambda, M, CorrectedBitSize):
        y1 = Imaxup * abs(2*sp.jv(1,((float(CorrectedBitSize)*(2*abs(Lambda) + 2*dN + dF)*(x+M))/(phi0*math.pow(10,10))))/((float(CorrectedBitSize)*(2*Lambda + 2*dN + dF)*(x+M))/(phi0*math.pow(10,10))))
        return y1

def Fraundown(x, Imaxdown, Lambda, M, CorrectedBitSize):
    y2 = Imaxdown * abs(2 * sp.jv(1, ((float(CorrectedBitSize) * (2 * abs(Lambda) + 2 * dN + dF) * (x + M)) / (phi0 * math.pow(10, 10)))) / ( (float(CorrectedBitSize) * (2 * Lambda + 2 * dN + dF) * (x + M)) / (phi0 * math.pow(10, 10))))
    return y2


 Iparamup = 1.5 * TempData["Ic+ (mA)"].max()
    Iparamdown = 1.5 * TempData2["Ic+ (mA)"].max()
    Lambparam = (0.00000009)
    Mparam = (200 / CorrectedBitSize_Squared)     #gives you H_shift

    #Create the Model and add specfic parameters. M deals with the H_Shift
    modelup = Model(Fraunup)
    params = modelup.make_params()
    params.add('Imaxup',value=Iparamup)
    params.add('Lambda',value=Lambparam)
    params.add('M',value=np.mean(Mparam),min=0,max=500)

    modeldown = Model(Fraundown)
    params = modeldown.make_params()
    params.add('Lambda',value=Lambparam)
    params.add('M',value=np.mean(Mparam),min=0,max=500)
    params.add('Imaxdown', value=Iparamdown)

    if MaxIndexup>MaxIndexdown:
        FitDataup = TempData.loc[TempData["Field (Oe)"] <= MaxIndexup]  

  FitDataup = FitDataup[~np.isnan(FitDataup['Ic+ (mA)'])].reset_index()
    FitDatadown = FitDatadown[~np.isnan(FitDatadown['Ic+ (mA)'])].reset_index()

    for x in range(len(Mparam)):
        resultsup = modelup.fit(FitDataup['Ic+ (mA)'],x=-FitDataup['Field (Oe)'], CorrectedBitSize=CorrectedBitSize[x], Imaxup=Iparamup, Lambda=Lambparam, M= Mparam[x], method='Powell')
        resultsdown = modeldown.fit(FitDatadown['Ic+ (mA)'], x=-FitDatadown['Field (Oe)'], CorrectedBitSize=CorrectedBitSize[x],Imaxdown=Iparamdown, Lambda=Lambparam, M=Mparam[x], method='Powell')

    #fit the value using the best results
    YFitValueup = Fraunup(TempData["Field (Oe)"], resultsup.best_values['Imaxup'], resultsup.best_values['Lambda'], resultsup.best_values['M'],  resultsup.best_values['CorrectedBitSize'])
    YFitValuedown = Fraundown(TempData2["Field (Oe)"], resultsdown.best_values['Imaxdown'], resultsdown.best_values['Lambda'], resultsdown.best_values['M'],  resultsdown.best_values['CorrectedBitSize'])

0 个答案:

没有答案