File: fluor_yield_comparison.py

package info (click to toggle)
xraylib 4.0.0%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 46,936 kB
  • sloc: ansic: 16,103; f90: 8,746; java: 6,766; python: 1,497; cpp: 1,305; pascal: 1,139; makefile: 809; ruby: 622; php: 594; perl: 573; cs: 193; sh: 125
file content (38 lines) | stat: -rw-r--r-- 1,198 bytes parent folder | download | duplicates (2)
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
import numpy as np
import xraylib_np as xrl_np
import matplotlib.pyplot as plt
from matplotlib import gridspec

Z = np.arange(3, 99)

yields_bad = xrl_np.FluorYield(Z, np.array([xrl_np.K_SHELL])).squeeze()

yields_good = []

with open('fluor_yield_revised.dat', 'r') as file:
    for line in file:
        [myZ, y] = line.split()
        yields_good.append(y)
    yields_good = np.asarray(yields_good, dtype=np.float64)


fig = plt.figure(figsize=(7, 10))
gs = gridspec.GridSpec(3, 1, height_ratios=[3, 1, 1])
ax = fig.add_subplot(gs[0])
ax.set_xlabel('Atomic number')
ax.set_ylabel('Fluorescence yield')
plot_bad, = ax.plot(Z, yields_bad, color='r', marker='o', label='Fitted Hubbell')
plot_good, = ax.plot(Z, yields_good[0:Z.shape[0]], color='g', marker='o', label='Recommended Hubbell')
ax.legend(handles=[plot_bad, plot_good], loc=4)

ax = fig.add_subplot(gs[1])
ax.set_ylabel('Absolute diff')
ax.plot(Z, (yields_good[0:Z.shape[0]] - yields_bad), color='b', marker='o')

ax = fig.add_subplot(gs[2])
ax.set_ylabel('Relative diff')
ax.plot(Z, (yields_good[0:Z.shape[0]] - yields_bad) / yields_good[0:Z.shape[0]], color='b', marker='o')

plt.draw()
plt.savefig('yield-comparison.png')
plt.close()