-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpaleo_view_v1_5_1.py
6507 lines (5716 loc) · 413 KB
/
paleo_view_v1_5_1.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
# Python modules
import base64
import string
import sys
import Tkinter as tk
import ttk
from os import chdir, environ, getcwd, listdir, mkdir, path
from shutil import copyfile
from StringIO import StringIO
from time import time, localtime, strftime
from tkFileDialog import *
from tkFont import Font
from tkMessageBox import *
import warnings
warnings.simplefilter('ignore')
# Python extension modules (requires extension installation)
from Crypto.Cipher import AES
import numpy as np
# imports for py2exe build -
import appdirs
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
import packaging.markers
# ---
import pandas as pd
# Python extension Matplot and Basemap modules
from mpl_toolkits.basemap import Basemap
import FileDialog
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
from matplotlib.colorbar import ColorbarBase
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.figure import Figure
from matplotlib.ticker import MaxNLocator
from matplotlib import rcParams
# Mac version?
MAC_VERSION = True # Make True for releases to enable Linux compatibility
# Tool library modules
from PaleoclimateToolDataFileHelper import PaleoclimateToolDataFileHelper
# TEST FLAG: Write stdout and stderr to console (not log files)
DEBUG = False
# Code for encrypting/decrypting the proxy password when saved/retrieved from the config file
BLOCK_SIZE = 32
PADDING = ' '
PadPassword = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(PadPassword(s)))
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
PASSWORDKEY = '\xe7Z\xb2\xc9\x03\xb4\x8c\x04A\xfe\x97\xc3\xf9\xc7\xd2\x1c\xb9\x1eh\xd0\x91E/\xdb\xc9\x9f\xf0\xda\x8e\x06\xae\xd5' # set using os.urandom(BLOCK_SIZE)
# Allow open interval step and size (set to False for releases)
OPEN_INTERVALS = False
## Application GUI
## * Constructs tool GUI components
## * Performs tool operations utilising climate data helper module
class ApplicationGUI(tk.Frame) :
## GUI Initilisation Methods ############################################################################################################################################
# Initialise GUI and workflow
def __init__(self, user_application_data_directory, master=None) :
tk.Frame.__init__(self, master)
self.grid()
# Create the Paleoclimate data file helper
self.data_file_helper = PaleoclimateToolDataFileHelper(application_gui=self)
# Configuration file (initially in the same directory as the tool, but copied to user application data directory)
self.tool_config_file = 'paleo_view_config.txt'
# User application data directory
self.user_application_data_directory = user_application_data_directory
# Initialise config parameters
self.climate_data_source = 'local' # local/url
self.climate_data_url = 'https://storage.googleapis.com/paleoview-data/'
self.climate_data_proxy_active = False
self.climate_data_proxy_url = 'http://example.proxy.com:80/'
self.climate_data_proxy_username = ''
self.climate_data_proxy_password = ''
self.climate_data_directory = ''
self.climate_data_local_data_type = 'netcdf' # netcdf/raw
self.default_file_generation_directory = ''
self.default_file_generation_directory_set = False
self.region_mask_directory = path.join(getcwd(), 'Map Data')
self.bias_correction_directory = path.join(getcwd(), 'Bias Corrections')
self.public_release = True
self.show_extended_colour_palettes_in_advance = False
self.unpack_downloaded_netcdf_data = False
# Current directory locations
self.current_figure_save_directory = ''
# Tool generation log file
self.tool_generation_log_file = 'paleo_view_generation_log.txt'
self.tool_generation_log_entry = { 'data_type' : None,
'data_action' : None,
'parameter_group' : None,
'parameter' : None,
'time_unit' : None,
'time_unit_value' : None,
'region' : None,
'period_from' : { 'year' : None, 'postfix' : None },
'period_until' : { 'year' : None, 'postfix' : None },
'interval_step' : None,
'interval_size' : None,
'bias_correction' : False,
'utilise_delta' : False,
'delta_as_percent' : False,
'delta_reference' : { 'year' : None, 'postfix' : None },
'grids_generated' : None,
'figure' : None,
'existing' : False,
'statistics_generated' : False,
'statistics_table' : None }
# Maximum maps and time series points
self.maximum_maps = 20
self.maximum_time_series_points = 500
self.maximum_interval_steps = self.maximum_maps - 1
# Month codes, names, shortnames
self.month_codes = self.data_file_helper.getMonthCodes()
self.month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
self.month_shortnames = ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D']
# Grid region statistics keys and names
self.grid_region_statistics_keys = ['minimum', 'percentile_5th', 'percentile_25th', 'percentile_50th', 'percentile_75th', 'percentile_95th', 'maximum',
'grid_mean', 'grid_stdev', 'area_mean', 'area_stdev']
self.grid_region_statistics_names = { 'minimum' : 'Minimum',
'percentile_5th' : '5th Percentile',
'percentile_25th' : 'Q1',
'percentile_50th' : 'Median',
'percentile_75th' : 'Q3',
'percentile_95th' : '95th Percentile',
'maximum' : 'Maximum',
'grid_mean' : 'Mean (grid)',
'grid_stdev' : 'Stdev (grid)',
'area_mean' : 'Area Mean',
'area_stdev' : 'Area Stdev' }
# Configuration relating to tool options:
self.tool_option_parameters = ['climate_data_source', 'climate_data_directory', 'climate_data_url', 'climate_data_proxy_active',
'climate_data_proxy_url', 'climate_data_proxy_username', 'climate_data_proxy_password',
'default_file_generation_directory', 'default_file_generation_directory_set', 'public_release',
'show_extended_colour_palettes_in_advance', 'climate_data_local_data_type']
self.tool_option_parameter_types = { 'climate_data_source' : str, 'climate_data_directory' : str, 'climate_data_url' : str,
'climate_data_proxy_active' : bool, 'climate_data_proxy_url' : str, 'climate_data_proxy_username' : str,
'climate_data_proxy_password' : str, 'default_file_generation_directory' : str,
'default_file_generation_directory_set' : bool, 'public_release' : bool, 'show_extended_colour_palettes_in_advance' : bool,
'climate_data_local_data_type' : str }
# Parameter fixed range colour scheme
self.parameter_fixed_range_colour_scheme = { 'temperature' : { 'mean-temperature' : { 'value' : {}, 'delta' : {} },
'minimum-temperature' : { 'value' : {}, 'delta' : {} },
'maximum-temperature' : { 'value' : {}, 'delta' : {} },
'diurnal-temperature-range' : { 'value' : {}, 'delta' : {} },
'annual-temperature-range' : { 'value' : {}, 'delta' : {} },
'isothermality' : { 'value' : {}, 'delta' : {} },
'temperature-seasonality' : { 'value' : {}, 'delta' : {} } },
'precipitation' : { 'mean-precipitation' : { 'value' : {}, 'delta' : {} },
'precipitation-seasonality' : { 'value' : {}, 'delta' : {} } },
'humidity' : { 'specific-humidity' : { 'value' : {}, 'delta' : {} },
'relative-humidity' : { 'value' : {}, 'delta' : {} } },
'sea-level-pressure' : { 'sea-level-pressure' : { 'value' : {}, 'delta' : {} } } }
self.parameter_fixed_range_colour_scheme['temperature']['mean-temperature']['value'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['mean-temperature']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['minimum-temperature']['value'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['minimum-temperature']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['maximum-temperature']['value'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['maximum-temperature']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['diurnal-temperature-range']['value'] = { 'min' : 0.0, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['diurnal-temperature-range']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['annual-temperature-range']['value'] = { 'min' : 0.0, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['annual-temperature-range']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['isothermality']['value'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['isothermality']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['temperature-seasonality']['value'] = { 'min' : 0.0, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['temperature']['temperature-seasonality']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['precipitation']['mean-precipitation']['value'] = { 'min' : 0.0, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['precipitation']['mean-precipitation']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['precipitation']['mean-precipitation']['%delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['precipitation']['precipitation-seasonality']['value'] = { 'min' : 0.0, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['precipitation']['precipitation-seasonality']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['humidity']['specific-humidity']['value'] = { 'min' : 0.0, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['humidity']['specific-humidity']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['humidity']['relative-humidity']['value'] = { 'min' : 0.0, 'first_boundary' : None, 'last_boundary' : None, 'max' : 100.0 }
self.parameter_fixed_range_colour_scheme['humidity']['relative-humidity']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['sea-level-pressure']['sea-level-pressure']['value'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
self.parameter_fixed_range_colour_scheme['sea-level-pressure']['sea-level-pressure']['delta'] = { 'min' : None, 'first_boundary' : None, 'last_boundary' : None, 'max' : None }
# Load config from file and warn if file not found
config_warning = self.loadConfig()
if config_warning :
showwarning('Error Loading Configuration', config_warning)
# Set the climate data source, url and directory, and the file generation, mask, and bias correction directories
self.data_file_helper.setClimateDataSource(self.climate_data_source)
self.data_file_helper.setClimateDataUrl(self.climate_data_url)
self.data_file_helper.setClimateDataProxy(self.climate_data_proxy_active, self.climate_data_proxy_url, self.climate_data_proxy_username, self.climate_data_proxy_password)
if not self.data_file_helper.checkClimateDataUrl() :
self.setToolOptions({ 'climate_data_url' : self.data_file_helper.getClimateDataUrl() })
self.data_file_helper.setClimateDataDirectory(self.climate_data_directory)
self.data_file_helper.setFileGenerationDirectory(self.default_file_generation_directory)
self.data_file_helper.setRegionMaskDirectory(self.region_mask_directory)
self.data_file_helper.setBiasCorrectionDirectory(self.bias_correction_directory)
# Tool Process steps
self.process_step = {}
self.process_step['data_type'] = { 'number' : '1', 'dependents' : [], 'completed': False }
self.process_step['parameter_selection'] = { 'number' : '2', 'dependents' : ['data_type'], 'completed': False }
self.process_step['region_selection'] = { 'number' : '3', 'dependents' : ['data_type', 'parameter_selection'], 'completed': False }
self.process_step['period_interval'] = { 'number' : '4', 'dependents' : ['data_type', 'parameter_selection', 'region_selection'], 'completed': False }
self.process_step['bias_correction'] = { 'number' : '5', 'dependents' : ['data_type', 'parameter_selection', 'region_selection', 'period_interval'], 'completed': False }
self.process_step['delta'] = { 'number' : '6', 'dependents' : ['data_type', 'parameter_selection', 'region_selection', 'period_interval', 'bias_correction'], 'completed': False }
self.process_step['generation'] = { 'number' : '7', 'dependents' : ['data_type', 'parameter_selection', 'region_selection', 'period_interval', 'bias_correction', 'delta'], 'completed': False }
# Process frames
self.createMenu()
# Configure the font for tool headings
default_font = Font(font='TkDefaultFont')
tool_label_font = Font(family=default_font.cget('family'), size=default_font.cget('size'), weight='bold')
# Tool sections
self.main_frame = tk.LabelFrame(self, padx=10, pady=5)
self.createDataTypeFrame()
self.createParameterSelectionFrame()
self.createRegionSelectionFrame()
self.createPeriodIntervalFrame()
self.createDeltaFrame()
self.createBiasCorrectionFrame()
self.createGenerationFrame()
self.main_frame.grid(row=0, column=0, sticky=tk.NW+tk.SE, padx=5, pady=5)
# Set initial Period Interval Values
self.setInitialPeriodIntervalValues()
# Flag when validation warnings are pending
self.validation_warning_pending = False
# Flag when warning produced by update call to validation method
self.warning_shown_for_update_validation = False
# Flag for forcing shifting focus when validation is triggered by option menus
self.force_shift_focus = False
# Flag warning messages so as to avoid calling additional validation checks triggered by focusout events
self.currently_showing_warning_message = False
# Setup colour schemes and palettes
self.map_colour_schemes = ['fixed_range', '90%_range']
self.map_colour_scheme_selection = ['Fixed range', '90% range']
self.map_colour_scheme = 'fixed_range'
self.map_colour_palette = '' # set within palette setup
#self.auto_map_colour_palette = True
self.reverse_map_colour_palette = False
self.map_colour_boundary_lines = True
self.map_colour_zero_boundary = False
self.setupColourPalettes()
# Use contoured colour maps?
self.use_contoured_grid_maps = True
# Show grid map land_boundaries?
self.show_grid_map_land_boundaries = True
# Map grid
self.show_map_grid_lines = True
self.map_grid_includes = ['ticks', 'lines']
self.map_grid_include_selection = ['ticks only', 'lines']
self.map_grid_include = 'ticks'
self.map_grid_spaces = [2.5, 5.0, 10.0, 15.0, 30.0]
self.map_grid_space_selection = ['2.5', '5.0', '10.0', '15.0', '30.0']
self.map_grid_space = None # use region grid space when not defined
# Load configuration from a file and return warning if any
def loadConfig(self) :
warning = ''
orig_config_file_path = path.join(getcwd(), self.tool_config_file)
user_config_file_path = path.join(self.user_application_data_directory, self.tool_config_file)
if not path.exists(user_config_file_path) and path.exists(orig_config_file_path) :
copyfile(orig_config_file_path, user_config_file_path)
if path.exists(user_config_file_path) :
f = open(user_config_file_path)
lines = f.readlines()
f.close()
for line in lines :
if line.find('=') != -1 :
name = 'self.' + line.split('=')[0].strip()
value = line.split('=',1)[1].strip()
# Decrypt proxy password
if name == 'self.climate_data_proxy_password' :
cipher = AES.new(PASSWORDKEY)
value = DecodeAES(cipher, value)
try :
exec(name + ' = eval(value)')
except Exception, e :
exec(name + ' = value')
else :
warning = 'Could not find configuration file. Using default configuration.'
return warning
# Get tool options
def getToolOptions(self, option_parameters=None) :
if not option_parameters :
option_parameters = self.tool_option_parameters
tool_options = {}
for option in option_parameters :
tool_options[option] = eval('self.'+option)
return tool_options
# Set tool options, including updating config file
def setToolOptions(self, tool_options) :
config_file_path = path.join(self.user_application_data_directory, self.tool_config_file)
# Read config file
if path.exists(config_file_path) :
# Read file lines
f = open(config_file_path)
file_lines = f.readlines()
f.close()
# Ensure last line has newline char
if len(file_lines) > 0 :
if file_lines[len(file_lines)-1].find('\n') == -1 :
file_lines[len(file_lines)-1] += '\n'
else :
file_lines = []
# Set options within tool and config file lines
for option, value in tool_options.items() :
# Set within tool
name = 'self.' + option
exec(name + ' = value')
# Encrypt proxy password
if option == 'climate_data_proxy_password' :
cipher = AES.new(PASSWORDKEY)
value = EncodeAES(cipher, value)
# Set within config file lines
found_within_file = False
for i, line in enumerate(file_lines) :
if line.find(option) != -1 :
if line.find('=') != -1 :
if line.split('=')[0].strip() == option :
file_lines[i] = line.split('=')[0] + '= ' + str(value) + '\n'
found_within_file = True
if not found_within_file :
file_lines.append(option + ' = ' + str(value) + '\n')
# Write config file
f = open(config_file_path, 'w')
f.writelines(file_lines)
f.close()
# Method setup colour palettes
def setupColourPalettes(self) :
self.colour_palettes = ['rainbow', 'red_blue', 'ar4', 'extended_red_blue']
self.map_colour_palette = 'rainbow'
self.extended_colour_palettes = ['extended_red_blue']
rainbow = ['#fa58f4', '#0000ff', '#819ff7', '#81f7f3', '#04b431', '#44ff00', '#ffff00', '#fe9a2e', '#fec3d2', '#ff0000', '#cc3300']
rainbow_reversed = rainbow[:]
rainbow_reversed.reverse()
red_blue = ['#0000ac', '#0000ff', '#8888ff', '#a9a9ff', '#d5d5ff', '#ffffff', '#ffd7d7', '#ffaaaa', '#ff6464', '#ff0000', '#cc3300']
red_blue_reversed = red_blue[:]
red_blue_reversed.reverse()
ar4 = ['#668bf1', '#94b0fe', '#b1c4fa', '#d1dcfb', '#eaeffc', '#ffffce', '#ffe898', '#ffc98e', '#f3a24b', '#ff8257', '#fc551d']
ar4_reversed = ar4[:]
ar4_reversed.reverse()
extended_red_blue = ['#7a0000', '#b50000', '#df0000', '#ff0000', '#fa563d', '#ffa495', '#ff7338', '#ffa161', '#fdb56b', '#fecd80',
'#f5ecc3', '#d7e2ff', '#b3ccf5', '#97b4fa', '#84a6ff', '#6989ec', '#4c80e6', '#3366d9', '#054baa', '#07378c',
'#0a2864', '#0a0931'] # already reversed
extended_red_blue_reversed = extended_red_blue[:]
extended_red_blue.reverse()
self.colour_palette_lists = { False : { 'rainbow' : rainbow, 'red_blue' : red_blue, 'ar4' : ar4, 'extended_red_blue' : extended_red_blue },
True : { 'rainbow' : rainbow_reversed, 'red_blue' : red_blue_reversed, 'ar4' : ar4_reversed, 'extended_red_blue' : extended_red_blue_reversed } }
self.colourmaps = { False : { 'rainbow' : LinearSegmentedColormap.from_list('rainbow', rainbow, N=11),
'red_blue' : LinearSegmentedColormap.from_list('red_blue', red_blue, N=11),
'ar4' : LinearSegmentedColormap.from_list('ar4', ar4, N=11),
'extended_red_blue' : LinearSegmentedColormap.from_list('extended_red_blue', extended_red_blue[6:17], N=11) },
True : { 'rainbow' : LinearSegmentedColormap.from_list('rainbow_reversed', rainbow_reversed, N=11),
'red_blue' : LinearSegmentedColormap.from_list('red_blue_reversed', red_blue_reversed, N=11),
'ar4' : LinearSegmentedColormap.from_list('ar4_reversed', ar4_reversed, N=11),
'extended_red_blue' : LinearSegmentedColormap.from_list('extended_red_blue_reversed', extended_red_blue_reversed[5:16], N=11) } }
# Menu GUI (will grow over time)
def createMenu(self) :
# Menu bar
top = self.winfo_toplevel()
self.menu_bar = tk.Menu(top, postcommand=self.shiftFocus)
top['menu'] = self.menu_bar
# File menu
self.file_menu = tk.Menu(self.menu_bar)
self.menu_bar.add_cascade(label='File', menu=self.file_menu)
self.file_menu.entryconfigure(0, state=tk.DISABLED)
self.file_menu.add_command(label='Quit', command=self.quit)
# Edit menu
self.edit_menu = tk.Menu(self.menu_bar)
self.menu_bar.add_cascade(label='Edit', menu=self.edit_menu)
self.edit_menu.entryconfigure(0, state=tk.DISABLED)
self.edit_menu.add_command(label='Map Options', command=self.editMapOptions)
self.edit_menu_indices = { 'map_options' : 1 }
# Configure menu
self.configure_menu = tk.Menu(self.menu_bar)
self.menu_bar.add_cascade(label='Configure', menu=self.configure_menu)
self.configure_menu.entryconfigure(0, state=tk.DISABLED)
self.configure_menu.add_command(label='Climate Data Location', command=self.configureClimateDataLocation)
self.configure_menu.add_command(label='Default Output Directory', command=self.configureDefaultFileGenerationDirectory)
self.configure_menu_indices = { 'climate_data_directory' : 1, 'default_file_generation_directory' : 2 }
# Download menu
self.download_menu = tk.Menu(self.menu_bar)
self.menu_bar.add_cascade(label='Download', menu=self.download_menu)
self.download_menu.entryconfigure(0, state=tk.DISABLED)
self.download_menu.add_command(label='Climate Data', command=self.downloadClimateData)
self.download_menu_indices = { 'climate_data_download' : 1 }
# GUI for Step 1: Data Type
def createDataTypeFrame(self) :
step_number = self.process_step['data_type']['number']
#self.data_type_frame = tk.LabelFrame(self, text='Step '+step_number+': Data Type', padx=10, pady=5)
self.data_type_frame = self.main_frame
# Data type and action lists
self.data_type_keys = ['map', 'series']
self.data_type_selection = ['Map Grid', 'Time Series']
self.data_action_keys = ['view', 'files']
self.data_action_selection = ['View', 'Generate Data Files']
# Parameter text variables
self.data_type_text = tk.StringVar()
self.data_type_text.set(self.data_type_selection[0])
self.data_action_text = tk.StringVar()
self.data_action_text.set(self.data_action_selection[0])
# Register validation and selection behaviour methods
select_data_type = self.data_type_frame.register(self.selectDataType)
select_data_action = self.data_type_frame.register(self.selectDataAction)
forced_shift_focus = self.data_type_frame.register(self.shiftFocus)
# Entry/selection fields
self.data_type_menu = tk.OptionMenu(self.data_type_frame, self.data_type_text, *self.data_type_selection)
self.data_type_menu.config(highlightthickness=0, anchor=tk.W, )
self.data_type_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, selection in enumerate(self.data_type_keys) :
self.data_type_menu['menu'].entryconfigure(i, command=(select_data_type, selection))
self.data_action_menu = tk.OptionMenu(self.data_type_frame, self.data_action_text, *self.data_action_selection)
self.data_action_menu.config(highlightthickness=0, anchor=tk.W)
self.data_action_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, selection in enumerate(self.data_action_keys) :
self.data_action_menu['menu'].entryconfigure(i, command=(select_data_action, selection))
# Arrange fields on frame with labels
row = 0
tk.Label(self.data_type_frame, text='Data:').grid(row=row, column=0, sticky=tk.NW+tk.SW, padx=0, pady=5)
self.data_type_menu.grid(row=row, column=1, sticky=tk.W+tk.E, padx=0, pady=5)
self.data_action_menu.grid(row=row, column=2, columnspan=3, sticky=tk.W+tk.E, padx=5, pady=5)
# GUI for Step 2: Parameter Selection
def createParameterSelectionFrame(self) :
step_number = self.process_step['parameter_selection']['number']
self.parameter_selection_frame = self.main_frame
self.time_unit_frame = self.main_frame
# Parameter codes, maps and selection lists
self.parameter_group_selection = ['Temperature', 'Precipitation', 'Humidity', 'Sea Level Pressure'] #, 'Southern Oscillation'] # Sync array order
self.parameter_group_codes = ['temperature', 'precipitation', 'humidity', 'sea-level-pressure'] #, 'southern-oscillation'] # ^
self.parameter_group_code_map = {}
self.parameter_group_selection_map = {}
for i, group_code in enumerate(self.parameter_group_codes) :
self.parameter_group_code_map[group_code] = self.parameter_group_selection[i]
self.parameter_group_selection_map[self.parameter_group_selection[i]] = group_code
self.parameter_via_group_selection = {} # Sync order of arrays
self.parameter_via_group_codes = {} # ^
self.parameter_via_group_selection['temperature'] = ['Mean Temperature', 'Minimum Temperature', 'Maximum Temperature', 'Diurnal Temperature Range', 'Annual Temperature Range', 'Isothermality', 'Temperature Seasonality']
self.parameter_via_group_codes['temperature'] = ['mean-temperature', 'minimum-temperature', 'maximum-temperature', 'diurnal-temperature-range', 'annual-temperature-range', 'isothermality', 'temperature-seasonality']
self.parameter_via_group_selection['precipitation'] = ['Mean Precipitation', 'Precipitation Seasonality']
self.parameter_via_group_codes['precipitation'] = ['mean-precipitation', 'precipitation-seasonality']
self.parameter_via_group_selection['humidity'] = ['Specific Humidity', 'Relative Humidity']
self.parameter_via_group_codes['humidity'] = ['specific-humidity', 'relative-humidity']
self.parameter_via_group_selection['sea-level-pressure'] = ['Sea Level Pressure']
self.parameter_via_group_codes['sea-level-pressure'] = ['sea-level-pressure']
#self.parameter_via_group_selection['southern-oscillation'] = ['SOI', 'ENSO']
#self.parameter_via_group_codes['southern-oscillation'] = ['soi', 'enso']
self.parameter_via_group_code_map = {}
self.parameter_via_group_selection_map = {}
for group_code in self.parameter_group_code_map.keys() :
self.parameter_via_group_code_map[group_code] = {}
self.parameter_via_group_selection_map[group_code] = {}
for i, parameter_code in enumerate(self.parameter_via_group_codes[group_code]) :
self.parameter_via_group_code_map[group_code][parameter_code] = self.parameter_via_group_selection[group_code][i]
self.parameter_via_group_selection_map[group_code][self.parameter_via_group_selection[group_code][i]] = parameter_code
self.parameter_restricted_via_data_type = {}
self.parameter_restricted_via_data_type['Map Grid'] = {}
#self.parameter_restricted_via_data_type['Map Grid']['southern-oscillation'] = [] # non-gridded data
# Parameter unit strings
self.parameter_unit_string = { 'temperature' : {}, 'precipitation' : {}, 'humidity' : {}, 'sea-level-pressure' : {} } #, 'southern-oscillation' : {} }
for parameter in ['mean-temperature', 'minimum-temperature', 'maximum-temperature', 'diurnal-temperature-range', 'annual-temperature-range'] :
self.parameter_unit_string['temperature'][parameter] = u'\u00B0' + 'C'
for parameter in ['isothermality', 'temperature-seasonality'] :
self.parameter_unit_string['temperature'][parameter] = ''
self.parameter_unit_string['precipitation']['mean-precipitation'] = 'mm/day'
self.parameter_unit_string['precipitation']['precipitation-seasonality'] = ''
self.parameter_unit_string['humidity']['specific-humidity'] = 'gm/kg'
self.parameter_unit_string['humidity']['relative-humidity'] = '%'
self.parameter_unit_string['sea-level-pressure']['sea-level-pressure'] = 'hPa'
#self.parameter_unit_string['southern-oscillation']['soi'] = ''
#self.parameter_unit_string['southern-oscillation']['enso'] = ''
# Parameters for time units
self.time_unit_selection = ['Month', 'Season', 'Annual', 'User-defined'] #, 'All Months']
self.time_unit_months_selection = self.month_names
self.time_unit_seasons_selection = ['DJF', 'MAM', 'JJA', 'SON']
self.selected_time_unit_month_indices = [0]
self.time_unit_seasons_month_indices = { 'DJF' : [0,1,11], 'MAM' : [2,3,4], 'JJA' : [5,6,7], 'SON' : [8,9,10] }
self.current_user_defined_time_unit_month_indices = []
self.time_unit_restricted_via_data_type = {}
self.time_unit_restricted_via_data_type['Map Grid'] = ['Month', 'Season', 'Annual', 'User-defined']
self.time_unit_restricted_via_parameter = {}
self.time_unit_restricted_via_parameter['temperature'] = {}
self.time_unit_restricted_via_parameter['temperature']['annual-temperature-range'] = ['Annual']
self.time_unit_restricted_via_parameter['temperature']['temperature-seasonality'] = ['Annual']
self.time_unit_restricted_via_parameter['precipitation'] = {}
self.time_unit_restricted_via_parameter['precipitation']['precipitation-seasonality'] = ['Annual']
self.time_unit_is_all_months = False
# Parameter text variables
self.parameter_group_text = tk.StringVar()
self.parameter_group_text.set(self.parameter_group_selection[0])
self.parameter_via_group_text = {}
self.parameter_via_group_text['temperature'] = tk.StringVar()
self.parameter_via_group_text['precipitation'] = tk.StringVar()
self.parameter_via_group_text['humidity'] = tk.StringVar()
self.parameter_via_group_text['sea-level-pressure'] = tk.StringVar()
#self.parameter_via_group_text['southern-oscillation'] = tk.StringVar()
self.parameter_via_group_text['temperature'].set(self.parameter_via_group_selection['temperature'][0])
self.parameter_via_group_text['precipitation'].set(self.parameter_via_group_selection['precipitation'][0])
self.parameter_via_group_text['humidity'].set(self.parameter_via_group_selection['humidity'][0])
self.parameter_via_group_text['sea-level-pressure'].set(self.parameter_via_group_selection['sea-level-pressure'][0])
#self.parameter_via_group_text['southern-oscillation'].set(self.parameter_via_group_selection['southern-oscillation'][0])
self.time_unit_text = tk.StringVar()
self.time_unit_text.set(self.time_unit_selection[0])
self.time_unit_months_text = tk.StringVar()
self.time_unit_months_text.set(self.time_unit_months_selection[0])
self.time_unit_seasons_text = tk.StringVar()
self.time_unit_seasons_text.set(self.time_unit_seasons_selection[0])
self.time_unit_other_text = tk.StringVar()
self.time_unit_other_text.set('')
# Register validation and selection behaviour methods
select_parameter_group = self.parameter_selection_frame.register(self.selectParameterGroup)
select_parameter = self.parameter_selection_frame.register(self.selectParameter)
select_time_unit = self.time_unit_frame.register(self.selectTimeUnit)
forced_shift_focus = self.time_unit_frame.register(self.shiftFocus)
# Entry/selection fields
self.parameter_group_menu = tk.OptionMenu(self.parameter_selection_frame, self.parameter_group_text, *self.parameter_group_selection)
self.parameter_group_menu.config(highlightthickness=0, anchor=tk.W)
self.parameter_group_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, group_code in enumerate(self.parameter_group_codes) :
self.parameter_group_menu['menu'].entryconfigure(i, command=(select_parameter_group, group_code))
# Dynamic parameter fields
self.parameter_via_group_menu = {}
for group_code in self.parameter_group_codes :
if len(self.parameter_via_group_codes[group_code]) > 1 or self.parameter_via_group_codes[group_code][0] != group_code :
self.parameter_via_group_menu[group_code] = tk.OptionMenu(self.parameter_selection_frame, self.parameter_via_group_text[group_code], *self.parameter_via_group_selection[group_code])
self.parameter_via_group_menu[group_code].config(highlightthickness=0, anchor=tk.W)
self.parameter_via_group_menu[group_code]['menu'].config(postcommand=(forced_shift_focus, True))
for i, parameter_code in enumerate(self.parameter_via_group_codes[group_code]) :
self.parameter_via_group_menu[group_code]['menu'].entryconfigure(i, command=(select_parameter, group_code, parameter_code))
else :
self.parameter_via_group_menu[group_code] = tk.Label(self.parameter_selection_frame, text='')
# Time unit fields
self.time_unit_menu = tk.OptionMenu(self.time_unit_frame, self.time_unit_text, *self.time_unit_selection)
self.time_unit_menu.config(highlightthickness=0, anchor=tk.W)
self.time_unit_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, selection in enumerate(self.time_unit_selection) :
self.time_unit_menu['menu'].entryconfigure(i, command=(select_time_unit, selection))
# Dynamic time unit fields
self.time_unit_months_menu = tk.OptionMenu(self.time_unit_frame, self.time_unit_months_text, *self.time_unit_months_selection)
self.time_unit_months_menu.config(highlightthickness=0, anchor=tk.W)
self.time_unit_months_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, selection in enumerate(self.time_unit_months_selection) :
self.time_unit_months_menu['menu'].entryconfigure(i, command=(select_time_unit, selection, 'months'))
self.time_unit_seasons_menu = tk.OptionMenu(self.time_unit_frame, self.time_unit_seasons_text, *self.time_unit_seasons_selection)
self.time_unit_seasons_menu.config(highlightthickness=0, anchor=tk.W)
self.time_unit_seasons_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, selection in enumerate(self.time_unit_seasons_selection) :
self.time_unit_seasons_menu['menu'].entryconfigure(i, command=(select_time_unit, selection, 'seasons'))
self.time_unit_other_label = tk.Label(self.time_unit_frame, textvariable=self.time_unit_other_text)
# Arrange fields on frame with labels
row = 1
tk.Label(self.parameter_selection_frame, text='Parameter:').grid(row=row, column=0, sticky=tk.NW+tk.SW, padx=0, pady=5)
self.parameter_group_menu.grid(row=row, column=1, sticky=tk.W+tk.E, padx=0, pady=5)
for group in self.parameter_via_group_codes :
self.parameter_via_group_menu[group].grid(row=row, column=2, columnspan=3, sticky=tk.W+tk.E, padx=5, pady=5)
self.parameter_via_group_menu[group].grid_remove()
self.current_parameter_group_field = self.parameter_via_group_menu[self.parameter_group_codes[0]]
self.current_parameter_group_field.grid()
row = 2
tk.Label(self.time_unit_frame, text='Time unit:').grid(row=row, column=0, sticky=tk.NW+tk.SW, padx=0, pady=5)
self.time_unit_menu.grid(row=row, column=1, sticky=tk.W+tk.E, padx=0, pady=5)
self.time_unit_seasons_menu.grid(row=row, column=2, columnspan=3, sticky=tk.W+tk.E, padx=5, pady=5)
self.time_unit_seasons_menu.grid_remove()
self.time_unit_other_label.grid(row=row, column=2, columnspan=3, sticky=tk.NW+tk.SW, padx=5, pady=5)
self.time_unit_other_label.grid_remove()
self.time_unit_months_menu.grid(row=row, column=2, columnspan=3, sticky=tk.W+tk.E, padx=5, pady=5)
self.current_time_unit_field = self.time_unit_months_menu
# Potentially restrict parameters and time units
self.restrictParameters()
self.restrictTimeUnit()
#self.parameter_selection_frame.grid(row=1, column=0, sticky=tk.NW+tk.SE, padx=5, pady=0)
# GUI for Step 3: Region Selection
def createRegionSelectionFrame(self) :
step_number = self.process_step['parameter_selection']['number']
self.region_selection_frame = self.main_frame
# Region selection lists
self.region_codes = ['globe', 'land', 'land-0-21KBP', 'ocean', 'ocean-0-21KBP', 'northern-hemisphere', 'southern-hemisphere', 'equatorial-pacific', 'n3', 'n3-4', 'n4',
'usa', 'canada', 'mexico', 'brazil', 'africa', 'europe', 'india', 'china', 'japan', 'australia-nz', 'central-asia',
'middle-east', 'east-former-soviet-union', 'west-former-soviet-union', 'rola', 'south-east-asia', 'west-pacific',
'alaska', 'greenland', 'antarctica', 'arctic-islands']
self.region_codes[5:] = sorted(self.region_codes[5:])
self.region_codes.append('user-defined')
self.region_code_map = {}
self.region_is_time_dependent = {}
self.region_selection = []
for region_code in self.region_codes :
if region_code == 'globe' :
region_name = 'Global'
elif region_code in ['usa', 'rola'] :
region_name = region_code.upper()
elif region_code in ['n3-4'] :
region_name = region_code.title().replace('-', '.')
elif region_code == 'australia-nz' :
region_name = 'Australia/NZ'
elif region_code in ['land', 'ocean'] :
region_name = region_code.title() + ' (fixed)'
elif region_code in ['land-0-21KBP'] :
region_name = 'Land (time dependent)'
elif region_code in ['ocean-0-21KBP'] :
region_name = 'Ocean (time dependent)'
else :
region_name = region_code.replace('-', ' ').title()
self.region_code_map[region_code] = region_name
if region_code in ['land-0-21KBP', 'ocean-0-21KBP'] :
self.region_is_time_dependent[region_code] = True
else :
self.region_is_time_dependent[region_code] = False
self.region_selection.append(region_name)
self.region_mask = self.data_file_helper.loadRegionMask(self.region_codes[0])
self.current_region = self.region_codes[0]
self.current_user_defined_region_mask = self.region_mask*0
# Region bounding box
self.region_bounding_box = {}
self.region_bounding_box['globe'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['land'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['ocean'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['land-0-21KBP'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['ocean-0-21KBP'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['northern-hemisphere'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['southern-hemisphere'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['equatorial-pacific'] = { 'centre': 180, 'lat' : [-30,30], 'lon' : [125,300], 'grid' : 10 }
self.region_bounding_box['n3'] = { 'centre': 180, 'lat' : [-30,30], 'lon' : [125,300], 'grid' : 10 }
self.region_bounding_box['n3-4'] = { 'centre': 180, 'lat' : [-30,30], 'lon' : [125,300], 'grid' : 10 }
self.region_bounding_box['n4'] = { 'centre': 180, 'lat' : [-30,30], 'lon' : [125,300], 'grid' : 10 }
self.region_bounding_box['usa'] = { 'centre': 0, 'lat' : [15,60], 'lon' : [-130,-55], 'grid' : 10 }
self.region_bounding_box['canada'] = { 'centre': 0, 'lat' : [35,80], 'lon' : [-150,-45], 'grid' : 10 }
self.region_bounding_box['mexico'] = { 'centre': 0, 'lat' : [5,40], 'lon' : [-125,-80], 'grid' : 10 }
self.region_bounding_box['brazil'] = { 'centre': 0, 'lat' : [-45,15], 'lon' : [-80,-25], 'grid' : 10 }
self.region_bounding_box['africa'] = { 'centre': 0, 'lat' : [-40,40], 'lon' : [-20,55], 'grid' : 10 }
self.region_bounding_box['europe'] = { 'centre': 0, 'lat' : [30,75], 'lon' : [-25,40], 'grid' : 10 }
self.region_bounding_box['india'] = { 'centre': 0, 'lat' : [0,45], 'lon' : [60,100], 'grid' : 10 }
self.region_bounding_box['china'] = { 'centre': 0, 'lat' : [15,60], 'lon' : [70,140], 'grid' : 10 }
self.region_bounding_box['japan'] = { 'centre': 0, 'lat' : [25,50], 'lon' : [125,150], 'grid' : 10 }
self.region_bounding_box['australia-nz'] = { 'centre': 180, 'lat' : [-50,-5], 'lon' : [110,185], 'grid' : 10 }
self.region_bounding_box['central-asia'] = { 'centre': 0, 'lat' : [20,60], 'lon' : [35,120], 'grid' : 10 }
self.region_bounding_box['middle-east'] = { 'centre': 0, 'lat' : [10,45], 'lon' : [30,65], 'grid' : 10 }
self.region_bounding_box['east-former-soviet-union'] = { 'centre': 180, 'lat' : [40,85], 'lon' : [55,195], 'grid' : 10 }
self.region_bounding_box['west-former-soviet-union'] = { 'centre': 0, 'lat' : [40,80], 'lon' : [15,65], 'grid' : 10 }
self.region_bounding_box['rola'] = { 'centre': 0, 'lat' : [-60,30], 'lon' : [-95,-45], 'grid' : 10 }
self.region_bounding_box['south-east-asia'] = { 'centre': 0, 'lat' : [-15,35], 'lon' : [65,155], 'grid' : 10 }
self.region_bounding_box['west-pacific'] = { 'centre': 180, 'lat' : [-35,25], 'lon' : [130,240], 'grid' : 10 }
self.region_bounding_box['alaska'] = { 'centre': 180, 'lat' : [50,75], 'lon' : [190,225], 'grid' : 10 }
self.region_bounding_box['greenland'] = { 'centre': 0, 'lat' : [55,90], 'lon' : [-75,-10], 'grid' : 10 }
self.region_bounding_box['antarctica'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
self.region_bounding_box['arctic-islands'] = { 'centre': 0, 'lat' : [55,85], 'lon' : [-130,-55], 'grid' : 10 }
self.region_bounding_box['user-defined'] = { 'centre': 0, 'lat' : [-90,90], 'lon' : [-180,180], 'grid' : 10 }
# Other parameters for regions
# Parameter text variables
self.region_selection_text = tk.StringVar()
self.region_selection_text.set(self.region_selection[0])
self.view_edit_region_button_text = tk.StringVar(value='View Region')
# Register validation and selection behaviour methods
select_region = self.region_selection_frame.register(self.selectRegion)
forced_shift_focus = self.region_selection_frame.register(self.shiftFocus)
# Entry/selection fields
self.region_selection_menu = tk.OptionMenu(self.region_selection_frame, self.region_selection_text, *self.region_selection)
self.region_selection_menu.config(highlightthickness=0, anchor=tk.W)
self.region_selection_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, selection in enumerate(self.region_codes) :
self.region_selection_menu['menu'].entryconfigure(i, command=(select_region, selection))
self.view_edit_region_button = tk.Button(self.region_selection_frame, textvariable=self.view_edit_region_button_text, state=tk.NORMAL, command=self.viewEditRegion)
# Arrange fields on frame with labels
row = 3
tk.Label(self.region_selection_frame, text='Region:').grid(row=row, column=0, sticky=tk.NW+tk.SW, padx=0, pady=5)
self.region_selection_menu.grid(row=row, column=1, sticky=tk.W+tk.E, padx=0, pady=5)
self.view_edit_region_button.grid(row=row, column=2, columnspan=2, sticky=tk.W, padx=5, pady=5)
# GUI for Step 4: Period
def createPeriodIntervalFrame(self) :
step_number = self.process_step['period_interval']['number']
self.period_interval_frame = self.main_frame
# Period and interval lists
self.period_postfix_keys = ['BP', 'AD']
self.period_postfix_selection = ['Before Present: <=1950', 'Anno Domini: 1-1989']
# Parameter text variables
self.period_text = { 'from' : tk.StringVar(), 'until' : tk.StringVar() }
self.period_postfix_text = { 'from' : tk.StringVar(), 'until' : tk.StringVar() }
self.period_postfix_text['from'].set(self.period_postfix_keys[0])
self.period_postfix_text['until'].set(self.period_postfix_keys[1])
self.interval_step_text = tk.StringVar()
self.interval_size_text = tk.StringVar()
self.current_interval_steps_text = tk.StringVar()
# Register validation and selection behaviour methods
validate_period = self.period_interval_frame.register(self.validatePeriod)
period_spinbox_arrow_press = self.period_interval_frame.register(self.periodSpinboxArrowPress)
select_period_postfix = self.period_interval_frame.register(self.selectPeriodPostfix)
validate_interval_step = self.period_interval_frame.register(self.validateIntervalStep)
validate_interval_size = self.period_interval_frame.register(self.validateIntervalSize)
interval_step_spinbox_arrow_press = self.period_interval_frame.register(self.intervalStepSpinboxArrowPress)
interval_size_spinbox_arrow_press = self.period_interval_frame.register(self.intervalSizeSpinboxArrowPress)
forced_shift_focus = self.period_interval_frame.register(self.shiftFocus)
# Entry/selection fields
period_from_frame = tk.Frame(self.period_interval_frame)
period_until_frame = tk.Frame(self.period_interval_frame)
interval_step_frame = tk.Frame(self.period_interval_frame)
interval_size_frame = tk.Frame(self.period_interval_frame)
self.period_ranges = { 'BP' : { 'min' : 0, 'max' : 22000, 'max-entry' : 21000 }, 'AD' : { 'min' : 1, 'max' : 1989 } }
self.current_period_values = { 'from' : range(20990, -1, -20), 'until' : range(1820, 1961, 20) }
self.period_bp_range_for_all_months = 1000 # used to avoid memory problems caused by 22000 spinbox values
self.previous_period_text_value = { 'from' : '150', 'until' : '1960' }
self.previous_period_changed_via = { 'from' : 'forced', 'until' : 'forced' }
self.current_valid_period_value = { 'from' : 150, 'until' : 1960 }
self.period_entry = {}
self.period_entry['from'] = tk.Spinbox(period_from_frame, textvariable=self.period_text['from'], values=tuple(map(str, self.current_period_values['from'])), width=6, justify=tk.CENTER)
self.period_entry['from'].config(validate='all', validatecommand=(validate_period, '%P', '%V', 'from'))
self.period_entry['from'].config(command=(period_spinbox_arrow_press, 'from'))
self.period_entry['until'] = tk.Spinbox(period_until_frame, textvariable=self.period_text['until'], values=tuple(map(str, self.current_period_values['until'])), width=6, justify=tk.CENTER)
self.period_entry['until'].config(validate='all', validatecommand=(validate_period, '%P', '%V', 'until'))
self.period_entry['until'].config(command=(period_spinbox_arrow_press, 'until'))
self.period_postfix_menu = {}
self.period_postfix_menu['from'] = tk.OptionMenu(period_from_frame, self.period_postfix_text['from'], *self.period_postfix_selection)
self.period_postfix_menu['until'] = tk.OptionMenu(period_until_frame, self.period_postfix_text['until'], *self.period_postfix_selection)
self.period_postfix_menu['from'].config(highlightthickness=0, anchor=tk.W)
self.period_postfix_menu['until'].config(highlightthickness=0, anchor=tk.W)
self.period_postfix_menu['from']['menu'].config(postcommand=(forced_shift_focus, True, 'from'))
self.period_postfix_menu['until']['menu'].config(postcommand=(forced_shift_focus, True, 'until'))
for i, selection in enumerate(self.period_postfix_keys) :
self.period_postfix_menu['from']['menu'].entryconfigure(i, command=(select_period_postfix, 'from', selection))
self.period_postfix_menu['until']['menu'].entryconfigure(i, command=(select_period_postfix, 'until', selection))
#self.period_postfix_menu['until']['menu'].entryconfigure(0, state=tk.DISABLED) # use if initial from is AD
if OPEN_INTERVALS :
self.interval_step_range = { 'min' : 1, 'max' : 10000 }
self.interval_step_values = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000]
self.current_interval_step_values = [1, 2, 5, 10, 20, 50, 100]
else :
self.interval_step_range = { 'min' : 10, 'max' : 10000 }
self.interval_step_values = [10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000]
self.current_interval_step_values = [10, 20, 50, 100]
self.current_valid_interval_step_value = 20
self.previous_interval_step_text_value = '20'
self.interval_step_entry = tk.Spinbox(interval_step_frame, textvariable=self.interval_step_text, values=tuple(map(str, self.current_interval_step_values)), width=6, justify=tk.CENTER)
self.interval_step_entry.config(validate='all', validatecommand=(validate_interval_step, '%P', '%V'))
self.interval_step_entry.config(command=(interval_step_spinbox_arrow_press))
self.current_interval_steps = 8
if OPEN_INTERVALS :
self.interval_size_range = { 'min' : 1, 'max' : 1000 }
self.interval_size_values = [1, 2, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 500, 1000]
self.current_interval_size_values = [1, 2, 5, 10, 20, 30, 40, 50, 60, 70, 80]
else :
self.interval_size_range = { 'min' : 10, 'max' : 100 }
self.interval_size_values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
self.current_interval_size_values = [10, 20, 30, 40, 50, 60, 70, 80]
self.current_valid_interval_size_value = 30
self.previous_interval_size_text_value = '30'
self.interval_size_entry = tk.Spinbox(interval_size_frame, textvariable=self.interval_size_text, values=tuple(map(str, self.current_interval_size_values)), width=6, justify=tk.CENTER)
self.interval_size_entry.config(validate='all', validatecommand=(validate_interval_size, '%P', '%V'))
self.interval_size_entry.config(command=(interval_size_spinbox_arrow_press))
# Arrange fields on frame with labels
row = 4
tk.Label(self.period_interval_frame, text='Period from:').grid(row=row, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.period_entry['from'].grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.period_postfix_menu['from'].grid(row=0, column=1, sticky=tk.W, padx=5, pady=0)
period_from_frame.grid(row=row, column=1, sticky=tk.NW+tk.SE, padx=0, pady=5)
row = 4
tk.Label(self.period_interval_frame, text='Interval step:').grid(row=row, column=2, sticky=tk.NW+tk.SW, padx=3, pady=0)
self.interval_step_entry.grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
tk.Label(interval_step_frame, text='years').grid(row=0, column=1, sticky=tk.NW+tk.SW, padx=5)#, pady=4)
interval_step_frame.grid(row=row, column=3, sticky=tk.NW+tk.SW, padx=0, pady=5)
tk.Button(self.period_interval_frame, text='?', command=self.periodAndIntervalHelp).grid(row=row, rowspan=2, column=4, sticky=tk.W, padx=5) # Help button
row = 5
tk.Label(self.period_interval_frame, text='Period until:').grid(row=row, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.period_entry['until'].grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.period_postfix_menu['until'].grid(row=0, column=1, sticky=tk.W, padx=5, pady=0)
period_until_frame.grid(row=row, column=1, sticky=tk.NW+tk.SE, padx=0, pady=5)
row = 5
tk.Label(self.period_interval_frame, text='Interval size:').grid(row=row, column=2, sticky=tk.NW+tk.SW, padx=3, pady=0)
self.interval_size_entry.grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
tk.Label(interval_size_frame, text='years').grid(row=0, column=1, sticky=tk.NW+tk.SW, padx=5)#, pady=4)
interval_size_frame.grid(row=row, column=3, sticky=tk.NW+tk.SW, padx=0, pady=5)
row = 8
tk.Label(self.period_interval_frame, textvariable=self.current_interval_steps_text).grid(row=row, column=0, columnspan=5, sticky=tk.NW+tk.SW, padx=0, pady=5)
self.period_interval_frame.columnconfigure(0, weight=1)
self.period_interval_frame.columnconfigure(1, weight=1000)
self.period_interval_frame.columnconfigure(2, weight=1)
self.period_interval_frame.columnconfigure(3, weight=1000)
self.period_interval_frame.columnconfigure(4, weight=1)
# Initilisation for Step 4: Set initial Period Interval Values
def setInitialPeriodIntervalValues(self) :
self.period_text['from'].set(str(self.current_valid_period_value['from']))
self.period_text['until'].set(str(self.current_valid_period_value['until']))
self.interval_step_text.set(str(self.current_valid_interval_step_value))
self.interval_size_text.set(str(self.current_valid_interval_size_value))
self.updateCurrentIntervalSteps()
# GUI for Step 5: Delta
def createDeltaFrame(self) :
step_number = self.process_step['delta']['number']
self.delta_frame = self.main_frame
# Delta reference period lists
self.delta_reference_period_codes = ['previous', 'next', 'present-day', 'oldest-record', 'user-defined']
self.delta_reference_value = { 'previous' : { 'year' : 150, 'postfix' : 'BP' }, 'next' : { 'year' : 1960, 'postfix' : 'AD' },
'present-day' : { 'year' : 1975, 'postfix' : 'AD' }, 'oldest-record' : { 'year' : 21000, 'postfix' : 'BP' },
'user-defined' : { 'year' : 170, 'postfix' : 'BP' } }
self.delta_reference_interval_pre_text = { 'previous' : '150 BP', 'next' : '1960 AD', 'present-day' : '1975 AD', 'oldest-record' : '21000 BP', 'user-defined' : '' }
self.delta_reference_interval_post_text = { 'previous' : ' (from)', 'next' : ' (until)', 'present-day' : ' (present day)', 'oldest-record' : ' (oldest record)', 'user-defined' : 'User-defined' }
self.utilise_delta_pre_text = { 'view' : 'View', 'files' : 'Generate' }
self.utilise_delta_post_text = ' change relative to:'
self.delta_as_percent_parameters = { 'temperature' : ['isothermality', 'temperature-seasonality'], 'precipitation' : ['mean-precipitation', 'precipitation-seasonality'], 'humidity' : [], 'sea-level-pressure' : [] } #, 'southern-oscillation' : [] }
self.delta_as_percent_parameters_defaults = { 'temperature' : { 'isothermality' : True, 'temperature-seasonality' : True },
'precipitation' : { 'mean-precipitation' : True, 'precipitation-seasonality' : True } }
# Delta text variables
self.utilise_delta = tk.IntVar()
self.utilise_delta.set(1)
self.utilise_delta_text = tk.StringVar()
self.utilise_delta_text.set(self.utilise_delta_pre_text['view'] + self.utilise_delta_post_text)
self.delta_as_percent = tk.IntVar()
self.delta_reference_interval_text = tk.StringVar()
self.delta_reference_interval_selection = []
for code in self.delta_reference_period_codes :
self.delta_reference_interval_selection.append(self.delta_reference_interval_pre_text[code] + self.delta_reference_interval_post_text[code])
self.delta_reference_interval_text.set(self.delta_reference_interval_selection[0])
self.delta_user_defined_reference_text = { 'year' : tk.StringVar(), 'postfix' : tk.StringVar() }
# Register validation and selection behaviour methods
select_delta_reference_interval = self.delta_frame.register(self.selectDeltaReferenceInterval)
forced_shift_focus = self.delta_frame.register(self.shiftFocus)
validate_delta_user_defined_reference = self.delta_frame.register(self.validateDeltaUserDefinedReference)
select_delta_user_defined_reference_postfix = self.delta_frame.register(self.selectDeltaUserDefinedReferencePostfix)
# Entry/selection fields
delta_select_frame = tk.Frame(self.delta_frame)
self.delta_checkbox = tk.Checkbutton(delta_select_frame, variable=self.utilise_delta, padx=0, command=self.deltaSelection)
self.delta_as_percent_checkbox = tk.Checkbutton(delta_select_frame, variable=self.delta_as_percent, text='Use % change', padx=0, state=tk.NORMAL, command=self.deltaAsPercentSelection)
delta_reference_frame = tk.Frame(self.delta_frame)
self.delta_reference_interval_menu = tk.OptionMenu(delta_reference_frame, self.delta_reference_interval_text, *self.delta_reference_interval_selection)
self.delta_reference_interval_menu.config(highlightthickness=0, anchor=tk.W, state=tk.NORMAL)
self.delta_reference_interval_menu['menu'].config(postcommand=(forced_shift_focus, True))
for i, code in enumerate(self.delta_reference_period_codes) :
self.delta_reference_interval_menu['menu'].entryconfigure(i, command=(select_delta_reference_interval, code))
self.current_delta_user_defined_reference_values = range(0, 1989, 20)
self.previous_delta_user_defined_reference_text_value = str(self.delta_reference_value['user-defined']['year'])
self.previous_delta_user_defined_reference_changed_via = 'forced'
self.current_valid_delta_user_defined_reference_value = self.delta_reference_value['user-defined']['year']
self.delta_user_defined_reference_frame = tk.Frame(delta_reference_frame)
self.delta_user_defined_reference_entry = tk.Spinbox(self.delta_user_defined_reference_frame, textvariable=self.delta_user_defined_reference_text['year'], values=tuple(map(str, self.current_delta_user_defined_reference_values)), width=6, justify=tk.CENTER)
self.delta_user_defined_reference_entry.config(validate='all', validatecommand=(validate_delta_user_defined_reference, '%P', '%V'))
self.delta_user_defined_reference_entry.config(command=self.deltaUserDefinedReferenceSpinboxArrowPress)
self.delta_user_defined_reference_postfix_menu = tk.OptionMenu(self.delta_user_defined_reference_frame, self.delta_user_defined_reference_text['postfix'], *self.period_postfix_selection)
self.delta_user_defined_reference_postfix_menu.config(highlightthickness=0, anchor=tk.W)
self.delta_user_defined_reference_postfix_menu['menu'].config(postcommand=(forced_shift_focus, True, 'delta-user-defined-reference'))
for i, selection in enumerate(self.period_postfix_keys) :
self.delta_user_defined_reference_postfix_menu['menu'].entryconfigure(i, command=(select_delta_user_defined_reference_postfix, selection))
self.delta_user_defined_reference_text['postfix'].set(self.delta_reference_value['user-defined']['postfix'])
self.delta_user_defined_reference_text['year'].set(str(self.delta_reference_value['user-defined']['year']))
# Arrange fields on frame with labels
row = 6
self.delta_checkbox.grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
tk.Label(delta_select_frame, textvariable=self.utilise_delta_text).grid(row=0, column=1, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.delta_as_percent_checkbox.grid(row=1, column=1, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.deltaAsPercentInclusion()
delta_select_frame.grid(row=row, column=0, columnspan=2, sticky=tk.NW+tk.SW, padx=0, pady=5)
self.delta_reference_interval_menu.grid(row=0, column=0, sticky=tk.W, padx=0, pady=0)
self.delta_user_defined_reference_entry.grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=5, pady=0)
self.delta_user_defined_reference_postfix_menu.grid(row=0, column=1, sticky=tk.W, padx=0, pady=0)
self.delta_user_defined_reference_frame.grid(row=0, column=1, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.delta_user_defined_reference_frame.grid_remove()
delta_reference_frame.grid(row=row, column=2, columnspan=2, sticky=tk.NW+tk.SW, padx=5, pady=5)
tk.Button(self.delta_frame, text='?', command=self.deltaAndBiasCorrectionHelp).grid(row=row, rowspan=2, column=4, sticky=tk.W, padx=5) # Help button
# GUI for Step 6: Bias Correction
def createBiasCorrectionFrame(self) :
step_number = self.process_step['bias_correction']['number']
self.bias_correction_frame = self.main_frame
# Delta text variables
self.utilise_bias_correction = tk.IntVar()
self.utilise_bias_correction.set(0)
self.enabled_bias_correction_set = True # initial setting when enabled
# Register validation and selection behaviour methods
forced_shift_focus = self.bias_correction_frame.register(self.shiftFocus)
# Entry/selection fields
bias_correction_select_frame = tk.Frame(self.bias_correction_frame)
self.bias_correction_checkbox = tk.Checkbutton(bias_correction_select_frame, variable=self.utilise_bias_correction, padx=0, command=self.biasCorrectionSelection)
self.bias_correction_checkbox.configure(state=tk.DISABLED)
self.bias_correction_label = tk.Label(bias_correction_select_frame, text='Apply model bias correction')
self.bias_correction_label.configure(state=tk.DISABLED)
# Arrange fields on frame with labels
row = 7
self.bias_correction_checkbox.grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=0, pady=0)
self.bias_correction_label.grid(row=0, column=1, sticky=tk.NW+tk.SW, padx=0, pady=0)
bias_correction_select_frame.grid(row=row, column=0, columnspan=2, sticky=tk.NW+tk.SW, padx=0, pady=0)
# GUI for Step 7: Generation
def createGenerationFrame(self) :
step_number = self.process_step['generation']['number']
self.generation_frame = self.main_frame
self.generation_options = { 'view' : { 'map' : 'View map grid plots', 'series' : 'View series plot' },
'files' : { 'map' : 'Generate the grid data files', 'series' : 'Generate the series data file' } }
# Get current config tool options
tool_option_values = self.getToolOptions()
# View
self.view_frame = tk.Frame(self.generation_frame)
self.view_button = tk.Button(self.view_frame, text='View', state=tk.NORMAL, command=self.viewPlot)
self.view_label_text = tk.StringVar(value=self.generation_options['view']['map'])
self.view_label = tk.Label(self.view_frame, textvariable=self.view_label_text, justify=tk.LEFT)
self.view_button.grid(row=0, column=0, sticky=tk.W, padx=0, pady=5)
tk.Label(self.view_frame, text=' :').grid(row=0, column=1, padx=0, pady=5)
self.view_label.grid(row=0, column=2, sticky=tk.NW+tk.SW, padx=0, pady=5)