6
6
for full notice, reference readme.md
7
7
"""
8
8
9
- # import statements
9
+ # import external packages
10
10
import tkinter as tk
11
11
from tkinter import filedialog
12
12
from tkinter import ttk
13
13
from tkinter import messagebox
14
14
import os
15
15
import threading
16
+ from pandas .errors import ParserError
16
17
17
18
#import copal
18
19
import copal
20
+ from copal .dataprep import multi_dataload
19
21
20
22
# ---------- INPUT PROCESSING AND HELPER FUNCTIONS ---------- #
21
23
@@ -71,6 +73,18 @@ def get_normalisation(normtype, normcol, normfile):
71
73
normfile = normfile
72
74
return (norm_check , normcol , normfile )
73
75
76
+ def clear_last_input ():
77
+ added_samples = len (input ['samplecolumns' ][- 1 ])
78
+ print ('clearing wrong input..' )
79
+ print ('number of added samples: {}' .format (added_samples ))
80
+ del input ['identifier' ][- 1 ]
81
+ del input ['filename' ][- 1 ]
82
+ del input ['sheetname' ][- 1 ]
83
+ del input ['skiprows' ][- 1 ]
84
+ del input ['input_type' ][- 1 ]
85
+ del input ['samplecolumns' ][- 1 ]
86
+ del input ['samplenames' ][- 1 * added_samples :]
87
+
74
88
def save_input_settings ():
75
89
""" saves first input file settings to global input variables """
76
90
global input
@@ -187,6 +201,93 @@ def check_input():
187
201
188
202
return True
189
203
204
+ def check_input_data (input ):
205
+ """
206
+ check if input data is valid and matches input specs
207
+ """
208
+ identifier = input ['identifier' ][- 1 ]
209
+ filename = input ['filename' ][- 1 ]
210
+ sheet = input ['sheetname' ][- 1 ]
211
+ skip_rows = input ['skiprows' ][- 1 ]
212
+ file_type = input ['input_type' ][- 1 ]
213
+ samplecolumns = input ['samplecolumns' ][- 1 ]
214
+
215
+ # try to load data
216
+ try :
217
+ data = multi_dataload (identifier , filename , sheet , skip_rows , file_type )
218
+ except FileNotFoundError as error :
219
+ warn_msg = "file not found! check input file name and path"
220
+ input_status_var .set (warn_msg )
221
+ messagebox .showwarning ("input error" , warn_msg )
222
+ clear_last_input ()
223
+ return False
224
+
225
+ except ParserError as error :
226
+ warn_msg = "problem parsing input file. is file type correct? error: {}" .format (error )
227
+ input_status_var .set ('loading data failed. check file type' )
228
+ messagebox .showwarning ("input error" , warn_msg )
229
+ clear_last_input ()
230
+ return False
231
+
232
+ except ValueError as error :
233
+ warn_msg = "something went wrong with loading data file. please check file input details. error: {}" .format (error )
234
+ input_status_var .set ("loading data failed. please check input details." )
235
+ messagebox .showwarning ("input error" , warn_msg )
236
+ clear_last_input ()
237
+ return False
238
+
239
+ except Exception as error :
240
+ warn_msg = "something went wrong with loading data. check input details. error: {}" .format (error )
241
+ input_status_var .set ("problem loading data. check input details" )
242
+ messagebox .showwarning ("input error" ,warn_msg )
243
+ clear_last_input ()
244
+ return False
245
+
246
+ # check if samplecolumns exist and check sample length
247
+ for col_pair in samplecolumns :
248
+ if not col_pair [0 ] in data .columns :
249
+ warn_msg = "start column header not in dataset: {}. check input" .format (col_pair [0 ])
250
+ input_status_var .set (warn_msg )
251
+ messagebox .showwarning ("input error" ,warn_msg )
252
+ clear_last_input ()
253
+ return False
254
+ if not col_pair [1 ] in data .columns :
255
+ warn_msg = "end column header not in dataset: {}. check input" .format (col_pair [1 ])
256
+ input_status_var .set (warn_msg )
257
+ messagebox .showwarning ("input error" ,warn_msg )
258
+ clear_last_input ()
259
+ return False
260
+
261
+ # check for samples with 0 or 1 slices
262
+ try :
263
+ sample_data = data .loc [:,col_pair [0 ]:col_pair [1 ]]
264
+ except Exception as error :
265
+ warn_msg = "sample could not be extracted from data. error: {}" .format (error )
266
+ "please check input"
267
+ input_status_var .set ("problem extracting sample from data. check input" )
268
+ messagebox .showwarning ("input error" ,warn_msg )
269
+ clear_last_input ()
270
+ return False
271
+
272
+ if sample_data .shape [1 ] < 2 :
273
+ warn_msg = "found sample with 0 or 1 columns: {}:{}. " .format (col_pair [0 ],col_pair [1 ])
274
+ "Please check input"
275
+ input_status_var .set (warn_msg )
276
+ messagebox .showwarning ("input error" , warn_msg )
277
+ clear_last_input ()
278
+ return False
279
+
280
+ # check for nan values in sample
281
+ if sample_data .isnull ().values .any ():
282
+ warn_msg = "sample contains missing (nan) values: {}:{}. " .format (col_pair [0 ],col_pair [1 ])
283
+ "please check input"
284
+ input_status_var .set (warn_msg )
285
+ messagebox .showwarning ("input error" , warn_msg )
286
+ clear_last_input ()
287
+ return False
288
+
289
+ return True
290
+
190
291
def check_output ():
191
292
"""
192
293
checks output details for possible errors by user
@@ -326,10 +427,12 @@ def save_proceed_handler(event = None):
326
427
"""
327
428
if check_input ():
328
429
save_input_settings ()
329
- output_frame = tk .Frame (root )
330
- output_frame .grid (row = 0 , column = 0 , sticky = "news" )
331
- output_options_frame (output_frame )
332
- output_frame .tkraise ()
430
+ if check_input_data (input ):
431
+ print_input ()
432
+ output_frame = tk .Frame (root )
433
+ output_frame .grid (row = 0 , column = 0 , sticky = "news" )
434
+ output_options_frame (output_frame )
435
+ output_frame .tkraise ()
333
436
334
437
def append_proceed_handler (event = None ):
335
438
"""
@@ -340,11 +443,12 @@ def append_proceed_handler(event = None):
340
443
"""
341
444
if check_input ():
342
445
append_extra_input ()
343
- print_input ()
344
- output_frame = tk .Frame (root )
345
- output_frame .grid (row = 0 , column = 0 , sticky = "news" )
346
- output_options_frame (output_frame )
347
- output_frame .tkraise ()
446
+ if check_input_data (input ):
447
+ print_input ()
448
+ output_frame = tk .Frame (root )
449
+ output_frame .grid (row = 0 , column = 0 , sticky = "news" )
450
+ output_options_frame (output_frame )
451
+ output_frame .tkraise ()
348
452
349
453
def save_extra_input_handler (event = None ):
350
454
"""
@@ -355,12 +459,13 @@ def save_extra_input_handler(event = None):
355
459
"""
356
460
if check_input ():
357
461
save_input_settings ()
358
- clear_input_vars ()
359
- extra_frame = tk .Frame (root )
360
- extra_frame .grid (row = 0 , column = 0 , sticky = "news" )
361
- input_frame (extra_frame )
362
- extra_input_buttons (extra_frame )
363
- extra_frame .tkraise ()
462
+ if check_input_data (input ):
463
+ clear_input_vars ()
464
+ extra_frame = tk .Frame (root )
465
+ extra_frame .grid (row = 0 , column = 0 , sticky = "news" )
466
+ input_frame (extra_frame )
467
+ extra_input_buttons (extra_frame )
468
+ extra_frame .tkraise ()
364
469
365
470
def append_extra_input_handler (event = None ):
366
471
"""
@@ -371,12 +476,13 @@ def append_extra_input_handler(event = None):
371
476
"""
372
477
if check_input ():
373
478
append_extra_input ()
374
- clear_input_vars ()
375
- extra_frame = tk .Frame (root )
376
- extra_frame .grid (row = 0 , column = 0 , sticky = "news" )
377
- input_frame (extra_frame )
378
- extra_input_buttons (extra_frame )
379
- extra_frame .tkraise ()
479
+ if check_input_data (input ):
480
+ clear_input_vars ()
481
+ extra_frame = tk .Frame (root )
482
+ extra_frame .grid (row = 0 , column = 0 , sticky = "news" )
483
+ input_frame (extra_frame )
484
+ extra_input_buttons (extra_frame )
485
+ extra_frame .tkraise ()
380
486
381
487
def save_output_and_run_handler (event = None ):
382
488
"""
0 commit comments