In [2]:
%matplotlib widget
import pyXRD
import matplotlib.pylab as plt
In [3]:
aa= pyXRD.XRDfile('XRD_T.raw')
reading as RAW RAW1 head= RAW1
In [4]:
print(len(aa.data))
aa.plot()
100
In [6]:
aa.info
Out[6]:
{'SCAN_cnt': 100, 'MEASURE_DATE': '10/14/07', 'MEASURE_TIME': '03:18:53', 'USER': 'Administrator', 'SITE': 'England', 'SAMPLE_ID': 'WO3', 'COMMENT': '', 'bug': b'\x00\x00', 'goniometer_code': 21, 'goniometer stage code': 9999, 'sample loader code': 0, 'goniometer controller code': 0, '(R4)_goniometer_radius': 250.0, '(R4) fixed divergence': 0.6, '(R4) fixed sample slit': 1.0, 'primary Soller slit': 2, 'primary monochromator': 0.0, '(R4) fixed antiscatter': 7.99, '(R4) fixed detector slit': 11.48, 'secondary Soller slit': 2, 'fixed thin film attachment': 0.0, 'beta filter': 0.0, 'secondary monochromator': 0.0, 'ANODE_MATERIAL': 'Cu', 'ALPHA_AVERAGE': 1.54184, 'ALPHA1': 1.5406, 'ALPHA2': 1.54439, 'BETA': 1.39222, 'ALPHA_RATIO': 0.5, 'measurement time': 0.0}
In [7]:
aa.D2plot(log=True)
(100, 13638)
In [6]:
aa.data[5].info
Out[6]:
{'STEPS': 13638, 'START_THETA': 5.0, 'START_2THETA': 10.0, 'DIVERGENCE': 0.597, 'VARDIVERGENCE': 'fix', 'HIGH_VOLTAGE': 9999.0, 'AMPLIFIER_GAIN': 9999.0, 'DISCRIMINATOR_1_LOWER_LEVEL': 9999.0, 'STEPSIZE': 0.0102662, 'STEPTIME': 15.03, 'TIMESTARTED': 6354.0, 'ROTATION_SPEEDrpm': 0.0, 'TEMPERATURE': -1.0, 'TEMP_RATE': -1.0, 'TEMP_DELAY': -1.0, 'GENERATOR_VOLTAGE': 40, 'GENERATOR_CURRENT': 40, 'USED_LAMBDA': 1.5406, 'index': 5, 'UNIT': 'counts'}
In [7]:
peak1= aa.peak_intensity(23.47, 23.9)
In [22]:
aa.data[2].plot()
aa2 = aa.data[2]
In [23]:
from pyXRD import FitPeak as FP
peaks, valleys=FP.peakdet(aa2.y, x=aa2.x , delta=0.03, plot=True)
plt.xlabel('2$\Theta$($\degree$)')
plt.ylabel('int')
Out[23]:
Text(0, 0.5, 'int')
In [24]:
peaks = peaks[1:]
model, param= FP.create_PicBack(aa2.x, aa2.y,peaks, valleys, back_degree=3, Guess=True, plot=False)
In [123]:
import numpy as np
x,y,z=FP.data_lim(np.vstack([aa.data[0].x,aa.data[0].y, aa.data[0].err]),[22,26])
peaks, valleys=FP.peakdet(y, x = x, delta=0.02, plot=0)
model, param= FP.create_PicBack(x,y, peaks, valleys, back_degree=1, Guess=True, plot=False)
%time out3 = model.fit(y, param, x=x, weights=1.0/z)
#np.sqrt(1.0/y)
out3.plot(show_init=0)
plt.title('weight =sqrt(1.0/y)')
print( out3.fit_report())
CPU times: total: 156 ms Wall time: 154 ms [[Model]] (((Model(polynomial, prefix='line_') + Model(pvoigt, prefix='pic0_')) + Model(pvoigt, prefix='pic1_')) + Model(pvoigt, prefix='pic2_')) [[Fit Statistics]] # fitting method = leastsq # function evals = 121 # data points = 391 # variables = 14 chi-square = 1403.26006 reduced chi-square = 3.72217522 Akaike info crit = 527.637732 Bayesian info crit = 583.199638 R-squared = 0.99999257 [[Variables]] line_c0: 499.556420 +/- 25.6391363 (5.13%) (init = 547.3846) line_c1: -16.1358178 +/- 1.04244903 (6.46%) (init = -17.35606) pic0_amplitude: 408.071452 +/- 5.46958997 (1.34%) (init = 386.8304) pic0_center: 23.1662587 +/- 6.0501e-04 (0.00%) (init = 23.17153) pic0_H: 0.11499434 +/- 0.00160257 (1.39%) (init = 0.1231944) pic0_Nu: 0.30319855 +/- 0.03240283 (10.69%) (init = 0.5) pic0_Beta: 0.13566677 +/- 0.00157784 (1.16%) == 'pic0_H*1.5707963/(pic0_Nu+(1.0-pic0_Nu)*1.4756646)' pic0_HL: 0.02771573 +/- 0.00301815 (10.89%) == '(0.72928*pic0_Nu +0.19289*pic0_Nu**2 + 0.07783*pic0_Nu**3)*pic0_H' pic0_HG: 0.09967840 +/- 0.00297424 (2.98%) == 'pic0_H*( 1 -0.74417*pic0_Nu -0.24781*pic0_Nu**2 - 0.00810* pic0_Nu**3)**0.5' pic1_amplitude: 406.290967 +/- 5.33980540 (1.31%) (init = 348.5991) pic1_center: 23.6546094 +/- 7.1572e-04 (0.00%) (init = 23.64891) pic1_H: 0.12687528 +/- 0.00200923 (1.58%) (init = 0.1334606) pic1_Nu: 0.43592336 +/- 0.03277866 (7.52%) (init = 0.5) pic1_Beta: 0.15713432 +/- 0.00195338 (1.24%) == 'pic1_H*1.5707963/(pic1_Nu+(1.0-pic1_Nu)*1.4756646)' pic1_HL: 0.04580353 +/- 0.00350110 (7.64%) == '(0.72928*pic1_Nu +0.19289*pic1_Nu**2 + 0.07783*pic1_Nu**3)*pic1_H' pic1_HG: 0.10053109 +/- 0.00375074 (3.73%) == 'pic1_H*( 1 -0.74417*pic1_Nu -0.24781*pic1_Nu**2 - 0.00810* pic1_Nu**3)**0.5' pic2_amplitude: 433.681087 +/- 5.08316746 (1.17%) (init = 401.9833) pic2_center: 24.4130111 +/- 6.0084e-04 (0.00%) (init = 24.41374) pic2_H: 0.11234719 +/- 0.00169044 (1.50%) (init = 0.1231944) pic2_Nu: 0.44484218 +/- 0.02758992 (6.20%) (init = 0.5) pic2_Beta: 0.13960833 +/- 0.00161682 (1.16%) == 'pic2_H*1.5707963/(pic2_Nu+(1.0-pic2_Nu)*1.4756646)' pic2_HL: 0.04150506 +/- 0.00258073 (6.22%) == '(0.72928*pic2_Nu +0.19289*pic2_Nu**2 + 0.07783*pic2_Nu**3)*pic2_H' pic2_HG: 0.08840596 +/- 0.00294413 (3.33%) == 'pic2_H*( 1 -0.74417*pic2_Nu -0.24781*pic2_Nu**2 - 0.00810* pic2_Nu**3)**0.5' [[Correlations]] (unreported correlations are < 0.100) C(line_c0, line_c1) = -0.9982 C(pic2_H, pic2_Nu) = -0.6404 C(pic1_H, pic1_Nu) = -0.6353 C(pic0_H, pic0_Nu) = -0.5980 C(pic0_amplitude, pic0_Nu) = +0.5880 C(pic1_amplitude, pic1_Nu) = +0.5361 C(pic2_amplitude, pic2_Nu) = +0.4495 C(line_c0, pic0_Nu) = -0.3243 C(line_c1, pic0_Nu) = +0.3090 C(line_c0, pic0_amplitude) = -0.2829 C(line_c1, pic0_amplitude) = +0.2691 C(pic0_Nu, pic1_Nu) = -0.2648 C(pic0_amplitude, pic0_H) = -0.2282 C(pic0_amplitude, pic1_Nu) = -0.2094 C(pic0_Nu, pic1_amplitude) = -0.2037 C(pic1_amplitude, pic1_H) = -0.2009 C(pic2_amplitude, pic2_H) = -0.1622 C(pic0_amplitude, pic1_amplitude) = -0.1484 C(line_c0, pic0_H) = +0.1116 C(pic0_Nu, pic1_H) = +0.1099 C(line_c1, pic0_H) = -0.1066 C(pic0_H, pic1_Nu) = +0.1026 C(pic0_Nu, pic2_Nu) = +0.1022
In [237]:
#fit all data
plt.close('all')
out = []
for i, pat in enumerate(aa.data):
x,y,z=FP.data_lim(np.vstack([pat.x,pat.y, pat.err]),[22,26])
peaks, valleys=FP.peakdet(y, x = x, delta=0.05, plot=0)
model, param= FP.create_PicBack(x, y, peaks, [valleys[0],valleys[-1]], back_degree=1, Guess=True, plot=False)
for ii in param:
if 'center' in ii:
param[ii].min= param[ii].value-0.03
param[ii].max= param[ii].value+0.03
#FP.plot_guess(x, y, model, param)
if not(i % 10):
print(i)
out3 = model.fit(y, param, x=x, weights=1.0/z)
out.append(out3)
0 10 20 30 40 50 60 70 80 90
In [242]:
#plot positions
out_plot ={}
maxn_pic = 4
for i_p in range(maxn_pic):
out_plot[f'pic{i_p}_center']=[]
out_plot[f'pic{i_p}_center_err']=[]
for fit in out:
for i_p in range(maxn_pic):
label = f'pic{str(i_p)}_center'
if label in fit.params:
out_plot[label].append(fit.params[label].value)
out_plot[label+'_err'].append(fit.params[label].stderr)
else:
out_plot[label].append(None)
out_plot[label+'_err'].append(None)
plt.close(fig1)
fig1=plt.figure()
for i_p in range(maxn_pic):
label = f'pic{str(i_p)}_center'
plt.plot(out_plot[label], label = label)
plt.show()
plt.legend()
Out[242]:
<matplotlib.legend.Legend at 0x248586a73d0>
In [241]:
out_plot ={}
maxn_pic = 4
for i_p in range(maxn_pic):
out_plot[f'pic{i_p}_amplitude']=[]
out_plot[f'pic{i_p}_amplitude_err']=[]
for fit in out:
for i_p in range(maxn_pic):
label = f'pic{str(i_p)}_amplitude'
if label in fit.params:
out_plot[label].append(fit.params[label].value)
out_plot[label+'_err'].append(fit.params[label].stderr)
else:
out_plot[label].append(None)
out_plot[label+'_err'].append(None)
plt.close(fig1)
fig1=plt.figure()
for i_p in range(maxn_pic):
label = f'pic{str(i_p)}_amplitude'
plt.plot(out_plot[label], label = label)
plt.show()
plt.legend()
Out[241]:
<matplotlib.legend.Legend at 0x24898a2f3d0>
In [231]:
components = out[35].eval_components()
plt.figure()
for model_name, model_value in components.items():
plt.plot(x, model_value)
In [234]:
out[35]
Out[234]:
Fit Result
Model: (((Model(polynomial, prefix='line_') + Model(pvoigt, prefix='pic0_')) + Model(pvoigt, prefix='pic1_')) + Model(pvoigt, prefix='pic2_'))
fitting method | leastsq |
# function evals | 121 |
# data points | 391 |
# variables | 14 |
chi-square | 2226.12192 |
reduced chi-square | 5.90483268 |
Akaike info crit. | 708.069718 |
Bayesian info crit. | 763.631624 |
R-squared | 0.99998754 |
name | value | standard error | relative error | initial value | min | max | vary | expression |
---|---|---|---|---|---|---|---|---|
line_c0 | 503.375866 | 32.0513731 | (6.37%) | 495.64338878368267 | -inf | inf | True | |
line_c1 | -16.3707345 | 1.30344259 | (7.96%) | -17.13020094733373 | -inf | inf | True | |
pic0_amplitude | 406.821381 | 6.88276548 | (1.69%) | 362.04780919999655 | 0.00000000 | inf | True | |
pic0_center | 23.1752435 | 7.5436e-04 | (0.00%) | 23.1766677 | 23.1366677 | 23.2166677 | True | |
pic0_H | 0.11391225 | 0.00199244 | (1.75%) | 0.11292819999999892 | 0.00000000 | inf | True | |
pic0_Nu | 0.29788247 | 0.04087739 | (13.72%) | 0.5 | 0.00000000 | 1.00000000 | True | |
pic0_Beta | 0.13413541 | 0.00196213 | (1.46%) | 0.14330470995599187 | -inf | inf | False | pic0_H*1.5707963/(pic0_Nu+(1.0-pic0_Nu)*1.4756646) |
pic0_HL | 0.02693032 | 0.00376521 | (13.98%) | 0.047722469198249545 | -inf | inf | False | (0.72928*pic0_Nu +0.19289*pic0_Nu**2 + 0.07783*pic0_Nu**3)*pic0_H |
pic0_HG | 0.09905268 | 0.00369899 | (3.73%) | 0.08488039898464605 | -inf | inf | False | pic0_H*( 1 -0.74417*pic0_Nu -0.24781*pic0_Nu**2 - 0.00810* pic0_Nu**3)**0.5 |
pic1_amplitude | 409.972784 | 6.87174409 | (1.68%) | 348.3321659999996 | 0.00000000 | inf | True | |
pic1_center | 23.6682393 | 9.8019e-04 | (0.00%) | 23.6694453 | 23.6294453 | 23.7094453 | True | |
pic1_H | 0.13677318 | 0.00279305 | (2.04%) | 0.15399299999999982 | 0.00000000 | inf | True | |
pic1_Nu | 0.45206599 | 0.04257467 | (9.42%) | 0.5 | 0.00000000 | 1.00000000 | True | |
pic1_Beta | 0.17042457 | 0.00269824 | (1.58%) | 0.1954155135763542 | -inf | inf | False | pic1_H*1.5707963/(pic1_Nu+(1.0-pic1_Nu)*1.4756646) |
pic1_HL | 0.05146676 | 0.00492582 | (9.57%) | 0.06507609436124993 | -inf | inf | False | (0.72928*pic1_Nu +0.19289*pic1_Nu**2 + 0.07783*pic1_Nu**3)*pic1_H |
pic1_HG | 0.10701524 | 0.00530368 | (4.96%) | 0.1157459986154274 | -inf | inf | False | pic1_H*( 1 -0.74417*pic1_Nu -0.24781*pic1_Nu**2 - 0.00810* pic1_Nu**3)**0.5 |
pic2_amplitude | 439.662976 | 6.50204189 | (1.48%) | 397.57912739999813 | 0.00000000 | inf | True | |
pic2_center | 24.3946048 | 8.1102e-04 | (0.00%) | 24.3983455 | 24.3583455 | 24.4383455 | True | |
pic2_H | 0.11775800 | 0.00236584 | (2.01%) | 0.13346059999999937 | 0.00000000 | inf | True | |
pic2_Nu | 0.49999761 | 0.03575657 | (7.15%) | 0.5 | 0.00000000 | 1.00000000 | True | |
pic2_Beta | 0.14943354 | 0.00225661 | (1.51%) | 0.16936011176617302 | -inf | inf | False | pic2_H*1.5707963/(pic2_Nu+(1.0-pic2_Nu)*1.4756646) |
pic2_HL | 0.04976322 | 0.00354922 | (7.13%) | 0.05639928177974974 | -inf | inf | False | (0.72928*pic2_Nu +0.19289*pic2_Nu**2 + 0.07783*pic2_Nu**3)*pic2_H |
pic2_HG | 0.08851082 | 0.00418797 | (4.73%) | 0.10031319880003672 | -inf | inf | False | pic2_H*( 1 -0.74417*pic2_Nu -0.24781*pic2_Nu**2 - 0.00810* pic2_Nu**3)**0.5 |
Parameter1 | Parameter 2 | Correlation |
---|---|---|
line_c0 | line_c1 | -0.9982 |
pic2_H | pic2_Nu | -0.6600 |
pic1_H | pic1_Nu | -0.6469 |
pic0_H | pic0_Nu | -0.5970 |
pic0_amplitude | pic0_Nu | +0.5898 |
pic1_amplitude | pic1_Nu | +0.5460 |
pic2_amplitude | pic2_Nu | +0.4439 |
line_c0 | pic0_Nu | -0.3198 |
line_c1 | pic0_Nu | +0.3045 |
line_c0 | pic0_amplitude | -0.2774 |
pic0_Nu | pic1_Nu | -0.2769 |
line_c1 | pic0_amplitude | +0.2638 |
pic0_amplitude | pic0_H | -0.2296 |
pic0_amplitude | pic1_Nu | -0.2233 |
pic0_Nu | pic1_amplitude | -0.2171 |
pic1_amplitude | pic1_H | -0.2083 |
pic0_amplitude | pic1_amplitude | -0.1614 |
pic2_amplitude | pic2_H | -0.1584 |
pic0_Nu | pic1_H | +0.1161 |
pic1_Nu | pic2_Nu | -0.1135 |
line_c0 | pic0_H | +0.1113 |
line_c1 | pic0_H | -0.1063 |
pic0_amplitude | pic1_H | +0.1040 |
pic0_H | pic1_Nu | +0.1036 |
pic0_Nu | pic2_Nu | +0.1013 |
In [ ]: