繁体   English   中英

使用Scherrer方程计算晶粒度

[英]Using Scherrer equation for calculating the grain size

我正在尝试通过Scherrer方程计算晶粒尺寸,但我陷入了FWHM。

import numpy as np
#import math

k = 0.94
wave_length = 1.5406e-10

data = np.genfromtxt("G3.txt")

indice = np.argmax(data[:,1])
peak = (data[indice, :])
#D = (k*wave_length) / (beta*cos((math.radian(theta))

对应的图形如图所示

信息: Scherrer方程 全宽相关问题

这是一个工作示例,假设您具有正态分布。 我在Jupyter控制台中运行它,因此,如果您不这样做,则必须跳过“魔术行”( %matplotlib notebook ),并在最后添加plt.show()

%matplotlib notebook
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np

numb = 500                                # data size
fwhm_in = 3                               # set FWHM for the artificial data
sigma = fwhm_in/2/np.sqrt(2*np.log(2))    # calculate sigma
xval = np.linspace(-10, 10, numb)         # calculate x and y values using the formula from Wikipedia (see link in question)
yval = (sigma*np.sqrt(2*np.pi))**(-1)*np.exp(-(xval)**2/(2*sigma**2))+np.random.normal(0, 0.03, numb)

def fitFunc(x, x0, sigm):                 # this defines the fit-function
    return (sigm*np.sqrt(2*np.pi))**(-1)*np.exp(-(x-x0)**2/(2*sigm**2))

guess = (0.5, 2)                          # tell the code with which values it should start the iteration. Close but not equal to the real values
fitParams, fitCovariance = curve_fit(fitFunc, xval, yval, guess) # do the actual fit
print(fitParams)

print('FWHM_calc = {:.3f}'.format(fwhm_in))
fwhm_fit = 2*fitParams[1]*np.sqrt(2*np.log(2))  # calculate the FWHM from the fitted sigma ( = fitParams[1], since fitParams[0] is the offset x0)
print('FWHM_fit = {:.3f}'.format(fwhm_fit))

plt.plot(xval,yval, 'r.', label='data')
plt.plot(xval, fitFunc(xval, fitParams[0], fitParams[1]), 'k-', label='fit', linewidth = 3)

plt.grid(True)
plt.legend()
ax = plt.gca()
ax.axvline(fwhm_fit/2, color='b')
ax.axvline(-fwhm_fit/2, color='b')

正态分布的FWHM(蓝色垂直线)示例。

很抱歉将其作为答案分享,但评论未提供我上传图片以澄清问题的信息。 因此,我在下面的图片中说明了问题(顺便说一句,我无法编辑或删除我勉强写的评论)。 我在运行代码时得到了这张图 我在运行代码时得到了这张图

这是我想要的图

此图说明了我在寻找什么

我不知道如何在python中解决这个问题(至少目前是这样)。 所以我在Matlab中做到了。

    clear all
    clc
    A = dlmread('YOUR DATAS'); %Firstly add to path
    plot(A(:,1),A(:,2)) %Plotting the graph
    hold on

    min_peak = input('Just write a value that is higher than minimum peak values: ');
%This value must be between requested peaks and non-requested peaks (you can see this in graph)
    [yval, yval_i] = findpeaks(A(:,2),'MinPeakHeight',min_peak); %Finding peaks
    scatter(A(yval_i,1), yval); %Showing peaks
    Beta = []; 
    xval = [];
    for k = 1:size(yval_i,1) %Finding x values corresponding to y (peak) values
        xval1 = A(yval_i(k),1);
        xval = [xval xval1];
    end
        Theta = xval / 2; 

    for i = 1:size(yval,1) %Finding half of max. peak values
        yval_i1 = yval_i(i,1);
        while (yval(i,1))/2 < A(yval_i1+1,2)
        yval_i1 = yval_i1+1;
        end

        yval_i2 = yval_i(i,1);
        while (yval(i,1))/2 < A(yval_i2-1,2)
        yval_i2 = yval_i2-1;
        end

        plot(A(yval_i2,1)*ones(size(A(:,2))), A(:,2));
        plot(A(yval_i1,1)*ones(size(A(:,2))), A(:,2));
    %     hold on
    %     scatter(A(yval_i1,1),A(yval_i1,2))
    %     scatter(A(yval_i2,1),A(yval_i2,2))
        B = abs(A(yval_i1,1)-A(yval_i2,1));
        Beta = [Beta B];
    end
    Beta

    K = 0.94;
    Lambda = 1.5406e-10;

    To = [];
    for j = 1:size(Beta,2)
    To1 = (K*Lambda)/(Beta(j)*cos(Theta(j)));
    To = [To To1];
    end
    To = abs(To)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM