In [1]:
"""
Example 7
- run SPECTRA without GUI
- calculate radiation power after transmitting various filters
"""
import sys
isjupyter = "ipykernel" in sys.modules
import spectra
# start without GUI (CLI mode)
spectra.Start(mode="c")
spectra.Open("sample.json")
spectra.SelectBL("X-ray-BL")
# partial power through 1x1mm^2 FE slit
spectra.SelectCalculation("fixed", "far", "ppower", "slitrect")
spectra.Set("config", "slitapt", [1,1])
spectra.StartCalculation(folder="./output", prefix="sample7", serial=-1)
result = spectra.GetResult()
total = ["None", result["Partial Power"]*1000]
spectra.Set("config", "filter", "Generic Filter")
filters = [
["Be", 1],
["Be", 10],
["C", 1],
["C", 10],
["Al", 1],
["Al", 10],
["Cu", 1],
["Cu", 10],
["Pb", 1],
["Pb", 10],
]
pp = []
for filter in filters:
spectra.Set("config", "fmateri", [filter])
spectra.StartCalculation()
result = spectra.GetResult()
pp.append([*filter, result["Filtered Power"]*1000])
if isjupyter:
from IPython.display import display, HTML
htmlc = "<table><caption>Power after various filters</caption>\n"
htmlc += "<thead><tr><th>Filter Type</th><th>Power (W)</th></tr></thead><tbody>\n"
htmlc += "<tr><td>{0:5}</td><td>{1:.1f}</td></tr>\n".format(total[0], total[1])
for item in pp:
htmlc += "<tr><td>{0:3}{1:.0f}t</td><td>{2:.1f}</td></tr>\n".format(item[0], item[1], item[2])
htmlc += "</tbody></table>"
display(HTML(htmlc))
else:
print("Power (W) after various filters")
print("{0:5} {1:6.1f}".format(total[0], total[1]))
for item in pp:
print("{0:3}{1:2.0f}t {2:6.1f}".format(item[0], item[1], item[2]))
# exit
spectra.Exit()
| Filter Type | Power (W) |
|---|---|
| None | 421.7 |
| Be 1t | 396.7 |
| Be 10t | 281.0 |
| C 1t | 362.8 |
| C 10t | 225.5 |
| Al 1t | 294.9 |
| Al 10t | 119.6 |
| Cu 1t | 84.8 |
| Cu 10t | 4.5 |
| Pb 1t | 6.2 |
| Pb 10t | 0.0 |
In [ ]: