Skip to content

Commit 8839ad0

Browse files
committed
Update to Version 24.1.0
1 parent 5ff796f commit 8839ad0

11 files changed

Lines changed: 162 additions & 43 deletions

File tree

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ keywords:
1919
- GUI
2020
- Python
2121
license: MIT
22-
version: 24.0.0
22+
version: 24.1.0
2323
date-released: '2023-03-25'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="topasgraphsim",
8-
version="24.0.0",
8+
version="24.1.0",
99
author="Sebastian Schäfer",
1010
author_email="sebastian.schaefer@student.uni-halle.de",
1111
description="GUI to analyze the results of a Monte-Carlo radiation simulation",

topasgraphsim/src/classes/main_viewer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ def drop(self, event):
4848
elif path[-4:] == ".mcc":
4949
if len(self.tabview.tabnames) == 0:
5050
self.tabview.add_tab(name = True)
51-
self.tabview.tab(self.tabview.tabnames[-1]).tab.options.load_measurement(path)
51+
self.tabview.tab(self.tabview.tabnames[-1]).tab.options.load_measurement(path)
52+
53+
elif path[-4:] == ".txt":
54+
if len(self.tabview.tabnames) == 0:
55+
self.tabview.add_tab(name = True)
56+
self.tabview.tab(self.tabview.tabnames[-1]).tab.options.load_txt(path)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import numpy as np
2+
import customtkinter as ctk
3+
4+
from .tgs_graph import TGS_Plot
5+
from .paramframe import Parameters
6+
from ..functions import pdd, dp
7+
from ..resources.language import Text
8+
from .profile import ProfileHandler
9+
from .scrollframe import ScrollFrame
10+
11+
class TXTMeasurement:
12+
def __init__(self, path, direction, data):
13+
14+
self.filename = path.split("/")[-1][:-4]
15+
self.direction = direction
16+
self.data = data
17+
18+
self.axis = self.data[:,0]
19+
self.dose = self.data[:,1]
20+
try: self.std_dev = self.data[:,2]
21+
except Exception: self.std_dev = np.array([0.0 for i in range(len(self.dose))])
22+
23+
def params(self):
24+
if self.direction == "Z":
25+
return pdd.calculate_parameters(
26+
np.array(self.axis),
27+
self.dose / max(self.dose),
28+
[],
29+
)
30+
else:
31+
params = dp.calculate_parameters(
32+
self.axis, self.dose / max(self.dose)
33+
)
34+
self.cax = params[1]
35+
return params
36+
37+
38+
class TXTImporter(ScrollFrame):
39+
def __init__(self, filepath, parent, plotlist, options):
40+
super().__init__(parent=parent)
41+
try: self.data = np.loadtxt(filepath)
42+
except Exception:
43+
self.bell()
44+
return
45+
self.text = Text()
46+
self.lang = ProfileHandler().get_attribute("language")
47+
self.plotlist = plotlist
48+
self.path = filepath
49+
self.options = options
50+
self.root = self.options.parent.master.master.parent
51+
self.pack_propagate(False)
52+
self.grid_propagate(False)
53+
self.canvas.pack_propagate(False)
54+
theme = ProfileHandler().get_attribute("color_scheme")
55+
colors2 = {"light": "#E5E5E5", "dark":"#212121"}
56+
colors3 = {"light": "#DBDBDB", "dark":"#2B2B2B"}
57+
self.configure(fg_color=colors2[theme])
58+
self.canvas.configure(bg=colors3[theme], highlightbackground=colors3[theme])
59+
self.scrollbar.configure(fg_color=colors3[theme])
60+
self.options.dataframe2.grid_remove()
61+
self.options.dataframe1.grid_remove()
62+
self.grid(row=0, rowspan=2, column=0, sticky="nsew")
63+
self.label = ctk.CTkLabel(self.viewPort, text=Text().direction[self.lang], font=("Bahnschrift", 14, "bold"))
64+
self.label.pack(anchor="n", pady=5)
65+
directions = ["X", "Y", "Z"]
66+
self.direction = ctk.StringVar()
67+
self.directions = [ctk.CTkRadioButton(self.viewPort, text=direction, variable=self.direction, value=direction) for direction in directions]
68+
[button.pack(anchor="w", pady=5) for button in self.directions]
69+
self.submitbutton = ctk.CTkButton(
70+
self.viewPort,
71+
text=Text().submit[ProfileHandler().get_attribute("language")],
72+
command=self.submit,
73+
)
74+
self.submitbutton.pack(anchor="s", pady=5)
75+
76+
def submit(self):
77+
78+
self.plotlist += [TGS_Plot(self.options, TXTMeasurement(self.path, self.direction.get(), self.data))]
79+
self.options.parameters.append(Parameters(self.options.paramslist.viewPort, self.plotlist[-1], self.lang))
80+
self.options.parameters[-1].grid(row=len(self.options.parameters)-1, sticky="ew", padx=5, pady=5)
81+
self.options.plotbuttons.append(ctk.CTkRadioButton(self.options.graphlist.viewPort, text=self.plotlist[-1].label, variable=self.options.current_plot, text_color = self.plotlist[-1].linecolor, value=self.plotlist[-1].label, command=self.options.change_current_plot, font=("Bahnschrift", 14, "bold")))
82+
self.options.plotbuttons[-1].grid(sticky="w", padx=5, pady=5)
83+
if len(self.options.parent.plots) == 1:
84+
self.options.enable_all_buttons()
85+
try:
86+
self.options.current_plot.set(self.plotlist[-1].label)
87+
self.options.filenames.append(self.path)
88+
self.options.parent.saved = False
89+
self.options.update_plotlist()
90+
self.options.parent.update()
91+
except IndexError:
92+
pass
93+
94+
self.canvas.unbind_all("<MouseWheel>")
95+
self.destroy()
96+
self.options.dataframe1.grid(row=1, column=0, sticky="nsew", padx=5, pady=5)
97+
self.options.dataframe2.grid(row=0, column=0, sticky="nsew", padx=5, pady=5)

