放射性核素衰变-radioactivedecay(2)

radioactivedecay 用于放射性核素衰变的简单分析计算的开源包,支持放射性核素、亚稳态和分支衰变的衰变链。

https://github.com/radioactivedecay/radioactivedecay

安装:pip install radioactivedecay

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
# %%
# ============ (2) ==================
import radioactivedecay as rd
import matplotlib.pyplot as plt
# 创建一组放射性源项:Inventory
inv = rd.Inventory({'U-235': 1}, 'Ci')

inv_t1 = inv.decay(50, 'd')
print(inv_t1.activities('Bq'))

# 绘图
inv.plot(50, 'd')
inv.plot(50, 'd', order='alphabetical')

# %%
import radioactivedecay as rd
import matplotlib.pyplot as plt

from cycler import cycler

plt.rcParams["font.family"] = "monospace"
cm = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']
ls = ['-', '--']
mk = ['+', 'x', '*', '^', 's']
me = [31, 71, 91, 113, 161]
cc = (cycler(color=cm) + cycler(linestyle=ls) * (cycler(marker=mk))) + cycler(markevery=me) * 2

DICT = {'U-235': 1e9,
'Rn-222': 1e9}

TIME = iter([10, 1])

for (hesu, huodu) in DICT.items():
t1 = next(TIME)
inv = rd.Inventory({hesu: huodu}, 'Bq')
inv_t1 = inv.decay(t1, 'd')
act_t1 = inv_t1.activities('Bq')

fig_name = f'{hesu} @ {huodu:0.2e} Bq'
fig_note = f'the Activity after {t1} days of Decay:\n'
fig_note += '\n'.join(f'- {k} {v:.2e} Bq' for (k, v) in act_t1.items())
print(fig_name, '\n' ,fig_note)

fig0 = plt.figure(figsize=(9, 9))
plt.gca().set_prop_cycle(cc)

fig, ax = inv.plot(t1, 'd', yscale='log', ymin=1e-8, order='alphabetical', fig=fig0)
plt.title(fig_name)
plt.text(0.3, 0.1, fig_note, transform=ax.transAxes)
plt.grid(True, linestyle=':', color='gray', alpha=0.5)

plt.show()
fig.savefig(f'decay_activity_{hesu}.png', dpi=300)