Using Scherrer equation for calculating the grain size
<p>I'm trying to calculate the grain size by Scherrer equation but I have stuck in FWHM. </p>

<pre><code>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))
</code></pre>

<p><a href="http://i.stack.imgur.com/1l5Pq.png" rel="nofollow"><img src="http://i.stack.imgur.com/1l5Pq.png" alt="Corresponding graphs looks likes as in the picture"></a></p>

<p>Information: <a href="https://en.wikipedia.org/wiki/Scherrer_equation" rel="nofollow">Scherrer equation</a>,  <a href="https://en.wikipedia.org/wiki/Full_width_at_half_maximum" rel="nofollow">Full width at half maximum</a>, <a href="http://stackoverflow.com/questions/29877427/python-find-fwhm-of-curve">Related question</a></p>

<p>I don't know how to solve this problem in python (at least for this moment). So I made it in Matlab.        </p>

<pre><code>    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 &lt; A(yval_i1+1,2)
        yval_i1 = yval_i1+1;
        end

        yval_i2 = yval_i(i,1);
        while (yval(i,1))/2 &lt; 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)
</code></pre>

python numpy physics