-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlockC_module4_ARID.nlogo
1776 lines (1457 loc) · 41.9 KB
/
BlockC_module4_ARID.nlogo
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GNU GENERAL PUBLIC LICENSE ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Module for calculation of ARID using GIS and weather data
;; Based on modified parts of:
;; Soil Water Balance model (NetLogo implementation)
;; Land model
;; Copyright (C) 2019 Andreas Angourakis ([email protected])
;; available at https://www.github.com/Andros-Spica/indus-village-model
;; implementing the Soil Water Balance model from Wallach et al. 2006 'Working with dynamic crop models' (p. 24-28 and p. 138-144).
;; This implementation uses parts of the Weather model to simulate input variables (i.e., temperature, solar radiation, precipitation, evapotranspiration)
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
extensions [ csv gis ]
;;;;;;;;;;;;;;;;;
;;;;; BREEDS ;;;;
;;;;;;;;;;;;;;;;;
breed [ sites site ]
breed [ flowHolders flowHolder ]
;;;;;;;;;;;;;;;;;
;;; VARIABLES ;;;
;;;;;;;;;;;;;;;;;
globals
[
patchesWithElevationData
noElevationDataTag
maxElevation
width
height
;;; GIS data holders
sitesData_EMIII-MMIA
sitesData_MMIB
elevationData
riversData
;;; weather input data
weatherInputData_firstYear
weatherInputData_lastYear
weatherInputData_YEARS
weatherInputData_yearLengthInDays
weatherInputData_DOY
weatherInputData_YEAR-DOY
weatherInputData_solarRadiation
weatherInputData_precipitation
weatherInputData_temperature
weatherInputData_maxTemperature
weatherInputData_minTemperature
;;; default constants
MUF ; Water Uptake coefficient (mm^3.mm^-3)
WP ; Water content at wilting Point (cm^3.cm^-3)
;;;; ETr
albedo_min
albedo_max
;;;; Soil Water Balance model global parameters
WHC_min
WHC_max
DC_min
DC_max
z_min
z_max
CN_min
CN_max
;;; variables
;;;; time tracking
currentYear
currentDayOfYear
maxFlowAccumulation
;;;; main (these follow a seasonal pattern and apply for all patches)
T ; average temperature of current day (ºC)
T_max ; maximum temperature of current day (ºC)
T_min ; minimum temperature of current day (ºC)
solarRadiation ; solar radiation of current day (MJ m-2)
RAIN ; precipitation of current day (mm)
precipitation_yearSeries
precipitation_cumYearSeries
]
sites-own
[
name
siteType
period
]
patches-own
[
elevation ; elevation above sea level [m]
flow_direction ; the numeric code for the (main) direction of flow or
; drainage within the land unit.
; Following Jenson & Domingue (1988) convention:
; NW = 64, N = 128, NE = 1,
; W = 32, <CENTRE>, E = 2,
; SW = 16, S = 8, SE = 4
flow_receive ; Boolean variable stating whether or not the land unit receives
; the flow of a neighbour.
flow_accumulation ; the amount of flow units accumulated in the land unit.
; A Flow unit is the volume of runoff water flowing from one land unit
; to another (assumed constant and without losses).
flow_accumulationState ; the state of the land unit regarding the calculation of flow
; accumulation (auxiliary variable).
isRiver
;;;; soil
DC ; Drainage coefficient (mm^3 mm^-3).
z ; root zone depth (mm).
CN ; Runoff curve number.
FC ; Water content at field capacity (cm^3.cm^-3)
WHC ; Water Holding Capacity of the soil (cm^3.cm^-3). Typical range from 0.05 to 0.25
ARID ; ARID index after Woli et al. 2012, ranging form 0 (no water shortage) to 1 (extreme water shortage)
WAT ; Water content in the soil profile for the rooting depth (mm)
WATp ; Volumetric Soil Water content (fraction : mm.mm-1). calculated as WAT/z
;;;; cover
albedo ; canopy reflection or albedo
netSolarRadiation ; net solar radiation discount canopy reflection or albedo
ETr ; reference evapotranspiration
ARID_modifier ; modifier coefficient based on the relative value of flow_accumulation
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
; --- loading/testing parameters -----------
import-map-with-flows ; import-world must be the first step
set-constants
set-parameters
setup-patches
; --- core procedures ----------------------
set currentYear weatherInputData_firstYear
set currentDayOfYear 1
;;; values are taken from input data
set-day-weather-from-input-data currentDayOfYear currentYear
ask patchesWithElevationData [ update-WAT ]
; --- display & output handling ------------------------
refresh-view
; -- time -------------------------------------
reset-ticks
end
to set-constants
; "constants" are variables that will not be explored as parameters
; and may be used during a simulation.
; MUF : Water Uptake coefficient (mm^3 mm^-3)
set MUF 0.096
; WP : Water content at wilting Point (cm^3.cm^-3)
set WP 0.06
end
to set-parameters
; set random seed
random-seed seed
;;; load weather input data from file
load-weather-input-data-table
parameters-check
;;; weather parameters are left with default values, but effectively ignored given that input weather is used.
set albedo_min 1E-6 + random-float 0.3
set albedo_max albedo_min + random-float 0.3
;;; Soil Water Balance model
set WHC_min random-float 0.1
set WHC_max WHC_min + random-float 0.1
set DC_min 1E-6 + random-float 0.45
set DC_max DC_min + random-float 0.45
set z_min random-float 1000
set z_max z_min + random-float 1000
set CN_min random-float 40
set CN_max CN_min + random-float 50
end
to parameters-check
;;; check if values were reset to 0 (NetLogo does that from time to time...!)
;;; and set default values (assuming they are not 0)
if (par_albedo_min = 0) [ set par_albedo_min 0.1 ]
if (par_albedo_max = 0) [ set par_albedo_max 0.5 ]
if (water-holding-capacity_min = 0) [ set water-holding-capacity_min 0.05 ]
if (water-holding-capacity_max = 0) [ set water-holding-capacity_max 0.25 ]
if (drainage-coefficient_min = 0) [ set drainage-coefficient_min 0.3 ]
if (drainage-coefficient_max = 0) [ set drainage-coefficient_max 0.7 ]
if (root-zone-depth_min = 0) [ set root-zone-depth_min 200 ]
if (root-zone-depth_max = 0) [ set root-zone-depth_max 2000 ]
if (runoff-curve_min = 0) [ set runoff-curve_min 30 ]
if (runoff-curve_max = 0) [ set runoff-curve_max 80 ]
end
to parameters-to-default
;;; set parameters to a default value
set par_albedo_min 0.1
set par_albedo_max 0.5
set water-holding-capacity_min 0.05
set water-holding-capacity_max 0.25
set drainage-coefficient_min 0.3
set drainage-coefficient_max 0.7
set root-zone-depth_min 200
set root-zone-depth_max 2000
set runoff-curve_min 30
set runoff-curve_max 80
end
to setup-patches
setup-soil-water-properties
setup-ARID-modifier
end
to import-map-with-flows
import-world "data/terrainWithFlows/BlockC_module2_flows world.csv"
;;; reduce patch size in pixels
set-patch-size 3
end
to setup-soil-water-properties
ask patchesWithElevationData
[
set albedo albedo_min + random-float (albedo_max - albedo_min)
; Water Holding Capacity of the soil (cm^3 cm^-3).
set WHC WHC_min + random-float (WHC_max - WHC_min)
; DC : Drainage coefficient (mm^3 mm^-3)
set DC DC_min + random-float (DC_max - DC_min)
; z : root zone depth (mm)
set z z_min + random (z_max - z_min)
; CN : Runoff curve number
set CN CN_min + random (CN_max - CN_max)
; FC : Water content at field capacity (cm^3.cm^-3)
set FC WP + WHC
; WAT0 : Initial Water content (mm)
set WAT z * FC
]
end
to setup-ARID-modifier
ask patchesWithElevationData
[
set ARID_modifier (1 - ARID-decrease-per-flow-accumulation * (flow_accumulation / maxFlowAccumulation))
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
; --- core procedures -------------------------
;;; values are taken from input data
set-day-weather-from-input-data currentDayOfYear currentYear
ask patchesWithElevationData [ update-WAT modify-ARID ]
; --- output handling ------------------------
refresh-view
; -- time -------------------------------------
advance-time
tick
; --- stop conditions -------------------------
if (currentYear = weatherInputData_lastYear and currentDayOfYear = last weatherInputData_yearLengthInDays) [stop]
end
;;; GLOBAL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to advance-time
set currentDayOfYear currentDayOfYear + 1
if (currentDayOfYear > item (currentYear - weatherInputData_firstYear) weatherInputData_yearLengthInDays)
[
set currentYear currentYear + 1
set currentDayOfYear 1
]
end
to set-day-weather-from-input-data [ dayOfYear year ]
;;; find corresponding index to year-dayOfYear pair
let yearAndDoyIndex position (word year "-" dayOfYear) weatherInputData_YEAR-DOY
;;; get values from weather input data
set solarRadiation item yearAndDoyIndex weatherInputData_solarRadiation
set T item yearAndDoyIndex weatherInputData_temperature
set T_min item yearAndDoyIndex weatherInputData_minTemperature
set T_max item yearAndDoyIndex weatherInputData_maxTemperature
set RAIN item yearAndDoyIndex weatherInputData_precipitation
if (dayOfYear = 1)
[
;;; fill values of precipitation_yearSeries and precipitation_cumYearSeries, used here only for visualisation
let yearLengthInDays item (currentYear - weatherInputData_firstYear) weatherInputData_yearLengthInDays
let yearAndLastDoyIndex position (word year "-" yearLengthInDays) weatherInputData_YEAR-DOY
set precipitation_yearSeries sublist weatherInputData_precipitation yearAndDoyIndex (yearAndLastDoyIndex + 1)
let yearTotal sum precipitation_yearSeries
set precipitation_cumYearSeries (list)
let cumulativeSum 0
foreach precipitation_yearSeries
[
i ->
set cumulativeSum cumulativeSum + i
set precipitation_cumYearSeries lput cumulativeSum precipitation_cumYearSeries
]
set precipitation_cumYearSeries map [i -> i / yearTotal] precipitation_cumYearSeries
]
ask patchesWithElevationData
[
set netSolarRadiation (1 - albedo) * solarRadiation
set ETr get-ETr
]
end
to-report get-ETr
;;; useful references:
;;; Suleiman A A and Hoogenboom G 2007
;;; Comparison of Priestley-Taylor and FAO-56 Penman-Monteith for Daily Reference Evapotranspiration Estimation in Georgia
;;; J. Irrig. Drain. Eng. 133 175–82 Online: http://ascelibrary.org/doi/10.1061/%28ASCE%290733-9437%282007%29133%3A2%28175%29
;;; also: Jia et al. 2013 - doi:10.4172/2168-9768.1000112
;;; Allen, R. G., Pereira, L. A., Raes, D., and Smith, M. 1998.
;;; “Crop evapotranspiration.”FAO irrigation and drainage paper 56, FAO, Rome.
;;; also: http://www.fao.org/3/X0490E/x0490e07.htm
;;; constants found in: http://www.fao.org/3/X0490E/x0490e07.htm
;;; see also r package: Evapotranspiration (consult source code)
let windSpeed 2 ; as recommended by: http://www.fao.org/3/X0490E/x0490e07.htm#estimating%20missing%20climatic%20data
;;; estimation of saturated vapour pressure (e_s) and actual vapour pressure (e_a)
let e_s (get-vapour-pressure T_max + get-vapour-pressure T_min) / 2
let e_a get-vapour-pressure T_min
; ... in absence of dew point temperature, as recommended by
; http://www.fao.org/3/X0490E/x0490e07.htm#estimating%20missing%20climatic%20data
; however, possibly min temp > dew temp under arid conditions
;;; slope of the vapor pressure-temperature curve (kPa ºC−1)
let DELTA 4098 * (get-vapour-pressure T) / (T + 237.3) ^ 2
;;; latent heat of vaporisation = 2.45 MJ.kg^-1
let lambda 2.45
;;; specific heat at constant pressure, 1.013 10-3 [MJ kg-1 °C-1]
let c_p 1.013 * 10 ^ -3
;;; ratio molecular weight of water vapour/dry air
let epsilon 0.622
;;; atmospheric pressure (kPa)
let P 101.3 * ((293 - 0.0065 * elevation) / 293) ^ 5.26
;;; psychometric constant (kPa ºC−1)
let gamma c_p * P / (epsilon * lambda)
;;; Penman-Monteith equation from: fao.org/3/X0490E/x0490e0 ; and from: weap21.org/WebHelp/Mabia_Alg ETRef.htm
; 900 and 0.34 for the grass reference; 1600 and 0.38 for the alfalfa reference
let C_n 900
let C_d 0.34
let ETr_temp (0.408 * DELTA * netSolarRadiation + gamma * (C_n / (T + 273)) * windSpeed * (e_s - e_a)) / (DELTA + gamma * (1 + C_d * windSpeed))
report ETr_temp
end
to-report get-vapour-pressure [ temp ]
report (0.6108 * exp(17.27 * temp / (temp + 237.3)))
end
to update-WAT
; Soil Water Balance model
; Using the approach of:
; 'Working with dynamic crop models: Methods, tools, and examples for agriculture and enviromnent'
; Daniel Wallach, David Makowski, James W. Jones, François Brun (2006, 2014, 2019)
; Model description in p. 24-28, R code example in p. 138-144.
; see also https://github.com/cran/ZeBook/blob/master/R/watbal.model.r
; Some additional info about run off at: https://engineering.purdue.edu/mapserve/LTHIA7/documentation/scs.htm
; and at: https://en.wikipedia.org/wiki/Runoff_curve_number
; Maximum abstraction (mm; for run off)
let S 25400 / CN - 254
; Initial Abstraction (mm; for run off)
let IA 0.2 * S
; WATfc : Maximum Water content at field capacity (mm)
let WATfc FC * z
; WATwp : Water content at wilting Point (mm)
let WATwp WP * z
; Change in Water Before Drainage (Precipitation - Runoff)
let RO 0
if (RAIN > IA)
[ set RO ((RAIN - 0.2 * S) ^ 2) / (RAIN + 0.8 * S) ]
; Calculating the amount of deep drainage
let DR 0
if (WAT + RAIN - RO > WATfc)
[ set DR DC * (WAT + RAIN - RO - WATfc) ]
; Calculate rate of change of state variable WAT
; Compute maximum water uptake by plant roots on a day, RWUM
let RWUM MUF * (WAT + RAIN - RO - DR - WATwp)
; Calculate the amount of water lost through transpiration (TR)
let TR min (list RWUM ETr)
let dWAT RAIN - RO - DR - TR
set WAT WAT + dWAT
set WATp WAT / z
set ARID 0
if (TR < ETr)
[ set ARID 1 - TR / ETr ]
end
to modify-ARID
set ARID ARID * ARID_modifier
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; DISPLAY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to refresh-view
if (display-mode = "elevation")
[
ask patchesWithElevationData [ display-elevation ]
]
if (display-mode = "albedo")
[
ask patchesWithElevationData [ display-albedo ]
]
if (display-mode = "ETr")
[
let maxETr max [ETr] of patchesWithElevationData
ask patchesWithElevationData [ display-ETr maxETr ]
]
if (display-mode = "drainage coefficient (DC)")
[
ask patchesWithElevationData [ display-DC ]
]
if (display-mode = "root zone depth (z)")
[
let maxZ max [z] of patchesWithElevationData
ask patchesWithElevationData [ display-z maxZ ]
]
if (display-mode = "runoff curve number (CN)")
[
let maxCN max [CN] of patchesWithElevationData
ask patchesWithElevationData [ display-CN maxCN ]
]
if (display-mode = "water content at field capacity (FC)")
[
let maxFC max [FC] of patchesWithElevationData
ask patchesWithElevationData [ display-FC maxFC ]
]
if (display-mode = "water holding Capacity (WHC)")
[
let maxWHC max [WHC] of patchesWithElevationData
ask patchesWithElevationData [ display-WHC maxWHC ]
]
if (display-mode = "soil water content (WATp)")
[
let maxWATp max [WATp] of patchesWithElevationData
ask patchesWithElevationData [ display-WATp maxWATp ]
]
if (display-mode = "ARID coefficient")
[
ask patchesWithElevationData [ display-arid ]
]
display-flows
end
to display-elevation
let elevationGradient 100 + (155 * (elevation / maxElevation))
set pcolor rgb (elevationGradient - 100) elevationGradient 0
end
to display-albedo
set pcolor 1 + 9 * albedo
end
to display-ETr [ maxETr ]
ifelse (maxETr = 0)
[ set pcolor 25 ]
[ set pcolor 22 + 6 * (1 - ETr / maxETr) ]
end
to display-DC
set pcolor 112 + 6 * (1 - DC)
end
to display-z [ maxZ ]
set pcolor 42 + 8 * (1 - z / maxZ)
end
to display-CN [ maxCN ]
set pcolor 72 + 6 * (1 - CN / maxCN)
end
to display-FC [ maxFC ]
set pcolor 82 + 6 * (1 - FC / maxFC)
end
to display-WHC [ maxWHC ]
set pcolor 92 + 6 * (1 - WHC / maxWHC)
end
to display-WATp [ maxWATp ]
set pcolor 102 + 6 * (1 - WATp / maxWATp)
end
to display-ARID
set pcolor 12 + 6 * ARID
end
to display-flows
ask flowHolders
[
ask my-links
[
ifelse (show-flows) [ show-link ] [ hide-link ]
]
]
end
to plot-precipitation-table
clear-plot
let yearLengthInDays item (currentYear - weatherInputData_firstYear) weatherInputData_yearLengthInDays
set-plot-x-range 0 (yearLengthInDays + 1)
;;; precipitation (mm/day) is summed by month
foreach n-values yearLengthInDays [j -> j]
[
dayOfYearIndex ->
plotxy (dayOfYearIndex + 1) (item dayOfYearIndex precipitation_yearSeries)
]
plot-pen-up
end
to plot-cumPrecipitation-table
clear-plot
let yearLengthInDays item (currentYear - weatherInputData_firstYear) weatherInputData_yearLengthInDays
set-plot-y-range -0.1 1.1
set-plot-x-range 0 (yearLengthInDays + 1)
;;; precipitation (mm/day) is summed by month
foreach n-values yearLengthInDays [j -> j]
[
dayOfYearIndex ->
plotxy (dayOfYearIndex + 1) (item dayOfYearIndex precipitation_cumYearSeries)
]
plot-pen-up
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; LOAD DATA FROM TABLES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to load-weather-input-data-table
;;; this procedure loads the values of the weather data input table
;;; the table contains:
;;; 1. 13 lines of metadata, to be ignored
;;; 2. one line with the headers of the table
;;; 3. remaining rows containing row name and values
let weatherTable csv:from-file "data/POWER_Point_Daily_19840101_20201231_035d0309N_024d8335E_LST.csv"
;;;==================================================================================================================
;;; mapping coordinates (row or columns) from headings (line 14 == index 13 -----------------------------------------
;;; NOTE: always correct raw mapping coordinates (start at 1) into list indexes (start at 0)
let variableNames item (14 - 1) weatherTable
let yearColumn position "YEAR" variableNames
let solarRadiationColumn position "ALLSKY_SFC_SW_DWN" variableNames
let precipitationColumn position "PRECTOTCORR" variableNames
let temperatureColumn position "T2M" variableNames
let temperatureMaxColumn position "T2M_MAX" variableNames
let temperatureMinColumn position "T2M_MIN" variableNames
;;;==================================================================================================================
;;; extract data---------------------------------------------------------------------------------------
;;; read variables per year and day (list of lists, matrix: year-day x variables)
let weatherData sublist weatherTable (15 - 1) (length weatherTable) ; select only those row corresponding to variable data, if there is anything else
;;; extract year-day of year pairs from the third and fourth columns
set weatherInputData_YEARS map [row -> item yearColumn row ] weatherData
;;; NASA-POWER data uses year, month, day of month, instead of day of year,
;;; so we need to calculate day of year of each row ourselves
set weatherInputData_DOY []
set weatherInputData_yearLengthInDays []
foreach (remove-duplicates weatherInputData_YEARS)
[
aYear ->
let aDoy 1
let lengthOfThisYear length (filter [i -> i = aYear] weatherInputData_YEARS)
set weatherInputData_yearLengthInDays lput lengthOfThisYear weatherInputData_yearLengthInDays
repeat lengthOfThisYear
[
set weatherInputData_DOY lput aDoy weatherInputData_DOY
set aDoy aDoy + 1
]
]
set weatherInputData_YEAR-DOY (map [[i j] -> (word i "-" j)] weatherInputData_YEARS weatherInputData_DOY)
;;; extract first and last year
set weatherInputData_firstYear first weatherInputData_YEARS
set weatherInputData_lastYear last weatherInputData_YEARS
;;; extract parameter values from the given column
;;; NOTE: read-from-string is required because the original file is formated in a way that NetLogo interprets values as strings.
set weatherInputData_solarRadiation map [row -> item solarRadiationColumn row ] weatherData
set weatherInputData_precipitation map [row -> item precipitationColumn row ] weatherData
set weatherInputData_temperature map [row -> item temperatureColumn row ] weatherData
set weatherInputData_maxTemperature map [row -> item temperatureMaxColumn row ] weatherData
set weatherInputData_minTemperature map [row -> item temperatureMinColumn row ] weatherData
end
@#$#@#$#@
GRAPHICS-WINDOW
379
10
1125
484
-1
-1
3.0
1
10
1
1
1
0
1
1
1
0
245
0
154
0
0
1
ticks
30.0
BUTTON
37
26
92
59
NIL
setup
NIL
1
T
OBSERVER
NIL
1
NIL
NIL
1
BUTTON
212
25
267
58
NIL
go
T
1
T
OBSERVER
NIL
4
NIL
NIL
1
INPUTBOX
35
74
135
134
seed
0.0
1
0
Number
BUTTON
94
26
149
59
NIL
go
NIL
1
T
OBSERVER
NIL
2
NIL
NIL
1
PLOT
1206
185
1841
369
Temperature
days
ºC
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"mean" 1.0 0 -16777216 true "" "plot T"
"min" 1.0 0 -13345367 true "" "plot T_min"
"max" 1.0 0 -2674135 true "" "plot T_max"
PLOT
1207
372
1799
514
Solar radiation
days
MJ/m2
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot solarRadiation"
MONITOR
29
155
108
200
NIL
currentYear
0
1
11
MONITOR
110
155
224
200
NIL
currentDayOfYear
0
1
11
CHOOSER
18
209
264
254
display-mode
display-mode
"elevation" "albedo" "ETr" "drainage coefficient (DC)" "root zone depth (z)" "runoff curve number (CN)" "water content at field capacity (FC)" "water holding Capacity (WHC)" "soil water content (WATp)" "ARID coefficient"
9
BUTTON
273
217
347
250
refresh view
refresh-view
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
151
25
211
58
+ year
repeat 365 [ go ]
NIL
1
T
OBSERVER
NIL
3
NIL
NIL
1
PLOT
1203
514
1864
672
precipitation
days
ppm
0.0
10.0
0.0
10.0
true
true
"" ""
PENS
"RAIN" 1.0 1 -16777216 true "" "plot RAIN"
"mean ETr" 1.0 0 -2674135 true "" "plot mean[ETr] of patches"
PLOT
1492
674
1749
794
cumulative year precipitation
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"set-plot-y-range -0.1 1.1\nlet yearLengthInDays item (currentYear - weatherInputData_firstYear) weatherInputData_yearLengthInDays\nset-plot-x-range 0 (yearLengthInDays + 1)" ""
PENS
"default" 1.0 0 -16777216 true "" "if (currentDayOfYear = 1) [ plot-cumPrecipitation-table ]"