-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComparison_plotting.py
More file actions
81 lines (67 loc) · 2.29 KB
/
Comparison_plotting.py
File metadata and controls
81 lines (67 loc) · 2.29 KB
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
# plotting for RZ R&D
# zh 20240305
from PDZreader import PDZFile
import pandas as pd
import plotly_express as px
from tkinter import filedialog
import os
def main():
pdzpaths: tuple[str] = filedialog.askopenfilenames(
title="Select PDZ Files to include in plot",
filetypes=[("PDZ File", "*.pdz")],
initialdir=os.getcwd(),
)
# print(pdzpaths)
pdz_dfs: list[pd.DataFrame] = []
for pdz_fname in pdzpaths:
pdz = PDZFile(f"{pdz_fname}")
df = pd.DataFrame(
data={
"Info": [
f"{pdz.pdz_file_name} ({pdz.spectrum1.source_voltage:.0f}kV / {pdz.spectrum1.source_current:.2f}uA / {pdz.spectrum1.filterDesciption} / {pdz.spectrum1.timeLive:.2f}s live)"
]
* 2048,
"Energy (keV)": pdz.spectrum1.energies,
"Counts": pdz.spectrum1.counts,
}
)
pdz_dfs.append(df)
# df = pd.DataFrame(
# data={
# "Info": [
# f"{pdz.name} ({pdz.spectrum3.sourceVoltage:.0f}kV / {pdz.spectrum3.sourceCurrent:.2f}uA / {pdz.spectrum3.filterDesciption} / {pdz.spectrum3.timeLive:.2f}s live)"
# ]
# * 2048,
# "Energy (keV)": pdz.spectrum3.energies,
# "Counts": pdz.spectrum3.counts,
# }
# )
# pdz_dfs.append(df)
df_all = pd.concat(pdz_dfs) # all
# plot
fig = px.line(df_all, x="Energy (keV)", y="Counts", color="Info")
fig.add_vline(
x=4.512,
annotation_text="Ti Kα",
annotation_position="bottom right",
line_width=1,
line_dash="dash",
line_color="gray",
)
fig.add_vline(
x=15.775,
annotation_text="Zr Kα",
annotation_position="bottom right",
line_width=1,
line_dash="dash",
line_color="gray",
)
fig.update_layout(legend=dict(yanchor="top", y=0.99, xanchor="right", x=0.99))
# fig.show()
# save interactive html file with plot
plot_name = input("Please Enter a Name for the Interactable Plot: ")
output_file_name = f"{plot_name}_interactable_plot.html"
fig.write_html(output_file_name)
print(f"File saved as {output_file_name}.")
if __name__ == "__main__":
main()