Skip to content

Commit fddfa6a

Browse files
committed
Added ability to plat spectral data
1 parent ec95398 commit fddfa6a

5 files changed

Lines changed: 43 additions & 2 deletions

File tree

topasgraphsim/src/classes/paramframe.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ def __init__(self, parent, tgs_graph, lang):
3434

3535
self.beamquality.grid(row=1, column=1, sticky="nsew", padx=2, pady=2)
3636
self.zmax.grid(row=2, column=1, sticky="nsew", padx=2, pady=2)
37+
38+
elif self.graph.direction == "s":
39+
40+
self.binlabel = ctk.CTkLabel(self, text=self.text.bins[self.lang], font=self.font, height=14)
41+
self.binsizelabel = ctk.CTkLabel(self, text=self.text.binsize[self.lang], font=self.font, height=14)
42+
self.minlabel = ctk.CTkLabel(self, text=self.text.min[self.lang], font=self.font, height=14)
43+
self.maxlabel = ctk.CTkLabel(self, text=self.text.max[self.lang], font=self.font, height=14)
44+
45+
self.bins = ctk.CTkLabel(self, text=str(self.parameters[0]), font=self.font, height=14)
46+
self.binsize = ctk.CTkLabel(self, text=str(self.parameters[1]), font=self.font, height=14)
47+
self.min = ctk.CTkLabel(self, text=str(self.parameters[2]), font=self.font, height=14)
48+
self.max = ctk.CTkLabel(self, text=str(self.parameters[3]), font=self.font, height=14)
49+
50+
self.namelabel.grid(row=0, column=0, columnspan=2, sticky="nsew", padx=2, pady=2)
51+
self.binlabel.grid(row=1, column=0, sticky="w", padx=2, pady=2)
52+
self.bins.grid(row=1, column=1, sticky="nsew", padx=2, pady=2)
53+
self.binsizelabel.grid(row=2, column=0, sticky="w", padx=2, pady=2)
54+
self.binsize.grid(row=2, column=1, sticky="nsew", padx=2, pady=2)
55+
self.minlabel.grid(row=3, column=0, sticky="w", padx=2, pady=2)
56+
self.min.grid(row=3, column=1, sticky="nsew", padx=2, pady=2)
57+
self.maxlabel.grid(row=4, column=0, sticky="w", padx=2, pady=2)
58+
self.max.grid(row=4, column=1, sticky="nsew", padx=2, pady=2)
3759

3860
else:
3961
self.halfwidthlabel = ctk.CTkLabel(self, text=self.text.fwhm[self.lang], font=self.font, height=14)

topasgraphsim/src/classes/sim_import.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from tkinter import simpledialog as sd
22

3+
import re
34
import numpy as np
45
import topas2numpy
56

@@ -17,6 +18,17 @@ def __init__(self, filepath):
1718
else:
1819
self.filename = self.filepath.split("\\")[-1][:-4]
1920

21+
with open(self.filepath, "r") as f:
22+
self.lines = f.readlines()
23+
for line in self.lines:
24+
if "Binned" in line:
25+
self.direction = "s"
26+
self.dose = np.array(self.lines[-1].split(","), dtype=np.float64)[1:-2]
27+
self.bins, self.binsize, self.min, self.max = re.findall(r"[-+]?(?:\d*\.*\d+)", self.lines[-3])
28+
self.axis = np.linspace(float(self.min), float(self.max), int(self.bins))
29+
self.std_dev = np.zeros(len(self.dose))
30+
return
31+
2032
self.data = topas2numpy.BinnedResult(self.filepath)
2133
bins = [dim.n_bins for dim in self.data.dimensions]
2234
if bins.count(1) != 2:
@@ -75,6 +87,8 @@ def params(self):
7587
self.dose / max(self.dose),
7688
self.std_dev / max(self.dose),
7789
)
90+
elif self.direction == "s":
91+
return self.bins, self.binsize, self.min, self.max
7892
else:
7993
params = dp.calculate_parameters(
8094
self.axis, self.dose / max(self.dose)

topasgraphsim/src/classes/tgs_graph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def data(self):
5050
axis = np.add(self.dataObject.axis,self.axshift)
5151
dose = self.dataObject.dose.copy()
5252
error = self.dataObject.std_dev.copy()
53+
5354
if self.normalize:
5455
if self.normalization == "maximum":
5556
error /= np.max(dose)
@@ -78,7 +79,7 @@ def plot(self, ax):
7879

7980
axis, dose, error = self.data()
8081
if self.caxcorrection:
81-
if self.direction != "Z":
82+
if self.direction != "Z" and self.direction != "s":
8283
axis = np.add(axis, self.dataObject.params()[1])
8384

8485
if self.error:

topasgraphsim/src/resources/language.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def __init__(self):
2020
"de": "Parameter konnten nicht berechnen werden!",
2121
"en": "Parameters could not be calculated!",
2222
}
23+
self.bins = {"de": "Klassenanzahl", "en": "Number of bins"}
24+
self.binsize = {"de": "Klassenbreite", "en": "Bin size"}
25+
self.min = {"de": "Minimum", "en": "Minimum"}
26+
self.max = {"de": "Maximum", "en": "Maximum"}
2327
self.criterion = {"de": "Kriterium", "en": "Criterion"}
2428
self.calcparams = {"de": "Parameter berechnen", "en": "Calculate parameters"}
2529
self.calculate = {"de": "Berechnen", "en": "Calculate"}

topasgraphsim/src/resources/profile.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geometry": "960x540+482+208",
2+
"geometry": "960x540+208+208",
33
"state": "normal",
44
"draganddrop": true,
55
"color_scheme": "light",

0 commit comments

Comments
 (0)