topasgraphsim/src/classes/options.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .tgs_graph import TGS_Plot
1616
from .sim_import import Simulation
1717
from .ptw_import import PTWMultimporter
18+
from .meas_import import TXTImporter
1819
from .profile import ProfileHandler
1920
from .paramframe import Parameters
2021

@@ -717,18 +718,19 @@ def load_topas(self, path = None):
717718
return
718719
for p in path:
719720
if p not in self.filenames:
720-
721+
721722
sim = TGS_Plot(self, Simulation(p))
722-
self.parent.plots.append(sim)
723-
self.filenames.append(p)
724-
self.parameters.append(Parameters(self.paramslist.viewPort, sim, self.lang))
725-
self.parameters[-1].grid(row=len(self.parameters)-1, sticky="ew", padx=5, pady=5)
726-
self.current_plot.set(sim.label)
727-
self.update_plotlist()
728-
self.plotbuttons.append(ctk.CTkRadioButton(self.graphlist.viewPort, text=sim.label, variable=self.current_plot, text_color = sim.linecolor, value=sim.label, command=self.change_current_plot, font=("Bahnschrift", 14, "bold")))
729-
self.plotbuttons[-1].grid(sticky="w", padx=5, pady=5)
730-
if len(self.parent.plots) == 1:
731-
self.enable_all_buttons()
723+
if sim.fail == False:
724+
self.parent.plots.append(sim)
725+
self.filenames.append(p)
726+
self.parameters.append(Parameters(self.paramslist.viewPort, sim, self.lang))
727+
self.parameters[-1].grid(row=len(self.parameters)-1, sticky="ew", padx=5, pady=5)
728+
self.current_plot.set(sim.label)
729+
self.update_plotlist()
730+
self.plotbuttons.append(ctk.CTkRadioButton(self.graphlist.viewPort, text=sim.label, variable=self.current_plot, text_color = sim.linecolor, value=sim.label, command=self.change_current_plot, font=("Bahnschrift", 14, "bold")))
731+
self.plotbuttons[-1].grid(sticky="w", padx=5, pady=5)
732+
if len(self.parent.plots) == 1:
733+
self.enable_all_buttons()
732734

733735
self.parent.saved = False
734736
self.parent.update()
@@ -739,8 +741,14 @@ def load_measurement(self, path = None):
739741

740742
if path != "" and path not in self.filenames:
741743
PTWMultimporter(path, self.tab(Text().data[self.lang]), self.parent.plots, self)
742-
743744

745+
def load_txt(self, path = None):
746+
if path == None:
747+
path = fd.askopenfilename(filetypes=[("TXT files", "*.txt")])
748+
749+
if path != "" and path not in self.filenames:
750+
TXTImporter(path, self.tab(Text().data[self.lang]), self.parent.plots, self)
751+
744752
def change_current_plot(self, event=None):
745753
plot_labels = [plot.label for plot in self.parent.plots]
746754
index = plot_labels.index(self.current_plot.get())

topasgraphsim/src/classes/sim_import.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def __init__(self, filepath):
2828
self.axis = np.linspace(float(self.min), float(self.max), int(self.bins))
2929
self.std_dev = np.zeros(len(self.dose))
3030
return
31-
32-
self.data = topas2numpy.BinnedResult(self.filepath)
31+
try: self.data = topas2numpy.BinnedResult(self.filepath)
32+
except Exception: return
3333
bins = [dim.n_bins for dim in self.data.dimensions]
3434
if bins.count(1) != 2:
3535
print("Unsupported Experiment Type!")

topasgraphsim/src/classes/tgs_graph.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,35 @@ class TGS_Plot():
66

