forked from Andros-Spica/SIMPLE-crop-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSIMPLE-crop-model.nlogo
3148 lines (2619 loc) · 77.3 KB
/
SIMPLE-crop-model.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 ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SIMPLE crop model (NetLogo implementation)
;; Copyright (C) 2021 Andreas Angourakis ([email protected])
;; available at https://www.github.com/Andros-Spica/indus-village-model
;; based on the model of Zhao et al. 2019 (https://doi.org/10.1016/j.eja.2019.01.009)
;; and implementing the Soil Water Balance model from Wallach et al. 2006 'Working with dynamic crop models' (p. 24-28 and p. 138-144).
;; available at https://www.github.com/Andros-Spica/SIMPLE-crop-model
;;
;; 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 vid]
;;;;;;;;;;;;;;;;;
;;;;; BREEDS ;;;;
;;;;;;;;;;;;;;;;;
; no breeds
;;;;;;;;;;;;;;;;;
;;; VARIABLES ;;;
;;;;;;;;;;;;;;;;;
globals
[
;;; default constants
totalPatches
maxDist
yearLengthInDays
typesOfCrops
;;;; Soil Water Balance model global parameters (conditions assumed to be locally homogeneous)
MUF ; Water Uptake coefficient (mm^3.mm^-3)
WP ; Water content at wilting Point (cm^3.cm^-3)
;;;; Crop management
f_Solar_max ; fSolar_max is the maximum fraction of radiation interception that a crop can reach
; Zhao et al. 2019 note: fSolar_max is considered as a management parameter, not a crop parameter, to account for different plant spacings. For most high-density crops, this value is set at 0.95.
;;; modified parameters
;;;; Simulated weather input
;;;; temperature (ºC)
temperature_annualMaxAt2m
temperature_annualMinAt2m
temperature_meanDailyFluctuation
temperature_dailyLowerDeviation
temperature_dailyUpperDeviation
;;;; precipitation (mm)
precipitation_yearlyMean
precipitation_yearlySd
precipitation_dailyCum_nSamples
precipitation_dailyCum_maxSampleSize
precipitation_dailyCum_plateauValue_yearlyMean
precipitation_dailyCum_plateauValue_yearlySd
precipitation_dailyCum_inflection1_yearlyMean
precipitation_dailyCum_inflection1_yearlySd
precipitation_dailyCum_rate1_yearlyMean
precipitation_dailyCum_rate1_yearlySd
precipitation_dailyCum_inflection2_yearlyMean
precipitation_dailyCum_inflection2_yearlySd
precipitation_dailyCum_rate2_yearlyMean
precipitation_dailyCum_rate2_yearlySd
;;;; CO2 (ppm)
CO2_annualMin
CO2_annualMax
CO2_meanDailyFluctuation
;;;; Solar radiation (MJ/m2)
solar_annualMax
solar_annualMin
solar_meanDailyFluctuation
;;;; ETr
albedo ; canopy reflection or albedo of hypothetical grass reference crop (0.23). See http://www.fao.org/3/X0490E/x0490e07.htm
elevation ; elevation above sea level [m]
;;;; Soil Water Balance model global parameters
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
;;;; Crop parameters (extracted from cropsTable.csv)
;;;; the above are lists of floats
;;;; Species-specific
RUE ; Radiation use efficiency (above ground only and without respiration) (g MJ−1 m-2)
T_base ; Base temperature for phenology development and growth (ºC)
T_opt ; Optimal temperature for biomass growth (ºC)
I_50maxH ; The maximum daily reduction in I50B due to heat stress (ºC d)
I_50maxW ; The maximum daily reduction in I50B due to drought stress (ºC d)
T_heat ; Threshold temperature to start accelerating senescence from heat stress (ºC). In the Zhao et al. 2019, named as T_max
T_extreme ; The extreme temperature threshold when RUE becomes 0 due to heat stress (ºC)
S_CO2 ; sensitivity of crop RUE (Relative increase in RUE) per ppm elevated CO2 above 350 ppm
S_Water ; sensitivity of crop RUE to the ARID index (representing water shortage; see below)
;;;; Cultivar-specific
T_sum ; Cumulative temperature requirement from sowing to maturity (ºC d)
HI ; Potential harvest index
I_50A ; Cumulative temperature requirement for leaf area development to intercept 50% of radiation (ºC d)
I_50B ; Cumulative temperature till maturity to reach 50% radiation interception due to leaf senescence (ºC d)
;;;; management
sugSowingDay ; sowing day (day of year)
sugHarvestingDay ; harvesting day (day of year)
;;; variables
;;;; time tracking
currentYear
currentDayOfYear
;;;; 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)
CO2 ; average CO2 concentration of the current day (ppm)
solarRadiation ; solar radiation of current day (MJ m-2)
netSolarRadiation ; net solar radiation discount canopy reflection or albedo, assuming hypothetical grass reference crop (albedo = 0.23)
ETr ; reference evapotranspiration
RAIN ; precipitation of current day (mm)
precipitation_yearSeries
precipitation_cumYearSeries
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
sowingDay
harvestingDay
TT ; cumulative mean temperature (ºC day)
biomass ; crop biomass (g)
yield ; crop biomass harvested (g)
;;; auxiliar variables
biomass_rate ; daily change in plant biomass (g)
f_solar ; the fraction of solar ra- diation intercepted by a crop canopy
I_50Blocal ; The cumulative temperature required to reach 50% of radiation interception during canopy senescence (I50B) (value affected by heat and drought stress)
f_CO2 ; CO2 impact
f_temp ; temperature impact
f_heat ; heat stress
f_water ; drought stress
;;;; counters and final measures
ARID_yearSeries ; registers daily values of ARID of the current year (used to export data)
ARID_yearSeries_lastYear ; saves daily values of ARID of the last year (used to export data)
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
; --- loading/testing parameters -----------
set-constants
load-crops-table
set-parameters
; --- core procedures ----------------------
set currentDayOfYear 1
setup-crops
update-weather
ask patches [ update-WAT ]
; --- output handling ------------------------
print-crop-table
setup-plot-crop
update-plot-crop
reset-ticks
end
to set-constants
; "constants" are variables that will not be explored as parameters
; and may be used during a simulation.
; In this example, the constants depend on the size of the dimensions (x,y)
set totalPatches count patches
; maximum distance
set maxDist sqrt (((max-pxcor - min-pxcor) ^ 2) + ((max-pxcor - min-pxcor) ^ 2))
set yearLengthInDays 365
; 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
; maximum fraction of radiation interception
set f_Solar_max 0.95
end
to set-parameters
; set random seed
random-seed randomSeed
; check parameters values
parameters-check
;;; setup parameters depending on the type of experiment
if (type-of-experiment = "user-defined")
[
;;; load parameters from user interface
;;; weather generation
set temperature_annualMaxAt2m temperature_annual-max-at-2m
set temperature_annualMinAt2m temperature_annual-min-at-2m
set temperature_meanDailyFluctuation temperature_mean-daily-fluctuation
set temperature_dailyLowerDeviation temperature_daily-lower-deviation
set temperature_dailyUpperDeviation temperature_daily-upper-deviation
set CO2_annualMin CO2-annual-min
set CO2_annualMax CO2-annual-max
set CO2_meanDailyFluctuation CO2-mean-daily-fluctuation
set solar_annualMax solar_annual-max
set solar_annualMin solar_annual-min
set solar_meanDailyFluctuation solar_mean-daily-fluctuation
set precipitation_yearlyMean precipitation_yearly-mean
set precipitation_yearlySd precipitation_yearly-sd
set precipitation_dailyCum_nSamples precipitation_daily-cum_n-samples
set precipitation_dailyCum_maxSampleSize precipitation_daily-cum_max-sample-size
set precipitation_dailyCum_plateauValue_yearlyMean precipitation_daily-cum_plateau-value_yearly-mean
set precipitation_dailyCum_plateauValue_yearlySd precipitation_daily-cum_plateau-value_yearly-sd
set precipitation_dailyCum_inflection1_yearlyMean precipitation_daily-cum_inflection1_yearly-mean
set precipitation_dailyCum_inflection1_yearlySd precipitation_daily-cum_inflection1_yearly-sd
set precipitation_dailyCum_rate1_yearlyMean precipitation_daily-cum_rate1_yearly-mean
set precipitation_dailyCum_rate1_yearlySd precipitation_daily-cum_rate1_yearly-sd
set precipitation_dailyCum_inflection2_yearlyMean precipitation_daily-cum_inflection2_yearly-mean
set precipitation_dailyCum_inflection2_yearlySd precipitation_daily-cum_inflection2_yearly-sd
set precipitation_dailyCum_rate2_yearlyMean precipitation_daily-cum_rate2_yearly-mean
set precipitation_dailyCum_rate2_yearlySd precipitation_daily-cum_rate2_yearly-sd
set albedo par_albedo
set elevation par_elevation
;;; Soil Water Balance model
set elevation par_elevation
set WHC water-holding-capacity
set DC drainage-coefficient
set z root-zone-depth
set CN runoff-curve
]
if (type-of-experiment = "random")
[
;;; use values from user interface as a maximum for random uniform distributions
set temperature_annualMaxAt2m 15 + random-float 25
set temperature_annualMinAt2m -15 + random-float 30
set temperature_meanDailyFluctuation random-float 5
set temperature_dailyLowerDeviation random-float 10
set temperature_dailyUpperDeviation random-float 10
set CO2_annualMin random-normal 250 20
set CO2_annualMax CO2_annualMin + random-float 10
set CO2_meanDailyFluctuation max (list 0 random-normal 2.5 0.5)
set solar_annualMin 1.5 + random-float 15
set solar_annualMax 20 + random-float 10
set solar_meanDailyFluctuation 3 + random-float 3
set precipitation_yearlyMean 200 + random-float 800
set precipitation_yearlySd random-float 200
set precipitation_dailyCum_nSamples 100 + random 200
set precipitation_dailyCum_maxSampleSize 5 + random 20
set precipitation_dailyCum_plateauValue_yearlyMean 0.2 + random-float 0.6
set precipitation_dailyCum_plateauValue_yearlySd random-float 0.4
set precipitation_dailyCum_inflection1_yearlyMean 40 + random 140
set precipitation_dailyCum_inflection1_yearlySd 20 + random 80
set precipitation_dailyCum_rate1_yearlyMean 0.01 + random-float 0.07
set precipitation_dailyCum_rate1_yearlySd 0.004 + random-float 0.02
set precipitation_dailyCum_inflection2_yearlyMean 180 + random 140
set precipitation_dailyCum_inflection2_yearlySd 20 + random 80
set precipitation_dailyCum_rate2_yearlyMean 0.01 + random-float 0.07
set precipitation_dailyCum_rate2_yearlySd 0.004 + random-float 0.02
set albedo 1E-6 + random-float 0.6
set elevation random-float 2000
;;; Soil Water Balance model
set elevation random-float 2000
set WHC 0.05 + random-float 0.2
set DC 1E-6 + random-float 0.9
set z 1E-6 + random-float 2500
set CN random-float 90
;;; NOTES about calibration:
;;; Global Horizontal Irradiation can vary from about 2 to 7 KWh/m-2 per day.
;;; (conversion kWh/m2 to MJ/m2 is 1 : 3.6)
;;; See approx. values in https://globalsolaratlas.info/
;;; and https://www.researchgate.net/publication/271722280_Solmap_Project_In_India%27s_Solar_Resource_Assessment
;;; see general info in http://www.physicalgeography.net/fundamentals/6i.html
]
; FC : Water content at field capacity (cm^3.cm^-3)
set FC WP + WHC
; WAT0 : Initial Water content (mm)
set WAT z * FC
;;; sowing/harvest dates are initialised as the ones suggested in cropTable.csv
set sowingDay sugSowingDay
set harvestingDay sugHarvestingDay
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)
;;; the default values of weather parameters aim to broadly represent conditions in Haryana, NW India.
if (temperature_annual-max-at-2m = 0) [ set temperature_annual-max-at-2m 37 ]
if (temperature_annual-min-at-2m = 0) [ set temperature_annual-min-at-2m 12.8 ]
if (temperature_mean-daily-fluctuation = 0) [ set temperature_mean-daily-fluctuation 2.2 ]
if (temperature_daily-lower-deviation = 0) [ set temperature_daily-lower-deviation 6.8 ]
if (temperature_daily-upper-deviation = 0) [ set temperature_daily-upper-deviation 7.9 ]
if (CO2-annual-min = 0) [ set CO2-annual-min 245 ]
if (CO2-annual-max = 0) [ set CO2-annual-max 255 ]
if (CO2-mean-daily-fluctuation = 0) [ set CO2-mean-daily-fluctuation 1 ]
if (solar_annual-max = 0) [ set solar_annual-max 24.2 ]
if (solar_annual-min = 0) [ set solar_annual-min 9.2 ]
if (solar_mean-daily-fluctuation = 0) [ set solar_mean-daily-fluctuation 3.3 ]
if (precipitation_yearly-mean = 0) [ set precipitation_yearly-mean 489 ]
if (precipitation_yearly-sd = 0) [ set precipitation_yearly-sd 142.2 ]
if (precipitation_daily-cum_n-samples = 0) [ set precipitation_daily-cum_n-samples 200 ]
if (precipitation_daily-cum_max-sample-size = 0) [ set precipitation_daily-cum_max-sample-size 10 ]
if (precipitation_daily-cum_plateau-value_yearly-mean = 0) [ set precipitation_daily-cum_plateau-value_yearly-mean 0.25 ]
if (precipitation_daily-cum_plateau-value_yearly-sd = 0) [ set precipitation_daily-cum_plateau-value_yearly-sd 0.1 ]
if (precipitation_daily-cum_inflection1_yearly-mean = 0) [ set precipitation_daily-cum_inflection1_yearly-mean 40 ]
if (precipitation_daily-cum_inflection1_yearly-sd = 0) [ set precipitation_daily-cum_inflection1_yearly-sd 5 ]
if (precipitation_daily-cum_rate1_yearly-mean = 0) [ set precipitation_daily-cum_rate1_yearly-mean 0.07 ]
if (precipitation_daily-cum_rate1_yearly-sd = 0) [ set precipitation_daily-cum_rate1_yearly-sd 0.02 ]
if (precipitation_daily-cum_inflection2_yearly-mean = 0) [ set precipitation_daily-cum_inflection2_yearly-mean 240 ]
if (precipitation_daily-cum_inflection2_yearly-sd = 0) [ set precipitation_daily-cum_inflection2_yearly-sd 20 ]
if (precipitation_daily-cum_rate2_yearly-mean = 0) [ set precipitation_daily-cum_rate2_yearly-mean 0.08 ]
if (precipitation_daily-cum_rate2_yearly-sd = 0) [ set precipitation_daily-cum_rate2_yearly-sd 0.02 ]
if (par_albedo = 0) [ set par_albedo 0.23 ]
if (par_elevation = 0) [ set par_elevation 200 ]
if (water-holding-capacity = 0) [ set water-holding-capacity 0.15 ]
if (drainage-coefficient = 0) [ set drainage-coefficient 0.55 ]
if (root-zone-depth = 0) [ set root-zone-depth 400 ]
if (runoff-curve = 0) [ set runoff-curve 65 ]
end
to parameters-to-default
;;; set parameters to a default value
set end-simulation-in-year 5
set temperature_annual-max-at-2m 37
set temperature_annual-min-at-2m 12.8
set temperature_mean-daily-fluctuation 2.2
set temperature_daily-lower-deviation 6.8
set temperature_daily-upper-deviation 7.9
set CO2-annual-min 245
set CO2-annual-max 255
set CO2-mean-daily-fluctuation 1
set solar_annual-max 24.2
set solar_annual-min 9.2
set solar_mean-daily-fluctuation 3.3
set precipitation_yearly-mean 489
set precipitation_yearly-sd 142.2
set precipitation_daily-cum_n-samples 200
set precipitation_daily-cum_max-sample-size 10
set precipitation_daily-cum_plateau-value_yearly-mean 0.25
set precipitation_daily-cum_plateau-value_yearly-sd 0.1
set precipitation_daily-cum_inflection1_yearly-mean 40
set precipitation_daily-cum_inflection1_yearly-sd 5
set precipitation_daily-cum_rate1_yearly-mean 0.07
set precipitation_daily-cum_rate1_yearly-sd 0.02
set precipitation_daily-cum_inflection2_yearly-mean 240
set precipitation_daily-cum_inflection2_yearly-sd 20
set precipitation_daily-cum_rate2_yearly-mean 0.08
set precipitation_daily-cum_rate2_yearly-sd 0.02
set par_albedo 0.23
set par_elevation 200
set water-holding-capacity 0.15
set drainage-coefficient 0.55
set root-zone-depth 400
set runoff-curve 65
end
to setup-crops
;;; initialise all crop related variables as list where items correspond to crops
set TT n-values (length typesOfCrops) [ j -> 0 ]
set biomass n-values (length typesOfCrops) [ j -> 0 ]
set yield n-values (length typesOfCrops) [ j -> 0 ]
set biomass_rate n-values (length typesOfCrops) [ j -> 0 ]
set f_solar n-values (length typesOfCrops) [ j -> 0 ]
set I_50Blocal n-values (length typesOfCrops) [ j -> 0 ]
set f_CO2 n-values (length typesOfCrops) [ j -> 0 ]
set f_temp n-values (length typesOfCrops) [ j -> 0 ]
set f_heat n-values (length typesOfCrops) [ j -> 0 ]
set f_water n-values (length typesOfCrops) [ j -> 0 ]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
; --- core procedures -------------------------
update-weather
update-WAT
update-crops
; --- output handling ------------------------
update-ARID_yearSeries
update-plot-crop
; -- time -------------------------------------
advance-time
tick
; --- stop conditions -------------------------
if (ticks = end-simulation-in-year * yearLengthInDays) [stop]
end
;;; GLOBAL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to advance-time
set currentDayOfYear currentDayOfYear + 1
if (currentDayOfYear > yearLengthInDays)
[
set currentYear currentYear + 1
set currentDayOfYear 1
]
end
to update-weather
;;; values are assigned using simple parametric models
;;; alternatively, a specific time series could be used
update-temperature currentDayOfYear
update-precipitation currentDayOfYear
set CO2 get-CO2 currentDayOfYear
set solarRadiation get-solar-radiation currentDayOfYear
set netSolarRadiation (1 - albedo) * solarRadiation
set ETr get-ETr
end
to update-temperature [ dayOfYear ]
set T get-temperature dayOfYear
set T_min T - temperature_dailyLowerDeviation
set T_max T + temperature_dailyUpperDeviation
end
to-report get-temperature [ dayOfYear ]
;;; get temperature base level for the current day (ºC at lowest elevation)
report (get-annual-sinusoid-with-fluctuation
temperature_annualMinAt2m
temperature_annualMaxAt2m
temperature_meanDailyFluctuation
dayOfYear
southHemisphere?
)
end
to update-precipitation [ dayOfYear ]
if (dayOfYear = 1) [ set-precipitation-of-year ]
set RAIN item (dayOfYear - 1) precipitation_yearSeries
end
to set-precipitation-of-year
;;; Initialisation ===================================================================
;;; get randomised values for parameters of the double logistic curve
let plateauValue clamp01 (random-normal precipitation_dailyCum_plateauValue_yearlyMean precipitation_dailyCum_plateauValue_yearlySd)
let inflection1 clampMinMax (random-normal precipitation_dailyCum_inflection1_yearlyMean precipitation_dailyCum_inflection1_yearlySd) 1 yearLengthInDays
let rate1 clampMin0 (random-normal precipitation_dailyCum_rate1_yearlyMean precipitation_dailyCum_rate1_yearlySd)
let inflection2 clampMinMax (random-normal precipitation_dailyCum_inflection2_yearlyMean precipitation_dailyCum_inflection2_yearlySd) 1 yearLengthInDays
let rate2 clampMin0 (random-normal precipitation_dailyCum_rate2_yearlyMean precipitation_dailyCum_rate2_yearlySd)
;print (word "plateauValue = " plateauValue ", inflection1 = " inflection1 ", rate1 = " rate1 ", inflection2 = " inflection2 ", rate2 = " rate2)
;;; get randomised total precipitation of current year
let totalYearPrecipitation clampMin0 (random-normal precipitation_yearlyMean precipitation_yearlySd)
;;; ==================================================================================
;;; Simulate *cumulative proportion of year precipitation*
;;; NOTE: double logistic curve as a proxy of the year series of daily cumulative precipitation
set precipitation_cumYearSeries (get-cumulative-curve
; parameters for creatin a double logistic curve
plateauValue inflection1 rate1 inflection2 rate2
; length of curve. NOTE: one more point besides lenghtOfCurve to account for the initial derivative
(yearLengthInDays + 1)
; parameters for stochastically breaking down the curve into steps
precipitation_dailyCum_nSamples precipitation_dailyCum_maxSampleSize
)
;;; Derivate *daily proportion of year precipitation* from simulated *cumulative proportion of year precipitation*.
;;; These are the difference between day i and day i - 1
let precipitation_propYearSeries get-incremets-from-curve precipitation_cumYearSeries
;;; exclude the first element (which is the extra theoretical day used for derivative calculation)
set precipitation_propYearSeries but-first precipitation_propYearSeries
;;; Calculate *daily precipitation* values by multipling *daily proportions of year precipitation* by the *year total precipitation*
set precipitation_yearSeries map [ i -> i * totalYearPrecipitation ] precipitation_propYearSeries
end
to-report get-solar-radiation [ dayOfYear ]
;;; get solar radiation for the current day (MJ/m2)
report max (list 0 (get-annual-sinusoid-with-fluctuation
solar_annualMin
solar_annualMax
solar_meanDailyFluctuation
dayOfYear
southHemisphere?
))
;;; NOTE: it might be possible to decrease solar radiation depending on the current day precipitation. Additional info on precipitation effect on solar radiation is needed.
end
to-report get-CO2 [ dayOfYear ]
;;; get CO2 atmospheric concentration for the current day (ppm)
report (get-annual-sinusoid-with-fluctuation
CO2_annualMin
CO2_annualMax
CO2_meanDailyFluctuation
dayOfYear
southHemisphere?
)
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
;=======================================================================================================
;;; START of SIMPLE crop model algorithms
;;; Zhao C, Liu B, Xiao L, Hoogenboom G, Boote K J, Kassie B T,
;;; Pavan W, Shelia V, Kim K S, Hernandez-Ochoa I M, Wallach D,
;;; Porter C H, Stockle C O, Zhu Y and Asseng S (2019)
;;; A SIMPLE crop model Eur. J. Agron. 104 97–106
;;; Online: https://doi.org/10.1016/j.eja.2019.01.009
;;; See also: "04-crop-model" directory within "indus-village-model".
;=======================================================================================================
to update-crops
foreach typesOfCrops
[
crop ->
let cropIndex position crop typesOfCrops
if ( is-growing cropIndex )
[
update-biomass cropIndex
]
if ( is-ripe cropIndex )
[
;;; calculate harvest yield
ifelse (item cropIndex TT >= item cropIndex T_sum)
[ set yield replace-item cropIndex yield (item cropIndex biomass * item cropIndex HI) ]
[ set yield replace-item cropIndex yield 0 ]
;;; reset biomass and auxiliary variables
reset-crop-variables cropIndex
]
]
end
to reset-crop-variables [ cropIndex ]
set TT replace-item cropIndex TT 0
set biomass replace-item cropIndex biomass 0
set biomass_rate replace-item cropIndex biomass_rate 0
set f_solar replace-item cropIndex f_solar 0
set I_50Blocal replace-item cropIndex I_50Blocal 0
set f_temp replace-item cropIndex f_temp 0
set f_CO2 replace-item cropIndex f_CO2 0
set f_heat replace-item cropIndex f_heat 0
set f_water replace-item cropIndex f_water 0
end
to-report is-growing [ cropIndex ]
let myCropSowingDay (item cropIndex sowingDay)
let myCropHarvestingDay (item cropIndex harvestingDay)
ifelse (myCropSowingDay < myCropHarvestingDay)
[
; summer crop (sowing day comes before harvesting day in the Jan-Dec calendar)
report (currentDayOfYear >= myCropSowingDay) and (currentDayOfYear < myCropHarvestingDay)
]
[
; winter crop (harvesting day comes before sowing day in the Jan-Dec calendar; ignore first year harvest)
report (currentDayOfYear >= myCropSowingDay) or (currentYear > 0 and currentDayOfYear < myCropHarvestingDay)
]
end
to-report is-ripe [ cropIndex ]
report (currentDayOfYear = item cropIndex harvestingDay)
end
to update-biomass [ cropIndex ]
update-TT cropIndex
update-f_CO2 cropIndex
update-f_Temp cropIndex
update-f_Heat cropIndex
update-f_Water cropIndex
set I_50Blocal replace-item cropIndex I_50Blocal ((item cropIndex I_50B) + (item cropIndex I_50maxW) * (1 - item cropIndex f_Water) + (item cropIndex I_50maxH) * (1 - item cropIndex f_Heat))
update-f_Solar cropIndex
set biomass_rate replace-item cropIndex biomass_rate (solarRadiation * (item cropIndex RUE) * (item cropIndex f_Solar) * (item cropIndex f_CO2) * (item cropIndex f_Temp) * (clampMin0 (min (list (item cropIndex f_Heat) (item cropIndex f_Water)))))
set biomass replace-item cropIndex biomass (item cropIndex biomass + item cropIndex biomass_rate)
end
to update-TT [ cropIndex ]
let deltaTT 0
ifelse ( T > item cropIndex T_base )
[
set deltaTT T - item cropIndex T_base
]
[
set deltaTT 0
]
set TT replace-item cropIndex TT (item cropIndex TT + deltaTT)
end
to update-f_CO2 [ cropIndex ]
ifelse ( CO2 <= 350 )
[
set f_CO2 replace-item cropIndex f_CO2 1 ; this is not specified in Zhao et al. 2019
]
[
ifelse ( CO2 > 700 )
[
set f_CO2 replace-item cropIndex f_CO2 (1 + (item cropIndex S_CO2) * 350)
]
[
set f_CO2 replace-item cropIndex f_CO2 (1 + (item cropIndex S_CO2) * (CO2 - 350))
]
]
end
to update-f_Temp [ cropIndex ]
ifelse ( T < item cropIndex T_base )
[
set f_Temp replace-item cropIndex f_Temp 0
]
[
ifelse ( T >= item cropIndex T_opt )
[
set f_Temp replace-item cropIndex f_Temp 1
]
[
set f_Temp replace-item cropIndex f_Temp ((T - item cropIndex T_base) / (item cropIndex T_opt - item cropIndex T_base))
]
]
end
to update-f_Heat [ cropIndex ]
ifelse ( T_max <= item cropIndex T_heat )
[
set f_Heat replace-item cropIndex f_Heat 1
]
[
ifelse ( T_max > item cropIndex T_extreme )
[
set f_Heat replace-item cropIndex f_Heat 0
]
[
set f_Heat replace-item cropIndex f_Heat ((T_max - item cropIndex T_heat) / (item cropIndex T_extreme - item cropIndex T_heat))
]
]
end
to update-f_Water [ cropIndex ]
set f_Water replace-item cropIndex f_Water (1 - (item cropIndex S_Water) * ARID)
end
to update-f_Solar [ cropIndex ]
let f_Solar_early (f_Solar_max / (1 + e ^ (-0.01 * (item cropIndex TT - item cropIndex I_50A))))
let f_Solar_late (f_Solar_max / (1 + e ^ (-0.01 * (item cropIndex TT - item cropIndex I_50Blocal))))
set f_Solar replace-item cropIndex f_Solar min (list f_Solar_early f_Solar_late)
;;; drought effect
if (item cropIndex f_Water < 0.1)
[
set f_Solar replace-item cropIndex f_Solar (item cropIndex f_Solar * (0.9 + item cropIndex f_Water))
]
end
;=======================================================================================================
;;; END of SIMPLE crop model algorithms
;;; Zhao C, Liu B, Xiao L, Hoogenboom G, Boote K J, Kassie B T,
;;; Pavan W, Shelia V, Kim K S, Hernandez-Ochoa I M, Wallach D,
;;; Porter C H, Stockle C O, Zhu Y and Asseng S (2019)
;;; A SIMPLE crop model Eur. J. Agron. 104 97–106
;;; Online: https://doi.org/10.1016/j.eja.2019.01.009
;;; See also: "04-crop-model" directory within "indus-village-model".
;=======================================================================================================
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; COUNTERS AND MEASURES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to update-ARID_yearSeries
; if starting a new year
if (currentDayOfYear = 1)
[
; save current year as last year
set ARID_yearSeries_lastYear ARID_yearSeries
; reset ARID_yearSeries if starting a new year
set ARID_yearSeries (list)
]
; append this day ARID to ARID_yearSeries
set ARID_yearSeries lput ARID ARID_yearSeries
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; DISPLAY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to plot-precipitation-table
clear-plot
;;; 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
;;; 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
to plot-precipitation-table-by-month
;;; precipitation (mm/day) is summed by month
let daysPerMonths [ 31 28 31 30 31 30 31 31 30 31 30 31 ] ; days per months -- (31 * 7) + (30 * 4) + 28
foreach n-values 12 [j -> j]
[
month ->
let startDay 1
if (month = 1) [ set startDay (item 0 daysPerMonths) + 1 ]
if (month > 1) [ set startDay sum (sublist daysPerMonths 0 month) + 1 ]
let endDay startDay + item month daysPerMonths
plotxy (startDay) (sum sublist precipitation_yearSeries (startDay - 1) (endDay - 1)) ; correct to list indexes (starting with 0 instead of 1)
]
plot-pen-up
end
to print-crop-table
output-print (word " | typesOfCrops | T_sum | HI | I_50A | I_50B | T_base | T_opt | RUE | I_50maxH | I_50maxW | T_heat | T_ext | S_water | sugSowingDay | sugHarvestingDay | ")
foreach n-values (length typesOfCrops) [j -> j]
[
cropIndex ->
output-print (word
" | " (item cropIndex typesOfCrops)
" | " (item cropIndex T_sum)
" | " (item cropIndex HI)
" | " (item cropIndex I_50A)
" | " (item cropIndex I_50B)
" | " (item cropIndex T_base)
" | " (item cropIndex T_opt)
" | " (item cropIndex RUE)
" | " (item cropIndex I_50maxH)
" | " (item cropIndex I_50maxW)
" | " (item cropIndex T_heat)
" | " (item cropIndex T_extreme)
" | " (item cropIndex S_water)