esilik - 1 year ago 184

Python Question

I'm trying to calculate the grain size by Scherrer equation but I have stuck in 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))

Information: Scherrer equation, Full width at half maximum, Related question

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

I don't know how to solve this problem in python (at least for this moment). So I made it in 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)
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**