77
def __init__(self, Options, ImportedData):
88

9-
self.options = Options
10-
self.lang = self.options.lang
11-
self.dataObject = ImportedData
12-
self.direction = self.dataObject.direction
13-
self.p = ProfileHandler()
14-
15-
self.normalize = self.p.get_attribute("normalize")
16-
self.caxcorrection = self.p.get_attribute("caxcorrection")
17-
self.normalization = self.p.get_attribute("normtype")
18-
self.points = self.p.get_attribute("show_points")
19-
self.error = self.p.get_attribute("show_error")
20-
21-
self.label = self.dataObject.filename
22-
self.linethickness = self.p.get_attribute("linethickness")
23-
self.linestyle = self.p.get_attribute("linestyle")
24-
self.linecolor = ProfileHandler().get_attribute("default_colors")[len(self.options.parent.plots)%len(ProfileHandler().get_attribute("default_colors"))]
25-
26-
self.dosefactor = self.p.get_attribute("dosefactor")
27-
self.doseshift = self.p.get_attribute("doseoffset")
28-
self.axshift = self.p.get_attribute("axshift")
29-
self.flip = self.p.get_attribute("flip")
30-
31-
self.set_tab_data()
9+
try:
10+
self.fail = False
11+
self.options = Options
12+
self.lang = self.options.lang
13+
self.dataObject = ImportedData
14+
self.direction = self.dataObject.direction
15+
self.p = ProfileHandler()
16+
17+
self.normalize = self.p.get_attribute("normalize")
18+
self.caxcorrection = self.p.get_attribute("caxcorrection")
19+
self.normalization = self.p.get_attribute("normtype")
20+
self.points = self.p.get_attribute("show_points")
21+
self.error = self.p.get_attribute("show_error")
22+
23+
self.label = self.dataObject.filename
24+
self.linethickness = self.p.get_attribute("linethickness")
25+
self.linestyle = self.p.get_attribute("linestyle")
26+
self.linecolor = ProfileHandler().get_attribute("default_colors")[len(self.options.parent.plots)%len(ProfileHandler().get_attribute("default_colors"))]
27+
28+
self.dosefactor = self.p.get_attribute("dosefactor")
29+
self.doseshift = self.p.get_attribute("doseoffset")
30+
self.axshift = self.p.get_attribute("axshift")
31+
self.flip = self.p.get_attribute("flip")
32+
33+
self.set_tab_data()
34+
except Exception:
35+
self.options.bell()
36+
self.fail = True
37+
return
3238

3339
def set_tab_data(self):
3440

topasgraphsim/src/classes/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class CheckForUpdates:
1010
def __init__(self):
1111

12-
currentVersion = "24.0.0"
12+
currentVersion = "24.1.0"
1313
try:
1414
newestVersion = requests.get(
1515
"https://api.github.com/repos/sebasj13/topasgraphsim/releases/latest"

topasgraphsim/src/functions/pdd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def calculate_parameters(axis, dose, std_dev):
1414
if type(std_dev) != np.ndarray or std_dev == []:
1515
TD20 = dose[(np.abs(axis - 200)).argmin()]
1616
TD10 = dose[(np.abs(axis - 100)).argmin()]
17+
print(TD10)
1718
Q = round(1.2661 * TD20 / TD10 - 0.0595, 5)
1819
zmax = round(axis[int(np.where(dose == max(dose))[0][0])], 5)
1920

@@ -57,5 +58,5 @@ def calculate_parameters(axis, dose, std_dev):
5758
5,
5859
)
5960
zmax = round(axis[int(np.where(dose == max(dose))[0][0])], 5)
60-
61+
print(TD10)
6162
return [Q, dQ, zmax]

topasgraphsim/src/resources/language.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self):
6363
"de": "Differenzgraph anzeigen",
6464
"en": "Show difference plot",
6565
}
66+
self.direction = {"de": "Richtung asuwählen...", "en": "Select direction..."}
6667
self.data = {"de": "Daten", "en": "Data"}
6768
self.gammasettings = {"de": "Gamma", "en": "Gamma"}
6869
self.generalsettings = {"de": "Allgemein", "en": "General"}
@@ -198,6 +199,7 @@ def __init__(self):
198199
self.plotgamma = {"de": "Gamma-Plot", "en": "Plot gamma"}
199200
self.showtable = {"de": "Wertetabelle anzeigen", "en": "Show parameter table"}
200201
self.select = {"de": "Messungen auswählen ...", "en": "Select measurements ..."}
202+
201203
self.showerror = {"de": "Fehler", "en": "Errorbars"}
202204
self.showgrid = {"de": "Raster anzeigen", "en": "Show grid"}
203205
self.gridoptions1 = {"de": "Große Gitterlinien", "en": "Large gridlines"}

0 commit comments

Comments
 (0)