/
refinementPlot.py
91 lines (71 loc) · 3.16 KB
/
refinementPlot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from calculateCHILSQRs import *
import numpy as np
import matplotlib.pyplot as plt
from crystallography import *
from projectData import PND_susceptibility as D
import os
def plotLIScontent(ax, L, params, D, printBool=False):
"""
ax: matplotlib.pyplot.Axes instance
L: wavelength of the used radiation
params: unit cell parameters of the crystal
D: dictionary returned by calculateCHILSQRs.readCHILSQ_FRs
"""
fileName = D['fileName']
FRobs = D['FRobs']
FRcalc = D['FRcalc']
w = D['weight']
q = D['q']
s = D['s']
nVar = D['nVar']
R1 = calcR1(FRobs, FRcalc, doPrint=printBool)*100
R2 = calcR2(FRobs, FRcalc, doPrint=printBool)*100
R3 = calcR3(FRobs, FRcalc, w, doPrint=printBool)*100
R4 = calcR4(FRobs, FRcalc, w, doPrint=printBool)*100
X2 = calcXsqrd(FRobs, FRcalc, w, nVar)
ax.text(0.01, 0.4, fileName+'\nR1 = {:3.2f}%\nR2 = {:3.2f}%\nR3 = {:3.2f}%\nR4 = {:3.2f}%\nX2 = {:3.2f}'.format(R1, R2, R3, R4, X2), transform=ax.transAxes, size=8)
ax.errorbar(q, FRobs, yerr=s, c='k', marker='*', linestyle='-', label='Observed', linewidth=1)
points, = ax.plot(q, FRcalc, 'r*-', label='Calculated', linewidth=1)
ax.plot(q, FRcalc-FRobs, 'b-', label='Difference', linewidth=1)
ax.legend(loc='upper right', fontsize=8)
#ax.set_xlabel(r'$q = \frac{4\pi\sin{\theta}}{\lambda}$')
#ax.set_ylabel(r'$FR = \frac{I_+}{I_-}$')
return points,
if __name__ == '__main__':
params = D.Dy_DBM_params
L = 1.4
fig = plt.figure()
axes = []
printing = False
fileNames = [x for x in os.listdir() if x.endswith('.lis')]
for n in range(len(fileNames)):
ax1 = fig.add_subplot(len(fileNames), 1, n+1)
axes.append(ax1)
fileName = fileNames[n]
data = readCHILSQ_FRs(fileNames[n])
extFile = [x for x in list(data.keys()) if x.endswith('.ext')][0]
A = data[extFile]
rows_cols = A.shape
h, k, l = A[:,0], A[:,1], A[:,2]
FRobs = A[:,3]
FRcalc = A[:,4]
w = A[:,-1]
q = q_from_theta(theta_from_d(d_from_hkl(h,k,l,params),L),L)
sort_indices = q.argsort()
q = q[sort_indices]
FRobs = FRobs[sort_indices]
FRcalc = FRcalc[sort_indices]
w = w[sort_indices]
R1 = calcR1(FRobs, FRcalc, doPrint=printing)*100
R2 = calcR2(FRobs, FRcalc, doPrint=printing)*100
R3 = calcR3(FRobs, FRcalc, w, doPrint=printing)*100
R4 = calcR4(FRobs, FRcalc, w, doPrint=printing)*100
X2 = calcXsqrd(FRobs, FRcalc, w, data['variables'])
ax1.text(0.01, 0.4, extFile+'\nR1 = {:3.2f}%\nR2 = {:3.2f}%\nR3 = {:3.2f}%\nR4 = {:3.2f}%\nX2 = {:3.2f}'.format(R1, R2, R3, R4, X2), transform=ax1.transAxes, size=8)
ax1.plot(q, FRobs, 'k*-', label='Observed', linewidth=1)
ax1.plot(q, FRcalc, 'r*-', label='Calculated', linewidth=1)
ax1.plot(q, FRcalc-FRobs, 'b-', label='Difference', linewidth=1)
ax1.legend(loc='upper right', fontsize=8)
ax1.set_xlabel(r'$q = \frac{4\pi\sin{\theta}}{\lambda}$')
ax1.set_ylabel(r'$FR = \frac{I_+}{I_-}$')
plt.show()