From 583ebf3aa63eb725deac37bf57e34e4d992f2649 Mon Sep 17 00:00:00 2001 From: unknown <asoalexandros@gmail.com> Date: Thu, 10 Apr 2025 14:48:36 +0200 Subject: [PATCH] sentech evaluation released! --- sentech/evaluation.py | 237 +++++++++++++++++++++++++++++ sentech/evaluation_multiple.py | 190 +++++++++++++++++++++++ sentech/interface_evaluation.ipynb | 101 ++++++++++++ sentech/interface_multiple.ipynb | 101 ++++++++++++ 4 files changed, 629 insertions(+) create mode 100644 sentech/evaluation.py create mode 100644 sentech/evaluation_multiple.py create mode 100644 sentech/interface_evaluation.ipynb create mode 100644 sentech/interface_multiple.ipynb diff --git a/sentech/evaluation.py b/sentech/evaluation.py new file mode 100644 index 0000000..7bdb6ca --- /dev/null +++ b/sentech/evaluation.py @@ -0,0 +1,237 @@ +import ipywidgets as widgets +import matplotlib.pyplot as plt +import pandas as pd +import os +import numpy as np + +import tkinter as tk +from tkinter import filedialog +import tkinter.messagebox + +def information_box(information): + #open dialog and hide the main window + root = tk.Tk() + root.withdraw() + root.attributes("-topmost", 1) + + root.update() + + #display meaagebox + tkinter.messagebox.showinfo(message=information,parent=root) + root.attributes("-topmost", 0) + root.destroy() + +def choose_folder(): + root = tk.Tk() + root.withdraw() + + root.attributes('-topmost', 1)#window stays above all other applications + root.update() + + #choose nonemty folder + folder = tk.filedialog.askdirectory(parent = root) + + while folder == '': + folder = tk.filedialog.askdirectory(parent = root) + + root.destroy() + return folder + +def change_state(widgets_list): + for widget in widgets_list: + widget.disabled = not widget.disabled + + +def get_device(file): + with open(file) as f: + lines = f.readlines() + + if lines[1] == "System: SI ALD RWTH [ALD 007]\n": + return 'ALD' + elif lines[1] == "System: SI 500 RWTH Aachen [500-211]\n": + return 'ICP-CL' + elif lines[1] == "Anlage: SI 500 RWTH Aachen\n": + return 'ICP-FL' + else: + return "" #No device detected + +def read_file(file): + device = get_device(file) + + if device == 'ALD': + with open(file) as f: + lines = f.readlines() + start_time = lines[4] + df = pd.read_csv(files[0],sep ='\t',skiprows = 10,encoding = 'ANSI',index_col=False) + elif device == 'ICP-CL': + with open(file) as f: + lines = f.readlines() + start_time = lines[4] + df = pd.read_csv(file,sep ='\t',skiprows = 10,encoding = 'ANSI',index_col=False) + elif device =='ICP-FL': + with open(file) as f: + lines = f.readlines() + start_time = lines[3] + df = pd.read_csv(file,sep ='\t',skiprows = 9,encoding = 'ANSI',index_col=False) + else: #device = "" + start_time = None + df = None + return device,df,start_time + + + +dir_button = widgets.Button(description = 'Choose Folder') +plot_button = widgets.Button(description = 'Plot') +next_file = widgets.Button(description = 'Next File') +previous_file = widgets.Button(description = 'Previous file') +current_file = widgets.Text(description = 'Current File',disabled = True,value = 'No File Selected') +x_axis = widgets.Dropdown(description = 'X-Axis',disabled = True) +y_axis = widgets.Dropdown(description = 'Y-Axis') +x_scale = widgets.Dropdown(description ='X-Scale',options = ['linear','log'],value = 'linear') +y_scale = widgets.Dropdown(description ='Y-Scale',options = ['linear','log'],value = 'linear') +output = widgets.Output() + +counter = 0 +folder = None +files = [] +df = None +start_time = None +device = None + +buttons = widgets.HBox([dir_button,plot_button,previous_file,next_file]) +config = widgets.HBox([x_axis,y_axis,current_file]) +scale = widgets.HBox([x_scale,y_scale]) + +display(buttons) +display(config) +display(scale) +display(output) + +all_widgets = [dir_button,plot_button,previous_file,next_file,y_axis,x_scale,y_scale] +def on_choose_folder_clicked(b): + global counter,folder,files,df,start_time,device + with output: + change_state(all_widgets) + current_file.value = 'No File Selected' + folder = choose_folder() + os.chdir(folder) #change current working directory + files = os.listdir(os.getcwd()) #get the files from the chosen directory + + # get all the valid files + valid_files = [] + for file in files: + if file.endswith('.log') == True: + device = get_device(file) + if device != "": + valid_files.append(file) + + files = valid_files.copy() + + if len(files) == 0: + information_box("No Valid Files Detected! Please Choose a New Folder!") + else: + counter = 0 + current_file.value = files[counter] + device,df,start_time = read_file(current_file.value) + options = list(df.columns.values) + x_axis.options = [options[0]] #only the first column + y_axis.options = options[1:] #the rest columns + x_axis.value = options[0] + y_axis.value = options[1] + change_state(all_widgets) + +dir_button.on_click(on_choose_folder_clicked) + +def on_previous_file_clicked(b): + global counter,folder,files,df,start_time,device + with output: + change_state(all_widgets) + if counter>0: + counter = counter -1 + current_file.value = files[counter] + device,df,start_time = read_file(current_file.value) + options = list(df.columns.values) + x_axis.options = [options[0]] #only the first column + y_axis.options = options[1:] #the rest columns + x_axis.value = options[0] + y_axis.value = options[1] + else: + information_box("There is no previous file!") + change_state(all_widgets) + +previous_file.on_click(on_previous_file_clicked) + +def on_next_file_clicked(b): + global counter,folder,files,df,start_time,device + with output: + change_state(all_widgets) + if counter<len(files)-1: + counter = counter +1 + current_file.value = files[counter] + device,df,start_time = read_file(current_file.value) + options = list(df.columns.values) + x_axis.options = [options[0]] #only the first column + y_axis.options = options[1:] #the rest columns + x_axis.value = options[0] + y_axis.value = options[1] + else: + information_box("There is no next file!") + change_state(all_widgets) + +next_file.on_click(on_next_file_clicked) + +def on_plot_clicked(b): + global counter,folder,files,df,start_time,device + with output: + change_state(all_widgets) + if current_file.value != 'No File Selected': #there is a file to plot + + fig,ax = plt.subplots() + fig.suptitle(device +" "+ start_time) + + if x_scale.value == 'log': + x = np.absolute(df[x_axis.value]) + ax.set_xscale('log') + else: + x = df[x_axis.value] + ax.set_xscale('linear') + + if y_scale.value == 'log': + y = np.absolute(df[y_axis.value]) + ax.set_yscale('log') + else: + y = df[y_axis.value] + ax.set_yscale('linear') + + ax.set_xlabel(x_axis.value) + ax.set_ylabel(y_axis.value) + + ax.plot(x,y,color = 'b') + + mng = plt.get_current_fig_manager() + mng.window.state('zoomed') + mng.window.attributes('-topmost', 1) + plt.show(block= True) + + else: + information_box("No file to plot!") + change_state(all_widgets) + +plot_button.on_click(on_plot_clicked) + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sentech/evaluation_multiple.py b/sentech/evaluation_multiple.py new file mode 100644 index 0000000..eecd8ed --- /dev/null +++ b/sentech/evaluation_multiple.py @@ -0,0 +1,190 @@ +import ipywidgets as widgets +import matplotlib.pyplot as plt +import pandas as pd +import os +import numpy as np + +import tkinter as tk +from tkinter import filedialog +import tkinter.messagebox + +def information_box(information): + #open dialog and hide the main window + root = tk.Tk() + root.withdraw() + root.attributes("-topmost", 1) + + root.update() + + #display meaagebox + tkinter.messagebox.showinfo(message=information,parent=root) + root.attributes("-topmost", 0) + root.destroy() + +def choose_folder(): + root = tk.Tk() + root.withdraw() + + root.attributes('-topmost', 1)#window stays above all other applications + root.update() + + #choose nonemty folder + folder = tk.filedialog.askdirectory(parent = root) + + while folder == '': + folder = tk.filedialog.askdirectory(parent = root) + + root.destroy() + return folder + +def change_state(widgets_list): + for widget in widgets_list: + widget.disabled = not widget.disabled + + +def get_device(file): + with open(file) as f: + lines = f.readlines() + + if lines[1] == "System: SI ALD RWTH [ALD 007]\n": + return 'ALD' + elif lines[1] == "System: SI 500 RWTH Aachen [500-211]\n": + return 'ICP-CL' + elif lines[1] == "Anlage: SI 500 RWTH Aachen\n": + return 'ICP-FL' + else: + return "" #No device detected + +def read_file(file): + device = get_device(file) + + if device == 'ALD': + with open(file) as f: + lines = f.readlines() + start_time = lines[4] + df = pd.read_csv(files[0],sep ='\t',skiprows = 10,encoding = 'ANSI',index_col=False) + elif device == 'ICP-CL': + with open(file) as f: + lines = f.readlines() + start_time = lines[4] + df = pd.read_csv(file,sep ='\t',skiprows = 10,encoding = 'ANSI',index_col=False) + elif device =='ICP-FL': + with open(file) as f: + lines = f.readlines() + start_time = lines[3] + df = pd.read_csv(file,sep ='\t',skiprows = 9,encoding = 'ANSI',index_col=False) + else: #device = "" + start_time = None + df = None + return device,df,start_time + + + +dir_button = widgets.Button(description = 'Choose Folder') +plot_button = widgets.Button(description = 'Plot') +instrument = widgets.Dropdown(description = 'Device', options =['ALD','ICP-CL','ICP-FL'],value = 'ALD') +selected_files = widgets.SelectMultiple(description = "Selected files",layout=widgets.Layout(width='1000px', height='300px')) +x_axis = widgets.Dropdown(description = 'X-Axis',disabled = True) +y_axis = widgets.Dropdown(description = 'Y-Axis') +x_scale = widgets.Dropdown(description ='X-Scale',options = ['linear','log'],value = 'linear') +y_scale = widgets.Dropdown(description ='Y-Scale',options = ['linear','log'],value = 'linear') +output = widgets.Output() + +counter = 0 +folder = None +files = [] +df = None +start_time = None +device = None + +buttons = widgets.HBox([dir_button,plot_button,instrument,selected_files]) +config = widgets.HBox([x_axis,y_axis]) +scale = widgets.HBox([x_scale,y_scale]) + +display(buttons) +display(config) +display(scale) +display(output) + +all_widgets = [dir_button,plot_button,instrument,y_axis,x_scale,y_scale,selected_files] +def on_choose_folder_clicked(b): + global folder,files,df,start_time,device + with output: + change_state(all_widgets) + folder = choose_folder() + os.chdir(folder) + files = os.listdir(os.getcwd()) #get the files from the chosen directory + + + # get all the valid files + valid_files = [] + for file in files: + if file.endswith('.log') == True: + device = get_device(file) + if device == instrument.value: + valid_files.append(file) + + files = valid_files.copy() + + if len(files) == 0: + information_box("No Valid Files Detected! Please Choose a New Folder!") + else: + device,df,start_time = read_file(files[0]) #read the first file for the columns + options = list(df.columns.values) + x_axis.options = [options[0]] #only the first column + y_axis.options = options[1:] #the rest columns + x_axis.value = options[0] + y_axis.value = options[1] + selected_files.options = files + selected_files.value = [files[0]] + change_state(all_widgets) + +dir_button.on_click(on_choose_folder_clicked) + + +def on_plot_clicked(b): + global folder,files,df,start_time,device + with output: + change_state(all_widgets) + if len(selected_files.value) != 0: + + fig,ax = plt.subplots() + fig.suptitle(device) + + if x_scale.value == 'log': + ax.set_xscale('log') + else: + ax.set_xscale('linear') + + if y_scale.value == 'log': + ax.set_yscale('log') + else: + ax.set_yscale('linear') + + ax.set_xlabel(x_axis.value) + ax.set_ylabel(y_axis.value) + + for file in selected_files.value: + device,df,start_time = read_file(file) + if x_scale.value == 'log': + x = np.absolute(df[x_axis.value]) + else: + x = df[x_axis.value] + if y_scale.value == 'log': + y = np.absolute(df[y_axis.value]) + else: + y = df[y_axis.value] + + ax.plot(x,y,label=start_time.split(":",1)[1]) + + fig.legend() + mng = plt.get_current_fig_manager() + mng.window.state('zoomed') + mng.window.attributes('-topmost', 1) + plt.show(block= True) + + else: + information_box("No file to plot!") + change_state(all_widgets) + +plot_button.on_click(on_plot_clicked) \ No newline at end of file diff --git a/sentech/interface_evaluation.ipynb b/sentech/interface_evaluation.ipynb new file mode 100644 index 0000000..50c63bc --- /dev/null +++ b/sentech/interface_evaluation.ipynb @@ -0,0 +1,101 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "e615178f-e424-4ae7-a128-5428c9b562d7", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "aae77e15a6e24e338168af62d7e535ff", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(Button(description='Choose Folder', style=ButtonStyle()), Button(description='Plot', style=Butt…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "bf091d232689478ba8dd2b126959a7ca", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(Dropdown(description='X-Axis', disabled=True, options=(), value=None), Dropdown(description='Y-…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4bd46526a6ed4548b0089c493119a0c3", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(Dropdown(description='X-Scale', options=('linear', 'log'), value='linear'), Dropdown(descriptio…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "304c86207ef5404fb073748b8a0f989e", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib tk\n", + "%run evaluation.py" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "150e0b0a-18c8-4e4e-b3cc-41ba2c1a66ad", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/sentech/interface_multiple.ipynb b/sentech/interface_multiple.ipynb new file mode 100644 index 0000000..fa52348 --- /dev/null +++ b/sentech/interface_multiple.ipynb @@ -0,0 +1,101 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "be13119e-5f63-4653-b7a4-6db7d23ac4e7", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "18ef0a86be264babad8b9fd730e168b8", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(Button(description='Choose Folder', style=ButtonStyle()), Button(description='Plot', style=Butt…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "db263f28efbf4417a0753a5946078434", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(Dropdown(description='X-Axis', disabled=True, options=(), value=None), Dropdown(description='Y-…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ad36b41387fb476f83c625be14fff5e6", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(Dropdown(description='X-Scale', options=('linear', 'log'), value='linear'), Dropdown(descriptio…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1f48650a48af455da3420f15ed912053", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%run evaluation_multiple.py\n", + "%matplotlib tk" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9517222f-dc7a-4660-8de9-e2ef0854a742", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- GitLab