-
Notifications
You must be signed in to change notification settings - Fork 1
/
SARDM_v0_8.py
5242 lines (4511 loc) · 364 KB
/
SARDM_v0_8.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 string
import sys
import time
import Tkinter as tk
from os import chdir, environ, getcwd, listdir, mkdir, path
from subprocess import call
from shutil import copyfile
from tkFileDialog import *
from tkFont import Font
from tkMessageBox import *
import warnings
warnings.simplefilter('ignore')
# Python extension module NumPy (requires extension installation)
import numpy as np
# Python extension module Matplot
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from matplotlib import rcParams
# Tool library modules
from MpFileExtractorAndGeneratorHelper import MpFileExtractorAndGeneratorHelper
from MpParameterBoundConstraintHelper import MpParameterBoundConstraintHelper
from SampleGenerator import SampleGenerator
# TEST FLAG:
# * Saves the generated template
# * Puts a pause in the generated batch file
DEBUG = False
## Configuration (future versions could load from a file)
## * Configures what Latin Hypercube Sampling distributions are available for each parameter
## * Maps the file row and column locations of the parameters
## * Configures the desired output formats for the parameters
## * Configures constraints for the parameters
## * Configures parameter data types
## * Configures the location of the RAMAS Metapop executable
## * Configures the names of the RAMAS Metapop output files
class MetapopConfiguration :
# Initialise with the default config
def __init__(self, user_app_data_dir, config_file) :
# Configuration file (initially in the same directory as the tool, but copied to user application data directory)
self.tool_config_file = config_file
# User application data directory
self.user_application_data_directory = user_app_data_dir
# Configure parameter list in desired order
self.parameters = ['Initial Abundance', 'Rmax', 'Carrying Capacity', 'Allee Effect', 'Probability of a Catastrophe 1', 'Local Multiplier 1', 'Stage Multiplier 1',
'Probability of a Catastrophe 2', 'Local Multiplier 2', 'Stage Multiplier 2', 'Dispersal Matrix', 'Correlation Matrix', 'Fecundity Rates',
'Survival Rates', 'Environmental Variation']
# Configure what Latin Hypercube Sampling distributions are available for each parameter
self.lhs_distributions = ['Uniform', 'Gaussian', 'Triangular', 'Lognormal', 'Beta']
self.lhs_distribution_settings = {}
self.lhs_distribution_settings['Uniform'] = [{ 'name' : 'Lower', 'postfix' : '%'}, { 'name' : 'Upper', 'postfix' : '%'}]
self.lhs_distribution_settings['Gaussian'] = [{ 'name' : 'Mean', 'postfix' : '%'}, { 'name' : 'Std. Dev.', 'postfix' : '%'}]
self.lhs_distribution_settings['Triangular'] = [{ 'name' : 'Lower (a)', 'postfix' : '%'}, { 'name' : 'Upper (b)', 'postfix' : '%'}, { 'name' : 'Mode (c)', 'postfix' : '%'}]
self.lhs_distribution_settings['Lognormal'] = [{ 'name' : 'Lower', 'postfix' : '%'}, { 'name' : 'Scale', 'postfix' : '%'}, { 'name' : 'Sigma', 'postfix' : ''}]
self.lhs_distribution_settings['Beta'] = [{ 'name' : 'Lower', 'postfix' : '%'}, { 'name' : 'Upper', 'postfix' : '%'}, { 'name' : 'Alpha', 'postfix' : ''}, { 'name' : 'Beta', 'postfix' : ''}]
self.parameter_includes_lhs_distributions = {}
self.parameter_includes_lhs_distributions['Rmax'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Carrying Capacity'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Allee Effect'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Probability of a Catastrophe 1'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Local Multiplier 1'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Stage Multiplier 1'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Probability of a Catastrophe 2'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Local Multiplier 2'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Stage Multiplier 2'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Dispersal Matrix'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Correlation Matrix'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Fecundity Rates'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Survival Rates'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Environmental Variation'] = self.lhs_distributions
self.parameter_includes_lhs_distributions['Initial Abundance'] = self.lhs_distributions
# Configure parameter mapping to MP file.
# * Dynamic variables define mappings to variables within the MP file needed to define parameter mappings.
# * Options define extracted values that alter the way parameters are processed.
# * Alternatives define different extraction specifications dependent on options.
# * Conditions for parameter inclusion defines a pattern match for a specified line or list of options.
# * Also alternative conditions may be defined dependent on options.
# * Additional parameters may relate to other model variables including links to temporal trends and other files.
self.parameter_mapping = {}
self.parameter_mapping['dynamic_variables'] = {}
self.parameter_mapping['dynamic_variables']['lifestages'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 10, 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['dynamic_variables']['female_stages'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 39, 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['dynamic_variables']['populations'] = { 'pattern' : '^Migration', 'value' : 'line-45' }
self.parameter_mapping['dynamic_variables']['migration_label_line'] = { 'pattern' : '^Migration', 'value' : 'line' }
self.parameter_mapping['dynamic_variables']['correlation_label_line'] = { 'pattern' : '^Correlation', 'value' : 'line' }
self.parameter_mapping['dynamic_variables']['stage_matrix_label_line'] = { 'pattern' : '^\d+ type\(s\) of stage matrix', 'value' : 'line' }
self.parameter_mapping['dynamic_variables']['stage_matrix_types'] = { 'pattern' : '^\d+ type\(s\) of stage matrix', 'value' : 'int(match.split()[0])' }
self.parameter_mapping['dynamic_variables']['std_dev_matrix_label_line'] = { 'pattern' : '^\d+ type\(s\) of st\.dev\. matrix', 'value' : 'line' }
self.parameter_mapping['dynamic_variables']['std_dev_matrix_types'] = { 'pattern' : '^\d+ type\(s\) of st\.dev\. matrix', 'value' : 'int(match.split()[0])' }
self.parameter_mapping['dynamic_variables']['constraints_matrix_label_line'] = { 'pattern' : '^Constraints Matrix', 'value' : 'line' }
self.parameter_mapping['dynamic_variables']['simulation_results_line'] = { 'pattern' : '^Simulation results', 'value' : 'line' }
self.parameter_mapping['dynamic_variables']['end_of_file_line'] = { 'pattern' : '^-End of file-', 'value' : 'line' }
self.parameter_mapping['search_for_dynamic_variables_from_row'] = 7 # ignore comment rows
self.parameter_mapping['omit_results_from_mp_template'] = { 'omit' : True, 'from_line' : 'simulation_results_line', 'to_line' : 'end_of_file_line-1' }
self.parameter_mapping['subset_masks'] = {}
self.parameter_mapping['subset_masks']['Fecundity Rates'] = { 'inverse' : True, 'number_rows' : 'lifestages', 'number_columns' : 'lifestages', 'start_row' : 'constraints_matrix_label_line+1', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['subset_masks']['Survival Rates'] = { 'inverse' : False, 'number_rows' : 'lifestages', 'number_columns' : 'lifestages', 'start_row' : 'constraints_matrix_label_line+1', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['options'] = {}
self.parameter_mapping['options']['Dispersal Matrix'] = {}
self.parameter_mapping['options']['Dispersal Matrix']['uses_function'] = { 'line' : 'migration_label_line+1', 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Dispersal Matrix']['a'] = { 'line' : 'migration_label_line+2', 'value' : 'float(line.split(\',\')[0])' }
self.parameter_mapping['options']['Dispersal Matrix']['b'] = { 'line' : 'migration_label_line+2', 'value' : 'float(line.split(\',\')[1])' }
self.parameter_mapping['options']['Dispersal Matrix']['c'] = { 'line' : 'migration_label_line+2', 'value' : 'float(line.split(\',\')[2])' }
self.parameter_mapping['options']['Dispersal Matrix']['Dmax'] = { 'line' : 'migration_label_line+2', 'value' : 'float(line.split(\',\')[3])' }
self.parameter_mapping['options']['Correlation Matrix'] = {}
self.parameter_mapping['options']['Correlation Matrix']['uses_function'] = { 'line' : 'correlation_label_line+1', 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Correlation Matrix']['a'] = { 'line' : 'correlation_label_line+2', 'value' : 'float(line.split(\',\')[0])' }
self.parameter_mapping['options']['Correlation Matrix']['b'] = { 'line' : 'correlation_label_line+2', 'value' : 'float(line.split(\',\')[1])' }
self.parameter_mapping['options']['Correlation Matrix']['c'] = { 'line' : 'correlation_label_line+2', 'value' : 'float(line.split(\',\')[2])' }
self.parameter_mapping['options']['Rmax'] = {}
self.parameter_mapping['options']['Rmax']['density_dependence_type_population_specific'] = { 'line' : 33, 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Rmax']['density_dependence_type_for_all'] = { 'from_line' : 34, 'lines' : 1, 'values' : 'line.split()[0]' }
self.parameter_mapping['options']['Rmax']['density_dependence_type_per_population'] = { 'from_line' : 45, 'lines' : 'populations', 'values' : 'line.split(\',\')[4]' }
self.parameter_mapping['options']['Carrying Capacity'] = {}
self.parameter_mapping['options']['Carrying Capacity']['density_dependence_type_population_specific'] = { 'line' : 33, 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Carrying Capacity']['density_dependence_type_for_all'] = { 'from_line' : 34, 'lines' : 1, 'values' : 'line.split()[0]' }
self.parameter_mapping['options']['Carrying Capacity']['density_dependence_type_per_population'] = { 'from_line' : 45, 'lines' : 'populations', 'values' : 'line.split(\',\')[4]' }
self.parameter_mapping['options']['Allee Effect'] = {}
self.parameter_mapping['options']['Allee Effect']['density_dependence_type_population_specific'] = { 'line' : 33, 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Allee Effect']['density_dependence_type_for_all'] = { 'from_line' : 34, 'lines' : 1, 'values' : 'line.split()[0]' }
self.parameter_mapping['options']['Allee Effect']['density_dependence_type_per_population'] = { 'from_line' : 45, 'lines' : 'populations', 'values' : 'line.split(\',\')[4]' }
self.parameter_mapping['options']['Probability of a Catastrophe 1'] = {}
self.parameter_mapping['options']['Probability of a Catastrophe 1']['density_dependence_type_population_specific'] = { 'line' : 33, 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Probability of a Catastrophe 1']['density_dependence_type_for_all'] = { 'from_line' : 34, 'lines' : 1, 'values' : 'line.split()[0]' }
self.parameter_mapping['options']['Probability of a Catastrophe 1']['density_dependence_type_per_population'] = { 'from_line' : 45, 'lines' : 'populations', 'values' : 'line.split(\',\')[4]' }
self.parameter_mapping['options']['Probability of a Catastrophe 1']['catastrophe_extent'] = { 'line' : 13, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Probability of a Catastrophe 1']['catastrophe_affects'] = { 'line' : 14, 'value_list' : 'line.strip().split(\',\')' }
self.parameter_mapping['options']['Local Multiplier 1'] = {}
self.parameter_mapping['options']['Local Multiplier 1']['density_dependence_type_population_specific'] = { 'line' : 33, 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Local Multiplier 1']['density_dependence_type_for_all'] = { 'from_line' : 34, 'lines' : 1, 'values' : 'line.split()[0]' }
self.parameter_mapping['options']['Local Multiplier 1']['density_dependence_type_per_population'] = { 'from_line' : 45, 'lines' : 'populations', 'values' : 'line.split(\',\')[4]' }
self.parameter_mapping['options']['Local Multiplier 1']['catastrophe_extent'] = { 'line' : 13, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Local Multiplier 1']['catastrophe_affects'] = { 'line' : 14, 'value_list' : 'line.strip().split(\',\')' }
self.parameter_mapping['options']['Stage Multiplier 1'] = {}
self.parameter_mapping['options']['Stage Multiplier 1']['catastrophe_extent'] = { 'line' : 13, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Stage Multiplier 1']['catastrophe_affects'] = { 'line' : 14, 'value_list' : 'line.strip().split(\',\')' }
self.parameter_mapping['options']['Probability of a Catastrophe 2'] = {}
self.parameter_mapping['options']['Probability of a Catastrophe 2']['density_dependence_type_population_specific'] = { 'line' : 33, 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Probability of a Catastrophe 2']['density_dependence_type_for_all'] = { 'from_line' : 34, 'lines' : 1, 'values' : 'line.split()[0]' }
self.parameter_mapping['options']['Probability of a Catastrophe 2']['density_dependence_type_per_population'] = { 'from_line' : 45, 'lines' : 'populations', 'values' : 'line.split(\',\')[4]' }
self.parameter_mapping['options']['Probability of a Catastrophe 2']['catastrophe_extent'] = { 'line' : 20, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Probability of a Catastrophe 2']['catastrophe_affects'] = { 'line' : 21, 'value_list' : 'line.strip().split(\',\')' }
self.parameter_mapping['options']['Local Multiplier 2'] = {}
self.parameter_mapping['options']['Local Multiplier 2']['density_dependence_type_population_specific'] = { 'line' : 33, 'value' : 'line.split()[0]' }
self.parameter_mapping['options']['Local Multiplier 2']['density_dependence_type_for_all'] = { 'from_line' : 34, 'lines' : 1, 'values' : 'line.split()[0]' }
self.parameter_mapping['options']['Local Multiplier 2']['density_dependence_type_per_population'] = { 'from_line' : 45, 'lines' : 'populations', 'values' : 'line.split(\',\')[4]' }
self.parameter_mapping['options']['Local Multiplier 2']['catastrophe_extent'] = { 'line' : 20, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Local Multiplier 2']['catastrophe_affects'] = { 'line' : 21, 'value_list' : 'line.strip().split(\',\')' }
self.parameter_mapping['options']['Stage Multiplier 2'] = {}
self.parameter_mapping['options']['Stage Multiplier 2']['catastrophe_extent'] = { 'line' : 20, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Stage Multiplier 2']['catastrophe_affects'] = { 'line' : 21, 'value_list' : 'line.strip().split(\',\')' }
self.parameter_mapping['options']['Probability of a Catastrophe 1 other extent'] = {}
self.parameter_mapping['options']['Probability of a Catastrophe 1 other extent']['catastrophe_extent'] = { 'line' : 13, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Probability of a Catastrophe 2 other extent'] = {}
self.parameter_mapping['options']['Probability of a Catastrophe 2 other extent']['catastrophe_extent'] = { 'line' : 20, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Fecundity Rates'] = {}
self.parameter_mapping['options']['Fecundity Rates']['sex_structure'] = { 'line' : 38, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Fecundity Rates']['mating_system'] = { 'line' : 40, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Survival Rates'] = {}
self.parameter_mapping['options']['Survival Rates']['sex_structure'] = { 'line' : 38, 'value' : 'line.strip()' }
self.parameter_mapping['options']['Survival Rates']['mating_system'] = { 'line' : 40, 'value' : 'line.strip()' }
self.parameter_mapping['alternatives'] = {}
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1'] = {}
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1']['Local'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'max', 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 13, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1']['Correlated'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'max', 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 13, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1']['Regional'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'max', 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 12, 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Stage Multiplier 1'] = {}
self.parameter_mapping['alternatives']['Stage Multiplier 1']['option'] = 'catastrophe_affects'
self.parameter_mapping['alternatives']['Stage Multiplier 1']['Abundances'] = { 'mask_values' : [1], 'number_rows' : 1, 'number_columns' : 'lifestages', 'start_row' : 'constraints_matrix_label_line+2*lifestages+2', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['alternatives']['Stage Multiplier 1']['Vital Rates'] = { 'mask_values' : [1], 'number_rows' : 'lifestages', 'number_columns' : 'lifestages', 'start_row' : 'constraints_matrix_label_line+lifestages+2', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2'] = {}
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2']['Local'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'max', 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 20, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2']['Correlated'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'max', 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 20, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2']['Regional'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'max', 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 19, 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Stage Multiplier 2'] = {}
self.parameter_mapping['alternatives']['Stage Multiplier 2']['option'] = 'catastrophe_affects'
self.parameter_mapping['alternatives']['Stage Multiplier 2']['Abundances'] = { 'mask_values' : [1], 'number_rows' : 1, 'number_columns' : 'lifestages', 'start_row' : 'constraints_matrix_label_line+3*lifestages+3', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['alternatives']['Stage Multiplier 2']['Vital Rates'] = { 'mask_values' : [1], 'number_rows' : 'lifestages', 'number_columns' : 'lifestages', 'start_row' : 'constraints_matrix_label_line+2*lifestages+3', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['alternatives']['Dispersal Matrix'] = {}
self.parameter_mapping['alternatives']['Dispersal Matrix']['option'] = 'uses_function'
self.parameter_mapping['alternatives']['Dispersal Matrix']['FALSE'] = { 'number_rows' : 'populations', 'number_columns' : 'populations', 'start_row' : 'migration_label_line+3', 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Dispersal Matrix']['TRUE'] = { 'calculate_matrix' : { 'type' : 'population', 'matrix' : 'dispersal', 'parameters' : {} }, 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 'migration_label_line+2', 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Correlation Matrix'] = {}
self.parameter_mapping['alternatives']['Correlation Matrix']['option'] = 'uses_function'
self.parameter_mapping['alternatives']['Correlation Matrix']['FALSE'] = { 'under_diagonal_only' : '', 'number_rows' : 'populations', 'number_columns' : 'populations', 'start_row' : 'correlation_label_line+3', 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Correlation Matrix']['TRUE'] = { 'calculate_matrix' : { 'type' : 'population', 'matrix' : 'correlation', 'parameters' : {} }, 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 'correlation_label_line+2', 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1 other extent'] = {}
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1 other extent']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1 other extent']['Local'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 12, 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1 other extent']['Correlated'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 12, 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 1 other extent']['Regional'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 13, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2 other extent'] = {}
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2 other extent']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2 other extent']['Local'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 19, 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2 other extent']['Correlated'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 19, 'start_column' : 1, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Probability of a Catastrophe 2 other extent']['Regional'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 20, 'delimiter' : ',' }
self.parameter_mapping['alternatives']['Fecundity Rates'] = {}
self.parameter_mapping['alternatives']['Fecundity Rates']['option'] = 'sex_structure'
fecundity_rates_submatrix_mask = { 'rows' : 'first' }
self.parameter_mapping['alternatives']['Fecundity Rates']['OnlyFemale'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'whole_matrix' : fecundity_rates_submatrix_mask } }
self.parameter_mapping['alternatives']['Fecundity Rates']['OnlyMale'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'whole_matrix' : fecundity_rates_submatrix_mask } }
self.parameter_mapping['alternatives']['Fecundity Rates']['AllIndividuals'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'whole_matrix' : fecundity_rates_submatrix_mask } }
self.parameter_mapping['alternatives']['Fecundity Rates']['TwoSexes'] = { 'option' : 'mating_system' }
self.parameter_mapping['alternatives']['Fecundity Rates']['TwoSexes']['Monogamous'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'quadrants' : { 'divide_at' : 'female_stages', 'upper_left' : fecundity_rates_submatrix_mask, 'lower_left' : fecundity_rates_submatrix_mask } } }
self.parameter_mapping['alternatives']['Fecundity Rates']['TwoSexes']['Polygynous'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'quadrants' : { 'divide_at' : 'female_stages', 'upper_left' : fecundity_rates_submatrix_mask, 'lower_left' : fecundity_rates_submatrix_mask } } }
self.parameter_mapping['alternatives']['Fecundity Rates']['TwoSexes']['Polyandrous'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'quadrants' : { 'divide_at' : 'female_stages', 'upper_right' : fecundity_rates_submatrix_mask, 'lower_right' : fecundity_rates_submatrix_mask } } }
self.parameter_mapping['alternatives']['Survival Rates'] = {}
self.parameter_mapping['alternatives']['Survival Rates']['option'] = 'sex_structure'
survival_rates_submatrix_mask = { 'rows' : 'all' }
self.parameter_mapping['alternatives']['Survival Rates']['OnlyFemale'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'whole_matrix' : survival_rates_submatrix_mask } }
self.parameter_mapping['alternatives']['Survival Rates']['OnlyMale'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'whole_matrix' : survival_rates_submatrix_mask } }
self.parameter_mapping['alternatives']['Survival Rates']['AllIndividuals'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'whole_matrix' : survival_rates_submatrix_mask } }
self.parameter_mapping['alternatives']['Survival Rates']['TwoSexes'] = { 'option' : 'mating_system' }
self.parameter_mapping['alternatives']['Survival Rates']['TwoSexes']['Monogamous'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'quadrants' : { 'divide_at' : 'female_stages', 'upper_left' : survival_rates_submatrix_mask, 'lower_right' : survival_rates_submatrix_mask } } }
self.parameter_mapping['alternatives']['Survival Rates']['TwoSexes']['Polygynous'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'quadrants' : { 'divide_at' : 'female_stages', 'upper_left' : survival_rates_submatrix_mask, 'lower_right' : survival_rates_submatrix_mask } } }
self.parameter_mapping['alternatives']['Survival Rates']['TwoSexes']['Polyandrous'] = { 'subset_of' : 'Stage Matrix', 'subset_mask' : { 'quadrants' : { 'divide_at' : 'female_stages', 'upper_left' : survival_rates_submatrix_mask, 'lower_right' : survival_rates_submatrix_mask } } }
self.parameter_mapping['alternatives']['conditions'] = {}
self.parameter_mapping['alternatives']['conditions']['Rmax'] = {}
self.parameter_mapping['alternatives']['conditions']['Rmax']['option'] = 'density_dependence_type_population_specific'
self.parameter_mapping['alternatives']['conditions']['Rmax']['No'] = { 'option' : 'density_dependence_type_for_all', 'values' : [], 'match_any' : ['LO', 'BH', 'LA', 'BA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Rmax']['Yes'] = { 'option' : 'density_dependence_type_per_population', 'values' : [], 'match_any' : ['LO', 'BH', 'LA', 'BA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Carrying Capacity'] = {}
self.parameter_mapping['alternatives']['conditions']['Carrying Capacity']['option'] = 'density_dependence_type_population_specific'
self.parameter_mapping['alternatives']['conditions']['Carrying Capacity']['No'] = { 'option' : 'density_dependence_type_for_all', 'values' : [], 'match_any' : ['LO', 'BH', 'CE', 'LA', 'BA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Carrying Capacity']['Yes'] = { 'option' : 'density_dependence_type_per_population', 'values' : [], 'match_any' : ['LO', 'BH', 'CE', 'LA', 'BA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Allee Effect'] = {}
self.parameter_mapping['alternatives']['conditions']['Allee Effect']['option'] = 'density_dependence_type_population_specific'
self.parameter_mapping['alternatives']['conditions']['Allee Effect']['No'] = { 'option' : 'density_dependence_type_for_all', 'values' : [], 'match_any' : ['EA', 'LA', 'BA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Allee Effect']['Yes'] = { 'option' : 'density_dependence_type_per_population', 'values' : [], 'match_any' : ['EA', 'LA', 'BA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1'] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['precondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['precondition']['option'] = 'density_dependence_type_population_specific'
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['precondition']['No'] = { 'option' : 'density_dependence_type_for_all', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['precondition']['Yes'] = { 'option' : 'density_dependence_type_per_population', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][False] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][False]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][False]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][False]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][True] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][True]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][True]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 1']['postcondition'][True]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1'] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['precondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['precondition']['option'] = 'density_dependence_type_population_specific'
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['precondition']['No'] = { 'option' : 'density_dependence_type_for_all', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['precondition']['Yes'] = { 'option' : 'density_dependence_type_per_population', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][False] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][False]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][False]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][False]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : [], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][True] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][True]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][True]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 1']['postcondition'][True]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : [], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 1'] = {}
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 1']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 1']['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 1']['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 1']['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2'] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['precondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['precondition']['option'] = 'density_dependence_type_population_specific'
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['precondition']['No'] = { 'option' : 'density_dependence_type_for_all', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['precondition']['Yes'] = { 'option' : 'density_dependence_type_per_population', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][False] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][False]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][False]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][False]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : [], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][True] = {}
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][True]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][True]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Probability of a Catastrophe 2']['postcondition'][True]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : [], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2'] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['precondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['precondition']['option'] = 'density_dependence_type_population_specific'
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['precondition']['No'] = { 'option' : 'density_dependence_type_for_all', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['precondition']['Yes'] = { 'option' : 'density_dependence_type_per_population', 'values' : [], 'match_any' : ['EX', 'CE', 'EA', 'CA', 'UD'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][False] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][False]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][False]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][False]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : ['Vital Rates'], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][True] = {}
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][True]['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][True]['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Local Multiplier 2']['postcondition'][True]['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates', 'Carrying Capacities', 'Dispersal Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 2'] = {}
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 2']['option'] = 'catastrophe_extent'
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 2']['Local'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 2']['Correlated'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['alternatives']['conditions']['Stage Multiplier 2']['Regional'] = { 'option' : 'catastrophe_affects', 'values' : [], 'match_any' : ['Abundances', 'Vital Rates'], 'match_none' : [], 'satisfied' : False }
self.parameter_mapping['conditions'] = {}
self.parameter_mapping['conditions']['Rmax'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Carrying Capacity'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Allee Effect'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Probability of a Catastrophe 1'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Local Multiplier 1'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Stage Multiplier 1'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Probability of a Catastrophe 2'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Local Multiplier 2'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Stage Multiplier 2'] = { 'choose_alternative' : True }
self.parameter_mapping['conditions']['Dispersal Matrix'] = { 'condition' : 'populations > 1', 'satisfied' : False }
self.parameter_mapping['conditions']['Correlation Matrix'] = { 'condition' : 'populations > 1', 'satisfied' : False }
self.parameter_mapping['additional'] = {}
self.parameter_mapping['additional']['Replications'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 7, 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['additional']['Duration'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 8, 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['additional']['Populations'] = { 'value' : 'populations' }
self.parameter_mapping['additional']['Density dependence'] = { 'line' : 26, 'value' : 'line.strip()' }
self.parameter_mapping['additional']['Stages'] = { 'value' : 'lifestages' }
self.parameter_mapping['additional']['population_coordinates'] = { 'number_rows' : 'populations', 'number_columns' : 2, 'start_row' : 45, 'start_column' : 2, 'delimiter' : ',' }
self.parameter_mapping['additional']['temporal_trend_in_k'] = { 'may_link_to_temporal_trend_files' : True, 'link_to_parameter' : 'Carrying Capacity', 'use_file_value' : 'first', 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 10, 'delimiter' : ',' }
self.parameter_mapping['additional']['relative_fecundity'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 16, 'delimiter' : ',' }
self.parameter_mapping['additional']['relative_survival'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 17, 'delimiter' : ',' }
self.parameter_mapping['additional']['relative_dispersal'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 25, 'delimiter' : ',' }
self.parameter_mapping['additional']['relative_variability_fecundity'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 26, 'delimiter' : ',' }
self.parameter_mapping['additional']['relative_variability_survival'] = { 'may_link_to_temporal_trend_files' : True, 'copy_files' : True, 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 27, 'delimiter' : ',' }
self.parameter_mapping['additional']['user_defined_density_dependence_function'] = { 'file_with_full_path' : True, 'line' : 35, 'value' : 'line.strip()' }
self.parameter_mapping['additional']['map_features'] = { 'file_with_full_path' : True, 'line' : 1, 'value' : 'line.split(\'map=\').pop().strip()' }
self.parameter_mapping['additional']['Probability of a Catastrophe 1 other extent'] = { 'choose_alternative' : True }
self.parameter_mapping['additional']['Probability of a Catastrophe 2 other extent'] = { 'choose_alternative' : True }
self.parameter_mapping['Rmax'] = { 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 6, 'delimiter' : ',' }
self.parameter_mapping['Carrying Capacity'] = { 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 7, 'delimiter' : ',' }
self.parameter_mapping['Allee Effect'] = { 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 9, 'delimiter' : ',' }
self.parameter_mapping['Probability of a Catastrophe 1'] = { 'choose_alternative' : True }
self.parameter_mapping['Local Multiplier 1'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'first', 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 12, 'delimiter' : ',' }
self.parameter_mapping['Stage Multiplier 1'] = { 'choose_alternative' : True }
self.parameter_mapping['Probability of a Catastrophe 2'] = { 'choose_alternative' : True }
self.parameter_mapping['Local Multiplier 2'] = { 'may_link_to_temporal_trend_files' : True, 'use_file_value' : 'first', 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 19, 'delimiter' : ',' }
self.parameter_mapping['Stage Multiplier 2'] = { 'choose_alternative' : True }
self.parameter_mapping['Dispersal Matrix'] = { 'choose_alternative' : True }
self.parameter_mapping['Correlation Matrix'] = { 'choose_alternative' : True }
self.parameter_mapping['Stage Matrix'] = { 'sectioned' : True, 'layers' : 'stage_matrix_types', 'number_rows' : 'lifestages', 'number_columns' : 'lifestages', 'start_row' : 'stage_matrix_label_line+5', 'next_layer' : '4+lifestages', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['Fecundity Rates'] = { 'choose_alternative' : True }
self.parameter_mapping['Survival Rates'] = { 'choose_alternative' : True }
self.parameter_mapping['Environmental Variation'] = { 'layers' : 'std_dev_matrix_types', 'number_rows' : 'lifestages', 'number_columns' : 'lifestages', 'start_row' : 'std_dev_matrix_label_line+2', 'next_layer' : '1+lifestages', 'start_column' : 1, 'delimiter' : ' ' }
self.parameter_mapping['Initial Abundance'] = { 'number_rows' : 'populations', 'number_columns' : 1, 'start_row' : 45, 'start_column' : 4, 'delimiter' : ',' }
# Configure parameter data type. The default is 'float', and thus no entry is required for floats.
self.parameter_data_types = {}
self.parameter_data_types['Carrying Capacity'] = 'integer'
self.parameter_data_types['Allee Effect'] = 'integer'
self.parameter_data_types['Initial Abundance'] = 'integer'
# Configure parameter output formats
self.data_frame_mp_file_heading = 'Modified MP file'
self.data_frame_heading_lines = 3
self.data_frame_field_width = 15
self.data_frame_percent_width = self.data_frame_field_width - 1
self.data_frame_field_width_substitution = 'FW'
self.data_frame_notes_marker = ' *'
self.parameter_output_format = {}
self.parameter_output_format['Rmax'] = { 'short_heading' : 'Rmax', 'mp_format' : '%.3G', 'display_format' : '%.3G', 'output_file_heading' : 'Rmax', 'output_file_format' : '%FW.3G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Carrying Capacity'] = { 'short_heading' : 'Capac', 'mp_format' : '%d', 'display_format' : '%d', 'output_file_heading' : ['Carrying', 'Capacity', ''], 'output_file_format' : '%FWd', 'output_file_percent_format' : '%FWd%%' }
self.parameter_output_format['Allee Effect'] = { 'short_heading' : 'Allee', 'mp_format' : '%d', 'display_format' : '%d', 'output_file_heading' : ['Allee', 'Effect', ''], 'output_file_format' : '%FWd', 'output_file_percent_format' : '%FWd%%' }
self.parameter_output_format['Probability of a Catastrophe 1'] = { 'short_heading' : 'ProbCat1', 'mp_format' : '%.5G', 'display_format' : '%.3G', 'output_file_heading' : ['Probability', 'Catastrophe', '1'], 'output_file_format' : '%FW.5G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Local Multiplier 1'] = { 'short_heading' : 'LocMult1', 'mp_format' : '%.3G', 'display_format' : '%.3G', 'output_file_heading' : ['Local', 'Multiplier', '1'], 'output_file_format' : '%FW.3G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Stage Multiplier 1'] = { 'short_heading' : 'StgMult1', 'mp_format' : '%.6G', 'display_format' : '%.3G', 'output_file_heading' : ['Stage', 'Multipliers', '1'], 'output_file_format' : '%FW.3G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Probability of a Catastrophe 2'] = { 'short_heading' : 'ProbCat2', 'mp_format' : '%.5G', 'display_format' : '%.3G', 'output_file_heading' : ['Probability', 'Catastrophe', '2'], 'output_file_format' : '%FW.5G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Local Multiplier 2'] = { 'short_heading' : 'LocMult2', 'mp_format' : '%.3G', 'display_format' : '%.3G', 'output_file_heading' : ['Local', 'Multiplier', '2'], 'output_file_format' : '%FW.3G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Stage Multiplier 2'] = { 'short_heading' : 'StgMult2', 'mp_format' : '%.6G', 'display_format' : '%.3G', 'output_file_heading' : ['Stage', 'Multipliers', '2'], 'output_file_format' : '%FW.3G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Dispersal Matrix'] = { 'short_heading' : 'Disp', 'mp_format' : '%.5G', 'display_format' : '%.3G', 'output_file_heading' : ['Dispersal', 'Matrix', ''], 'output_file_format' : '%FW.3G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Stage Matrix'] = { 'mp_format' : '%.9G' }
self.parameter_output_format['Fecundity Rates'] = { 'short_heading' : 'Fecund', 'mp_format' : '%.9G', 'display_format' : '%.3G', 'output_file_heading' : ['Fecundity', 'Rates', ''], 'output_file_format' : '%FW.5G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Survival Rates'] = { 'short_heading' : { 'single' : 'Surv', 'multiple' : ['LowSurv', 'HiSurv'] }, 'mp_format' : '%.9G', 'display_format' : '%.3G', 'output_file_heading' : ['Survival', 'Rates', ''], 'output_file_format' : '%FW.5G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Environmental Variation'] = { 'short_heading' : 'EnvVar', 'mp_format' : '%.9G', 'display_format' : '%.3G', 'output_file_heading' : ['Environmental', 'Variation', ''], 'output_file_format' : '%FW.5G', 'output_file_percent_format' : '%FW.1f%%' }
self.parameter_output_format['Initial Abundance'] = { 'short_heading' : 'InitN', 'mp_format' : '%d', 'display_format' : '%d', 'output_file_heading' : ['Initial', 'Abundance', ''], 'output_file_format' : '%FWd', 'output_file_percent_format' : '%FWd%%' }
self.parameter_output_format['Correlation Matrix'] = { 'short_heading' : 'Corr', 'mp_format' : '%.5G', 'display_format' : '%.3G', 'output_file_heading' : ['Correlation', 'Matrix', ''], 'output_file_format' : '%FW.3G', 'output_file_percent_format' : '%FW.1f%%' }
# Configure how to select the initial parameter value displayed
self.parameter_initial_display = {}
self.parameter_initial_display['Initial Abundance'] = 'first_non_zero'
self.parameter_initial_display['Rmax'] = 'first_non_zero'
self.parameter_initial_display['Carrying Capacity'] = 'first_non_zero'
self.parameter_initial_display['Allee Effect'] = 'first_non_zero'
self.parameter_initial_display['Probability of a Catastrophe 1'] = 'first_non_zero'
self.parameter_initial_display['Local Multiplier 1'] = 'first_non_zero'
self.parameter_initial_display['Stage Multiplier 1'] = 'first_non_zero'
self.parameter_initial_display['Probability of a Catastrophe 2'] = 'first_non_zero'
self.parameter_initial_display['Local Multiplier 2'] = 'first_non_zero'
self.parameter_initial_display['Stage Multiplier 2'] = 'first_non_zero'
self.parameter_initial_display['Dispersal Matrix'] = 'first_non_zero'
self.parameter_initial_display['Correlation Matrix'] = 'first_non_zero'
self.parameter_initial_display['Fecundity Rates'] = 'last_non_zero'
self.parameter_initial_display['Survival Rates'] = 'last_non_zero'
self.parameter_initial_display['Environmental Variation'] = 'first_non_zero'
# Configure how to express the data frame values for the parameters (default uses unique or percentage)
self.parameter_data_frame = {}
self.parameter_data_frame['Initial Abundance'] = 'sum_values'
self.parameter_data_frame['Carrying Capacity'] = 'sum_values'
# Configure how to express the result input values for the parameters (default uses unique or percentage)
self.parameter_result_input = {}
self.parameter_result_input['Initial Abundance'] = 'sum_values'
self.parameter_result_input['Rmax'] = 'first_value'
self.parameter_result_input['Carrying Capacity'] = 'sum_values'
self.parameter_result_input['Allee Effect'] = 'first_value'
self.parameter_result_input['Probability of a Catastrophe 1'] = 'unique_or_percent'
self.parameter_result_input['Local Multiplier 1'] = 'unique_or_percent'
self.parameter_result_input['Stage Multiplier 1'] = 'unique_or_percent'
self.parameter_result_input['Probability of a Catastrophe 2'] = 'unique_or_percent'
self.parameter_result_input['Local Multiplier 2'] = 'unique_or_percent'
self.parameter_result_input['Stage Multiplier 2'] = 'unique_or_percent'
self.parameter_result_input['Dispersal Matrix'] = 'percent_change'
self.parameter_result_input['Correlation Matrix'] = 'percent_change'
self.parameter_result_input['Fecundity Rates'] = 'unique_or_percent' # was 'last_non_zero'
self.parameter_result_input['Survival Rates'] = ['min_non_zero', 'max']
self.parameter_result_input['Environmental Variation'] = 'percent_change'
# Configure file generation numbering format
self.file_generation_numbering_format = '_%04d' # generates numbering from _0001
# Configure parameter constraints
self.parameter_constraints = {}
self.parameter_constraints['Rmax'] = [{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_CELL_VALUES, 'lower' : 1 }]
self.parameter_constraints['Probability of a Catastrophe 1'] = [{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_CELL_VALUES, 'lower' : 0, 'upper' : 1 }]
self.parameter_constraints['Probability of a Catastrophe 2'] = [{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_CELL_VALUES, 'lower' : 0, 'upper' : 1 }]
self.parameter_constraints['Dispersal Matrix'] = [{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_CELL_VALUES, 'lower' : 0, 'upper' : 1 },
{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_COLUMN_SUMS, 'upper' : 1 }]
self.parameter_constraints['Correlation Matrix'] = [{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_CELL_VALUES, 'lower' : 0, 'upper' : 1 }]
self.parameter_constraints['Survival Rates'] = [{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_CELL_VALUES, 'lower' : 0, 'upper' : 1 },
{ 'constraint_type' : MpParameterBoundConstraintHelper.LIMITED_COLUMN_SUMS, 'upper' : 1 }]
# Configure the constraint probability threshold for unbounded distributions (tail)
self.constraint_probability_threshold_for_unbounded_distributions = 0.01
# Configure constraint application strategies (only warnings implemented to date)
self.constraint_application_strategy = {}
self.constraint_application_strategy['Rmax'] = MpParameterBoundConstraintHelper.WARNING_ONLY
self.constraint_application_strategy['Probability of a Catastrophe 1'] = MpParameterBoundConstraintHelper.WARNING_ONLY
self.constraint_application_strategy['Probability of a Catastrophe 2'] = MpParameterBoundConstraintHelper.WARNING_ONLY
self.constraint_application_strategy['Dispersal Matrix'] = MpParameterBoundConstraintHelper.WARNING_ONLY
self.constraint_application_strategy['Correlation Matrix'] = MpParameterBoundConstraintHelper.WARNING_ONLY
self.constraint_application_strategy['Survival Rates'] = MpParameterBoundConstraintHelper.WARNING_ONLY
# Configure selection of results collected in the desired presentation order
self.metapop_results = ['Expected Minimum Abundance', 'Final number of occupied patches', 'Final N for persistent runs', 'Total extinction risk', 'Quasi extinction risk']
# Configure the names of the RAMAS Metapop result files that may be used by the tool
self.metapop_result_files = ['Abund.txt', 'FinalStageN.txt', 'Harvest.txt', 'HarvestRisk.txt', 'IntExpRisk.txt', 'IntExtRisk.txt', 'IntPerDec.txt', 'LocalOcc.txt', 'LocExtDur.txt', 'MetapopOcc.txt', 'QuasiExp.txt', 'QuasiExt.txt', 'TerExpRisk.txt', 'TerExtRisk.txt', 'TerPerDec.txt']
# Configure the result file details (not all used)
self.metapop_result_file_details = {}
self.metapop_result_file_details['Abund.txt'] = { 'title' : 'Trajectory summary' }
self.metapop_result_file_details['FinalStageN.txt'] = { 'title' : 'Final stage abundances' }
self.metapop_result_file_details['Harvest.txt'] = { 'title' : 'Harvest summary' }
self.metapop_result_file_details['HarvestRisk.txt'] = { 'title' : 'Risk of low harvest' }
self.metapop_result_file_details['IntExpRisk.txt'] = { 'title' : 'Interval explosion risk' }
self.metapop_result_file_details['IntExtRisk.txt'] = { 'title' : 'Interval extinction risk' }
self.metapop_result_file_details['IntPerDec.txt'] = { 'title' : 'Interval percent decline' }
self.metapop_result_file_details['LocalOcc.txt'] = { 'title' : 'Local occupancy' }
self.metapop_result_file_details['LocExtDur.txt'] = { 'title' : 'Local extinction duration' }
self.metapop_result_file_details['MetapopOcc.txt'] = { 'title' : 'Metapopulation occupancy' }
self.metapop_result_file_details['QuasiExp.txt'] = { 'title' : 'Time to quasi-explosion' }
self.metapop_result_file_details['QuasiExt.txt'] = { 'title' : 'Time to quasi-extinction' }
self.metapop_result_file_details['TerExpRisk.txt'] = { 'title' : 'Terminal explosion risk' }
self.metapop_result_file_details['TerExtRisk.txt'] = { 'title' : 'Terminal extinction risk' }
self.metapop_result_file_details['TerPerDec.txt'] = { 'title' : 'Terminal percent decline' }
# Configure any extraction dependencies that exist between result files
self.metapop_result_file_dependencies = {}
self.metapop_result_file_dependencies['IntExtRisk.txt'] = { 'dependent_on' : ['QuasiExt.txt'] }
# Configure result component mapping to RAMAS Metapop result files
common_result_component_mapping = {}
common_result_component_mapping['populations'] = { 'pattern' : '^\s+\d+\s+populations', 'value' : 'match' } # not used as yet
common_result_component_mapping['replications'] = { 'pattern' : '^\s+\d+\s+replications', 'value' : 'match' } # not used as yet
common_result_component_mapping['duration'] = { 'pattern' : 'Duration = \d+', 'value' : 'int(match.split()[2])' }
self.metapop_result_component_mapping = {}
self.metapop_result_component_mapping['Abund.txt'] = { 'process_order' : ['duration', 'title_line', 'mean_final_n', 'mean_n', 'time'] }
self.metapop_result_component_mapping['Abund.txt']['duration'] = common_result_component_mapping['duration']
self.metapop_result_component_mapping['Abund.txt']['title_line'] = { 'pattern' : self.metapop_result_file_details['Abund.txt']['title'], 'value' : 'line' }
self.metapop_result_component_mapping['Abund.txt']['mean_final_n'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 'title_line+duration+4', 'start_column' : 4, 'delimiter' : '' }
self.metapop_result_component_mapping['Abund.txt']['mean_n'] = { 'number_rows' : 'duration+1', 'number_columns' : 1, 'start_row' : 'title_line+4', 'start_column' : 4, 'delimiter' : '' }
self.metapop_result_component_mapping['Abund.txt']['time'] = { 'number_rows' : 'duration+1', 'number_columns' : 1, 'start_row' : 'title_line+4', 'start_column' : 1, 'delimiter' : '' }
self.metapop_result_component_mapping['QuasiExt.txt'] = { 'process_order' : ['quasi_ext_threshold'] }
self.metapop_result_component_mapping['QuasiExt.txt']['quasi_ext_threshold'] = { 'pattern' : 'Threshold level = \d+', 'value' : 'int(match.split()[3])' }
self.metapop_result_component_mapping['IntExtRisk.txt'] = { 'process_order' : ['title_line', 'expected_min_n', 'initial_threshold', 'initial_ext_risk', 'quasi_ext_threshold', 'thresholds_to_quasi', 'ext_risk_to_quasi'] }
self.metapop_result_component_mapping['IntExtRisk.txt']['title_line'] = { 'pattern' : self.metapop_result_file_details['IntExtRisk.txt']['title'], 'value' : 'line' }
self.metapop_result_component_mapping['IntExtRisk.txt']['expected_min_n'] = { 'pattern' : 'Expected minimum abundance = \d+.\d+', 'value' : 'float(match.split()[4])' }
self.metapop_result_component_mapping['IntExtRisk.txt']['initial_threshold'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 'title_line+5', 'start_column' : 1, 'delimiter' : '' }
self.metapop_result_component_mapping['IntExtRisk.txt']['initial_ext_risk'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 'title_line+5', 'start_column' : 2, 'delimiter' : '' }
self.metapop_result_component_mapping['IntExtRisk.txt']['quasi_ext_threshold'] = { 'dependent_on' : { 'result_file' : 'QuasiExt.txt', 'component' : 'quasi_ext_threshold' } }
self.metapop_result_component_mapping['IntExtRisk.txt']['thresholds_to_quasi'] = { 'until_value_condition' : '>= quasi_ext_threshold', 'start_row' : 'title_line+5', 'column' : 1, 'delimiter' : '' }
self.metapop_result_component_mapping['IntExtRisk.txt']['ext_risk_to_quasi'] = { 'number_rows' : 'len(thresholds_to_quasi)', 'number_columns' : 1, 'start_row' : 'title_line+5', 'start_column' : 2, 'delimiter' : '' }
self.metapop_result_component_mapping['MetapopOcc.txt'] = { 'process_order' : ['duration', 'title_line', 'final_n_occ_patches', 'n_occ_patches', 'time'] }
self.metapop_result_component_mapping['MetapopOcc.txt']['duration'] = common_result_component_mapping['duration']
self.metapop_result_component_mapping['MetapopOcc.txt']['title_line'] = { 'pattern' : self.metapop_result_file_details['MetapopOcc.txt']['title'], 'value' : 'line' }
self.metapop_result_component_mapping['MetapopOcc.txt']['final_n_occ_patches'] = { 'number_rows' : 1, 'number_columns' : 1, 'start_row' : 'title_line+duration+4', 'start_column' : 4, 'delimiter' : '' }
self.metapop_result_component_mapping['MetapopOcc.txt']['n_occ_patches'] = { 'number_rows' : 'duration+1', 'number_columns' : 1, 'start_row' : 'title_line+4', 'start_column' : 4, 'delimiter' : '' }
self.metapop_result_component_mapping['MetapopOcc.txt']['time'] = { 'number_rows' : 'duration+1', 'number_columns' : 1, 'start_row' : 'title_line+4', 'start_column' : 1, 'delimiter' : '' }
# Configure result mapping to RAMAS Metapop result file components
self.metapop_result_mapping = {}
self.metapop_result_mapping['Expected Minimum Abundance'] = { 'collect' : [{ 'result_file' : 'IntExtRisk.txt', 'component' : 'expected_min_n' }], 'value' : 'expected_min_n' }
self.metapop_result_mapping['Final number of occupied patches'] = { 'collect' : [{ 'result_file' : 'MetapopOcc.txt', 'component' : 'final_n_occ_patches' }], 'value' : 'final_n_occ_patches' }
self.metapop_result_mapping['Final N for persistent runs'] = { 'collect' : [{ 'result_file' : 'Abund.txt', 'component' : 'mean_final_n' }, { 'result_file' : 'IntExtRisk.txt', 'component' : 'initial_threshold' }, { 'result_file' : 'IntExtRisk.txt', 'component' : 'initial_ext_risk' }], 'condition' : 'initial_threshold == 0 and initial_ext_risk < 1', 'value' : 'mean_final_n/(1-initial_ext_risk)', 'alt_value' : 'mean_final_n' }
self.metapop_result_mapping['Total extinction risk'] = { 'collect' : [{ 'result_file' : 'IntExtRisk.txt', 'component' : 'initial_threshold' }, { 'result_file' : 'IntExtRisk.txt', 'component' : 'initial_ext_risk' }], 'condition' : 'initial_threshold == 0', 'value' : 'initial_ext_risk', 'alt_value' : '0.0' }
self.metapop_result_mapping['Quasi extinction risk'] = { 'collect' : [{ 'result_file' : 'IntExtRisk.txt', 'component' : 'initial_threshold' }, { 'result_file' : 'IntExtRisk.txt', 'component' : 'quasi_ext_threshold' }, { 'result_file' : 'IntExtRisk.txt', 'component' : 'thresholds_to_quasi' }, { 'result_file' : 'IntExtRisk.txt', 'component' : 'ext_risk_to_quasi' }], 'condition' : 'initial_threshold <= quasi_ext_threshold', 'value' : 'linear_interpolate(quasi_ext_threshold, thresholds_to_quasi, ext_risk_to_quasi)', 'alt_value' : '0.0' }
# Configure result output and result summary formats
self.result_summary_run_heading = 'Run'
self.result_summary_heading_lines = self.data_frame_heading_lines
self.result_summary_field_width = self.data_frame_field_width # = 15
self.result_summary_percent_width = self.result_summary_field_width-1
self.result_summary_field_width_substitution = self.data_frame_field_width_substitution
self.result_output_format = {}
self.result_output_format['Expected Minimum Abundance'] = { 'short_heading' : 'EMA', 'output_file_heading' : ['Expected', 'Minimum', 'Abundance'], 'output_file_format' : '%FW.4G' }
self.result_output_format['Final number of occupied patches'] = { 'short_heading' : 'FinalOcc', 'output_file_heading' : ['Final number', 'of occupied', 'patches'], 'output_file_format' : '%FW.4G' }
self.result_output_format['Final N for persistent runs'] = { 'short_heading' : 'FinalN', 'output_file_heading' : ['Final N for', 'persistent', 'runs'], 'output_file_format' : '%FW.4G' }
self.result_output_format['Total extinction risk'] = { 'short_heading' : 'Ext', 'output_file_heading' : ['Total', 'extinction', 'risk'], 'output_file_format' : '%FW.4G' }
self.result_output_format['Quasi extinction risk'] = { 'short_heading' : 'QuasiExt', 'output_file_heading' : ['Quasi', 'extinction', 'risk'], 'output_file_format' : '%FW.4G' }
# Configure selection of result plots collected in the desired presentation order
self.metapop_result_plots = ['Predicted Abundance', 'Predicted Metapopulation Occupancy']
# Configure result plot mapping to RAMAS Metapop result file components
self.metapop_result_plot_mapping = {}
self.metapop_result_plot_mapping['Predicted Abundance'] = { 'fields': ['Time', 'Average'], 'collect' : [{ 'result_file' : 'Abund.txt', 'component' : 'time' }, { 'result_file' : 'Abund.txt', 'component' : 'mean_n' }], 'value' : 'join_arrays(time,mean_n)' }
self.metapop_result_plot_mapping['Predicted Metapopulation Occupancy'] = { 'fields': ['Time', 'Average'], 'collect' : [{ 'result_file' : 'MetapopOcc.txt', 'component' : 'time' }, { 'result_file' : 'MetapopOcc.txt', 'component' : 'n_occ_patches' }], 'value' : 'join_arrays(time,n_occ_patches)' }
# Configure result plot calculated data (calculated across samples)
common_fields = ['Time', 'Minimum', 'Mean-2SD', 'Mean-1SD', 'Mean', 'Mean+1SD', 'Mean+2SD', 'Maximum']
common_calculations = { 'fields' : common_fields, 'calculations' : { 'Minimum' : { 'field' : 'Average', 'calculate' : 'minimum' },
'Mean-2SD' : { 'field' : 'Average', 'calculate' : 'mean-2*stdev' },
'Mean-1SD' : { 'field' : 'Average', 'calculate' : 'mean-1*stdev' },
'Mean' : { 'field' : 'Average', 'calculate' : 'mean' },
'Mean+1SD' : { 'field' : 'Average', 'calculate' : 'mean+1*stdev' },
'Mean+2SD' : { 'field' : 'Average', 'calculate' : 'mean+2*stdev' },
'Maximum' : { 'field' : 'Average', 'calculate' : 'maximum' } } }
self.result_plot_calculated_data = {}
self.result_plot_calculated_data['Predicted Abundance'] = common_calculations
self.result_plot_calculated_data['Predicted Metapopulation Occupancy'] = common_calculations
# Configure result plot file and visualisation details
self.result_plot_intervals = ['mean', 'mean-1sd', 'mean-2sd', 'min-mean-max']
self.result_plot_default_interval = 'mean-2sd'
self.result_plot_interval_data = {}
self.result_plot_interval_data['mean'] = 'Mean'
self.result_plot_interval_data['mean-1sd'] = { 'lower' : 'Mean-1SD', 'mid' : 'Mean', 'upper' : 'Mean+1SD' }
self.result_plot_interval_data['mean-2sd'] = { 'lower' : 'Mean-2SD', 'mid' : 'Mean', 'upper' : 'Mean+2SD' }
self.result_plot_interval_data['min-mean-max'] = { 'lower' : 'Minimum', 'mid' : 'Mean', 'upper' : 'Maximum' }
self.result_plot_interval_label = {}
self.result_plot_interval_label['mean'] = 'Mean'
self.result_plot_interval_label['mean-1sd'] = 'Mean '+u'\u00B1'+' 1 Standard Deviation'
self.result_plot_interval_label['mean-2sd'] = 'Mean '+u'\u00B1'+' 2 Standard Deviation'
self.result_plot_interval_label['min-mean-max'] = 'Minimum-Mean-Maximum'
self.result_plot_file_details = {}
self.result_plot_file_details['Predicted Abundance'] = { 'filename' : 'Predicted_Abundance', 'fields' : common_fields }
self.result_plot_file_details['Predicted Metapopulation Occupancy'] = { 'filename' : 'Predicted_Metapopulation_Occupancy', 'fields' : common_fields }
self.result_plot_view_details = {}
self.result_plot_view_details['Predicted Abundance'] = {}
self.result_plot_view_details['Predicted Abundance']['mean'] = { 'plot_type' : 'time_series', 'plot_title' : 'Predicted Abundance', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['mean'], 'y_label' : self.result_plot_interval_label['mean'] }
self.result_plot_view_details['Predicted Abundance']['mean-1sd'] = { 'plot_type' : 'time_series_interval', 'plot_title' : 'Predicted Abundance', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['mean-1sd'], 'y_label' : self.result_plot_interval_label['mean-1sd'] }
self.result_plot_view_details['Predicted Abundance']['mean-2sd'] = { 'plot_type' : 'time_series_interval', 'plot_title' : 'Predicted Abundance', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['mean-2sd'], 'y_label' : self.result_plot_interval_label['mean-2sd'] }
self.result_plot_view_details['Predicted Abundance']['min-mean-max'] = { 'plot_type' : 'time_series_interval', 'plot_title' : 'Predicted Abundance', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['min-mean-max'], 'y_label' : self.result_plot_interval_label['min-mean-max'] }
self.result_plot_view_details['Predicted Metapopulation Occupancy'] = {}
self.result_plot_view_details['Predicted Metapopulation Occupancy']['mean'] = { 'plot_type' : 'time_series', 'plot_title' : 'Predicted Metapopulation Occupancy', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['mean'], 'y_label' : self.result_plot_interval_label['mean'] }
self.result_plot_view_details['Predicted Metapopulation Occupancy']['mean-1sd'] = { 'plot_type' : 'time_series_interval', 'plot_title' : 'Predicted Metapopulation Occupancy', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['mean-1sd'], 'y_label' : self.result_plot_interval_label['mean-1sd'] }
self.result_plot_view_details['Predicted Metapopulation Occupancy']['mean-2sd'] = { 'plot_type' : 'time_series_interval', 'plot_title' : 'Predicted Metapopulation Occupancy', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['mean-2sd'], 'y_label' : self.result_plot_interval_label['mean-2sd'] }
self.result_plot_view_details['Predicted Metapopulation Occupancy']['min-mean-max'] = { 'plot_type' : 'time_series_interval', 'plot_title' : 'Predicted Metapopulation Occupancy', 'x_data' : 'Time', 'x_label' : 'Time',
'y_data' : self.result_plot_interval_data['min-mean-max'], 'y_label' : self.result_plot_interval_label['min-mean-max'] }
# Configuration not in tool options (yet)
self.minimum_number_of_samples = 50
self.maximum_parameter_matrix_size = 2500
self.oversized_parameter_matrix_frame_size = 6
# Configuration relating to tool options:
self.tool_option_parameters = ['metapop_exe_location',
'run_metapop_batch_locally',
'default_generated_file_location',
'number_of_metapop_iterations',
'metapop_simulation_duration',
'use_mp_baseline_values',
'reset_sampling_when_loading_file',
'default_number_of_lhs_samples',
'default_number_of_random_samples',
'enforce_minimum_number_of_samples',
'default_lhs_uniform_distr_lower_setting',
'default_lhs_uniform_distr_upper_setting',
'default_lhs_gaussian_distr_mean_setting',
'default_lhs_gaussian_distr_stdev_setting',
'default_lhs_triangular_distr_lower_setting',
'default_lhs_triangular_distr_upper_setting',
'default_lhs_triangular_distr_mode_setting',
'default_lhs_lognormal_distr_lower_setting',
'default_lhs_lognormal_distr_scale_setting',
'default_lhs_lognormal_distr_scale_increment',
'default_lhs_lognormal_distr_sigma_setting',
'default_lhs_lognormal_distr_sigma_increment',
'default_lhs_beta_distr_lower_setting',
'default_lhs_beta_distr_upper_setting',
'default_lhs_beta_distr_alpha_setting',
'default_lhs_beta_distr_alpha_increment',
'default_lhs_beta_distr_beta_setting',
'default_lhs_beta_distr_beta_increment',
'default_sample_bounds_for_random',
'default_sample_bounds_for_full_factorial',
'auto_run_results_summary_tool']
self.tool_option_parameter_types = {'metapop_exe_location' : str,
'run_metapop_batch_locally' : bool,
'default_generated_file_location' : str,
'number_of_metapop_iterations' : int,
'metapop_simulation_duration' : int,
'use_mp_baseline_values' : bool,
'reset_sampling_when_loading_file' : bool,
'default_number_of_lhs_samples' : int,
'default_number_of_random_samples' : int,
'enforce_minimum_number_of_samples' : bool,
'default_lhs_uniform_distr_lower_setting' : float,
'default_lhs_uniform_distr_upper_setting' : float,
'default_lhs_gaussian_distr_mean_setting' : float,
'default_lhs_gaussian_distr_stdev_setting' : float,
'default_lhs_triangular_distr_lower_setting' : float,
'default_lhs_triangular_distr_upper_setting' : float,
'default_lhs_triangular_distr_mode_setting' : float,
'default_lhs_lognormal_distr_lower_setting' : float,
'default_lhs_lognormal_distr_scale_setting' : float,
'default_lhs_lognormal_distr_scale_increment' : float,
'default_lhs_lognormal_distr_sigma_setting' : float,
'default_lhs_lognormal_distr_sigma_increment' : float,
'default_lhs_beta_distr_lower_setting' : float,
'default_lhs_beta_distr_upper_setting' : float,
'default_lhs_beta_distr_alpha_setting' : float,
'default_lhs_beta_distr_alpha_increment' : float,
'default_lhs_beta_distr_beta_setting' : float,
'default_lhs_beta_distr_beta_increment' : float,
'default_sample_bounds_for_random' : float,
'default_sample_bounds_for_full_factorial' : float,
'auto_run_results_summary_tool' : bool}
# Mapping for LHS option default settings
self.lhs_option_default_settings = {}
self.lhs_option_default_settings['Uniform'] = { 'Lower' : 'default_lhs_uniform_distr_lower_setting', 'Upper' : 'default_lhs_uniform_distr_upper_setting' }
self.lhs_option_default_settings['Gaussian'] = { 'Mean' : 'default_lhs_gaussian_distr_mean_setting', 'Std. Dev.' : 'default_lhs_gaussian_distr_stdev_setting' }
self.lhs_option_default_settings['Triangular'] = { 'Lower (a)' : 'default_lhs_triangular_distr_lower_setting', 'Upper (b)' : 'default_lhs_triangular_distr_upper_setting', 'Mode (c)' : 'default_lhs_triangular_distr_mode_setting' }
self.lhs_option_default_settings['Lognormal'] = { 'Lower' : 'default_lhs_lognormal_distr_lower_setting', 'Scale' : 'default_lhs_lognormal_distr_scale_setting', 'Scale Increment' : 'default_lhs_lognormal_distr_scale_increment', 'Sigma' : 'default_lhs_lognormal_distr_sigma_setting', 'Sigma Increment' : 'default_lhs_lognormal_distr_sigma_increment' }
self.lhs_option_default_settings['Beta'] = { 'Lower' : 'default_lhs_beta_distr_lower_setting', 'Upper' : 'default_lhs_beta_distr_upper_setting', 'Alpha' : 'default_lhs_beta_distr_alpha_setting', 'Alpha Increment' : 'default_lhs_beta_distr_alpha_increment', 'Beta' : 'default_lhs_beta_distr_beta_setting', 'Beta Increment' : 'default_lhs_beta_distr_beta_increment' }
# The local/ext disk location of the RAMAS Metapop program
self.metapop_exe_location = r'C:\Program Files\RAMASGIS\Metapop.exe'
# Metapop batch file run on local machine
self.run_metapop_batch_locally = True
# The default local disk location for generated files
self.default_generated_file_location = r'C:\afat32\Dropbox\GlobalEcologyGroup\ProjectCode\SensitivityAnalysisToolset\v0.4\Test'
# The number of RAMAS Metapop iterations/replications per scenario and simulation duration
self.number_of_metapop_iterations = 100
self.metapop_simulation_duration = 20
self.use_mp_baseline_values = False
# Reset the sampling parameters when loading a new baseline file
self.reset_sampling_when_loading_file = True
# The default number of samples for LHS/Random
self.default_number_of_lhs_samples = None
self.default_number_of_random_samples = None
self.enforce_minimum_number_of_samples = True
# The default LHS settings
self.default_lhs_uniform_distr_lower_setting = 90.
self.default_lhs_uniform_distr_upper_setting = 110.
self.default_lhs_gaussian_distr_mean_setting = 100.
self.default_lhs_gaussian_distr_stdev_setting = 5.
self.default_lhs_triangular_distr_lower_setting = 90.
self.default_lhs_triangular_distr_upper_setting = 110.
self.default_lhs_triangular_distr_mode_setting = 100.
self.default_lhs_lognormal_distr_lower_setting = 100.
self.default_lhs_lognormal_distr_scale_setting = 10.
self.default_lhs_lognormal_distr_scale_increment = 1.
self.default_lhs_lognormal_distr_sigma_setting = 1.
self.default_lhs_lognormal_distr_sigma_increment = 0.1
self.default_lhs_beta_distr_lower_setting = 90.
self.default_lhs_beta_distr_upper_setting = 110.
self.default_lhs_beta_distr_alpha_setting = 1.
self.default_lhs_beta_distr_alpha_increment = 0.1
self.default_lhs_beta_distr_beta_setting = 1.
self.default_lhs_beta_distr_beta_increment = 0.1
# The default sample bounds for Random/Full Factorial
self.default_sample_bounds_for_random = 10.
self.default_sample_bounds_for_full_factorial = 20.
# Results summary tool is auto run when sample file generated
self.auto_run_results_summary_tool = False
# End config for tool options
# Load config from file and warn if file not found
self.config_warning = self.loadConfig()
# 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].strip()
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')
# 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 :
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()
# END MetapopConfiguration
## Application GUI
## * Constructs tool GUI components using parameter configuration
## * Defines and follows a workflow of step completion
## * Performs tool operations utilising mp file helper and sample generator modules
class ApplicationGUI(tk.Frame) :
# Initialise GUI and workflow
def __init__(self, application_name, user_application_data_directory, master=None) :
tk.Frame.__init__(self, master)
self.grid()
# Set user application data directory
self.user_application_data_directory = user_application_data_directory
# Load MP File Parameter Configuration
self.config = MetapopConfiguration(self.user_application_data_directory, application_name+'_config.txt')
# Warn if config file not loaded properly
if self.config.config_warning :
showwarning('Error Loading Configuration', self.config.config_warning)
# Create a MP file extractor and generator helper
self.mp_file_helper = MpFileExtractorAndGeneratorHelper(self.config)
# Create a MP parameter constraint helper
self.mp_constraint_helper = MpParameterBoundConstraintHelper(self.config)
# Get current config tool options
tool_option_values = self.config.getToolOptions()
# If batch is run locally and current Metapop exe location doesn't exist try to find it
if tool_option_values['run_metapop_batch_locally'] and not path.exists(tool_option_values['metapop_exe_location']) :
metapop_exe_path = environ['PROGRAMFILES']
metapop_exe_path = path.join(metapop_exe_path, self.findMatchingInDirectory(metapop_exe_path, 'RAMASGIS'))
metapop_exe_path = path.join(metapop_exe_path, self.findMatchingInDirectory(metapop_exe_path, 'Metapop.exe'))
if self.mp_file_helper.splitPath(metapop_exe_path)['name'].lower().find('metapop.exe') != -1 :
self.config.setToolOptions({ 'metapop_exe_location' : metapop_exe_path })
# Maintain flag to indicate that the parameters were successfully extracted from the baseline file
self.extraction_ok = False
# Extracted parameter values from the baseline MP file when loaded
self.baseline_parameter_values = { 'extracted' : {}, 'calculated' : {}, 'file_links' : {} }
# Record generated MP file count and output directory and flag generate completed or error
self.generated_file_count = 0
self.generate_directory_ok = False
self.generate_directory = {} # name, (parent) directory, path, and timestamped (optional directory name)
self.file_generate_complete = False
self.file_generate_error = False
# Record the results directory and flag generate completed or error
self.results_directory = {} # name, (parent) directory, and path
self.results_summary_generation_complete = False
self.results_summary_generated = False
self.results_summary_generation_error = False
# Current directory locations
self.current_figure_save_directory = ''
# 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
# Set the current parameter LHS distribution viewed
self.current_parameter_lhs_distribution_viewed = None
# Entry field map for recovering field details from its pathname
self.entry_field_map = {}
# MP Generation Process steps
self.process_step = {}
self.process_step['mp_file_load'] = { 'number' : '1', 'dependents' : [], 'completed': False }
self.process_step['sampling_settings'] = { 'number' : '2', 'dependents' : ['mp_file_load'], 'completed': False }
self.process_step['parameter_settings'] = { 'number' : '3', 'dependents' : ['mp_file_load', 'sampling_settings'], 'completed': False }
self.process_step['file_generation'] = { 'number' : '4', 'dependents' : ['mp_file_load', 'sampling_settings', 'parameter_settings'], 'completed': False }
# MP Results Process steps
self.results_process_step = {}
self.results_process_step['results_directory'] = { 'number' : '1', 'dependents' : [], 'completed': False }
self.results_process_step['results_selection'] = { 'number' : '2', 'dependents' : ['results_directory'], 'completed': False }
self.results_process_step['results_summary_generation'] = { 'number' : '3', 'dependents' : ['results_directory', 'results_selection'], 'completed': False }
# Process frames
self.createMenu()
# Configure the font for tool headings
default_font = Font(font='TkDefaultFont')
self.tool_label_font = Font(family=default_font.cget('family'), size=default_font.cget('size'), weight='bold')
# MP Generation frames
generation_tool_label = tk.Label(self, text='MP Sampling Generation', font=self.tool_label_font)
self.mp_generation_frame = tk.LabelFrame(self, labelwidget=generation_tool_label, relief=tk.RAISED, padx=5, pady=5)
self.createFileLoadFrame()
self.createSamplingFrame()
self.createParameterFrame()
self.createGenerateFrame()
self.mp_generation_frame.grid(row=0, column=0, padx=5, pady=5)
# 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.add_command(label='Load MP File', command=self.loadMPFile)
self.file_menu.add_command(label='Quit', command=self.quit)
# Run menu
self.run_menu = tk.Menu(self.menu_bar)
self.menu_bar.add_cascade(label='Run', menu=self.run_menu)
self.run_menu.add_command(label='RAMAS Metapop Batch', command=self.runBatch)
self.run_menu.add_command(label='Results Summary', command=self.runResults)
# Options menu
self.options_menu = tk.Menu(self.menu_bar)
self.menu_bar.add_cascade(label='Options', menu=self.options_menu)
self.options_menu.add_command(label='Edit', command=self.editOptions)
# Ensures menu selection triggers entry field validation focusout events
def shiftFocus(self, force_after=False) :
self.focus_set()
if force_after and self.validation_warning_pending :
self.force_shift_focus = True
# MP Generation: GUI for Step 1: Baseline MP File
def createFileLoadFrame(self) :
step_number = self.process_step['mp_file_load']['number']
self.file_load_frame = tk.LabelFrame(self.mp_generation_frame, text='Step '+step_number+': Baseline MP File', padx=10, pady=10)
# Create load button and labels and place them on a grid
self.load_button = tk.Button(self.file_load_frame, text='Load MP File', command=self.loadMPFile)
self.load_label_text = tk.StringVar(value=' : Select a baseline MP file to load')
self.load_label = tk.Label(self.file_load_frame, textvariable=self.load_label_text)
self.load_button.grid(row=0, column=0, sticky=tk.NW+tk.SW, padx=1)
self.load_label.grid(row=0, column=1, sticky=tk.NW+tk.SW)
# Create a frame for displaying the MP file settings
self.mp_file_settings_frame = tk.Frame(self.file_load_frame)
self.mp_file_settings_frame.grid(row=1, column=0, columnspan=2, sticky=tk.NW+tk.SW, padx=0, pady=5)
self.file_load_frame.grid(row=0, column=0, sticky=tk.NW+tk.SE, padx=5, pady=5)
# MP Generation: GUI for Step 2: Sampling
def createSamplingFrame(self) :
# Configure sample type selection
self.sampling_types = ['Latin Hypercube', 'Random', 'Full Factorial']
self.sampling_details = {}
self.sampling_details['Latin Hypercube'] = { 'sample_number_required' : True, 'sample_number' : tk.StringVar() }
self.sampling_details['Random'] = { 'sample_number_required' : True, 'sample_number' : tk.StringVar() }
self.sampling_details['Full Factorial'] = { 'sample_number_required' : False }
self.selected_sampling_type = tk.StringVar()
self.sampling_type_radiobutton = {}
self.sample_number_entry = {}
step_number = self.process_step['sampling_settings']['number']
sampling_frame = tk.LabelFrame(self.mp_generation_frame, text='Step '+step_number+': Sampling', padx=10, pady=10)
# Register validation and selection behaviour methods
validate_samples = sampling_frame.register(self.validateNumberOfSamples)
sampling_row = 0
for index, sample_type in enumerate(self.sampling_types) :
# Create GUI elements and place them on a grid
# Sampling type selection
self.sampling_type_radiobutton[sample_type] = tk.Radiobutton(sampling_frame, text=None, variable=self.selected_sampling_type, value=sample_type, state=tk.DISABLED, command=self.updateSamplingType)
self.sampling_type_radiobutton[sample_type].grid(row=sampling_row, column=0, sticky=tk.NW)
tk.Label(sampling_frame, text=sample_type).grid(row=sampling_row, column=1, columnspan=2, sticky=tk.NW)
# Select the first radio button and deselect others and any corresponding number of samples entries
if index == 0 :
self.sampling_type_radiobutton[sample_type].select()
self.current_sampling_type = sample_type
else :
self.sampling_type_radiobutton[sample_type].deselect()
# Include number of samples when required
if self.sampling_details[sample_type]['sample_number_required'] :
tk.Label(sampling_frame, text=': Number of samples:').grid(row=sampling_row, column=3, sticky=tk.NW)