forked from eleanorecc/MICCORDEA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRICEPEST-Original.py
2530 lines (2172 loc) · 92.7 KB
/
RICEPEST-Original.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
#NAME: RICEPEST Spatial Model
#DESCRIPTION: Generic RICEPEST tool for calculating attainable and actual yields based on supplied parameters
#REQUIREMENTS: ArcGIS Spatial Analyst Extension
#DEVELOPED BY: Confidence Duku (AfricaRice), Adam Sparks (IRRI), Sander Zwart (AfricaRice)
#BASED ON WORK DONE BY: Laetitia Willocquet and Serge Savary (IRRI)
#ORIGINAL VERSION WITH UNMODIFIED PS3
import arcpy
import sys
import os
arcpy.AddMessage("\n NAME: RICEPEST Spatial Model")
arcpy.AddMessage(" DEVELOPED BY: Confidence Duku (AfricaRice), Adam Sparks (IRRI) and Sander Zwart (AfricaRice)")
arcpy.AddMessage(" BASED ON WORK BY: Laetitia Willocquet and Serge Savary (IRRI)")
arcpy.AddMessage(" REQUIREMENTS: ArcGIS Spatial Analyst Extension")
arcpy.AddMessage("\nSetting Environment Variables")
#obtaining directory for script and associated folders
scriptPath = sys.argv[0]
PathName = os.path.dirname(scriptPath)
#Setting environment variables;
arcpy.env.extent = "MINOF"
arcpy.env.scratchWorkspace = PathName + "\\Output"
arcpy.env.cellSize = "MINOF"
arcpy.env.workspace = PathName + "\\ab50"
arcpy.env.overwriteOutput = 1
path = PathName + "\\Output\\"
path1 = PathName + "\\Yields\\"
#analysisType = sys.argv[4]
analysisType = "Actual Yield"
cropEst = "Transplanted"
TransplantDays = 20
prodSituation = "PS2"
arcpy.AddMessage("RUNNING, " + prodSituation + " ," + analysisType)
arcpy.CheckOutExtension("Spatial")
#Prefix the climate and disease data with the following to distinguish them
RadGDB = arcpy.ListRasters("rad*", "GRID")
TempGDB = arcpy.ListRasters("tmean*", "GRID")
IniTemp = arcpy.ListRasters("i*", "GRID")
BlastGDB = arcpy.ListRasters("*blast*", "TIF")
BlightGDB = arcpy.ListRasters("*bblight*", "TIF")
if prodSituation == "PS1":
PANW = 0
LEAFW = 10
STEMW = 6
ROOTW = 5
TBASE = 8
#calculating the sum of temperature between crop establishment and the start of simulation
jt = 0
rt = 0
kt = 0
#check if rice variety is direct seeded or transplanted.
if cropEst == "Direct Seeded":
arcpy.AddMessage("\nCalculating Sum of Initial Temperature for Direct Seeded Systems")
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if rt == 0:
out3 = arcpy.sa.Minus(raster, TBASE)
out2 = arcpy.sa.Con(out3, 0, out3, where1)
rt = rt + 1
ty = str(rt)
name = "out2_" + ty
out2.save(path + name)
else:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out2 = out2 + out6
rt = rt + 1
ty = str(rt)
name = "out2_" + ty
out2.save(path + name)
elif cropEst == "Transplanted":
arcpy.AddMessage("Calculating Sum of Initial Temperature for Transplanted Systems\n")
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if jt == 0:
if kt != TransplantDays:
out3 = arcpy.sa.Minus(raster, TBASE)
out4 = arcpy.sa.Con(out3, 0, out3, where1)
jt = jt + 1
kt = kt + 1
else:
break
else:
if kt != TransplantDays:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out4 = out4 + out6
jt = jt + 1
kt = kt + 1
else:
break
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if rt == 0:
out3 = arcpy.sa.Minus(raster, TBASE)
out23 = arcpy.sa.Con(out3, 0, out3, where1)
rt = rt + 1
ty = str(rt)
name = "out23_" + ty
out23.save(path + name)
else:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out23 = out23 + out6
rt = rt + 1
ty = str(rt)
name = "out23_" + ty
name1 = "sumtr"
out23.save(path + name)
out22 = 0.785 * out4
out22.save(path + "tshock")
out2 = out23 - out22
out2.save(path + name1)
#calculating sum of temp above TBASE
i = 0
for temp in TempGDB:
test = 0
where1 = "\"VALUE\" < %d" % test
tempDate = temp[5:]
#calculating sum of temperature
bn = i + 15
ft = str(bn)
arcpy.AddMessage("SIMULATION AT " + ft + " DACE")
arcpy.AddMessage(" Calculating Sum of Temperature above TBASE")
if i == 0:
out4 = arcpy.sa.Minus(temp, TBASE)
out5 = arcpy.sa.Con(out4, 0, out4, where1)
co_sumt = out5 + out2
i = i + 1
ty = str(i)
name = "sumt" + ty
co_sumt.save(path + name)
else:
DTemp = arcpy.sa.Minus(temp, TBASE)
DTemp1 = arcpy.sa.Con(DTemp, 0, DTemp, where1)
co_sumt = DTemp1 + co_sumt
i = i + 1
ty = str(i)
name = "sumt" + ty
co_sumt.save(path + name)
def sla():
arcpy.AddMessage(" Calculating Specific Leaf Area")
#calculating SLA
#always add 1 to the value of sumt**
#hence sumt007 with value of 0.07 becomes 1.07 in the equation
sumt0 = (-435 * (1**2))+(2755 * 1)-2320
sumt05 = (-435 * (1.5**2))+(2755 * 1.5)-2320
sumt1 = (-435 * (2**2))+(2755 * 2)-2320
sumt2 = (-435 * (3**2))+(2755 * 3)-2320
where0 = "\"VALUE\" <= %d" % sumt0
where05 = "\"VALUE\" <= %d" % sumt05
where1 = "\"VALUE\" <= %d" % sumt1
where2 = "\"VALUE\" <= %d" % sumt2
SLA = arcpy.sa.Con(co_sumt, 0.037, (arcpy.sa.Con(co_sumt, 0.03, 0.017, where05)), where0)
arcpy.BuildPyramids_management(SLA)
return SLA
mysevl = 0
trysevl = co_sumt
oneRaster = arcpy.sa.Divide(trysevl, trysevl)
Sevl = arcpy.sa.Times(oneRaster, mysevl)
def SHB ():
#The first Damage mechanism due to Sheath Blight
prshbl = arcpy.sa.Times(0.00076, Sevl)
if i == 1:
rshbl = arcpy.sa.Times(prshbl, LEAFW)
else:
rshbl = arcpy.sa.Times(prshbl, thisLEAFW)
#trshbl = arcpy.sa.Times(rshbl, Days)
#The second Damage mechanism due to Sheath Blight
pshbrf = arcpy.sa.Divide(Sevl, 100)
shbrf = arcpy.sa.Minus(1, pshbrf)
return [rshbl, shbrf]
#Damage mechanism due to Brown Spot
mybsdm = 0
bsdm = arcpy.sa.Times(oneRaster, mybsdm)
def BS (beta=6.3):
pbsrf = arcpy.sa.Divide(bsdm, 100)
pbsrf1 = arcpy.sa.Minus(1, pbsrf)
bsrf = arcpy.sa.Power(pbsrf1, beta)
return bsrf
#Damage mechanism due to Bacterial Leaf Blight
if analysisType == "Attainable Yield":
blight = 0
blbrf = arcpy.sa.Minus(oneRaster, blight)
elif analysisType == "Actual Yield":
arcpy.AddMessage(" Calculating Reduction factor for BLIGHT")
for blight in BlightGDB:
blightDate = blight[7:]
if tempDate == blightDate:
pblbrf = arcpy.sa.Divide(blight, 100)
blbrf = arcpy.sa.Minus(1, pblbrf)
break
else:
blbrf = 1
#Damage mechanism due to Rice Leaf Blast
if analysisType == "Attainable Yield":
blast = 0
rlbrf = arcpy.sa.Minus(oneRaster, blast)
elif analysisType == "Actual Yield":
arcpy.AddMessage(" Calculating Reduction factor for BLAST")
for blast in BlastGDB:
blastDate = blast[6:]
if tempDate == blastDate:
prlbrf = arcpy.sa.Divide(blast, 100)
prlbrf2 = arcpy.sa.Minus(1, prlbrf)
rlbrf = arcpy.sa.Power(prlbrf2, 3)
break
else:
rlbrf = 1
#Damage mechanism due to Sheath Rot
myshrdm = 0
shrdm = arcpy.sa.Times(oneRaster, myshrdm)
def SHR ():
shrrf = arcpy.sa.Minus(1, shrdm)
#shrrf = arcpy.sa.Times(pshrrf, Days)
return shrrf
#Damage mechanism due to White Heads
mywhdm = 0
whdm = arcpy.sa.Times(oneRaster, mywhdm)
def WH ():
whrf = arcpy.sa.Minus(1, whdm)
#whrf = arcpy.sa.Times(pwhrf, Days)
return whrf
#Damage mechanism due to Weeds
myweeddm = 0
weeddm = arcpy.sa.Times(oneRaster, myweeddm)
def WEEDS ():
prfwd = arcpy.sa.Times(weeddm, -0.003)
prfwd1 = arcpy.sa.Exp(prfwd)
rfwd = arcpy.sa.Minus(1, prfwd1)
weedrf = arcpy.sa.Minus(1, rfwd)
return weedrf
#Calculating LAI after treatment with Sheath Blight + Brown Spot + Bacterial leaf Blight
def LAI ():
arcpy.AddMessage(" Calculating Leaf Area Index")
thisSLA = sla()
this_shb1 = SHB()
this_shbrf = this_shb1[1]
this_bsrf = BS()
if i == 1:
pLAI = arcpy.sa.Times(thisSLA, LEAFW)
else:
pLAI = arcpy.sa.Times(thisSLA, thisLEAFW)
pLAI1 = arcpy.sa.Times(blbrf, pLAI)
pLAI2 = arcpy.sa.Times(rlbrf, pLAI1)
pLAI3 = arcpy.sa.Times(this_shbrf, pLAI2)
LAI = arcpy.sa.Times(this_bsrf, pLAI3)
return LAI
#Calculating actual radiation
for rad in RadGDB:
radDate = rad[3:]
if tempDate == radDate:
this_RAD = rad
break
#Calculating the Rate of Growth and the Pool of assimilates
def POOL (k=-0.6):
arcpy.AddMessage(" Calculating Pool of assimilates")
sumt09 = (-435 * (1.9**2))+(2755 * 1.9)-2320
where09 = "VALUE <= 0.9"
RUE = arcpy.sa.Con(co_sumt, 1.3, 1.2, where09)
this_LAI = LAI()
pRG1 = arcpy.sa.Times(k, this_LAI)
pRG2 = arcpy.sa.Exp(pRG1)
pRG3 = arcpy.sa.Minus(1, pRG2)
pRG4 = arcpy.sa.Times(pRG3, this_RAD)
pRG5 = arcpy.sa.Times(pRG4, RUE)
#Calculating the rate of growth after treatment with Weeds
this_weedrf = WEEDS()
RG = arcpy.sa.Times(pRG5, this_weedrf)
#mRG = arcpy.sa.Times(RG, Days)
ty = str(i)
name = "pool" + ty
RG.save(path + name)
return RG
arcpy.AddMessage(" Calculating coefficients of partitioning")
#Calculating the coefficient of partitioning of leaves relative to DVS
def COPARTL ():
sumt00 = (-435 * (1**2))+(2755 * 1)-2320
sumt07 = (-435 * (1.7**2))+(2755 * 1.7)-2320
where0 = "\"VALUE\" <= %d" % sumt00
where07 = "\"VALUE\" <= %d" % sumt07
copartl = arcpy.sa.Con(co_sumt, 0.55, (arcpy.sa.Con(co_sumt, 0.45, 0, where07)), where0)
return copartl
#Calculating the coefficient of partitioning of roots relative to DVS
def COPARTR ():
sumt00 = (-435 * (1**2))+(2755 * 1)-2320
sumt08 = (-435 * (1.8**2))+(2755 * 1.8)-2320
where0 = "\"VALUE\" <= %d" % sumt00
where08 = "\"VALUE\" < %d" % sumt08
copartr = arcpy.sa.Con(co_sumt, 0.3, arcpy.sa.Con(co_sumt, 0.1, 0, where08), where0)
return copartr
#Calculating the coefficient of partitioning of panicles relative to DVS
def COPARTP ():
sumt075 = (-435 * (1.75**2))+(2755 * 1.75)-2320
sumt11 = (-435 * (2.1**2))+(2755 * 2.1)-2320
where075 = "\"VALUE\" > %d" % sumt075
where11 = "\"VALUE\" >= %d" % sumt11
copartp = arcpy.sa.Con(co_sumt, 1, arcpy.sa.Con(co_sumt, 0.3, 0, where075), where11)
return copartp
#Calculating the coefficient of partitioning of stems relative to DVS
this_copartp = COPARTP ()
this_copartl = COPARTL ()
def COPARTST ():
pr_copartst = arcpy.sa.Minus(this_copartl, this_copartp)
copartst = arcpy.sa.Minus(1, pr_copartst)
return copartst
#Partitioning of assimilates
this_copartst = COPARTST()
this_POOL = POOL()
def PART ():
arcpy.AddMessage(" Calculating partitioning of assimilates")
#Calculate the partitioning of assimilates to leaves
this_copartr = COPARTR()
this = arcpy.sa.Minus(1, this_copartr)
pr_partl = arcpy.sa.Times(this_POOL, this_copartl)
partl = arcpy.sa.Times(pr_partl, this)
#Calculate the partitioning of assimilates to panicles
pr_partp = arcpy.sa.Times(this_POOL, this_copartp)
partp = arcpy.sa.Times(pr_partp, this)
#Calculate the partitioning of assimilates to stems
pr_partst = arcpy.sa.Times(this_POOL, this_copartst)
partst = arcpy.sa.Times(pr_partst, this)
#Calculate the partitioning of assimilates to roots
partr = arcpy.sa.Times(this_POOL, this_copartr)
return[partl, partp, partst, partr]
#Redistribution of reserves accumulated in the stems
def RDIST():
arcpy.AddMessage(" Calculating the redistribution of reserves accumulated in the stems")
sumt1 = (-435 * (2**2))+(2755 * 2)-2320
where1 = "\"VALUE\" < %d" % sumt1
rdist = arcpy.sa.Con(co_sumt, 0, 4.42, where1)
return rdist
#Calculating the relative rate of senescence
def RRSENL ():
arcpy.AddMessage(" Calculating the relative rate of senescence")
#sumt107 = (-425 * (2.07**2))+(2550 * 2.07)-2125
sumt13 = (-435 * (2.3**2))+(2755 * 2.3)-2320
#sumt163 = (-425 * (2.63**2))+(2550 * 2.63)-2125
where1 = "\"VALUE\" < %d" % sumt13
#where2 = "\"VALUE\" <= %d" % sumt13
#where3 = "\"VALUE\" <= %d" % sumt163
rrsenl = arcpy.sa.Con(co_sumt, 0, 0.04, where1)
return rrsenl
#Increase in dry weight of organs
this_rdist = RDIST()
this_part = PART()
this_partp = this_part[1]
this_partl = this_part[0]
this_partst = this_part[2]
this_partr = this_part[3]
this_rrsenl = RRSENL()
this_shb = SHB()
this_trshbl = this_shb[0]
arcpy.AddMessage(" Calculating the dry weight of organs\n")
#Calculate the increase in dry weight for panicles
ppanw1 = arcpy.sa.Plus(this_rdist, this_partp)
#Calculating the dry weight of panicles after Sheath Rot infection
this_shrrf = SHR()
ppanw2 = arcpy.sa.Times(ppanw1, this_shrrf)
#Calculating the dry weight of panicles after Sheath Rot and White Head infections
this_whrf = WH()
ppanw3 = arcpy.sa.Times(ppanw2, this_whrf)
#Calculate the increase in dry weight for stems
pstemw = arcpy.sa.Minus(this_partst, this_rdist)
#Calculate the increase in dry weight in leaves
if i == 1:
rsenl = arcpy.sa.Times(this_rrsenl, LEAFW)
else:
rsenl = arcpy.sa.Times(this_rrsenl, thisLEAFW)
pLEAFW = arcpy.sa.Minus(this_partl, rsenl)
#Calculating the leaf dry weight after treatment with Sheath Blight DM 1a
pleafw2 = arcpy.sa.Minus(pLEAFW, this_trshbl)
if i == 1:
thisPANW = arcpy.sa.Plus(ppanw3, PANW)
thisSTEMW = arcpy.sa.Plus(pstemw, STEMW)
thisROOTW = arcpy.sa.Plus(ROOTW, this_partr)
thisLEAFW = arcpy.sa.Plus(LEAFW, pleafw2)
ty = str(i)
name = "leafw" + ty
thisLEAFW.save(path + name)
else:
thisPANW = thisPANW + ppanw3
thisSTEMW = thisSTEMW + pstemw
thisROOTW = thisROOTW + this_partr
thisLEAFW = thisLEAFW + pleafw2
ty = str(i)
name = "leafw" + ty
thisLEAFW.save(path + name)
output = path1 + "Yield_PS1"
thisPANW.save(output)
arcpy.AddMessage("COMPLETED")
elif prodSituation == "PS2":
PANW = 0
LEAFW = 6
STEMW = 4
ROOTW = 3
TBASE = 8
#calculating the sum of temperature between crop establishment and the start of simulation
jt = 0
rt = 0
kt = 0
#check if rice variety is directed seeded or transplanted.
if cropEst == "Direct Seeded":
arcpy.AddMessage("Calculating Sum of Initial Temperature for Direct Seeded Systems")
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if rt == 0:
out3 = arcpy.sa.Minus(raster, TBASE)
out2 = arcpy.sa.Con(out3, 0, out3, where1)
rt = rt + 1
ty = str(rt)
name = "out2_" + ty
out2.save(path + name)
else:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out2 = out2 + out6
rt = rt + 1
ty = str(rt)
name = "out2_" + ty
out2.save(path + name)
elif cropEst == "Transplanted":
arcpy.AddMessage("Calculating Sum of Initial Temperature for Transplanted Systems\n")
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if jt == 0:
if kt != TransplantDays:
out3 = arcpy.sa.Minus(raster, TBASE)
out4 = arcpy.sa.Con(out3, 0, out3, where1)
jt = jt + 1
kt = kt + 1
else:
break
else:
if kt != TransplantDays:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out4 = out4 + out6
jt = jt + 1
kt = kt + 1
else:
break
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if rt == 0:
out3 = arcpy.sa.Minus(raster, TBASE)
out23 = arcpy.sa.Con(out3, 0, out3, where1)
rt = rt + 1
ty = str(rt)
name = "out23_" + ty
out23.save(path + name)
else:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out23 = out23 + out6
rt = rt + 1
ty = str(rt)
name = "out23_" + ty
name1 = "sumtr"
out23.save(path + name)
out22 = 0.785 * out4
out22.save(path + "tshock")
out2 = out23 - out22
out2.save(path + name1)
#calculating sum of temp above TBASE
i = 0
for temp in TempGDB:
test = 0
where1 = "\"VALUE\" < %d" % test
tempDate = temp[5:]
#calculating sum of temperature
bn = i + 15
ft = str(bn)
arcpy.AddMessage("SIMULATION AT " + ft + " DACE")
arcpy.AddMessage(" Calculating Sum of Temperature above TBASE")
if i == 0:
out4 = arcpy.sa.Minus(temp, TBASE)
out5 = arcpy.sa.Con(out4, 0, out4, where1)
co_sumt = out5 + out2
i = i + 1
ty = str(i)
name = "sumt" + ty
co_sumt.save(path + name)
else:
DTemp = arcpy.sa.Minus(temp, TBASE)
DTemp1 = arcpy.sa.Con(DTemp, 0, DTemp, where1)
co_sumt = DTemp1 + co_sumt
i = i + 1
ty = str(i)
name = "sumt" + ty
co_sumt.save(path + name)
def sla():
arcpy.AddMessage(" Calculating Specific Leaf Area")
#calculating SLA
#always add 1 to the value of sumt**
#hence sumt007 with value of 0.07 becomes 1.07 in the equation
sumt0 = (-435 * (1**2))+(2755 * 1)-2320
sumt05 = (-435 * (1.5**2))+(2755 * 1.5)-2320
sumt1 = (-435 * (2**2))+(2755 * 2)-2320
sumt2 = (-435 * (3**2))+(2755 * 3)-2320
where0 = "\"VALUE\" <= %d" % sumt0
where05 = "\"VALUE\" <= %d" % sumt05
where1 = "\"VALUE\" <= %d" % sumt1
where2 = "\"VALUE\" <= %d" % sumt2
SLA = arcpy.sa.Con(co_sumt, 0.037, (arcpy.sa.Con(co_sumt, 0.03, 0.017, where05)), where0)
arcpy.BuildPyramids_management(SLA)
return SLA
mysevl = 0
trysevl = co_sumt
oneRaster = arcpy.sa.Divide(trysevl, trysevl)
Sevl = arcpy.sa.Times(oneRaster, mysevl)
def SHB ():
#The first Damage mechanism due to Sheath Blight
prshbl = arcpy.sa.Times(0.00076, Sevl)
if i == 1:
rshbl = arcpy.sa.Times(prshbl, LEAFW)
else:
rshbl = arcpy.sa.Times(prshbl, thisLEAFW)
#trshbl = arcpy.sa.Times(rshbl, Days)
#The second Damage mechanism due to Sheath Blight
pshbrf = arcpy.sa.Divide(Sevl, 100)
shbrf = arcpy.sa.Minus(1, pshbrf)
return [rshbl, shbrf]
#Damage mechanism due to Brown Spot
mybsdm = 0
bsdm = arcpy.sa.Times(oneRaster, mybsdm)
def BS (beta=6.3):
pbsrf = arcpy.sa.Divide(bsdm, 100)
pbsrf1 = arcpy.sa.Minus(1, pbsrf)
bsrf = arcpy.sa.Power(pbsrf1, beta)
return bsrf
#Damage mechanism due to Bacterial Leaf Blight
if analysisType == "Attainable Yield":
blight = 0
blbrf = arcpy.sa.Minus(oneRaster, blight)
elif analysisType == "Actual Yield":
arcpy.AddMessage(" Calculating Reduction factor for BLIGHT")
for blight in BlightGDB:
blightDate = blight[7:]
if tempDate == blightDate:
pblbrf = arcpy.sa.Divide(blight, 100)
blbrf = arcpy.sa.Minus(1, pblbrf)
break
else:
blbrf = 1
#Damage mechanism due to Rice Leaf Blast
if analysisType == "Attainable Yield":
blast = 0
rlbrf = arcpy.sa.Minus(oneRaster, blast)
elif analysisType == "Actual Yield":
arcpy.AddMessage(" Calculating Reduction factor for BLAST")
for blast in BlastGDB:
blastDate = blast[6:]
if tempDate == blastDate:
prlbrf = arcpy.sa.Divide(blast, 100)
prlbrf2 = arcpy.sa.Minus(1, prlbrf)
rlbrf = arcpy.sa.Power(prlbrf2, 3)
break
else:
rlbrf = 1
#Damage mechanism due to Sheath Rot
myshrdm = 0
shrdm = arcpy.sa.Times(oneRaster, myshrdm)
def SHR ():
shrrf = arcpy.sa.Minus(1, shrdm)
#shrrf = arcpy.sa.Times(pshrrf, Days)
return shrrf
#Damage mechanism due to White Heads
mywhdm = 0
whdm = arcpy.sa.Times(oneRaster, mywhdm)
def WH ():
whrf = arcpy.sa.Minus(1, whdm)
#whrf = arcpy.sa.Times(pwhrf, Days)
return whrf
#Damage mechanism due to Weeds
myweeddm = 0
weeddm = arcpy.sa.Times(oneRaster, myweeddm)
def WEEDS ():
prfwd = arcpy.sa.Times(weeddm, -0.003)
prfwd1 = arcpy.sa.Exp(prfwd)
rfwd = arcpy.sa.Minus(1, prfwd1)
weedrf = arcpy.sa.Minus(1, rfwd)
return weedrf
#Calculating LAI after treatment with Sheath Blight + Brown Spot + Bacterial leaf Blight
def LAI ():
arcpy.AddMessage(" Calculating Leaf Area Index")
thisSLA = sla()
this_shb1 = SHB()
this_shbrf = this_shb1[1]
this_bsrf = BS()
if i == 1:
pLAI = arcpy.sa.Times(thisSLA, LEAFW)
else:
pLAI = arcpy.sa.Times(thisSLA, thisLEAFW)
pLAI1 = arcpy.sa.Times(blbrf, pLAI)
pLAI2 = arcpy.sa.Times(rlbrf, pLAI1)
pLAI3 = arcpy.sa.Times(this_shbrf, pLAI2)
LAI = arcpy.sa.Times(this_bsrf, pLAI3)
return LAI
#Calculating actual radiation
for rad in RadGDB:
radDate = rad[3:]
if tempDate == radDate:
this_RAD = rad
break
#Calculating the Rate of Growth and the Pool of assimilates
def POOL (k=-0.6):
arcpy.AddMessage(" Calculating Pool of assimilates")
where1 = "VALUE <= 0.9"
RUE = arcpy.sa.Con(co_sumt, 1.1, 1, where1)
this_LAI = LAI()
pRG1 = arcpy.sa.Times(k, this_LAI)
pRG2 = arcpy.sa.Exp(pRG1)
pRG3 = arcpy.sa.Minus(1, pRG2)
pRG4 = arcpy.sa.Times(pRG3, this_RAD)
pRG5 = arcpy.sa.Times(pRG4, RUE)
#Calculating the rate of growth after treatment with Weeds
this_weedrf = WEEDS()
RG = arcpy.sa.Times(pRG5, this_weedrf)
#mRG = arcpy.sa.Times(RG, Days)
ty = str(i)
name = "pool" + ty
RG.save(path + name)
return RG
arcpy.AddMessage(" Calculating coefficients of partitioning")
#Calculating the coefficient of partitioning of leaves relative to DVS
def COPARTL ():
sumt00 = (-435 * (1**2))+(2755 * 1)-2320
sumt07 = (-435 * (1.7**2))+(2755 * 1.7)-2320
where0 = "\"VALUE\" <= %d" % sumt00
where07 = "\"VALUE\" <= %d" % sumt07
copartl = arcpy.sa.Con(co_sumt, 0.55, (arcpy.sa.Con(co_sumt, 0.45, 0, where07)), where0)
return copartl
#Calculating the coefficient of partitioning of roots relative to DVS
def COPARTR ():
sumt00 = (-435 * (1**2))+(2755 * 1)-2320
sumt08 = (-435 * (1.8**2))+(2755 * 1.8)-2320
where0 = "\"VALUE\" <= %d" % sumt00
where08 = "\"VALUE\" < %d" % sumt08
copartr = arcpy.sa.Con(co_sumt, 0.3, arcpy.sa.Con(co_sumt, 0.1, 0, where08), where0)
return copartr
#Calculating the coefficient of partitioning of panicles relative to DVS
def COPARTP ():
sumt075 = (-435 * (1.75**2))+(2755 * 1.75)-2320
sumt11 = (-435 * (2.1**2))+(2755 * 2.1)-2320
where075 = "\"VALUE\" > %d" % sumt075
where11 = "\"VALUE\" >= %d" % sumt11
copartp = arcpy.sa.Con(co_sumt, 1, arcpy.sa.Con(co_sumt, 0.3, 0, where075), where11)
return copartp
#Calculating the coefficient of partitioning of stems relative to DVS
this_copartp = COPARTP ()
this_copartl = COPARTL ()
def COPARTST ():
pr_copartst = arcpy.sa.Minus(this_copartl, this_copartp)
copartst = arcpy.sa.Minus(1, pr_copartst)
return copartst
#Partitioning of assimilates
this_copartst = COPARTST()
this_POOL = POOL()
def PART ():
arcpy.AddMessage(" Calculating partitioning of assimilates")
#Calculate the partitioning of assimilates to leaves
this_copartr = COPARTR()
this = arcpy.sa.Minus(1, this_copartr)
pr_partl = arcpy.sa.Times(this_POOL, this_copartl)
partl = arcpy.sa.Times(pr_partl, this)
#Calculate the partitioning of assimilates to panicles
pr_partp = arcpy.sa.Times(this_POOL, this_copartp)
partp = arcpy.sa.Times(pr_partp, this)
#Calculate the partitioning of assimilates to stems
pr_partst = arcpy.sa.Times(this_POOL, this_copartst)
partst = arcpy.sa.Times(pr_partst, this)
#Calculate the partitioning of assimilates to roots
partr = arcpy.sa.Times(this_POOL, this_copartr)
return[partl, partp, partst, partr]
#Redistribution of reserves accumulated in the stems
def RDIST():
arcpy.AddMessage(" Calculating the redistribution of reserves accumulated in the stems")
sumt1 = (-435 * (2**2))+(2755 * 2)-2320
where1 = "\"VALUE\" < %d" % sumt1
rdist = arcpy.sa.Con(co_sumt, 0, 4.42, where1)
return rdist
#Calculating the relative rate of senescence
def RRSENL ():
arcpy.AddMessage(" Calculating the relative rate of senescence")
#sumt107 = (-425 * (2.07**2))+(2550 * 2.07)-2125
sumt13 = (-435 * (2.3**2))+(2755 * 2.3)-2320
#sumt163 = (-425 * (2.63**2))+(2550 * 2.63)-2125
where1 = "\"VALUE\" <= %d" % sumt13
#where2 = "\"VALUE\" <= %d" % sumt13
#where3 = "\"VALUE\" <= %d" % sumt163
rrsenl = arcpy.sa.Con(co_sumt, 0, 0.04, where1)
return rrsenl
#Increase in dry weight of organs
this_rdist = RDIST()
this_part = PART()
this_partp = this_part[1]
this_partl = this_part[0]
this_partst = this_part[2]
this_partr = this_part[3]
this_rrsenl = RRSENL()
this_shb = SHB()
this_trshbl = this_shb[0]
arcpy.AddMessage(" Calculating the dry weight of organs\n")
#Calculate the increase in dry weight for panicles
ppanw1 = arcpy.sa.Plus(this_rdist, this_partp)
#Calculating the dry weight of panicles after Sheath Rot infection
this_shrrf = SHR()
ppanw2 = arcpy.sa.Times(ppanw1, this_shrrf)
#Calculating the dry weight of panicles after Sheath Rot and White Head infections
this_whrf = WH()
ppanw3 = arcpy.sa.Times(ppanw2, this_whrf)
#Calculate the increase in dry weight for stems
pstemw = arcpy.sa.Minus(this_partst, this_rdist)
#Calculate the increase in dry weight in leaves
if i == 1:
rsenl = arcpy.sa.Times(this_rrsenl, LEAFW)
else:
rsenl = arcpy.sa.Times(this_rrsenl, thisLEAFW)
pLEAFW = arcpy.sa.Minus(this_partl, rsenl)
#Calculating the leaf dry weight after treatment with Sheath Blight DM 1a
pleafw2 = arcpy.sa.Minus(pLEAFW, this_trshbl)
if i == 1:
thisPANW = arcpy.sa.Plus(ppanw3, PANW)
thisSTEMW = arcpy.sa.Plus(pstemw, STEMW)
thisROOTW = arcpy.sa.Plus(ROOTW, this_partr)
thisLEAFW = arcpy.sa.Plus(LEAFW, pleafw2)
ty = str(i)
name = "leafw" + ty
thisLEAFW.save(path + name)
else:
thisPANW = thisPANW + ppanw3
thisSTEMW = thisSTEMW + pstemw
thisROOTW = thisROOTW + this_partr
thisLEAFW = thisLEAFW + pleafw2
ty = str(i)
name = "leafw" + ty
thisLEAFW.save(path + name)
output = path1 + "Yield_PS2"
thisPANW.save(output)
arcpy.AddMessage("COMPLETED")
elif prodSituation == "PS3":
PANW = 0
LEAFW = 17
STEMW = 15
ROOTW = 7
TBASE = 8
#calculating the sum of temperature between crop establishment and the start of simulation
jt = 0
rt = 0
kt = 0
#check if rice variety is direct seeded or transplanted.
if cropEst == "Direct Seeded":
arcpy.AddMessage("Calculating Sum of Initial Temperature for Direct Seeded Systems")
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if rt == 0:
out3 = arcpy.sa.Minus(raster, TBASE)
out2 = arcpy.sa.Con(out3, 0, out3, where1)
rt = rt + 1
ty = str(rt)
name = "out2_" + ty
out2.save(path + name)
else:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out2 = out2 + out6
rt = rt + 1
ty = str(rt)
name = "out2_" + ty
out2.save(path + name)
elif cropEst == "Transplanted":
arcpy.AddMessage("Calculating Sum of Initial Temperature for Transplanted Systems\n")
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if jt == 0:
if kt != TransplantDays:
out3 = arcpy.sa.Minus(raster, TBASE)
out4 = arcpy.sa.Con(out3, 0, out3, where1)
jt = jt + 1
kt = kt + 1
else:
break
else:
if kt != TransplantDays:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out4 = out4 + out6
jt = jt + 1
kt = kt + 1
else:
break
for raster in IniTemp:
test = 0
where1 = "\"VALUE\" < %d" % test
if rt == 0:
out3 = arcpy.sa.Minus(raster, TBASE)
out23 = arcpy.sa.Con(out3, 0, out3, where1)
rt = rt + 1
ty = str(rt)
name = "out23_" + ty
out23.save(path + name)
else:
out1 = arcpy.sa.Minus(raster, TBASE)
out6 = arcpy.sa.Con(out1, 0, out1, where1)
out23 = out23 + out6
rt = rt + 1
ty = str(rt)
name = "out23_" + ty
name1 = "sumtr"
out23.save(path + name)
out22 = 0.785 * out4
out22.save(path + "tshock")
out2 = out23 - out22
out2.save(path + name1)
#calculating sum of temp above TBASE
i = 0
for temp in TempGDB:
test = 0
where1 = "\"VALUE\" < %d" % test
tempDate = temp[5:]
#calculating sum of temperature
bn = i + 15
ft = str(bn)
arcpy.AddMessage("SIMULATION AT " + ft + " DACE")
arcpy.AddMessage(" Calculating Sum of Temperature above TBASE")
if i == 0:
out4 = arcpy.sa.Minus(temp, TBASE)
out5 = arcpy.sa.Con(out4, 0, out4, where1)
co_sumt = out5 + out2
i = i + 1
ty = str(i)
name = "sumt" + ty
co_sumt.save(path + name)
else:
DTemp = arcpy.sa.Minus(temp, TBASE)
DTemp1 = arcpy.sa.Con(DTemp, 0, DTemp, where1)
co_sumt = DTemp1 + co_sumt
i = i + 1
ty = str(i)
name = "sumt" + ty
co_sumt.save(path + name)
def sla():
arcpy.AddMessage(" Calculating Specific Leaf Area")
#calculating SLA
#always add 1 to the value of sumt**
#hence sumt007 with value of 0.07 becomes 1.07 in the equation
sumt0 = (-650 * (1**2))+(3750 * 1)-3100
sumt1 = (-650 * (2**2))+(3750 * 2)-3100
sumt2 = (-650 * (3**2))+(3750 * 3)-3100
where0 = "\"VALUE\" <= %d" % sumt0
where1 = "\"VALUE\" <= %d" % sumt1
where2 = "\"VALUE\" <= %d" % sumt2
SLA = arcpy.sa.Con(co_sumt, 0.037, (arcpy.sa.Con(co_sumt, 0.018, 0.017, where1)), where0)
arcpy.BuildPyramids_management(SLA)
return SLA