2017-09-20 7 views
0

フィットしたガウス曲線下の粒子の数を数える必要があります。フィッティングされた曲線の面積は、限界(平均-3 *シグマ)〜(平均±3 *シグマ)内の関数を積分することによって見つけることができる。これを解決するために私を助けてくださいますか?あなたの親切な配慮に感謝します。面積下の粒子数を数えるためのガウス関数の積分

import pylab as py 
import numpy as np 
from scipy import optimize 
from scipy.stats import stats 
import matplotlib.pyplot as plt 
import pandas as pd 

BackPFT='T067.csv' 
df_180 = pd.read_csv(BackPFT, error_bad_lines=False, header=1) 
x_180=df_180.iloc[:,3] 
y_180=df_180.iloc[:,4] 

#want to plot the distribution of s calculated by the following equation 
s=np.sqrt((((16*x_180**2*38.22**2)/((4*38.22**2-y_180**2)**2))+1))-1 
#Shape of this distribution is Gaussian 
#I need to fit this distribution by following parameter 
mean=0.433 
sigma=0.014 
draw=s 
#Definition of bin number 
bi=np.linspace(0.01,8, 1000) 
data = py.hist(draw.dropna(), bins = bi) 
#Definition of Gaussian function 
def f(x, a, b, c): 
    return (a * py.exp(-(x - mean)**2.0/(2 *sigma**2))) 
x = [0.5 * (data[1][i] + data[1][i+1]) for i in xrange(len(data[1])-1)] 
y = data[0] 
#Fitting the peak of the distribution 
popt, pcov = optimize.curve_fit(f, x, y) 
chi2, p = stats.chisquare(popt) 
x_fit = py.linspace(x[0], x[-1], 80000) 
y_fit = f(x_fit, *popt) 
plot(x_fit, y_fit, lw=3, color="r",ls="--") 
plt.xlim(0,2) 
plt.tick_params(axis='both', which='major', labelsize=20) 
plt.show() 

問題は、定義された関数(f)をどのように統合し、その領域の下の数を数えるかです。ここでファイルT067.csvを添付します。あなたの親切な配慮に事前に感謝します。

+0

このコードにはいくつかの問題があります。重要な行ごとにコメントを追加して、何が起こっているのか、少なくとも達成しようとしていることを伝えてください。 – Gabriel

+0

@Gabrielよろしくお願いします。ここで私はあなたが望むように編集する。さらに詳しい情報が必要な場合は、私に知らせてください。 –

+0

コードを削除して、不可欠ではないものを可能な限り削除する必要があります。また、問題点を詳しく説明してください。 – Gabriel

答えて

0
BackPFT='T061.csv' 

df_180 = pd.read_csv(BackPFT, skip_blank_lines=True ,skiprows=1,header=None,skipfooter=None,engine='python') 

x_180=df_180.iloc[:,3] 
y_180=df_180.iloc[:,4] 

b=42.4 
E=109.8 
LET=24.19 
REL=127.32 

mean=0.339; m1=0.259 
sigma=0.012; s1=0.015 

s=np.sqrt((((16*x_180**2*b**2)/((4*b**2-y_180**2)**2))+1))-1 
draw=s 
bi=np.linspace(0,8, 2000) 
binwidth=0.004 
#I want to plot the dsitribution of s. This distribution has three gaussian peaks 
data = py.hist(draw.dropna(), bins = bi,color='gray',) 
#first Gaussian function for the first peak (peaks counted from the right) 
def f(x, a, b, c): 
    return (a * py.exp(-(x - mean)**2.0/(2 *sigma**2))) 
# fitting the function (Gaussian) 
x = [0.5 * (data[1][i] + data[1][i+1]) for i in xrange(len(data[1])-1)] 
y = data[0] 
popt, pcov = optimize.curve_fit(f, x, y) 
chi, p = stats.chisquare(popt) 
x_fit = py.linspace(x[0], x[-1], 80000) 
y_fit = f(x_fit, *popt) 
plot(x_fit, y_fit, lw=5, color="r",ls="--") 

#integration of first function f 
gaussF = lambda x, a: f(x, a, sigma, mean) 
bins=((6*sigma)/(binwidth)) 
delta = ((mean+3*sigma) - (mean-3*sigma))/bins 
f1 = lambda x : f(x, popt[0], sigma, mean) 
result = quad(f1,mean-3*sigma,mean+3*sigma) 
area = result[0] # this give the area after integration of the gaussian 
numPar = area/delta # this gives the number of particle under the integrated area 
print"\n\tArea under curve = ", area, "\n\tNumber of particel= ", numPar 

ここにファイルT061.csvがあります。彼の親切な協力と関心のおかげでDr. I Putu Susilaに感謝します。

+0

@ Gabriel、親愛なる私はあなたの問題を解決することができませんでした。しかし、あなたの親切な懸念と協力に感謝します。私はここに私の欲望の解決策を入れました。やっと私は解決策を見つけました。あなたの親切な助けをもう一度ありがとう。 –

関連する問題