-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
1632 lines (1398 loc) · 70.5 KB
/
gui.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Created on %(20-December-2016)s
@author: %(Mustafa)s
"""
import sys
import os
import timeit
import time
import traceback
import faulthandler
import multiprocessing
from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import Element
import xml.etree.ElementTree as etree
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
QMainWindow,
QApplication,
QPushButton,
QWidget,
QTabWidget,
QVBoxLayout,
QGridLayout,
QLabel,
QLineEdit,
QComboBox,
QCheckBox,
QFileDialog,
QMessageBox,
QMdiArea,
QTextEdit,
QMdiSubWindow)
from normcopinfill import NormCopulaInfill
NormCopulaInfill.verbose = True
faulthandler.enable()
class OutLog:
'''
A class to print console messages to the messages window in the GUI
'''
def __init__(self, edit, out=None):
"""(edit, out=None) -> can write stdout, stderr to a
QTextEdit.
edit = QTextEdit
out = alternate stream ( can be the original sys.stdout )
"""
self.edit = edit
self.out = out
return
def write(self, m):
self.edit.insertPlainText(m)
return
class MainWindow(QTabWidget):
'''
Control panel of the plotting GUI
'''
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.conf_input_tab = QWidget()
self.flags_tab = QWidget()
self.addTab(self.conf_input_tab, 'Configure Input')
self.currentChanged.connect(self.back_tab)
self.addTab(self.flags_tab, 'Flags')
self.conf_input_tab_UI()
self.flags_tab_UI()
self.flags_tab.setDisabled(True)
self.gui_debug = True
self.read_succ = True
print('#' * 50)
print('Ready....')
print('#' * 50, '\n')
if not self.plot_ecops_check_box.isChecked() == True:
self.ecop_bins_line.setDisabled(True)
if not self.n_rand_infill_check_box.isChecked() == True:
self.n_rand_infill_line.setDisabled(True)
if not self.min_corr_check_box.isChecked() == True:
self.min_corr_line.setDisabled(True)
if not self.max_time_check_box.isChecked() == True:
self.max_time_lag_corr_line.setDisabled(True)
if not self.cut_cdf_thresh_check_box.isChecked() == True:
self.cut_cdf_thresh_line.setDisabled(True)
self.plot_ecops_check_box.stateChanged.connect(self.ecops_state)
self.n_rand_infill_check_box.stateChanged.connect(self.n_rand_infill_state)
self.min_corr_check_box.stateChanged.connect(self.min_corr_state)
self.max_time_check_box.stateChanged.connect(self.max_time_state)
self.cut_cdf_thresh_check_box.stateChanged.connect(self.cut_cdf_thresh_state)
return
def conf_input_tab_UI(self):
'''
The Configure Input tab
'''
# # Create Grids ##
self.main_layout = QVBoxLayout()
self.grid = QGridLayout()
i = 0
# # Input File Box ##
self.in_q_orig_file_lab = QLabel('Input File:')
self.in_q_orig_file_line = QLineEdit()
self.in_q_orig_file_line.setText(r'P:/Synchronize/IWS/Discharge_data_longer_series/final_q_data/neckar_q_data.csv')
self.in_q_orig_file_btn = QPushButton('Browse')
self.in_q_orig_file_btn.clicked.connect(lambda: self.get_input_dir(_input=True))
self.grid.addWidget(self.in_q_orig_file_lab, i, 0)
self.grid.addWidget(self.in_q_orig_file_line, i, 1, 1, 20)
self.grid.addWidget(self.in_q_orig_file_btn, i, 21)
self.in_q_orig_file_lab.setToolTip(str('Full path to the input csv file.'))
self.in_q_orig_file_line.setToolTip(str('Full path to the input csv file.'))
self.in_q_orig_file_btn.setToolTip(str('Browse to the input csv file.'))
self.in_q_orig_file = self.in_q_orig_file_line.text()
i += 1
# # Coordinates file box ##
self.in_coords_file_lab = QLabel('Coordinates File:')
self.in_coords_file_line = QLineEdit()
self.in_coords_file_btn = QPushButton('Browse')
self.in_coords_file_btn.clicked.connect(lambda: self.get_coords_dir(_input=True))
self.grid.addWidget(self.in_coords_file_lab, i, 0)
self.grid.addWidget(self.in_coords_file_line, i, 1, 1, 20)
self.grid.addWidget(self.in_coords_file_btn, i, 21)
self.in_coords_file_lab.setToolTip(str('Full path to the input coordinates file.'))
self.in_coords_file_line.setToolTip(str('Full path to the input coordinates file.'))
self.in_coords_file_btn.setToolTip(str('Browse to the input coordinates file.'))
self.in_coords_file = self.in_coords_file_line.text()
i += 1
# # Output directory box ##
self.out_dir_lab = QLabel('Output Directory:')
self.out_dir_line = QLineEdit()
self.out_dir_btn = QPushButton('Browse')
self.out_dir_btn.clicked.connect(lambda: self.get_out_dir(_input=True))
self.grid.addWidget(self.out_dir_lab, i, 0)
self.grid.addWidget(self.out_dir_line, i, 1, 1, 20)
self.grid.addWidget(self.out_dir_btn, i, 21)
self.out_dir_lab.setToolTip(str('Directory to the output folder (where the results will be saved).'))
self.out_dir_line.setToolTip(str('Directory to the output folder (where the results will be saved).'))
self.out_dir_btn.setToolTip(str('Browse to output directory'))
self.out_dir = self.out_dir_line.text()
i += 1
# # Date Format box ##
self.date_fmt_lab = QLabel('Date Format:')
self.date_fmt_box = QComboBox()
self.date_fmt_box.addItems(['1999-03-15', '1999-Mar-15', '1999-March-15',
'99-03-15', '99-Mar-15', '99-March-15',
'15-03-1999', '15-Mar-1999', '15-March-1999',
'15-03-99', '15-Mar-99', '15-March-99',
'03-15-1999', 'Mar-15-1999', 'March-15-1999',
'03-15-99', 'Mar-15-99', 'March-15-99',
'1999.03.15', '1999.Mar.15', '1999.March.15',
'99.03.15', '99.Mar.15', '99.March.15',
'15.03.1999', '15.Mar.1999', '15.March.1999',
'15.03.99', '15.Mar.99', '15.March.99',
'03.15.1999', 'Mar.15.1999', 'March.15.1999',
'03.15.99', 'Mar.15.99', 'March.15.99',
'1999/03/15', '1999/Mar/15', '1999/March/15',
'99/03/15', '99/Mar/15', '99/March/15',
'15/03/1999', '15/Mar/1999', '15/March/1999',
'15/03/99', '15/Mar/99', '15/March/99',
'03/15/1999', 'Mar/15/1999', 'March/15/1999',
'03/15/99', 'Mar/15/99', 'March/15/99'])
self.grid.addWidget(self.date_fmt_lab, i, 0)
self.grid.addWidget(self.date_fmt_box, i, 1, 1, 20)
self.date_fmt_lab.setToolTip(str('Select Date Format.'))
self.date_fmt_box.setToolTip(str('Select Date Format.'))
i += 1
# # Infill Stations box ##
self.infill_stns_lab = QLabel('Infill Stations:')
self.infill_stns_line = QLineEdit(str(''))
self.grid.addWidget(self.infill_stns_lab, i, 0)
self.grid.addWidget(self.infill_stns_line, i, 1, 1, 20)
self.infill_stns_lab.setToolTip(str('list of infill stations'))
self.infill_stns_line.setToolTip(str('list of infill stations.'))
i += 1
# # Drop stations box ##
self.drop_stns_lab = QLabel('Drop Stations:')
self.drop_stns_line = QLineEdit('')
self.grid.addWidget(self.drop_stns_lab, i, 0)
self.grid.addWidget(self.drop_stns_line, i, 1, 1, 20)
self.drop_stns_lab.setToolTip(str('list of stations to drop.'))
self.drop_stns_line.setToolTip(str('list of stations to drop.'))
i += 1
# # Censor period box ##
self.censor_period_lab = QLabel('Censor Period:')
self.censor_period_line = QLineEdit('')
self.grid.addWidget(self.censor_period_lab, i, 0)
self.grid.addWidget(self.censor_period_line, i, 1, 1, 20)
self.drop_stns_lab.setToolTip(str('time period of simulation'))
self.drop_stns_line.setToolTip(str('time period of simulation.'))
i += 1
# # Interval type box##
self.infill_interval_type_lab = QLabel('Infill interval type:')
self.infill_interval_type_box = QComboBox()
self.infill_interval_type_box.addItems(['slice', 'individual', 'all'])
self.grid.addWidget(self.infill_interval_type_lab, i, 0)
self.grid.addWidget(self.infill_interval_type_box, i, 1, 1, 20)
self.infill_interval_type_lab.setToolTip(str('Type of infill.'))
self.infill_interval_type_box.setToolTip(str('Type of infill.'))
i += 1
# # Infill type box ##
self.infill_type_lab = QLabel('Infill type:')
self.infill_type_box = QComboBox()
self.infill_type_box.addItems(['discharge', 'precipitation', 'discharge-censored'])
self.grid.addWidget(self.infill_type_lab, i, 0)
self.grid.addWidget(self.infill_type_box, i, 1, 1, 20)
self.infill_type_lab.setToolTip(str('Infill Type.'))
self.infill_type_box.setToolTip(str('Infill Type.'))
i += 1
# # minimum valid values box ##
self.min_valid_vals_lab = QLabel('Minimum Valid Values:')
self.min_valid_vals_line = QLineEdit()
self.grid.addWidget(self.min_valid_vals_lab, i, 0)
self.grid.addWidget(self.min_valid_vals_line, i, 1, 1, 20)
self.min_valid_vals_lab.setToolTip(str('Minimum Valid Values.'))
self.min_valid_vals_line.setToolTip(str('Minimum Valid Values.'))
i += 1
# # Minimum nearest stations box ##
self.n_nrn_min_lab = QLabel('Minimum Nearest stations:')
self.n_nrn_min_line = QLineEdit()
self.grid.addWidget(self.n_nrn_min_lab, i, 0)
self.grid.addWidget(self.n_nrn_min_line, i, 1, 1, 20)
self.n_nrn_min_lab.setToolTip(str('Minimum Nearest stations'))
self.n_nrn_min_line.setToolTip(str('Minimum Nearest stations'))
i += 1
# # Maximum nearest stations box ##
self.n_nrn_max_lab = QLabel('Maximum Nearest Stations:')
self.n_nrn_max_line = QLineEdit()
self.grid.addWidget(self.n_nrn_max_lab, i, 0)
self.grid.addWidget(self.n_nrn_max_line, i, 1, 1, 20)
self.n_nrn_max_lab.setToolTip(str('Maximum Nearest Stations.'))
self.n_nrn_max_line.setToolTip(str('Maximum Nearest Stations.'))
i += 1
# # number of cpus box ##
self.ncpus_lab = QLabel('Number of CPUs:')
self.ncpus_box = QComboBox()
self.xcpus = multiprocessing.cpu_count()
self.rncpus = list(range(1, self.xcpus + 1))
self.strncpus = str(",".join(str(x) for x in self.rncpus))
self.ncpus_box.addItems(self.strncpus.split(","))
self.grid.addWidget(self.ncpus_lab, i, 0)
self.grid.addWidget(self.ncpus_box, i, 1, 1, 20)
self.ncpus_lab.setToolTip(str('Number of CPUs.'))
self.ncpus_box.setToolTip(str('Number of CPUs.'))
i += 1
# # Separator box ##
self.sep_lab = QLabel('Seperator:')
self.sep_box = QComboBox()
self.sep_box.addItems([';', ',', ':', '.'])
self.grid.addWidget(self.sep_lab, i, 0)
self.grid.addWidget(self.sep_box, i, 1, 1, 20)
self.sep_lab.setToolTip(str('seperator.'))
self.sep_box.setToolTip(str('seperator.'))
i += 1
# # Frequency box ##
self.freq_lab = QLabel('Freq:')
self.freq_box = QComboBox()
self.freq_box.addItems(['D', 's', 'min', 'H', 'w', 'm'])
self.grid.addWidget(self.freq_lab, i, 0)
self.grid.addWidget(self.freq_box, i, 1, 1, 20)
self.freq_lab.setToolTip(str('frequency.'))
self.freq_box.setToolTip(str('frequency.'))
i += 1
# # Save button ##
self.save_lab = 'Save Configuration file'
self.save_btn = QPushButton()
self.save_btn.setText(self.save_lab)
self.save_btn.clicked.connect(lambda: self.save_xml_dir())
self.grid.addWidget(self.save_btn, i, 1, 1, 9)
self.save_btn.setToolTip(str('Save configuration file'))
# # Load button ##
self.load_lab = 'Load Configuration file'
self.load_btn = QPushButton()
self.load_btn.setText(self.load_lab)
self.load_btn.clicked.connect(lambda: self.load_file())
self.grid.addWidget(self.load_btn, i, 12, 1, 9)
self.load_btn.setToolTip(str('Load configuration file'))
i += 1
# # Read data button ##
self.read_data_lab = 'Proceed to next tab!'
self.read_data_btn = QPushButton()
self.read_data_btn.setText(self.read_data_lab)
self.read_data_btn.clicked.connect(lambda: self.read_data())
self.grid.addWidget(self.read_data_btn, i, 1, 1, 20)
self.read_data_btn.setToolTip(str('Read data and move to the next tab!'))
i += 1
self.main_layout.addLayout(self.grid)
self.conf_input_tab.setLayout(self.main_layout)
def flags_tab_UI(self):
'''
The Render tab
'''
self.flags_layout = QVBoxLayout()
self.flags_grid = QGridLayout()
i = 0
# # Debug mode flag ##
self.debug_check_box = QCheckBox('Debug Mode', self)
self.debug_check_box.setText("Debug Mode")
self.flags_grid.addWidget(self.debug_check_box, i, 1, 1, 10)
# # Compare infill flag ##
self.compare_infill_check_box = QCheckBox('Compare Infill', self)
self.compare_infill_check_box.setText("Compare Infill")
self.flags_grid.addWidget(self.compare_infill_check_box, i, 10, 1, 10)
i += 1
# # Flag susp flag ##
self.flag_susp_check_box = QCheckBox('Flag Susp', self)
self.flag_susp_check_box.setText("Flag Susp")
self.flags_grid.addWidget(self.flag_susp_check_box, i, 1, 1, 10)
# # Force infill flag ##
self.force_infill_check_box = QCheckBox('Force infill', self)
self.force_infill_check_box.setText("Force infill")
self.flags_grid.addWidget(self.force_infill_check_box, i, 10, 1, 10)
i += 1
# # Take minimum stations flag ##
self.take_min_stns_check_box = QCheckBox('Take min stations', self)
self.take_min_stns_check_box.setText("Take Min stations")
self.flags_grid.addWidget(self.take_min_stns_check_box, i, 1, 1, 10)
self.take_min_stns_check_box.setChecked(True)
# # read pickles flag ##
self.read_pickles_check_box = QCheckBox('Read pickles', self)
self.read_pickles_check_box.setText("Read pickles")
self.flags_grid.addWidget(self.read_pickles_check_box, i, 10, 1, 10)
i += 1
# # overwrite flag ##
self.overwrite_check_box = QCheckBox('Overwrite', self)
self.overwrite_check_box.setText("Overwrite")
self.flags_grid.addWidget(self.overwrite_check_box, i, 1, 1, 10)
# # plot diag flag ##
self.plot_diag_check_box = QCheckBox('Plot Diag', self)
self.plot_diag_check_box.setText("Plot Diag")
self.flags_grid.addWidget(self.plot_diag_check_box, i, 10, 1, 10)
i += 1
# # plot step flag ##
self.plot_step_cdf_pdf_check_box = QCheckBox('plot step cdf pdf', self)
self.plot_step_cdf_pdf_check_box.setText("plot step cdf pdf")
self.flags_grid.addWidget(self.plot_step_cdf_pdf_check_box, i, 1, 1, 10)
# # plot neighbours flag ##
self.plot_neighbors_flag_check_box = QCheckBox('plot neighbours', self)
self.plot_neighbors_flag_check_box.setText("plot neighbours")
self.flags_grid.addWidget(self.plot_neighbors_flag_check_box, i, 10, 1, 10)
i += 1
# # Ignore bad stations ##
self.ignore_bad_stns_flag_check_box = QCheckBox('Ignore bad stations', self)
self.ignore_bad_stns_flag_check_box.setText("Ignore bad stations")
self.flags_grid.addWidget(self.ignore_bad_stns_flag_check_box, i, 1, 1, 10)
self.ignore_bad_stns_flag_check_box.setChecked(True)
# # use best stations flag ##
self.use_best_stns_flag_check_box = QCheckBox('Use best Stations', self)
self.use_best_stns_flag_check_box.setText("Use best stations")
self.flags_grid.addWidget(self.use_best_stns_flag_check_box, i, 10, 1, 10)
self.use_best_stns_flag_check_box.setChecked(True)
i += 1
# # dont stop flag ##
self.dont_stop_flag_check_box = QCheckBox('Dont stop', self)
self.dont_stop_flag_check_box.setText("Dont stop")
self.flags_grid.addWidget(self.dont_stop_flag_check_box, i, 1, 1, 10)
# # plot long term corrs flag ##
self.plot_long_term_corrs_flag_check_box = QCheckBox('Plot long term corrs', self)
self.plot_long_term_corrs_flag_check_box.setText("Plot long term corrs")
self.flags_grid.addWidget(self.plot_long_term_corrs_flag_check_box, i, 10, 1, 10)
i += 1
# # plot nearest stations flag ##
self.plot_nrst_stns_flag_check_box = QCheckBox("Plot nearest stations", self)
self.plot_nrst_stns_flag_check_box.setText("Plot nearest stations")
self.flags_grid.addWidget(self.plot_nrst_stns_flag_check_box, i, 1, 1, 10)
# # nearest stations box ##
self.nrst_stns_type_lab = QLabel('nrst stns type:')
self.nrst_stns_type_box = QComboBox()
self.nrst_stns_type_box.addItems(['dist', 'rank', 'symm'])
self.flags_grid.addWidget(self.nrst_stns_type_lab, i, 10, 1, 1)
self.flags_grid.addWidget(self.nrst_stns_type_box, i, 11, 1, 2)
i += 1
# # plot ecops flag ##
self.plot_ecops_check_box = QCheckBox("Plot ecops", self)
self.flags_grid.addWidget(self.plot_ecops_check_box, i, 1, 1, 10)
self.ecop_bins_lab = QLabel('ecops:')
self.ecop_bins_line = QLineEdit()
self.ecop_bins_line.setText("15")
self.flags_grid.addWidget(self.ecop_bins_lab, i, 10, 1, 10)
self.flags_grid.addWidget(self.ecop_bins_line, i, 11, 1, 2)
self.ecop_bins_lab.setToolTip(str('Directory to the output folder (where the results will be saved).'))
self.ecop_bins_line.setToolTip(str('Directory to the output folder (where the results will be saved).'))
i += 1
# # Save step vars flag ##
self.save_step_vars_flag_check_box = QCheckBox('Save step vars', self)
self.flags_grid.addWidget(self.save_step_vars_flag_check_box, i, 1, 1, 10)
# # cmpt plot stats flag ##
self.cmpt_plot_stats_check_box = QCheckBox("Cmpt plot stats", self)
self.flags_grid.addWidget(self.cmpt_plot_stats_check_box, i, 10, 1, 10)
i += 1
# # cmpt plot avail stns flag ##
self.cmpt_plot_avail_stns_check_box = QCheckBox("Cmpt plot avail stns", self)
self.flags_grid.addWidget(self.cmpt_plot_avail_stns_check_box, i, 1, 1, 10)
self.plot_rand_check_box = QCheckBox("Plot Rand", self)
self.flags_grid.addWidget(self.plot_rand_check_box, i, 10, 1, 10)
i += 1
self.stn_based_mp_infill_check_box = QCheckBox("station based mp infill")
self.flags_grid.addWidget(self.stn_based_mp_infill_check_box, i, 1, 1, 10)
i += 1
self.n_rand_infill_check_box = QCheckBox('n rand infill', self)
self.flags_grid.addWidget(self.n_rand_infill_check_box, i, 1, 1, 10)
self.n_rand_infill_lab = QLabel("n rand infill: ")
self.n_rand_infill_line = QLineEdit()
self.n_rand_infill_line.setText("10")
self.flags_grid.addWidget(self.n_rand_infill_lab, i, 10)
self.flags_grid.addWidget(self.n_rand_infill_line, i, 11, 1, 2)
self.n_rand_infill_lab.setToolTip(str(''))
self.n_rand_infill_line.setToolTip(str(''))
i += 1
self.min_corr_check_box = QCheckBox('min corr', self)
self.flags_grid.addWidget(self.min_corr_check_box, i, 1, 1, 10)
self.min_corr_lab = QLabel("min corr: ")
self.min_corr_line = QLineEdit()
self.min_corr_line.setText("0.5")
self.flags_grid.addWidget(self.min_corr_lab, i, 10)
self.flags_grid.addWidget(self.min_corr_line, i, 11, 1, 2)
self.min_corr_lab.setToolTip(str(''))
self.min_corr_line.setToolTip(str(''))
i += 1
self.max_time_check_box = QCheckBox('max time lag corr', self)
self.flags_grid.addWidget(self.max_time_check_box, i, 1, 1, 10)
self.max_time_lag_corr_lab = QLabel("Max time lag corr: ")
self.max_time_lag_corr_line = QLineEdit("6")
self.flags_grid.addWidget(self.max_time_lag_corr_lab, i, 10)
self.flags_grid.addWidget(self.max_time_lag_corr_line, i, 11, 1, 2)
i += 1
self.cut_cdf_thresh_check_box = QCheckBox('cut cdf thresh', self)
self.flags_grid.addWidget(self.cut_cdf_thresh_check_box, i, 1, 1, 10)
self.cut_cdf_thresh_lab = QLabel("cut cdf thresh: ")
self.cut_cdf_thresh_line = QLineEdit("0.5")
self.flags_grid.addWidget(self.cut_cdf_thresh_lab, i, 10)
self.flags_grid.addWidget(self.cut_cdf_thresh_line, i, 11, 1, 2)
i += 1
# # default button ##
self.default_btn = QPushButton('Default')
self.flags_grid.addWidget(self.default_btn, i, 10, 1, 3)
self.default_btn.clicked.connect(lambda: self.default_ticks())
i += 1
# # add space ##
self.space_lab = QLabel(' ')
self.space_lab.setFixedHeight(50)
self.flags_grid.addWidget(self.space_lab, i, 0)
i += 1
# # runn button ##
self.run_lab = 'Run!'
self.run_btn = QPushButton()
self.run_btn.setText(self.run_lab)
self.run_btn.clicked.connect(lambda: self.run())
self.flags_grid.addWidget(self.run_btn, i, 1, 1, 15)
self.run_btn.setToolTip(str('Run!'))
i += 1
# # back button ##
self.back_lab = 'Back'
self.back_btn = QPushButton()
self.back_btn.setText(self.back_lab)
self.back_btn.clicked.connect(lambda: self.back())
self.flags_grid.addWidget(self.back_btn, i, 1, 1, 15)
self.back_btn.setToolTip(str('Go back to previous Tab!'))
i += 1
self.flags_layout.addLayout(self.flags_grid)
self.flags_tab.setLayout(self.flags_layout)
def ecops_state(self):
if self.plot_ecops_check_box.isChecked() == True:
self.ecop_bins_line.setDisabled(False)
else:
self.ecop_bins_line.setDisabled(True)
def n_rand_infill_state(self):
if self.n_rand_infill_check_box.isChecked() == True:
self.n_rand_infill_line.setDisabled(False)
else:
self.n_rand_infill_line.setDisabled(True)
def min_corr_state(self):
if self.min_corr_check_box.isChecked() == True:
self.min_corr_line.setDisabled(False)
else:
self.min_corr_line.setDisabled(True)
def max_time_state(self):
if self.max_time_check_box.isChecked() == True:
self.max_time_lag_corr_line.setDisabled(False)
else:
self.max_time_lag_corr_line.setDisabled(True)
def cut_cdf_thresh_state(self):
if self.cut_cdf_thresh_check_box.isChecked() == True:
self.cut_cdf_thresh_line.setDisabled(False)
else:
self.cut_cdf_thresh_line.setDisabled(True)
def read_data(self):
self.read_succ = True
try:
self.in_q_orig_file = self.in_q_orig_file_line.text()
assert self.in_q_orig_file
print('\u2714', "Input file is:", self.in_q_orig_file)
except Exception as msg:
self.show_error('Please Select a valid Input file', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading input file")
self.read_succ = False
try:
self.in_coords_file = self.in_coords_file_line.text()
assert self.in_coords_file
print('\u2714', "Coordinates file is:", self.in_coords_file)
except Exception as msg:
self.show_error('Please Select a valid Coordinates file', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Main Coordinates file")
self.read_succ = False
try:
self.out_dir = self.out_dir_line.text()
assert self.out_dir
print('\u2714', "Output directory is:", self.out_dir)
except Exception as msg:
self.show_error('Please Select a valid Output Directory', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Output directory")
self.read_succ = False
try:
self.date_fmt_choice = ['%Y-%m-%d', '%Y-%b-%d', '%Y-%B-%d',
'%y-%m-%d', '%y-%b-%d', '%y-%B-%d',
'%d-%m-%Y', '%d-%b-%Y', '%d-%B-%Y',
'%d-%m-%y', '%d-%b-%y', '%d-%B-%y',
'%m-%d-%Y', '%b-%d-%Y', '%B-%d-%Y',
'%m-%d-%y', '%b-%d-%y', '%B-%d-%y',
'%Y.%m.%d', '%Y.%b.%d', '%Y.%B.%d',
'%y.%m.%d', '%y.%b.%d', '%y.%B.%d',
'%d.%m.%Y', '%d.%b.%Y', '%d.%B.%Y',
'%d.%m.%y', '%d.%b.%y', '%d.%B.%y',
'%m.%d.%Y', '%b.%d.%Y', '%B.%d.%Y',
'%m.%d.%y', '%b.%d.%y', '%B.%d.%y',
'%Y/%m/%d', '%Y/%b/%d', '%Y/%B/%d',
'%y/%m/%d', '%y/%b/%d', '%y/%B/%d',
'%d/%m/%Y', '%d/%b/%Y', '%d/%B/%Y',
'%d/%m/%y', '%d/%b/%', '%d/%B/%y',
'%m/%d/%Y', '%b/%d/%Y', '%B/%d/%Y',
'%m/%d/%y', '%b/%d/%y', '%B/%d/%y']
self.date_fmt = self.date_fmt_choice[self.date_fmt_box.currentIndex()]
assert self.date_fmt
print('\u2714', "Date Format is:", self.date_fmt_box.currentText())
except Exception as msg:
self.show_error('Please Select a valid Date format', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Date format")
print(self.date_fmt)
self.read_succ = False
try:
self.infill_stns = str(self.infill_stns_line.text())
self.infill_stns_list = self.infill_stns.split(";")
assert self.infill_stns_list
print('\u2714', "Infill Stations:", self.infill_stns_list)
except Exception as msg:
self.show_error('Please Specify infill stations (values must be separated by a ";")', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading infill stations")
self.read_succ = False
try:
self.drop_stns = str(self.drop_stns_line.text())
self.drop_stns_list = self.drop_stns.split(";")
assert self.drop_stns_list
print('\u2714', "Stations to drop:", self.drop_stns_list)
except:
print('\u2714', "No stations to drop")
try:
self.censor_period = str(self.censor_period_line.text())
self.censor_period_list = self.censor_period.split(";")
assert self.censor_period_list
print('\u2714', "Censor period:", self.censor_period_list)
except Exception as msg:
self.show_error('Please Specify a valid Censor Period, (values must be separated by a ";")', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Censor Period")
self.read_succ = False
try:
self.infill_interval_type = self.infill_interval_type_box.currentText()
assert self.infill_interval_type
print('\u2714', "Infill Interval Type is:", self.infill_interval_type)
except Exception as msg:
self.show_error('Please Select a valid infill interval type', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Interval type")
self.read_succ = False
try:
self.infill_type = self.infill_type_box.currentText()
assert self.infill_type
print('\u2714', "Infill Type is:", self.infill_type)
except Exception as msg:
self.show_error('Please Select a valid infill type', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Infill Type")
self.read_succ = False
try:
self.min_valid_vals = int(self.min_valid_vals_line.text())
assert self.min_valid_vals
print('\u2714', "Minimum Valid Values:", self.min_valid_vals)
except Exception as msg:
self.show_error('Please specify an integer in the Minimum valid values box', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Minimum Valid Values")
self.read_succ = False
try:
self.n_nrn_min = int(self.n_nrn_min_line.text())
assert self.n_nrn_min
print('\u2714', "Minimum nearest stations:", self.n_nrn_min)
except Exception as msg:
self.show_error('Please specify an integer in Minimum nearest stations box', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Minimum nearest station")
self.read_succ = False
try:
self.n_nrn_max = int(self.n_nrn_max_line.text())
assert self.n_nrn_max
print('\u2714', "Maximum nearest stations:", self.n_nrn_max)
except Exception as msg:
self.show_error('Please specify an integer in Maximum nearest stations box', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Maximum nearest stations")
self.read_succ = False
try:
self.ncpus = int(self.ncpus_box.currentText())
assert self.ncpus
assert isinstance(self.ncpus, int)
print('\u2714', "Number of CPUs:", self.ncpus)
except Exception as msg:
self.show_error('Please Select a valid Number of CPUs', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Number of CPUs")
self.read_succ = False
try:
self.sep = self.sep_box.currentText()
assert self.sep
print('\u2714', "Separator is:", self.sep)
except Exception as msg:
self.show_error('Please Select a valid Separator', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Separator")
self.read_succ = False
try:
self.freq = self.freq_box.currentText()
assert self.freq
print('\u2714', "Freq is:", self.freq)
except Exception as msg:
self.show_error('Please Select a valid Freq', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error reading Freq")
self.read_succ = False
try:
if self.read_succ == True:
self.flags_tab.setDisabled(False)
print('\n')
print('\u2714' * 37)
print('Data read successfully....')
print('\u2714' * 37, '\n')
self.conf_input_tab.setDisabled(True)
self.setCurrentIndex(self.currentIndex() + 1)
else:
self.flags_tab.setDisabled(True)
print('\n')
print('\u2716' * 37)
print("Error reading data")
print('\u2716' * 37, '\n')
except Exception as msg:
self.show_error('Please check your data', QMessageBox.Critical, details=repr(msg))
self.flags_tab.setDisabled(True)
# define NormalCopulaInfill (imported script) #
self.infill_cop = NormCopulaInfill(in_var_file=self.in_q_orig_file,
out_dir=self.out_dir,
infill_stns=self.infill_stns_list,
min_valid_vals=self.min_valid_vals,
infill_interval_type=self.infill_interval_type,
infill_type=self.infill_type,
infill_dates_list=self.censor_period_list,
in_coords_file=self.in_coords_file,
n_min_nebs=self.n_nrn_min,
n_max_nebs=self.n_nrn_max,
ncpus=self.ncpus,
skip_stns=self.drop_stns_list,
sep=self.sep,
time_fmt=self.date_fmt,
freq=self.freq,
verbose=True,
)
def run(self):
try:
self.conf_input_tab.setDisabled(True)
self.flags_tab.setDisabled(True)
print('\a\a\a\a Started on %s \a\a\a\a\n' % time.asctime())
start = timeit.default_timer()
if self.debug_check_box.isChecked() == True:
self.infill_cop.debug_mode_flag = True
else:
self.infill_cop.debug_mode_flag = False
if self.plot_diag_check_box.isChecked() == True:
self.infill_cop.plot_diag_flag = True
else:
self.infill_cop.plot_diag_flag = False
if self.plot_step_cdf_pdf_check_box.isChecked() == True:
self.infill_cop.plot_step_cdf_pdf_flag = True
else:
self.infill_cop.plot_step_cdf_pdf_flag = False
if self.compare_infill_check_box.isChecked() == True:
self.infill_cop.compare_infill_flag = True
else:
self.infill_cop.compare_infill_flag = False
if self.flag_susp_check_box.isChecked() == True:
self.infill_cop.flag_susp_flag = True
else:
self.infill_cop.flag_susp_flag = False
if self.force_infill_check_box.isChecked() == True:
self.infill_cop.force_infill_flag = True
else:
self.infill_cop.force_infill_flag = False
if self.plot_neighbors_flag_check_box.isChecked() == True:
self.infill_cop.plot_neighbors_flag = True
else:
self.infill_cop.plot_neighbors_flag = False
if self.take_min_stns_check_box.isChecked() == True:
self.infill_cop.take_min_stns_flag = True
else:
self.infill_cop.take_min_stns_flag = False
if self.overwrite_check_box.isChecked() == True:
self.infill_cop.overwrite_flag = True
else:
self.infill_cop.overwrite_flag = False
if self.read_pickles_check_box.isChecked() == True:
self.infill_cop.read_pickles_flag = True
else:
self.infill_cop.read_pickles_flag = False
if self.use_best_stns_flag_check_box.isChecked() == True:
self.infill_cop.use_best_stns_flag = True
else:
self.infill_cop.use_best_stns_flag = False
if self.dont_stop_flag_check_box.isChecked() == True:
self.infill_cop.dont_stop_flag = True
else:
self.infill_cop.dont_stop_flag = False
if self.plot_long_term_corrs_flag_check_box.isChecked() == True:
self.infill_cop.plot_long_term_corrs_flag = True
else:
self.infill_cop.plot_long_term_corrs_flag = False
if self.save_step_vars_flag_check_box.isChecked() == True:
self.infill_cop.save_step_vars_flag = True
else:
self.infill_cop.save_step_vars_flag = False
if self.plot_rand_check_box.isChecked() == True:
self.infill_cop.plot_rand_flag = True
else:
self.infill_cop.plot_rand_flag = False
if self.stn_based_mp_infill_check_box.isChecked() == True:
self.infill_cop.stn_based_mp_infill = True
else:
self.infill_cop.stn_based_mp_infill = False
if self.save_step_vars_flag_check_box.isChecked() == True:
self.infill_cop.save_step_vars_flag = True
else:
self.infill_cop.save_step_vars_flag = False
if self.infill_cop.nrst_stns_type == 'dist':
self.infill_cop.cmpt_plot_nrst_stns()
elif self.infill_cop.nrst_stns_type == 'rank':
self.infill_cop.cmpt_plot_rank_corr_stns()
# elif self.infill_cop.nrst_stns_type == 'symm':
# self.infill_cop.cmpt_plot_symm_stns()
else:
pass
if self.n_rand_infill_check_box.isChecked() == True:
self.infill_cop.n_rand_infill_values = int(self.n_rand_infill_line.text())
else:
pass
if self.min_corr_check_box.isChecked() == True:
self.infill_cop.min_corr = float(self.n_rand_infill_line.text())
else:
pass
if self.max_time_check_box.isChecked() == True:
self.infill_cop.max_time_lag_corr = int(self.max_time_lag_corr_line.text())
else:
pass
if not self.cut_cdf_thresh_check_box.isChecked() == True:
self.infill_cop.cut_cdf_thresh = self.cut_cdf_thresh_line.text()
else:
pass
if self.save_step_vars_flag_check_box.isChecked() == True:
self.infill_cop.nrst_stns_type = self.nrst_stns_type_box.currentText()
else:
pass
if self.plot_nrst_stns_flag_check_box.isChecked() == True:
self.infill_cop.cmpt_plot_nrst_stns()
else:
pass
if self.plot_ecops_check_box.isChecked() == True:
self.infill_cop.cop_bins = int(self.ecop_bins_line.text())
self.infill_cop.plot_ecops()
else:
pass
if self.ignore_bad_stns_flag_check_box.isChecked() == True:
self.infill_cop.ignore_bad_stns_flag = True
else:
self.infill_cop.ignore_bad_stns_flag = False
if self.cmpt_plot_stats_check_box.isChecked() == True:
self.infill_cop.plot_stats()
else:
pass
self.infill_cop.infill()
if self.cmpt_plot_avail_stns_check_box.isChecked() == True:
self.infill_cop.cmpt_plot_avail_stns()
else:
pass
self.infill_cop.plot_summary()
stop = timeit.default_timer() # Ending time
print(('\n\a\a\a Done with everything on %s. Total run time was about %0.4f seconds \a\a\a') % (time.asctime(), stop - start))
self.conf_input_tab.setDisabled(False)
self.setCurrentIndex(self.currentIndex() - 1)
except Exception as msg:
self.show_error('Simulation Error', QMessageBox.Critical, details=repr(msg))
print('\u2716', "Error Running simulation")
finally:
self.conf_input_tab.setDisabled(False)
self.setCurrentIndex(self.currentIndex() - 1)
def back(self):
self.setCurrentIndex(self.currentIndex() - 1)
self.flags_tab.setDisabled(True)
self.conf_input_tab.setDisabled(False)
def back_tab(self):
if self.currentIndex() == 0:
self.flags_tab.setDisabled(True)
self.conf_input_tab.setDisabled(False)
def plot_step_cdf_pdf(self, state):
if self.plot_step_cdf_pdf_check_box.isChecked() == True:
print("plot step cdf pdf is set to: ON")
else:
print("plot step cdf pdf is set to: OFF")
def plot_diag(self, state):
if self.plot_diag_check_box.isChecked() == True:
print("Plot diag is set to: ON")
else:
print("Plot diag is set to: OFF")
def overwrite(self, state):
if self.overwrite_check_box.isChecked() == True:
print("Overwrite is set to: ON")
else:
self.infill_cop.read_pickles_flag = False
print("Overwrite is set to: OFF")
def read_pickles(self, state):
if self.read_pickles_check_box.isChecked() == True:
print("Read pickles is set to: ON")
else:
print("Read pickles is set to: OFF")
def take_min_stns(self, state):
if self.take_min_stns_check_box.isChecked() == True:
print("Take min stations is set to: ON")
else:
print("Take min stations is set to: OFF")
def force_infill(self, state):
if self.force_infill_check_box.isChecked() == True:
print("Force infill is set to: ON")
else:
print("Force infill is set to: OFF")
def flag_susp(self, state):
if self.flag_susp_check_box.isChecked() == True:
print("Flag Susp is set to: ON")
else:
print("Flag Susp is set to: OFF")
def debug_mode(self, state):
if self.debug_check_box.isChecked() == True:
print("Debug mode is set to: ON")
else:
print("Debug mode is set to: OFF")
def compare_infill(self, state):
if self.compare_infill_check_box.isChecked() == True:
print("Compare infill is set to: ON")
else:
print("Compare infill is set to: OFF")
def get_input_dir(self, _input=True):
if _input:
dlg = QFileDialog()
dlg.setFileMode(QFileDialog.FileMode())