forked from FAO-SID/GSOCseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage-2-running-the-model.html
2043 lines (1996 loc) · 379 KB
/
stage-2-running-the-model.html
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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Chapter 1 | Stage 2: running the model | 10.Stage_2_running_the_model.knit</title>
<meta name="description" content="" />
<meta name="generator" content="bookdown 0.22 and GitBook 2.6.7" />
<meta property="og:title" content="Chapter 1 | Stage 2: running the model | 10.Stage_2_running_the_model.knit" />
<meta property="og:type" content="book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Chapter 1 | Stage 2: running the model | 10.Stage_2_running_the_model.knit" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<script src="libs/header-attrs-2.8/header-attrs.js"></script>
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter" data-level="1" data-path=""><a href="#stage-2-running-the-model"><i class="fa fa-check"></i><b>1</b> | Stage 2: running the model</a>
<ul>
<li class="chapter" data-level="1.1" data-path=""><a href="#overview-of-the-main-commands-to-perform-the-rothc-calculations"><i class="fa fa-check"></i><b>1.1</b> Overview of the main commands to perform the RothC calculations</a></li>
<li class="chapter" data-level="1.2" data-path=""><a href="#initialization---spin-up-phase"><i class="fa fa-check"></i><b>1.2</b> Initialization - Spin up phase</a>
<ul>
<li class="chapter" data-level="1.2.1" data-path=""><a href="#roth_c_spin_up_unc_v2.r-equilibrium-runs"><i class="fa fa-check"></i><b>1.2.1</b> “ROTH_C_SPIN_UP_UNC_v2.R” (equilibrium runs)</a></li>
<li class="chapter" data-level="1.2.2" data-path=""><a href="#script-number-13.b.-roth_c_spin_up_unc_v66.r-analytical-solution"><i class="fa fa-check"></i><b>1.2.2</b> Script Number 13.B. “ROTH_C_SPIN_UP_UNC_v66.R” (analytical solution)</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path=""><a href="#warm-up-phase"><i class="fa fa-check"></i><b>1.3</b> Warm up phase</a>
<ul>
<li class="chapter" data-level="1.3.1" data-path=""><a href="#script-number-14a.-roth_c_warm_up_v4.r-no-land-use-change"><i class="fa fa-check"></i><b>1.3.1</b> Script Number 14A. “ROTH_C_WARM_UP_v4.R” No Land use change</a></li>
<li class="chapter" data-level="1.3.2" data-path=""><a href="#script-number-14b.-roth_c_warm_up_v4.r-land-use-change-simulation"><i class="fa fa-check"></i><b>1.3.2</b> Script Number 14B. “ROTH_C_WARM_UP_v4.R” Land use change simulation</a></li>
</ul></li>
<li class="chapter" data-level="1.4" data-path=""><a href="#forward-phase-script-number-15.-roth_c_forward_v2.r"><i class="fa fa-check"></i><b>1.4</b> Forward phase: Script Number 15. “ROTH_C_forward_v2.R”</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./"></a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<!--bookdown:title:end-->
<!--bookdown:title:start-->
<div id="stage-2-running-the-model" class="section level1" number="1">
<h1><span class="header-section-number">Chapter 1</span> | Stage 2: running the model</h1>
<p>Once all input layers are prepared, harmonized and stacked, we will run the three modeling phases (spin up, warm up and forward phase). At this stage, we will run the model three times, once for each phase using three different scripts (scripts 13 A -equilibrium run or 13 B-analytical solution, 14 and 15), which use the same RothC function. For each script we will need the previously created raster stacks and target points. Each script will generate output vector points (containing the modeling results, i.e. SOC stocks of the different carbon pools of the RothC model). The output vector of each phase will be used as an input of the next modeling phase. Finally, after running the final modeling phase, the forward phase, we will obtain an output vector containing the SOC data for each projected scenario. This output vector will be used as input for the final script (script 16) to generate the raster files to build the sequestration potential maps.</p>
<div id="overview-of-the-main-commands-to-perform-the-rothc-calculations" class="section level2" number="1.1">
<h2><span class="header-section-number">1.1</span> Overview of the main commands to perform the RothC calculations</h2>
<p>The RothC function is the core of the next three scripts and will be used to simulate the different C pools over the defined time periods. In the following a brief overview of the commands we will be running to perform the RothC calculations will be provided.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># ROTH C MODEL FUNCTION .</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="do">########## function set up starts############### </span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>Roth_C<span class="ot"><-</span><span class="cf">function</span>(Cinputs,years,DPMptf, RPMptf, BIOptf, HUMptf, FallIOM,Temp,Precip,Evp,Cov,Cov1,Cov2,soil.thick,SOC,clay,DR,bare1){</span></code></pre></div>
<p>This function will calculate first the “Temperature factor per month” using a function from the SOILR package called “fT.RothC” :</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Temperature factor per month</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>fT<span class="ot">=</span><span class="fu">fT.RothC</span>(Temp[,<span class="dv">2</span>]) </span></code></pre></div>
<p>Then the function will calculate the “Moisture factor per month” (this function was modified from the original SOILR moisture function, to include the soil cover effect, as in the original RothC model (See Chapter 4):</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Moisture effects per month . </span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>fw1func<span class="ot"><-</span><span class="cf">function</span>(P, E, <span class="at">S.Thick =</span> <span class="dv">30</span>, <span class="at">pClay =</span> <span class="fl">32.0213</span>, <span class="at">pE =</span> <span class="dv">1</span>, bare) </span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> M <span class="ot">=</span> P <span class="sc">-</span> E <span class="sc">*</span> pE</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> Acc.TSMD <span class="ot">=</span> <span class="cn">NULL</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">2</span><span class="sc">:</span><span class="fu">length</span>(M)) {</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> B <span class="ot">=</span> <span class="fu">ifelse</span>(bare[i] <span class="sc">==</span> <span class="cn">FALSE</span>, <span class="dv">1</span>, <span class="fl">1.8</span>)</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> Max.TSMD <span class="ot">=</span> <span class="sc">-</span>(<span class="dv">20</span> <span class="sc">+</span> <span class="fl">1.3</span> <span class="sc">*</span> pClay <span class="sc">-</span> <span class="fl">0.01</span> <span class="sc">*</span> (pClay<span class="sc">^</span><span class="dv">2</span>)) <span class="sc">*</span> (S.Thick<span class="sc">/</span><span class="dv">23</span>) <span class="sc">*</span> (<span class="dv">1</span><span class="sc">/</span>B)</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[<span class="dv">1</span>] <span class="ot">=</span> <span class="fu">ifelse</span>(M[<span class="dv">1</span>] <span class="sc">></span> <span class="dv">0</span>, <span class="dv">0</span>, M[<span class="dv">1</span>])</span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (Acc.TSMD[i <span class="sc">-</span> <span class="dv">1</span>] <span class="sc">+</span> M[i] <span class="sc"><</span> <span class="dv">0</span>) {</span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[i] <span class="ot">=</span> Acc.TSMD[i <span class="sc">-</span> <span class="dv">1</span>] <span class="sc">+</span> M[i]</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span> (Acc.TSMD[i] <span class="ot">=</span> <span class="dv">0</span>)</span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (Acc.TSMD[i] <span class="sc"><=</span> Max.TSMD) {</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[i] <span class="ot">=</span> Max.TSMD</span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a> b <span class="ot">=</span> <span class="fu">ifelse</span>(Acc.TSMD <span class="sc">></span> <span class="fl">0.444</span> <span class="sc">*</span> Max.TSMD, <span class="dv">1</span>, (<span class="fl">0.2</span> <span class="sc">+</span> <span class="fl">0.8</span> <span class="sc">*</span> ((Max.TSMD <span class="sc">-</span> </span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a> Acc.TSMD)<span class="sc">/</span>(Max.TSMD <span class="sc">-</span> <span class="fl">0.444</span> <span class="sc">*</span> Max.TSMD))))</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a> b<span class="ot"><-</span><span class="fu">clamp</span>(b,<span class="at">lower=</span><span class="fl">0.2</span>)</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="fu">data.frame</span>(Acc.TSMD, b, Max.TSMD))</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a>fW_2<span class="ot"><-</span> <span class="fu">fw1func</span>(<span class="at">P=</span>(Precip[,<span class="dv">2</span>]), <span class="at">E=</span>(Evp[,<span class="dv">2</span>]), <span class="at">S.Thick =</span> soil.thick, <span class="at">pClay =</span> clay, <span class="at">pE =</span> <span class="dv">1</span>, <span class="at">bare=</span>bare1)<span class="sc">$</span>b </span></code></pre></div>
<p>Then the function will calculate the “vegetation cover factor” effect:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Vegetation Cover effects </span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>fC<span class="ot"><-</span>Cov2[,<span class="dv">2</span>]</span></code></pre></div>
<p>In each script, we will need to set the factor frame to run the model (500 years for spin up, 18/20 years for the warm-up, 20 years for the forward), and run the model. We will have two options: one from the SoilR package (using “lsoda” function to solve the differential equations) and one from the soilassessment package that allows to change the differential equation solver, by default we will use the “euler” method, which is faster.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Set the factors frame for Model calculations</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>xi.frame<span class="ot">=</span><span class="fu">data.frame</span>(years,<span class="fu">rep</span>(fT<span class="sc">*</span>fW_2<span class="sc">*</span>fC<span class="sc">*</span>fPR,<span class="at">length.out=</span><span class="fu">length</span>(years)))</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a><span class="co"># RUN THE MODEL from soilassessment</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a><span class="co">#Roth C soilassesment</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>Model3_spin<span class="ot">=</span><span class="fu">carbonTurnover</span>(<span class="at">tt=</span>years,<span class="at">C0=</span><span class="fu">c</span>(DPMptf, RPMptf, BIOptf, HUMptf, FallIOM),<span class="at">In=</span>Cinputs,<span class="at">Dr=</span>DR,<span class="at">clay=</span>clay,<span class="at">effcts=</span>xi.frame, <span class="st">"euler"</span>) </span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>Ct3_spin<span class="ot">=</span>Model3_spin[,<span class="dv">2</span><span class="sc">:</span><span class="dv">6</span>]</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a><span class="co"># RUN THE MODEL FROM SOILR</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="co">#Model3_spin=RothCModel(t=years,C0=c(DPMptf, RPMptf, BIOptf, HUMptf, FallIOM),In=Cinputs,DR=DR,clay=clay,xi=xi.frame, pass=TRUE) </span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a><span class="co">#Ct3_spin=getC(Model3_spin)</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a><span class="co"># Get the final pools of the time series</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a>poolSize3_spin<span class="ot">=</span><span class="fu">as.numeric</span>(<span class="fu">tail</span>(Ct3_spin,<span class="dv">1</span>))</span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a><span class="fu">return</span>(poolSize3_spin)</span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a><span class="er">}</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a><span class="do">########## function set up ends###############</span></span></code></pre></div>
</div>
<div id="initialization---spin-up-phase" class="section level2" number="1.2">
<h2><span class="header-section-number">1.2</span> Initialization - Spin up phase</h2>
<p>To estimate initial carbon pools and equilibrium carbon inputs, two alternatives are provided. Users can run the initialization phase using the equilibrium procedure (explained in section 5.4.1.1) implemented in Script 13 A; or use the analytical procedure (explained in section 5.4.1.2) implemented in Script 13 B. Users may be more familiar with the equilibrium procedure (e.g. Smith et al. 2005; 2006; 2007; Gottschalk et al., 2012) and run Script 13A However, depending on the size of the target area and selected equilibrium period this approach might require a considerable execution time. A minimum of 500 years is suggested to reach equilibrium with reduced computational time. However, it must be noted that spin up runs for 500 years may not necessarily end up in equilibrium SOC stocks, depending on soil, climate and land use conditions. Increasing the duration (1000-2000 years) will reduce deviations with the cost of additional computation time. The analytical approach implemented in Script 13.B (see section 10.1.2) was developed as a time-effective and precise alternative to overcome these issues.</p>
<div id="roth_c_spin_up_unc_v2.r-equilibrium-runs" class="section level3" number="1.2.1">
<h3><span class="header-section-number">1.2.1</span> “ROTH_C_SPIN_UP_UNC_v2.R” (equilibrium runs)</h3>
<p>Script number 13.A implements the first modeling phase (spin up) using the original equilibrium run approach (see section 5.4.1.1). In this script we will load the stack generated in script number 10 and the target points (Section 9.7, QGIS model number 1). We will obtain an output vector containing our target points. This script runs the RothC model for a minimum of 500 years to calculate the equilibrium carbon inputs (the carbon inputs needed to reach the 2001 SOC stocks) and the SOC stocks for the different pools. It first runs using a standard C input of 1 tC ha<sup>-1</sup> yr<sup>-1</sup>, and then equilibrium inputs are estimated from the obtained results and GSOCmap stocks (See Chapters 5 and 6). In this script we will use pedotransfer functions to estimate the SOC stocks of the different pools from the total SOC stock (Weihermüller et al., 2013) to accelerate the spin up process. All that information will be saved to the output vector (shapefile file).
The SPIN UP Phase will allow us to calculate two outputs that will be saved to a point vector layer called “C_INPUT_EQ.shp”: equilibrium carbon inputs (Ceq) and the carbon stocks of the different soil C pools to run the second phase (WARM UP phase). First, the following packages are loaded into R:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list=</span><span class="fu">ls</span>()) </span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(SoilR)</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(raster)</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(rgdal)</span></code></pre></div>
<p>Then we will set the working directory.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>WD_FOLDER<span class="ot"><-</span>(<span class="st">"C:/TRAINING_MATERIALS_GSOCseq_MAPS_28-09-2020"</span>)</span></code></pre></div>
<p>Then, we need to load the target points created in the “qgis procedure number 1”.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Vector must be an empty points vector. </span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="fu">setwd</span>(WD_FOLDER)</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>Vector<span class="ot"><-</span><span class="fu">readOGR</span>(<span class="st">"INPUTS/TARGET_POINTS/Target_Points_sub.shp"</span>)</span></code></pre></div>
<p>Then we need to open the stack with all the spin-up variables to run the model (from script number 7).</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Stack_Set_1 is a stack that contains the spatial variables </span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>Stack_Set_1<span class="ot"><-</span> <span class="fu">stack</span>(<span class="st">"INPUTS/STACK/Stack_Set_SPIN_UP_AOI.tif"</span>)</span></code></pre></div>
<p>We will run the next lines of the code and create an empty vector variable to save the outputs results of the model and the pedotransfer functions:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Create A vector to save the results</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ<span class="ot"><-</span>Vector</span></code></pre></div>
<p>Now, we need to extract the input variables from the raster stack to the target points (now called “Vector”). This step will allow us to continue working with a “dataframe” instead of a raster stack layer.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co"># extract variables to points</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>Vector_variables<span class="ot"><-</span><span class="fu">extract</span>(Stack_Set_1,Vector,<span class="at">df=</span><span class="cn">TRUE</span>)</span></code></pre></div>
<p>The next lines will define the different variables from the Vector_variables pool. We need to individualize them in separate variables. The last line of this block will set the number of years to run the RothC function.</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Extract the layers from the Vector</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>SOC_im<span class="ot"><-</span>Vector_variables[[<span class="dv">2</span>]] <span class="co"># first band of the stack is the second column of the vector</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>clay_im<span class="ot"><-</span>Vector_variables[[<span class="dv">3</span>]]</span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a>DR_im<span class="ot"><-</span>Vector_variables[[<span class="dv">40</span>]]</span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a>LU_im<span class="ot"><-</span>Vector_variables[[<span class="dv">41</span>]]</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Define Years for Cinputs calculations</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a>years<span class="ot">=</span><span class="fu">seq</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">12</span>,<span class="dv">500</span>,<span class="at">by=</span><span class="dv">1</span><span class="sc">/</span><span class="dv">12</span>)</span></code></pre></div>
<p>Once we have defined the variables and time frame, we can start using the the RothC function.</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co"># ROTH C MODEL FUNCTION .</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="do">########## function set up starts###############</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>Roth_C<span class="ot"><-</span><span class="cf">function</span>(Cinputs,years,DPMptf, RPMptf, BIOptf, HUMptf, FallIOM,Temp,Precip,Evp,Cov,Cov1,Cov2,soil.thick,SOC,clay,DR,bare1,LU)</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Paddy fields coefficient fPR = 0.4 if the target point is class = 13 , else fPR=1</span></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a><span class="co"># From Shirato and Yukozawa 2004</span></span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a>fPR<span class="ot">=</span>(LU <span class="sc">==</span> <span class="dv">13</span>)<span class="sc">*</span><span class="fl">0.4</span> <span class="sc">+</span> (LU<span class="sc">!=</span><span class="dv">13</span>)<span class="sc">*</span><span class="dv">1</span></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true" tabindex="-1"></a><span class="co">#Temperature effects per month</span></span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true" tabindex="-1"></a>fT<span class="ot">=</span><span class="fu">fT.RothC</span>(Temp[,<span class="dv">2</span>]) </span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true" tabindex="-1"></a><span class="co">#Moisture effects per month . </span></span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true" tabindex="-1"></a>fw1func<span class="ot"><-</span><span class="cf">function</span>(P, E, <span class="at">S.Thick =</span> <span class="dv">30</span>, <span class="at">pClay =</span> <span class="fl">32.0213</span>, <span class="at">pE =</span> <span class="dv">1</span>, bare) </span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb13-19"><a href="#cb13-19" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb13-20"><a href="#cb13-20" aria-hidden="true" tabindex="-1"></a> M <span class="ot">=</span> P <span class="sc">-</span> E <span class="sc">*</span> pE</span>
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true" tabindex="-1"></a> Acc.TSMD <span class="ot">=</span> <span class="cn">NULL</span></span>
<span id="cb13-22"><a href="#cb13-22" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">2</span><span class="sc">:</span><span class="fu">length</span>(M)) {</span>
<span id="cb13-23"><a href="#cb13-23" aria-hidden="true" tabindex="-1"></a> B <span class="ot">=</span> <span class="fu">ifelse</span>(bare[i] <span class="sc">==</span> <span class="cn">FALSE</span>, <span class="dv">1</span>, <span class="fl">1.8</span>)</span>
<span id="cb13-24"><a href="#cb13-24" aria-hidden="true" tabindex="-1"></a> Max.TSMD <span class="ot">=</span> <span class="sc">-</span>(<span class="dv">20</span> <span class="sc">+</span> <span class="fl">1.3</span> <span class="sc">*</span> pClay <span class="sc">-</span> <span class="fl">0.01</span> <span class="sc">*</span> (pClay<span class="sc">^</span><span class="dv">2</span>)) <span class="sc">*</span> (S.Thick<span class="sc">/</span><span class="dv">23</span>) <span class="sc">*</span> (<span class="dv">1</span><span class="sc">/</span>B)</span>
<span id="cb13-25"><a href="#cb13-25" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[<span class="dv">1</span>] <span class="ot">=</span> <span class="fu">ifelse</span>(M[<span class="dv">1</span>] <span class="sc">></span> <span class="dv">0</span>, <span class="dv">0</span>, M[<span class="dv">1</span>])</span>
<span id="cb13-26"><a href="#cb13-26" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (Acc.TSMD[i <span class="sc">-</span> <span class="dv">1</span>] <span class="sc">+</span> M[i] <span class="sc"><</span> <span class="dv">0</span>) {</span>
<span id="cb13-27"><a href="#cb13-27" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[i] <span class="ot">=</span> Acc.TSMD[i <span class="sc">-</span> <span class="dv">1</span>] <span class="sc">+</span> M[i]</span>
<span id="cb13-28"><a href="#cb13-28" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb13-29"><a href="#cb13-29" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span> (Acc.TSMD[i] <span class="ot">=</span> <span class="dv">0</span>)</span>
<span id="cb13-30"><a href="#cb13-30" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (Acc.TSMD[i] <span class="sc"><=</span> Max.TSMD) {</span>
<span id="cb13-31"><a href="#cb13-31" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[i] <span class="ot">=</span> Max.TSMD</span>
<span id="cb13-32"><a href="#cb13-32" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb13-33"><a href="#cb13-33" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb13-34"><a href="#cb13-34" aria-hidden="true" tabindex="-1"></a> b <span class="ot">=</span> <span class="fu">ifelse</span>(Acc.TSMD <span class="sc">></span> <span class="fl">0.444</span> <span class="sc">*</span> Max.TSMD, <span class="dv">1</span>, (<span class="fl">0.2</span> <span class="sc">+</span> <span class="fl">0.8</span> <span class="sc">*</span> ((Max.TSMD <span class="sc">-</span> </span>
<span id="cb13-35"><a href="#cb13-35" aria-hidden="true" tabindex="-1"></a> Acc.TSMD)<span class="sc">/</span>(Max.TSMD <span class="sc">-</span> <span class="fl">0.444</span> <span class="sc">*</span> Max.TSMD))))</span>
<span id="cb13-36"><a href="#cb13-36" aria-hidden="true" tabindex="-1"></a> b<span class="ot"><-</span><span class="fu">clamp</span>(b,<span class="at">lower=</span><span class="fl">0.2</span>)</span>
<span id="cb13-37"><a href="#cb13-37" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="fu">data.frame</span>(b)) </span>
<span id="cb13-38"><a href="#cb13-38" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb13-39"><a href="#cb13-39" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-40"><a href="#cb13-40" aria-hidden="true" tabindex="-1"></a>fW_2<span class="ot"><-</span> <span class="fu">fw1func</span>(<span class="at">P=</span>(Precip[,<span class="dv">2</span>]), <span class="at">E=</span>(Evp[,<span class="dv">2</span>]), <span class="at">S.Thick =</span> soil.thick, <span class="at">pClay =</span> clay, <span class="at">pE =</span> <span class="dv">1</span>, <span class="at">bare=</span>bare1)<span class="sc">$</span>b </span>
<span id="cb13-41"><a href="#cb13-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-42"><a href="#cb13-42" aria-hidden="true" tabindex="-1"></a><span class="co">#Vegetation Cover effects </span></span>
<span id="cb13-43"><a href="#cb13-43" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-44"><a href="#cb13-44" aria-hidden="true" tabindex="-1"></a>fC<span class="ot"><-</span>Cov2[,<span class="dv">2</span>]</span>
<span id="cb13-45"><a href="#cb13-45" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-46"><a href="#cb13-46" aria-hidden="true" tabindex="-1"></a><span class="co"># Set the factors frame for Model calculations</span></span>
<span id="cb13-47"><a href="#cb13-47" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-48"><a href="#cb13-48" aria-hidden="true" tabindex="-1"></a>xi.frame<span class="ot">=</span><span class="fu">data.frame</span>(years,<span class="fu">rep</span>(fT<span class="sc">*</span>fW_2<span class="sc">*</span>fC<span class="sc">*</span>fPR,<span class="at">length.out=</span><span class="fu">length</span>(years)))</span>
<span id="cb13-49"><a href="#cb13-49" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-50"><a href="#cb13-50" aria-hidden="true" tabindex="-1"></a><span class="co"># RUN THE MODEL from soilassessment</span></span>
<span id="cb13-51"><a href="#cb13-51" aria-hidden="true" tabindex="-1"></a><span class="co">#Roth C soilassesment</span></span>
<span id="cb13-52"><a href="#cb13-52" aria-hidden="true" tabindex="-1"></a>Model3_spin<span class="ot">=</span><span class="fu">carbonTurnover</span>(<span class="at">tt=</span>years,<span class="at">C0=</span><span class="fu">c</span>(DPMptf, RPMptf, BIOptf, HUMptf, FallIOM),<span class="at">In=</span>Cinputs,<span class="at">Dr=</span>DR,<span class="at">clay=</span>clay,<span class="at">effcts=</span>xi.frame, <span class="st">"euler"</span>) </span>
<span id="cb13-53"><a href="#cb13-53" aria-hidden="true" tabindex="-1"></a>Ct3_spin<span class="ot">=</span>Model3_spin[,<span class="dv">2</span><span class="sc">:</span><span class="dv">6</span>]</span>
<span id="cb13-54"><a href="#cb13-54" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-55"><a href="#cb13-55" aria-hidden="true" tabindex="-1"></a><span class="co"># RUN THE MODEL FROM SOILR</span></span>
<span id="cb13-56"><a href="#cb13-56" aria-hidden="true" tabindex="-1"></a><span class="co">#Model3_spin=RothCModel(t=years,C0=c(DPMptf, RPMptf, BIOptf, HUMptf, FallIOM),In=Cinputs,DR=DR,clay=clay,xi=xi.frame, pass=TRUE) </span></span>
<span id="cb13-57"><a href="#cb13-57" aria-hidden="true" tabindex="-1"></a><span class="co">#Ct3_spin=getC(Model3_spin)</span></span>
<span id="cb13-58"><a href="#cb13-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-59"><a href="#cb13-59" aria-hidden="true" tabindex="-1"></a><span class="co"># Get the final pools of the time series</span></span>
<span id="cb13-60"><a href="#cb13-60" aria-hidden="true" tabindex="-1"></a>poolSize3_spin<span class="ot">=</span><span class="fu">as.numeric</span>(<span class="fu">tail</span>(Ct3_spin,<span class="dv">1</span>))</span>
<span id="cb13-61"><a href="#cb13-61" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-62"><a href="#cb13-62" aria-hidden="true" tabindex="-1"></a><span class="fu">return</span>(poolSize3_spin)</span>
<span id="cb13-63"><a href="#cb13-63" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb13-64"><a href="#cb13-64" aria-hidden="true" tabindex="-1"></a><span class="do">########## function set up ends###############</span></span></code></pre></div>
<p>After setting the RothC function we will iterate it over each one of the target points.<br />
For each target point we extract the climate variables and the monthly vegetation cover values. Each variable will be assigned to an R variable.</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Iterates over the area of interest</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="do">########for loop starts###############</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">dim</span>(Vector_variables)[<span class="dv">1</span>]) {</span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Extract the variables </span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a>Vect<span class="ot"><-</span><span class="fu">as.data.frame</span>(Vector_variables[i,])</span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a>Temp<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">4</span><span class="sc">:</span><span class="dv">15</span>]))</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a>Temp<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Temp=</span>Temp[,<span class="dv">1</span>])</span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a>Precip<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">16</span><span class="sc">:</span><span class="dv">27</span>]))</span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a>Precip<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Precip=</span>Precip[,<span class="dv">1</span>])</span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a>Evp<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">28</span><span class="sc">:</span><span class="dv">39</span>]))</span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a>Evp<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Evp=</span>Evp[,<span class="dv">1</span>])</span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a>Cov<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">42</span><span class="sc">:</span><span class="dv">53</span>]))</span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a>Cov1<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Cov=</span>Cov[,<span class="dv">1</span>])</span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a>Cov2<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Cov=</span>Cov[,<span class="dv">1</span>])</span></code></pre></div>
<p>The next line will avoid running the model over points with unreliable data, that may contain missing values or unrealistic values.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Avoid calculus over Na values </span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> (<span class="fu">any</span>(<span class="fu">is.na</span>(Evp[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(Temp[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(SOC_im[i])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(clay_im[i])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(Precip[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(Cov2[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(Cov1[,<span class="dv">1</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(DR_im[i])) <span class="sc">|</span> (SOC_im[i]<span class="sc"><</span><span class="dv">0</span>) <span class="sc">|</span> (clay_im[i]<span class="sc"><</span><span class="dv">0</span>) ) {C_INPUT_EQ[i,<span class="dv">2</span>]<span class="ot"><-</span><span class="dv">0</span>}<span class="cf">else</span>{</span></code></pre></div>
<p>Now we will set the value of each variable (SOC, Clay, DR, and Land Use) needed to run the model. The bare1 variable is used to derive the moisture factor.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Set the variables from the images</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>soil.thick<span class="ot">=</span><span class="dv">30</span> <span class="co">#Soil thickness (organic layer topsoil), in cm</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>SOC<span class="ot"><-</span>SOC_im[i] <span class="co">#Soil organic carbon in Mg/ha </span></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>clay<span class="ot"><-</span>clay_im[i] <span class="co">#Percent clay %</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a>DR<span class="ot"><-</span>DR_im[i] <span class="co"># DPM/RPM (decomplosable vs resistant plant material.)</span></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a>bare1<span class="ot"><-</span>(Cov1<span class="sc">></span><span class="fl">0.8</span>) <span class="co"># If the surface is bare or vegetated</span></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a>LU<span class="ot"><-</span>LU_im[i]</span></code></pre></div>
<p>The next line will calculate the IOM fraction of the SOC, from the SOC value:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="co">#IOM using Falloon method</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>FallIOM<span class="ot">=</span><span class="fl">0.049</span><span class="sc">*</span>SOC<span class="sc">^</span>(<span class="fl">1.139</span>) </span></code></pre></div>
<p>Now there are two options to calculate the uncertainties. One is to use your own SOC uncertainty layer: by loading it into R with the following lines of code:</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="co"># If you use a SOC uncertainty layer turn on this. First open the layer SOC_UNC </span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="co">#(it must have the same extent and resolution of the SOC layer)</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a><span class="co">#SOC_min<-(1-(SOC_UNC/100))*SOC</span></span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a><span class="co">#SOC_max<-(1+(SOC_UNC/100))*SOC</span></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Define SOC min, max Clay min and max. </span></span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a>SOC_min<span class="ot"><-</span>SOC<span class="sc">*</span><span class="fl">0.8</span></span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a>SOC_max<span class="ot"><-</span>SOC<span class="sc">*</span><span class="fl">1.2</span></span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a>clay_min<span class="ot"><-</span>clay<span class="sc">*</span><span class="fl">0.9</span></span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a>clay_max<span class="ot"><-</span>clay<span class="sc">*</span><span class="fl">1.1</span></span></code></pre></div>
<p>The script then uses the RothC function with the parameters listed below. We want to estimate the annual Carbon inputs needed to reach the actual GSOCmap value (equilibrium C inputs). We will first run the model assuming “Cinputs” equal 1. We can assume that SOC stock values when there are no C inputs (“Cinputs” equal to 0) will be equal to the inert organic carbon stocks (SOC=FallIOM). We can then build a simple linear model to estimate the “Cinputs” value needed to reach SOC FAO actual value (equilibrium C inputs, See modeling approach, Chapter 5 and 6).
b<-1</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="co"># C input equilibrium. (Ceq)</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>fb<span class="ot"><-</span><span class="fu">Roth_C</span>(<span class="at">Cinputs=</span>b,<span class="at">years=</span>years,<span class="at">DPMptf=</span><span class="dv">0</span>, <span class="at">RPMptf=</span><span class="dv">0</span>, <span class="at">BIOptf=</span><span class="dv">0</span>, <span class="at">HUMptf=</span><span class="dv">0</span>, <span class="at">FallIOM=</span>FallIOM,<span class="at">Temp=</span>Temp,<span class="at">Precip=</span>Precip,<span class="at">Evp=</span>Evp,<span class="at">Cov=</span>Cov,<span class="at">Cov1=</span>Cov1,<span class="at">Cov2=</span>Cov2,<span class="at">soil.thick=</span>soil.thick,<span class="at">SOC=</span>SOC,<span class="at">clay=</span>clay,<span class="at">DR=</span>DR,<span class="at">bare1=</span>bare1)</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a>fb_t<span class="ot"><-</span>fb[<span class="dv">1</span>]<span class="sc">+</span>fb[<span class="dv">2</span>]<span class="sc">+</span>fb[<span class="dv">3</span>]<span class="sc">+</span>fb[<span class="dv">4</span>]<span class="sc">+</span>fb[<span class="dv">5</span>]</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a>m<span class="ot"><-</span>(fb_t<span class="sc">-</span>FallIOM)<span class="sc">/</span>(b)</span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a>Ceq<span class="ot"><-</span>(SOC<span class="sc">-</span>FallIOM)<span class="sc">/</span>m</span></code></pre></div>
<p>We will repeat the “C input eq. code” to calculate minimum and maximum carbon inputs at equilibrium, using the combination of environmental variables listed in chapter 12 (Uncertainties).</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="co"># UNCERTAINTIES C input equilibrium (MINIMUM)</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>FallIOM_min<span class="ot">=</span><span class="fl">0.049</span><span class="sc">*</span>SOC_min<span class="sc">^</span>(<span class="fl">1.139</span>) </span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a>fb_min<span class="ot"><-</span><span class="fu">Roth_C</span>(<span class="at">Cinputs=</span>b,<span class="at">years=</span>years,<span class="at">DPMptf=</span><span class="dv">0</span>, <span class="at">RPMptf=</span><span class="dv">0</span>, <span class="at">BIOptf=</span><span class="dv">0</span>, <span class="at">HUMptf=</span><span class="dv">0</span>, <span class="at">FallIOM=</span>FallIOM,<span class="at">Temp=</span>Temp<span class="sc">*</span><span class="fl">1.02</span>,<span class="at">Precip=</span>Precip<span class="sc">*</span><span class="fl">0.95</span>,<span class="at">Evp=</span>Evp,<span class="at">Cov=</span>Cov,<span class="at">Cov1=</span>Cov1,<span class="at">Cov2=</span>Cov2,<span class="at">soil.thick=</span>soil.thick,<span class="at">SOC=</span>SOC_min,<span class="at">clay=</span>clay_min,<span class="at">DR=</span>DR,<span class="at">bare1=</span>bare1)</span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>fb_t_MIN<span class="ot"><-</span>fb_min[<span class="dv">1</span>]<span class="sc">+</span>fb_min[<span class="dv">2</span>]<span class="sc">+</span>fb_min[<span class="dv">3</span>]<span class="sc">+</span>fb_min[<span class="dv">4</span>]<span class="sc">+</span>fb_min[<span class="dv">5</span>]</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>m<span class="ot"><-</span>(fb_t_MIN<span class="sc">-</span>FallIOM_min)<span class="sc">/</span>(b)</span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a>Ceq_MIN<span class="ot"><-</span>(SOC_min<span class="sc">-</span>FallIOM_min)<span class="sc">/</span>m</span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a><span class="co"># UNCERTAINTIES C input equilibrium (MAXIMUM)</span></span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a>FallIOM_max<span class="ot">=</span><span class="fl">0.049</span><span class="sc">*</span>SOC_max<span class="sc">^</span>(<span class="fl">1.139</span>) </span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a>fb_max<span class="ot"><-</span><span class="fu">Roth_C</span>(<span class="at">Cinputs=</span>b,<span class="at">years=</span>years,<span class="at">DPMptf=</span><span class="dv">0</span>, <span class="at">RPMptf=</span><span class="dv">0</span>, <span class="at">BIOptf=</span><span class="dv">0</span>, <span class="at">HUMptf=</span><span class="dv">0</span>, <span class="at">FallIOM=</span>FallIOM,<span class="at">Temp=</span>Temp<span class="sc">*</span><span class="fl">0.98</span>,<span class="at">Precip=</span>Precip<span class="sc">*</span><span class="fl">1.05</span>,<span class="at">Evp=</span>Evp,<span class="at">Cov=</span>Cov,<span class="at">Cov1=</span>Cov1,<span class="at">Cov2=</span>Cov2,<span class="at">soil.thick=</span>soil.thick,<span class="at">SOC=</span>SOC_max,<span class="at">clay=</span>clay_max,<span class="at">DR=</span>DR,<span class="at">bare1=</span>bare1)</span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a>fb_t_MAX<span class="ot"><-</span>fb_max[<span class="dv">1</span>]<span class="sc">+</span>fb_max[<span class="dv">2</span>]<span class="sc">+</span>fb_max[<span class="dv">3</span>]<span class="sc">+</span>fb_max[<span class="dv">4</span>]<span class="sc">+</span>fb_max[<span class="dv">5</span>]</span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a>m<span class="ot"><-</span>(fb_t_MAX<span class="sc">-</span>FallIOM_max)<span class="sc">/</span>(b)</span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a>Ceq_MAX<span class="ot"><-</span>(SOC_max<span class="sc">-</span>FallIOM_max)<span class="sc">/</span>m </span></code></pre></div>
<p>Now for each land use, we will run the “pedotransfer functions” (Weiherm&uuller et al., 2013) to estimate the values of the SOC pools. Here is the example for the croplands land use. Then the same code will be executed for the rest of the land use classes.</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="co"># SOC POOLS AFTER 500 YEARS RUN WITH C INPUT EQUILIBRIUM</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> (LU<span class="sc">==</span><span class="dv">2</span>){</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>RPM_p_2<span class="ot"><-</span>((<span class="fl">0.184</span><span class="sc">*</span>SOC <span class="sc">+</span> <span class="fl">0.1555</span>)<span class="sc">*</span>(clay <span class="sc">+</span> <span class="fl">1.275</span>)<span class="sc">^</span>(<span class="sc">-</span><span class="fl">0.1158</span>))<span class="sc">*</span><span class="fl">0.9902+0.4788</span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>BIO_p_2<span class="ot"><-</span>((<span class="fl">0.014</span><span class="sc">*</span>SOC <span class="sc">+</span> <span class="fl">0.0075</span>)<span class="sc">*</span>(clay <span class="sc">+</span> <span class="fl">8.8473</span>)<span class="sc">^</span>(<span class="fl">0.0567</span>))<span class="sc">*</span><span class="fl">1.09038+0.04055</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>HUM_p_2<span class="ot"><-</span>((<span class="fl">0.7148</span><span class="sc">*</span>SOC <span class="sc">+</span> <span class="fl">0.5069</span>)<span class="sc">*</span>(clay <span class="sc">+</span> <span class="fl">0.3421</span>)<span class="sc">^</span>(<span class="fl">0.0184</span>))<span class="sc">*</span><span class="fl">0.9878-0.3818</span></span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a>DPM_p_2<span class="ot"><-</span>SOC<span class="sc">-</span>FallIOM<span class="sc">-</span>RPM_p_2<span class="sc">-</span>HUM_p_2<span class="sc">-</span>BIO_p_2</span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>feq_t<span class="ot"><-</span>RPM_p_2<span class="sc">+</span>BIO_p_2<span class="sc">+</span>HUM_p_2<span class="sc">+</span>DPM_p_2<span class="sc">+</span>FallIOM</span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a><span class="co">#uncertainties MIN</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a>RPM_p_2_min<span class="ot"><-</span>((<span class="fl">0.184</span><span class="sc">*</span>SOC_min <span class="sc">+</span> <span class="fl">0.1555</span>)<span class="sc">*</span>(clay_min <span class="sc">+</span> <span class="fl">1.275</span>)<span class="sc">^</span>(<span class="sc">-</span><span class="fl">0.1158</span>))<span class="sc">*</span><span class="fl">0.9902+0.4788</span></span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a>BIO_p_2_min<span class="ot"><-</span>((<span class="fl">0.014</span><span class="sc">*</span>SOC_min <span class="sc">+</span> <span class="fl">0.0075</span>)<span class="sc">*</span>(clay_min <span class="sc">+</span> <span class="fl">8.8473</span>)<span class="sc">^</span>(<span class="fl">0.0567</span>))<span class="sc">*</span><span class="fl">1.09038+0.04055</span></span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a>HUM_p_2_min<span class="ot"><-</span>((<span class="fl">0.7148</span><span class="sc">*</span>SOC_min <span class="sc">+</span> <span class="fl">0.5069</span>)<span class="sc">*</span>(clay_min <span class="sc">+</span> <span class="fl">0.3421</span>)<span class="sc">^</span>(<span class="fl">0.0184</span>))<span class="sc">*</span><span class="fl">0.9878-0.3818</span></span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a>DPM_p_2_min<span class="ot"><-</span>SOC_min<span class="sc">-</span>FallIOM_min<span class="sc">-</span>RPM_p_2_min<span class="sc">-</span>HUM_p_2_min<span class="sc">-</span>BIO_p_2_min</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a>feq_t_min<span class="ot"><-</span>RPM_p_2_min<span class="sc">+</span>BIO_p_2_min<span class="sc">+</span>HUM_p_2_min<span class="sc">+</span>DPM_p_2_min<span class="sc">+</span>FallIOM_min</span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a><span class="co">#uncertainties MAX</span></span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a>RPM_p_2_max<span class="ot"><-</span>((<span class="fl">0.184</span><span class="sc">*</span>SOC_max <span class="sc">+</span> <span class="fl">0.1555</span>)<span class="sc">*</span>(clay_max <span class="sc">+</span> <span class="fl">1.275</span>)<span class="sc">^</span>(<span class="sc">-</span><span class="fl">0.1158</span>))<span class="sc">*</span><span class="fl">0.9902+0.4788</span></span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a>BIO_p_2_max<span class="ot"><-</span>((<span class="fl">0.014</span><span class="sc">*</span>SOC_max <span class="sc">+</span> <span class="fl">0.0075</span>)<span class="sc">*</span>(clay_max <span class="sc">+</span> <span class="fl">8.8473</span>)<span class="sc">^</span>(<span class="fl">0.0567</span>))<span class="sc">*</span><span class="fl">1.09038+0.04055</span></span>
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true" tabindex="-1"></a>HUM_p_2_max<span class="ot"><-</span>((<span class="fl">0.7148</span><span class="sc">*</span>SOC_max <span class="sc">+</span> <span class="fl">0.5069</span>)<span class="sc">*</span>(clay_max <span class="sc">+</span> <span class="fl">0.3421</span>)<span class="sc">^</span>(<span class="fl">0.0184</span>))<span class="sc">*</span><span class="fl">0.9878-0.3818</span></span>
<span id="cb21-18"><a href="#cb21-18" aria-hidden="true" tabindex="-1"></a>DPM_p_2_max<span class="ot"><-</span>SOC_max<span class="sc">-</span>FallIOM_max<span class="sc">-</span>RPM_p_2_max<span class="sc">-</span>HUM_p_2_max<span class="sc">-</span>BIO_p_2_max</span>
<span id="cb21-19"><a href="#cb21-19" aria-hidden="true" tabindex="-1"></a>feq_t_max<span class="ot"><-</span>RPM_p_2_max<span class="sc">+</span>BIO_p_2_max<span class="sc">+</span>HUM_p_2_max<span class="sc">+</span>DPM_p_2_max<span class="sc">+</span>FallIOM_max</span></code></pre></div>
<p>Finally, we will save the outputs pools to the variables C_INPUT_EQ :</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">2</span>]<span class="ot"><-</span>SOC</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">3</span>]<span class="ot"><-</span>Ceq</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">4</span>]<span class="ot"><-</span>feq_t</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">5</span>]<span class="ot"><-</span>DPM_p_2</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">6</span>]<span class="ot"><-</span>RPM_p_2</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">7</span>]<span class="ot"><-</span>BIO_p_2</span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">8</span>]<span class="ot"><-</span>HUM_p_2</span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">9</span>]<span class="ot"><-</span>FallIOM</span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">10</span>]<span class="ot"><-</span>Ceq_MIN</span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">11</span>]<span class="ot"><-</span>Ceq_MAX</span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">12</span>]<span class="ot"><-</span>feq_t_min</span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">13</span>]<span class="ot"><-</span>DPM_p_2_min</span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">14</span>]<span class="ot"><-</span>RPM_p_2_min</span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">15</span>]<span class="ot"><-</span>BIO_p_2_min</span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">16</span>]<span class="ot"><-</span>HUM_p_2_min</span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">17</span>]<span class="ot"><-</span>FallIOM_min</span>
<span id="cb22-17"><a href="#cb22-17" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">18</span>]<span class="ot"><-</span>feq_t_max</span>
<span id="cb22-18"><a href="#cb22-18" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">19</span>]<span class="ot"><-</span>DPM_p_2_max</span>
<span id="cb22-19"><a href="#cb22-19" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">20</span>]<span class="ot"><-</span>RPM_p_2_max</span>
<span id="cb22-20"><a href="#cb22-20" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">21</span>]<span class="ot"><-</span>BIO_p_2_max</span>
<span id="cb22-21"><a href="#cb22-21" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">22</span>]<span class="ot"><-</span>HUM_p_2_max</span>
<span id="cb22-22"><a href="#cb22-22" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ[i,<span class="dv">23</span>]<span class="ot"><-</span>FallIOM_max</span></code></pre></div>
<p>In order to properly save the output vector, we will change the names of the fields:</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="co">#rename de columns</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">2</span>]<span class="ot">=</span><span class="st">"SOC_FAO"</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">3</span>]<span class="ot">=</span><span class="st">"Cinput_EQ"</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">4</span>]<span class="ot">=</span><span class="st">"SOC_pedotransfer"</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">5</span>]<span class="ot">=</span><span class="st">"DPM_pedotransfer"</span></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">6</span>]<span class="ot">=</span><span class="st">"RPM_pedotransfer"</span></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">7</span>]<span class="ot">=</span><span class="st">"BIO_pedotransfer"</span></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">8</span>]<span class="ot">=</span><span class="st">"HUM_pedotransfer"</span></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">9</span>]<span class="ot">=</span><span class="st">"IOM_pedotransfer"</span></span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">10</span>]<span class="ot">=</span><span class="st">"CIneq_min"</span></span>
<span id="cb23-11"><a href="#cb23-11" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">11</span>]<span class="ot">=</span><span class="st">"CIneq_max"</span></span>
<span id="cb23-12"><a href="#cb23-12" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">12</span>]<span class="ot">=</span><span class="st">"SOC_min"</span></span>
<span id="cb23-13"><a href="#cb23-13" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">13</span>]<span class="ot">=</span><span class="st">"DPM_min"</span></span>
<span id="cb23-14"><a href="#cb23-14" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">14</span>]<span class="ot">=</span><span class="st">"RPM_min"</span></span>
<span id="cb23-15"><a href="#cb23-15" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">15</span>]<span class="ot">=</span><span class="st">"BIO_min"</span></span>
<span id="cb23-16"><a href="#cb23-16" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">16</span>]<span class="ot">=</span><span class="st">"HUM_min"</span></span>
<span id="cb23-17"><a href="#cb23-17" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">17</span>]<span class="ot">=</span><span class="st">"IOM_min"</span></span>
<span id="cb23-18"><a href="#cb23-18" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">18</span>]<span class="ot">=</span><span class="st">"SOC_max"</span></span>
<span id="cb23-19"><a href="#cb23-19" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">19</span>]<span class="ot">=</span><span class="st">"DPM_max"</span></span>
<span id="cb23-20"><a href="#cb23-20" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">20</span>]<span class="ot">=</span><span class="st">"RPM_max"</span></span>
<span id="cb23-21"><a href="#cb23-21" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">21</span>]<span class="ot">=</span><span class="st">"BIO_max"</span></span>
<span id="cb23-22"><a href="#cb23-22" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">22</span>]<span class="ot">=</span><span class="st">"HUM_max"</span></span>
<span id="cb23-23"><a href="#cb23-23" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">23</span>]<span class="ot">=</span><span class="st">"IOM_max"</span></span></code></pre></div>
<p>Finally, we will set the output directory and save the output vector:</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># SAVE the Points (shapefile)</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="fu">writeOGR</span>(C_INPUT_EQ, <span class="st">"."</span>, <span class="st">"OUTPUTS/1_SPIN_UP/SPIN_UP_County_AOI"</span>, <span class="at">driver=</span><span class="st">"ESRI Shapefile"</span>) </span></code></pre></div>
</div>
<div id="script-number-13.b.-roth_c_spin_up_unc_v66.r-analytical-solution" class="section level3" number="1.2.2">
<h3><span class="header-section-number">1.2.2</span> Script Number 13.B. “ROTH_C_SPIN_UP_UNC_v66.R” (analytical solution)</h3>
<p>Script number 13.B implements the first modeling phase (spin up) using the analytical solution approach (see section 5.4.1.2), developed by Dechow et al. (2019) and adapted to spatial simulations.</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="co">#12/11/2020</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a><span class="co"># SPATIAL SOIL R for VECTORS</span></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a><span class="do">###### SPIN UP ################</span></span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a><span class="co"># MSc Ing Agr Luciano E Di Paolo</span></span>
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Dr Ing Agr Guillermo E Peralta</span></span>
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Dr. Ing Rene Dechow</span></span>
<span id="cb25-10"><a href="#cb25-10" aria-hidden="true" tabindex="-1"></a><span class="do">################################</span></span>
<span id="cb25-11"><a href="#cb25-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-12"><a href="#cb25-12" aria-hidden="true" tabindex="-1"></a><span class="do">################################################################################</span></span>
<span id="cb25-13"><a href="#cb25-13" aria-hidden="true" tabindex="-1"></a><span class="co">#13_1_ROTHC_C_SPIN_UP_UNC_v66.R</span></span>
<span id="cb25-14"><a href="#cb25-14" aria-hidden="true" tabindex="-1"></a><span class="do">################################################################################</span></span>
<span id="cb25-15"><a href="#cb25-15" aria-hidden="true" tabindex="-1"></a><span class="co"># This script does some regionalized uncertainty runs with RothC it quantifies</span></span>
<span id="cb25-16"><a href="#cb25-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Pool distributions and equilibrium C input for a minimum and maximum scenario</span></span>
<span id="cb25-17"><a href="#cb25-17" aria-hidden="true" tabindex="-1"></a><span class="co">#Input:</span></span>
<span id="cb25-18"><a href="#cb25-18" aria-hidden="true" tabindex="-1"></a><span class="co"># a point.shp file with SOC and un</span></span>
<span id="cb25-19"><a href="#cb25-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-20"><a href="#cb25-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-21"><a href="#cb25-21" aria-hidden="true" tabindex="-1"></a><span class="do">###################################</span></span>
<span id="cb25-22"><a href="#cb25-22" aria-hidden="true" tabindex="-1"></a><span class="co"># SOilR from Sierra, C.A., M. Mueller, S.E. Trumbore (2012). </span></span>
<span id="cb25-23"><a href="#cb25-23" aria-hidden="true" tabindex="-1"></a><span class="co">#Models of soil organic matter decomposition: the SoilR package, version 1.0 Geoscientific Model Development, 5(4), </span></span>
<span id="cb25-24"><a href="#cb25-24" aria-hidden="true" tabindex="-1"></a><span class="co">#1045--1060. URL http://www.geosci-model-dev.net/5/1045/2012/gmd-5-1045-2012.html.</span></span>
<span id="cb25-25"><a href="#cb25-25" aria-hidden="true" tabindex="-1"></a><span class="do">#####################################</span></span></code></pre></div>
<p>In this script we will load the stack generated in script number 10 and the target points (Section 9.7, QGIS model number 1). We will obtain an output vector containing our target points. This script estimates the SOC stocks for the different pools and the equilibrium carbon inputs (the carbon inputs needed to reach the 2001 SOC stocks),assuming homogeneous soil, climatic and management conditions.
First, the script estimates the fractions (fi) of DPM, RPM, BIO and HUM pools at equilibrium following the set of equations and intermediate coefficients described in Annex 3. Once the fractions of the different pools are estimated, the amount of Carbon (tC ha<sup>-1</sup>) in each pool is estimated from the total SOC stock. Finally, Carbon inputs (Ci) at equilibrium are estimated from the generated results.
All results will be saved to the output vector (shapefile file). Using this approach, the spin up phase will allow us to obtain two key outputs that will be saved to a point vector layer called “C_INPUT_EQ.shp”: equilibrium carbon inputs (Ceq) and the carbon stocks of the different soil C pools to run the second phase (warm up phase).
First, we need to load the packages into R:</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list=</span><span class="fu">ls</span>()) </span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(SoilR)</span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(raster)</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(rgdal)</span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(soilassessment)</span></code></pre></div>
<p>Then we define the function to estimate the Inert Organic Carbon content (IOM; t C ha<sup>-1</sup>) according to the equation (see eq. 5.2) given by Falloon et al. (1998):</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="do">########################################################</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="co"># calculates some iom in t / ha</span></span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a><span class="co"># input</span></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. c total carbpn stock in t /ha</span></span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a><span class="do">#####################################################</span></span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a>fIOM.Falloon.RothC <span class="ot">=</span><span class="cf">function</span>(c, <span class="at">par1=</span><span class="sc">-</span><span class="fl">1.31</span>, <span class="at">par2=</span><span class="fl">1.139</span>)</span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a>{</span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># IOM=10^(par1+par2*log10(c))</span></span>
<span id="cb27-10"><a href="#cb27-10" aria-hidden="true" tabindex="-1"></a> IOM<span class="ot">=</span><span class="fl">0.049</span><span class="sc">*</span>SOC<span class="sc">^</span>(<span class="fl">1.139</span>) </span>
<span id="cb27-11"><a href="#cb27-11" aria-hidden="true" tabindex="-1"></a> IOM</span>
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p>Then from lines 61-176 we will define the main function that will estimate the fraction of each carbon pool at equilibrium and the carbon inputs at equilibrium (“fget_equilibrium_factions.RothC_input”).</p>
<p>The inputs of this function are (line 61):</p>
<ul>
<li><em>xi</em> = is a scalar representing an averaged rate modifying factor (rmf; average of temperature, soil moisture, vegetation cover and anaerobic/paddy rice factors).<br />
</li>
<li><em>C.tot</em> = represents the initial C stock (and therefore C stock in equilibrium; that will correspond to the FAO GSOCmap)<br />
</li>
<li><em>clay</em> = clay content in %</li>
<li><em>fractI</em> = vector of Cinput fractions (these fractions 1, 2 and 3 correspond to the <span class="math inline">\(\gamma_{DPM}\)</span>, <span class="math inline">\(\gamma_{RPM}\)</span>, <span class="math inline">\(\gamma_{HUM}\)</span> partition coefficients, that represent the proportion of DPM, RPM and HUM of the incoming residues. The fractions are derived from the decomposability of incoming C inputs (e.g. DPM/RPM ratio). The way to estimate these <span class="math inline">\(\gamma_{DPM}\)</span>, <span class="math inline">\(\gamma_{RPM}\)</span>, <span class="math inline">\(\gamma_{HUM}\)</span> partition coefficients (named as “fractI” in the script) is going to be defined later at line 229.</li>
</ul>
<div class="sourceCode" id="cb28"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="do">#################################################################################</span></span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="co"># fget_equilibrium_fractions.RothC_input </span></span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a><span class="co"># brief: quantifies pool distribution and C input for RothC at equilibrium</span></span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a><span class="co">#Input</span></span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a><span class="co"># xi= scalar representing an averaged modifying factor</span></span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a><span class="co"># C.tot = initial C stock (and C stock in equilibrium)</span></span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a><span class="co"># clay = clay content</span></span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a><span class="co"># fractI = vector of Cinput fractions that enter the DPM, RPM, HUM </span></span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a><span class="co"># with a DR of 1.44 fractI becomes [1] 0.5901639 0.4098361 0.0000000</span></span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a><span class="co"># by fractI=c((DR)/(DR+1),1-(DR)/(DR+1),0)</span></span>
<span id="cb28-11"><a href="#cb28-11" aria-hidden="true" tabindex="-1"></a><span class="co">#Output</span></span>
<span id="cb28-12"><a href="#cb28-12" aria-hidden="true" tabindex="-1"></a><span class="co"># list with pools at equilibrium and C input at equilibrium</span></span>
<span id="cb28-13"><a href="#cb28-13" aria-hidden="true" tabindex="-1"></a><span class="do">################################################################################</span></span>
<span id="cb28-14"><a href="#cb28-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-15"><a href="#cb28-15" aria-hidden="true" tabindex="-1"></a>fget_equilibrium_fractions.RothC_input<span class="ot">=</span><span class="cf">function</span>(<span class="at">xi=</span><span class="dv">1</span>,C.tot,clay, fractI)</span>
<span id="cb28-16"><a href="#cb28-16" aria-hidden="true" tabindex="-1"></a>{ </span>
<span id="cb28-17"><a href="#cb28-17" aria-hidden="true" tabindex="-1"></a> rmf<span class="ot">=</span>xi</span>
<span id="cb28-18"><a href="#cb28-18" aria-hidden="true" tabindex="-1"></a> IOM<span class="ot">=</span> <span class="fu">fIOM.Falloon.RothC</span>(<span class="at">c =</span> C.tot)</span>
<span id="cb28-19"><a href="#cb28-19" aria-hidden="true" tabindex="-1"></a> C.active<span class="ot">=</span>C.tot<span class="sc">-</span>IOM </span></code></pre></div>
<p>The output of this function (at line 174) will be a list of two elements: the first element is a vector of 5 elements containing the C stocks of the different SOC pools and the second element is the carbon input at equilibrium.</p>
<p>From lines 67-175, the analytical solution to estimate SOC pools and estimate equilibrium Carbon inputs is implemented. First we will need to define the proportion of decomposed carbon that goes to the BIO pool (46%; “fract.rooted.to.bio”) or to the HUM pool (54%; “fract.rooted.to.hum”) using the default coefficients from the original RothC model. At lines 76-82 we will define the decomposition rates (k) for each pool (using the default k values of the original RothC model).</p>
<div class="sourceCode" id="cb29"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="do">########################################################################</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a> <span class="co">#The analytical solution of RothC</span></span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># Parameter</span></span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a> fract.rooted.to.bio <span class="ot">=</span> <span class="fl">0.46</span></span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a> fract.rooted.to.hum <span class="ot">=</span> <span class="fl">0.54</span></span>
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true" tabindex="-1"></a> ks <span class="ot">=</span> <span class="fu">c</span>(<span class="at">k.DPM =</span> <span class="dv">10</span>, <span class="at">k.RPM =</span> <span class="fl">0.3</span>, <span class="at">k.BIO =</span> <span class="fl">0.66</span>, <span class="at">k.HUM =</span> <span class="fl">0.02</span>, </span>
<span id="cb29-11"><a href="#cb29-11" aria-hidden="true" tabindex="-1"></a> <span class="at">k.IOM =</span> <span class="dv">0</span>)</span>
<span id="cb29-12"><a href="#cb29-12" aria-hidden="true" tabindex="-1"></a> ks<span class="ot">=</span><span class="fu">as.numeric</span>(ks)</span>
<span id="cb29-13"><a href="#cb29-13" aria-hidden="true" tabindex="-1"></a> k.dpm<span class="ot">=</span>ks[<span class="dv">1</span>]</span>
<span id="cb29-14"><a href="#cb29-14" aria-hidden="true" tabindex="-1"></a> k.rpm<span class="ot">=</span>ks[<span class="dv">2</span>]</span>
<span id="cb29-15"><a href="#cb29-15" aria-hidden="true" tabindex="-1"></a> k.bio<span class="ot">=</span>ks[<span class="dv">3</span>]</span>
<span id="cb29-16"><a href="#cb29-16" aria-hidden="true" tabindex="-1"></a> k.hum<span class="ot">=</span>ks[<span class="dv">4</span>]</span></code></pre></div>
<p>Then we will define the Carbon Use Efficiency (CUE) at line 86. We will require the CUE later to estimate intermediate coefficients (<span class="math inline">\(\alpha\)</span>). The CUE represents the amount of carbon that goes to the BIO + HUM pools (from the total decomposed carbon). The amount of carbon that is outputted in form of CO2 or stored in the BIO and HUM pools is determined by the clay content of the soil (following the original equation in the RothC model), so the CUE is dependent on clay content.</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># the carbon use efficiency</span></span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true" tabindex="-1"></a> cue<span class="ot">=</span> <span class="dv">1</span><span class="sc">/</span>(<span class="dv">1</span><span class="sc">+</span> <span class="fl">1.67</span> <span class="sc">*</span> (<span class="fl">1.85</span> <span class="sc">+</span> <span class="fl">1.6</span> <span class="sc">*</span> <span class="fu">exp</span>(<span class="sc">-</span><span class="fl">0.0786</span> <span class="sc">*</span> clay)))</span></code></pre></div>
<p>From lines 88-113, we will need to define a number of intermediate coefficients (referred as <span class="math inline">\(\alpha\)</span>, <span class="math inline">\(\lambda\)</span>, and c in the equations detailed in Annex 3). These coefficients will then allow us to estimate the fraction of each carbon pool at equilibrium. $$1 and <span class="math inline">\(\alpha\)</span> 2 coefficients will be estimated from the carbon use efficiency and from the proportion of carbon that goes to BIO or HUM (defined in lines 74-75). The intermediate coefficients <span class="math inline">\(\alpha\)</span> 1.1 to <span class="math inline">\(\alpha\)</span> 2.2 will be derived from the decomposition rates of each pool already defined in lines 76-82; and from the average rate modifying factor (rmf; average of temperature, soil moisture, vegetation cover and anaerobic/paddy rice factors). The c coefficient will be estimated from the previously estimated <span class="math inline">\(\alpha\)</span> coefficients (lines 111-113). <span class="math inline">\(\lambda\)</span> (Lambda) intermediate coefficients (lines 106-107) are not required in this stationary version and are currently disabled.</p>
<div class="sourceCode" id="cb31"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="do">########################################################################</span></span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># All the coefficients alpha.1 und alpha.2</span></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a> alpha<span class="fl">.1</span><span class="ot">=</span>cue<span class="sc">*</span>fract.rooted.to.bio</span>
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true" tabindex="-1"></a> alpha<span class="fl">.2</span><span class="ot">=</span>cue<span class="sc">*</span>fract.rooted.to.hum</span>
<span id="cb31-6"><a href="#cb31-6" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb31-7"><a href="#cb31-7" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb31-8"><a href="#cb31-8" aria-hidden="true" tabindex="-1"></a> <span class="co"># All the coefficients a.1.1, a.1.2, a.2.1, a2.2</span></span>
<span id="cb31-9"><a href="#cb31-9" aria-hidden="true" tabindex="-1"></a> <span class="do">########################################################################</span></span>
<span id="cb31-10"><a href="#cb31-10" aria-hidden="true" tabindex="-1"></a> a.<span class="fl">1.1</span><span class="ot">=</span>k.bio<span class="sc">*</span>rmf<span class="sc">*</span>(alpha<span class="fl">.1</span><span class="dv">-1</span>)</span>
<span id="cb31-11"><a href="#cb31-11" aria-hidden="true" tabindex="-1"></a> a.<span class="fl">1.2</span><span class="ot">=</span>alpha<span class="fl">.1</span><span class="sc">*</span>k.hum<span class="sc">*</span>rmf</span>
<span id="cb31-12"><a href="#cb31-12" aria-hidden="true" tabindex="-1"></a> a.<span class="fl">2.1</span><span class="ot">=</span>alpha<span class="fl">.2</span><span class="sc">*</span>k.bio<span class="sc">*</span>rmf</span>
<span id="cb31-13"><a href="#cb31-13" aria-hidden="true" tabindex="-1"></a> a.<span class="fl">2.2</span><span class="ot">=</span>k.hum<span class="sc">*</span>rmf<span class="sc">*</span>(alpha<span class="fl">.2</span><span class="dv">-1</span>)</span>
<span id="cb31-14"><a href="#cb31-14" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb31-15"><a href="#cb31-15" aria-hidden="true" tabindex="-1"></a> <span class="do">#########################################################################</span></span>
<span id="cb31-16"><a href="#cb31-16" aria-hidden="true" tabindex="-1"></a> <span class="do">#########################################################################</span></span>
<span id="cb31-17"><a href="#cb31-17" aria-hidden="true" tabindex="-1"></a> <span class="co"># The Eigenvalues lambda 1 and lambda 2</span></span>
<span id="cb31-18"><a href="#cb31-18" aria-hidden="true" tabindex="-1"></a> <span class="do">#########################################################################</span></span>
<span id="cb31-19"><a href="#cb31-19" aria-hidden="true" tabindex="-1"></a> lambda<span class="fl">.1</span><span class="ot">=</span> (a.<span class="fl">1.1</span><span class="sc">+</span>a.<span class="fl">2.2</span>)<span class="sc">/</span><span class="dv">2</span><span class="sc">-</span><span class="fu">sqrt</span>(((a.<span class="fl">1.1</span><span class="sc">+</span>a.<span class="fl">2.2</span>)<span class="sc">/</span><span class="dv">2</span>)<span class="sc">*</span>((a.<span class="fl">1.1</span><span class="sc">+</span>a.<span class="fl">2.2</span>)<span class="sc">/</span><span class="dv">2</span>)<span class="sc">+</span>a.<span class="fl">1.2</span><span class="sc">*</span>a.<span class="fl">2.1</span><span class="sc">-</span>a.<span class="fl">1.1</span><span class="sc">*</span>a.<span class="fl">2.2</span>)</span>
<span id="cb31-20"><a href="#cb31-20" aria-hidden="true" tabindex="-1"></a> lambda<span class="fl">.2</span><span class="ot">=</span> (a.<span class="fl">1.1</span><span class="sc">+</span>a.<span class="fl">2.2</span>)<span class="sc">/</span><span class="dv">2</span><span class="sc">+</span><span class="fu">sqrt</span>(((a.<span class="fl">1.1</span><span class="sc">+</span>a.<span class="fl">2.2</span>)<span class="sc">/</span><span class="dv">2</span>)<span class="sc">*</span>((a.<span class="fl">1.1</span><span class="sc">+</span>a.<span class="fl">2.2</span>)<span class="sc">/</span><span class="dv">2</span>)<span class="sc">+</span>a.<span class="fl">1.2</span><span class="sc">*</span>a.<span class="fl">2.1</span><span class="sc">-</span>a.<span class="fl">1.1</span><span class="sc">*</span>a.<span class="fl">2.2</span>)</span>
<span id="cb31-21"><a href="#cb31-21" aria-hidden="true" tabindex="-1"></a> <span class="do">#########################################################################</span></span>
<span id="cb31-22"><a href="#cb31-22" aria-hidden="true" tabindex="-1"></a> <span class="co"># The c.0.1; c.0.2; c.0.3 values</span></span>
<span id="cb31-23"><a href="#cb31-23" aria-hidden="true" tabindex="-1"></a> <span class="do">#########################################################################</span></span>
<span id="cb31-24"><a href="#cb31-24" aria-hidden="true" tabindex="-1"></a> c.<span class="fl">0.1</span><span class="ot">=</span> (alpha<span class="fl">.2</span> <span class="sc">*</span> a.<span class="fl">1.2</span> <span class="sc">-</span> alpha<span class="fl">.1</span> <span class="sc">*</span> a.<span class="fl">2.2</span>)<span class="sc">/</span>(a.<span class="fl">1.1</span><span class="sc">*</span>a.<span class="fl">2.2</span><span class="sc">-</span>a.<span class="fl">1.2</span><span class="sc">*</span>a.<span class="fl">2.1</span>)</span>
<span id="cb31-25"><a href="#cb31-25" aria-hidden="true" tabindex="-1"></a> c.<span class="fl">0.2</span><span class="ot">=</span> (alpha<span class="fl">.2</span> <span class="sc">*</span> a.<span class="fl">1.2</span> <span class="sc">-</span> alpha<span class="fl">.1</span> <span class="sc">*</span> a.<span class="fl">2.2</span>)<span class="sc">/</span>(a.<span class="fl">1.1</span><span class="sc">*</span>a.<span class="fl">2.2</span><span class="sc">-</span>a.<span class="fl">1.2</span><span class="sc">*</span>a.<span class="fl">2.1</span>)</span>
<span id="cb31-26"><a href="#cb31-26" aria-hidden="true" tabindex="-1"></a> c.<span class="fl">0.3</span><span class="ot">=</span> (a.<span class="fl">1.2</span>)<span class="sc">/</span>(a.<span class="fl">1.1</span><span class="sc">*</span>a.<span class="fl">2.2</span><span class="sc">-</span>a.<span class="fl">1.2</span><span class="sc">*</span>a.<span class="fl">2.1</span>)</span></code></pre></div>
<p>Then, from lines 115-155, we will define the u coefficients (see intermediate equations in Annex 3), which are functions integrating model structure and related to the proportion of C of each pool entering other pools. These u coefficients will be estimated from the previously defined <span class="math inline">\(\alpha\)</span> and c coefficients, from the decomposition rates (k) and from the rate modifying factor (rmf). We will define in total a set of 11 u coefficients, that we will finally require to estimate the SOC fraction of each pool.</p>
<div class="sourceCode" id="cb32"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># BIO pool quantification</span></span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a> u.bio.dpm<span class="ot">=</span>(c.<span class="fl">0.2</span>) <span class="co">#65</span></span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a> u.bio.rpm<span class="ot">=</span>(c.<span class="fl">0.1</span>) <span class="co">#66</span></span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a> u.bio.hum<span class="ot">=</span>(c.<span class="fl">0.3</span>) <span class="co">#67</span></span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-10"><a href="#cb32-10" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-11"><a href="#cb32-11" aria-hidden="true" tabindex="-1"></a> <span class="co"># HUM pool quantification ( is all C.78)</span></span>
<span id="cb32-12"><a href="#cb32-12" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-13"><a href="#cb32-13" aria-hidden="true" tabindex="-1"></a> u.hum.dpm<span class="ot">=</span> <span class="dv">1</span><span class="sc">/</span>a.<span class="fl">1.2</span><span class="sc">*</span>((<span class="sc">-</span>c.<span class="fl">0.2</span><span class="sc">*</span>a.<span class="fl">1.1</span><span class="sc">-</span>alpha<span class="fl">.1</span>))</span>
<span id="cb32-14"><a href="#cb32-14" aria-hidden="true" tabindex="-1"></a> u.hum.rpm<span class="ot">=</span> <span class="dv">1</span><span class="sc">/</span>a.<span class="fl">1.2</span><span class="sc">*</span>(<span class="sc">-</span>c.<span class="fl">0.2</span><span class="sc">*</span>a.<span class="fl">1.1</span><span class="sc">-</span>alpha<span class="fl">.1</span>)</span>
<span id="cb32-15"><a href="#cb32-15" aria-hidden="true" tabindex="-1"></a> u.hum.hum<span class="ot">=</span> <span class="dv">1</span><span class="sc">/</span>a.<span class="fl">1.2</span><span class="sc">*</span>(<span class="sc">-</span>c.<span class="fl">0.3</span><span class="sc">*</span>a.<span class="fl">1.1</span>)</span>
<span id="cb32-16"><a href="#cb32-16" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb32-17"><a href="#cb32-17" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-18"><a href="#cb32-18" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-19"><a href="#cb32-19" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-20"><a href="#cb32-20" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-21"><a href="#cb32-21" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-22"><a href="#cb32-22" aria-hidden="true" tabindex="-1"></a> <span class="co"># DPM C ( is all C.79)</span></span>
<span id="cb32-23"><a href="#cb32-23" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-24"><a href="#cb32-24" aria-hidden="true" tabindex="-1"></a> u.dpm.dpm<span class="ot">=</span><span class="dv">1</span><span class="sc">/</span>k.dpm<span class="sc">/</span>rmf </span>
<span id="cb32-25"><a href="#cb32-25" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb32-26"><a href="#cb32-26" aria-hidden="true" tabindex="-1"></a> <span class="co">#C.dpm=i.dpm * u.dpm.dpm + C0 * s.dpm</span></span>
<span id="cb32-27"><a href="#cb32-27" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb32-28"><a href="#cb32-28" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-29"><a href="#cb32-29" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-30"><a href="#cb32-30" aria-hidden="true" tabindex="-1"></a> <span class="co"># RPM C ( is all C.80)</span></span>
<span id="cb32-31"><a href="#cb32-31" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-32"><a href="#cb32-32" aria-hidden="true" tabindex="-1"></a> u.rpm.rpm<span class="ot">=</span><span class="dv">1</span><span class="sc">/</span>k.rpm<span class="sc">/</span>rmf</span>
<span id="cb32-33"><a href="#cb32-33" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb32-34"><a href="#cb32-34" aria-hidden="true" tabindex="-1"></a> <span class="co">#C.rpm=i.rpm * u.rpm.rpm + C0 *s.rpm</span></span>
<span id="cb32-35"><a href="#cb32-35" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb32-36"><a href="#cb32-36" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-37"><a href="#cb32-37" aria-hidden="true" tabindex="-1"></a> <span class="co"># Total C ( is all C.78)</span></span>
<span id="cb32-38"><a href="#cb32-38" aria-hidden="true" tabindex="-1"></a> <span class="do">######################################################################################################</span></span>
<span id="cb32-39"><a href="#cb32-39" aria-hidden="true" tabindex="-1"></a> u.dpm<span class="ot">=</span>u.dpm.dpm<span class="sc">+</span>u.bio.dpm<span class="sc">+</span>u.hum.dpm</span>
<span id="cb32-40"><a href="#cb32-40" aria-hidden="true" tabindex="-1"></a> u.rpm<span class="ot">=</span>u.rpm.rpm<span class="sc">+</span>u.bio.rpm<span class="sc">+</span>u.hum.rpm</span>
<span id="cb32-41"><a href="#cb32-41" aria-hidden="true" tabindex="-1"></a> u.hum<span class="ot">=</span>u.bio.hum<span class="sc">+</span>u.hum.hum</span></code></pre></div>
<p>To end the “fget_equilibrium_factions.RothC_input” function, we will define how to estimate the fraction (fi) of each active SOC pool to the total SOC at equilibrium. These fractions are going to be estimated following the equations 5.5 to 5.8 already explained in section 5.4.1.2, from the u coefficients and the <span class="math inline">\(\gamma_{DPM}\)</span>, <span class="math inline">\(\gamma_{RPM}\)</span>, <span class="math inline">\(\gamma_{HUM}\)</span> partition coefficients (fract I):</p>
<p><span class="math display">\[\begin{equation}
\tag{5.5}
f_{DPM} = \frac{DPM\ u_{DPM}}{DPM\ u_{DPM} + RPM\ u_{RPM}+ HUM\ u_{HUM}}
\end{equation}\]</span></p>
<p><span class="math display">\[\begin{equation}
\tag{5.6}
f_{RPM} = \frac{RPM\ u_{RPM}}{DPM\ u_{DPM}+ RPM\ u_{RPM} +HUM\ u_{HUM}}
\end{equation}\]</span></p>
<p><span class="math display">\[\begin{equation}
\tag{5.7}
f_{BIO} = \frac{DPM\ u_{BIO} DPM + RPM\ u_{BIO} RPM + HUM\ u_{BIO} HUM}{DPM \ u_{DPM} + RPM\ u_{RPM} +HUM\ u_{HUM}}
\end{equation}\]</span></p>
<p><span class="math display">\[\begin{equation}
\tag{5.8}
f_{HUM} = \frac{\gamma_{DPM} \ u_{HUM} DPM+ RPM\ u_{HUM} RPM + HUM\ u_{HUM} HUM}{DPM\ u_{DPM} + RPM\ u_{RPM}+ HUM u_{HUM}}
\end{equation}\]</span></p>
<p>As all pool fractions will be estimated by dividing by the same term (<span class="math inline">\(\gamma_{DPM}u_{DPM}+RPM\ u_{RPM}+HUM\ u_{HUM}\)</span>) we will define it in line 157. Then we will define the equations to estimate the fraction of each pool in lines 159-162. Finally, at line 164 we will create a vector containing the fraction of each active pool (<span class="math inline">\(f_{DPM}\)</span>, <span class="math inline">\(d_{RPM}\)</span>, <span class="math inline">\(f_{BIO}\)</span>, <span class="math inline">\(f_{HUM}\)</span>).</p>
<div class="sourceCode" id="cb33"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>Nenner<span class="ot">=</span> fractI[<span class="dv">1</span>]<span class="sc">*</span>u.dpm<span class="sc">+</span>fractI[<span class="dv">2</span>]<span class="sc">*</span>u.rpm<span class="sc">+</span>fractI[<span class="dv">3</span>]<span class="sc">*</span>u.hum</span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a> fract.dpm<span class="ot">=</span> fractI[<span class="dv">1</span>]<span class="sc">*</span>u.dpm.dpm<span class="sc">/</span>Nenner</span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true" tabindex="-1"></a> fract.rpm<span class="ot">=</span> fractI[<span class="dv">2</span>]<span class="sc">*</span>u.rpm.rpm<span class="sc">/</span>Nenner</span>
<span id="cb33-5"><a href="#cb33-5" aria-hidden="true" tabindex="-1"></a> fract.bio<span class="ot">=</span> (fractI[<span class="dv">1</span>]<span class="sc">*</span>u.bio.dpm<span class="sc">+</span>fractI[<span class="dv">2</span>]<span class="sc">*</span>u.bio.rpm<span class="sc">+</span>fractI[<span class="dv">3</span>]<span class="sc">*</span>u.bio.hum)<span class="sc">/</span>Nenner</span>
<span id="cb33-6"><a href="#cb33-6" aria-hidden="true" tabindex="-1"></a> fract.hum<span class="ot">=</span> (fractI[<span class="dv">1</span>]<span class="sc">*</span>u.hum.dpm<span class="sc">+</span>fractI[<span class="dv">2</span>]<span class="sc">*</span>u.hum.rpm<span class="sc">+</span>fractI[<span class="dv">3</span>]<span class="sc">*</span>u.hum.hum)<span class="sc">/</span>Nenner </span>
<span id="cb33-7"><a href="#cb33-7" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb33-8"><a href="#cb33-8" aria-hidden="true" tabindex="-1"></a> fract.all<span class="ot">=</span><span class="fu">c</span>(fract.dpm,fract.rpm,fract.bio,fract.hum)</span></code></pre></div>
<p>The SOC stocks (t C/ha) of each pool will be estimated by multiplying the fraction of each active pool by the total active SOC stock (t C/ha) (line 169). We will define a vector containing all four active fractions (line 170), plus the IOM fraction (line 171) (total 5 fractions); and a vector containing the SOC stocks of all five pools (line 172).</p>
<div class="sourceCode" id="cb34"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="do">###################################################</span></span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># IOM</span></span>
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a> <span class="do">###################################################</span></span>
<span id="cb34-4"><a href="#cb34-4" aria-hidden="true" tabindex="-1"></a> fract.all_stock<span class="ot">=</span>(fract.all<span class="sc">*</span>C.active)</span>
<span id="cb34-5"><a href="#cb34-5" aria-hidden="true" tabindex="-1"></a> fract.all<span class="ot">=</span>fract.all_stock<span class="sc">/</span>C.tot</span>
<span id="cb34-6"><a href="#cb34-6" aria-hidden="true" tabindex="-1"></a> fract.all<span class="ot">=</span><span class="fu">append</span>(fract.all,IOM<span class="sc">/</span>C.tot)</span>
<span id="cb34-7"><a href="#cb34-7" aria-hidden="true" tabindex="-1"></a> pools<span class="ot">=</span>fract.all<span class="sc">*</span>C.tot</span></code></pre></div>
<p>In the last step of this function, we will define how to estimate C inputs following equation 5.11 explained in section 5.4.1.2 (line 173); and we will define the output of this function as a list containing the C inputs at equilibrium plus the SOC stocks of all five pools of the RothC model (line 174).</p>
<div class="sourceCode" id="cb35"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a>Cin<span class="ot">=</span>(C.tot<span class="sc">-</span>pools[<span class="dv">5</span>])<span class="sc">/</span>Nenner</span>
<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">list</span>(pools,Cin)</span>
<span id="cb35-3"><a href="#cb35-3" aria-hidden="true" tabindex="-1"></a><span class="er">}</span></span></code></pre></div>
<p>From lines 180-217, we will set the working directory, and create a vector that contains the results and extract the data from the already created spin up stack (total SOC stocks, clay content, DPR/RPM ratio, Land use class)</p>
<div class="sourceCode" id="cb36"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Set working directory </span></span>
<span id="cb36-2"><a href="#cb36-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-3"><a href="#cb36-3" aria-hidden="true" tabindex="-1"></a>WD_FOLDER<span class="ot">=</span>(<span class="st">"D:/TRAINING_MATERIALS_GSOCseq_MAPS_12-11-2020"</span>)</span>
<span id="cb36-4"><a href="#cb36-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-5"><a href="#cb36-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Vector must be an empty points vector. </span></span>
<span id="cb36-6"><a href="#cb36-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-7"><a href="#cb36-7" aria-hidden="true" tabindex="-1"></a><span class="fu">setwd</span>(WD_FOLDER)</span>
<span id="cb36-8"><a href="#cb36-8" aria-hidden="true" tabindex="-1"></a>Vector<span class="ot"><-</span><span class="fu">readOGR</span>(<span class="st">"INPUTS/TARGET_POINTS/target_points_World_SouthAmerica.shp"</span>)</span>
<span id="cb36-9"><a href="#cb36-9" aria-hidden="true" tabindex="-1"></a><span class="co">#Vector2<-readOGR("INPUTS/TARGET_POINTS/Deutschland/target_points.shp")</span></span>
<span id="cb36-10"><a href="#cb36-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Stack_Set_1 is a stack that contains the spatial variables </span></span>
<span id="cb36-11"><a href="#cb36-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-12"><a href="#cb36-12" aria-hidden="true" tabindex="-1"></a>Stack_Set_1<span class="ot"><-</span> <span class="fu">stack</span>(<span class="st">"INPUTS/STACK/Stack_Set_SPIN_UP_AOI.tif"</span>)</span>
<span id="cb36-13"><a href="#cb36-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-14"><a href="#cb36-14" aria-hidden="true" tabindex="-1"></a><span class="co"># Create A vector to save the results</span></span>
<span id="cb36-15"><a href="#cb36-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-16"><a href="#cb36-16" aria-hidden="true" tabindex="-1"></a>C_INPUT_EQ<span class="ot"><-</span>Vector</span>
<span id="cb36-17"><a href="#cb36-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-18"><a href="#cb36-18" aria-hidden="true" tabindex="-1"></a><span class="co"># use this only for backup</span></span>
<span id="cb36-19"><a href="#cb36-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-20"><a href="#cb36-20" aria-hidden="true" tabindex="-1"></a><span class="co"># C_INPUT_EQ<-readOGR("OUTPUTS/1_SPIN_UP/SPIN_UP_BSAS_27-03-2020_332376.shp")</span></span>
<span id="cb36-21"><a href="#cb36-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-22"><a href="#cb36-22" aria-hidden="true" tabindex="-1"></a><span class="co"># extract variables to points</span></span>
<span id="cb36-23"><a href="#cb36-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-24"><a href="#cb36-24" aria-hidden="true" tabindex="-1"></a>Vector_variables<span class="ot"><-</span><span class="fu">extract</span>(Stack_Set_1,Vector,<span class="at">df=</span><span class="cn">TRUE</span>)</span>
<span id="cb36-25"><a href="#cb36-25" aria-hidden="true" tabindex="-1"></a><span class="co"># Extract the layers from the Vector</span></span>
<span id="cb36-26"><a href="#cb36-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-27"><a href="#cb36-27" aria-hidden="true" tabindex="-1"></a>SOC_im<span class="ot"><-</span>Vector_variables[[<span class="dv">2</span>]] <span class="co"># primera banda del stack</span></span>
<span id="cb36-28"><a href="#cb36-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-29"><a href="#cb36-29" aria-hidden="true" tabindex="-1"></a>clay_im<span class="ot"><-</span>Vector_variables[[<span class="dv">3</span>]] <span class="co"># segunda banda del stack </span></span>
<span id="cb36-30"><a href="#cb36-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-31"><a href="#cb36-31" aria-hidden="true" tabindex="-1"></a>DR_im<span class="ot"><-</span>Vector_variables[[<span class="dv">40</span>]]</span>
<span id="cb36-32"><a href="#cb36-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-33"><a href="#cb36-33" aria-hidden="true" tabindex="-1"></a>LU_im<span class="ot"><-</span>Vector_variables[[<span class="dv">41</span>]]</span>
<span id="cb36-34"><a href="#cb36-34" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-35"><a href="#cb36-35" aria-hidden="true" tabindex="-1"></a><span class="co"># Define Years for Cinputs calculations</span></span>
<span id="cb36-36"><a href="#cb36-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb36-37"><a href="#cb36-37" aria-hidden="true" tabindex="-1"></a><span class="co">#years=seq(1/12,2000,by=1/12)</span></span></code></pre></div>
<p>At line 221 , we will set the function called " Roth_C_equi_analy " . This function will be iterated over the target points, calculating the soil carbon pools defined in the Roth C model. The inputs of this function are:</p>
<ul>
<li>C inputs (carbon inputs),</li>
<li>Temp (temperature)</li>
<li>Precip (precipitation)</li>
<li>Evp (evapotranspiration)</li>
<li>Cov2 (vegetation cover)
soil.thick (soil thickness = 30 cm)</li>
<li>SOC (initial total SOC stocks)</li>
<li>clay (clay content at 0-30cm)</li>
<li>DR (the DPM/RPM ratio)</li>
<li>bare1 (coefficient indicating whether the soil is covered or vegetated)</li>
<li>LU (land use class)</li>
</ul>
<p>The outputs of this function are two: 1) The five soil carbon pools (gummi[[1]]), 2) the carbon inputs of equilibrium (gummi[[2]]). The previous function “fget_equilibrium_factions.RothC_input” is inside this function is . The main purpose of this function is to get the values of the input variables for the “fget_equilibrium_factions.RothC_input” function.</p>
<div class="sourceCode" id="cb37"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="co"># ROTH C MODEL FUNCTION . </span></span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a><span class="do">########## function set up starts###############</span></span>
<span id="cb37-4"><a href="#cb37-4" aria-hidden="true" tabindex="-1"></a>Roth_C_equi_analy<span class="ot"><-</span><span class="cf">function</span>(Cinputs,Temp,Precip,Evp,Cov2,soil.thick,SOC,clay,DR,bare1,LU)</span>
<span id="cb37-5"><a href="#cb37-5" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb37-6"><a href="#cb37-6" aria-hidden="true" tabindex="-1"></a>{</span></code></pre></div>
<p>So , first, at line 228 we calculate a vector of three elements, called “FractI”. This variable represents the carbon input fraction of DPM , RPM and HUM (the <span class="math inline">\(\gamma_{DPM}\)</span>, <span class="math inline">\(\gamma_{RPM}\)</span>, <span class="math inline">\(\gamma_{HUM}\)</span> partition coefficients). Normally, if we do not have organic amendments , the Humic fraction is set to 0.</p>
<div class="sourceCode" id="cb38"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#------------------------</span></span>
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># c input distribution</span></span>
<span id="cb38-3"><a href="#cb38-3" aria-hidden="true" tabindex="-1"></a> <span class="co">#-------------------------</span></span>
<span id="cb38-4"><a href="#cb38-4" aria-hidden="true" tabindex="-1"></a> fractI<span class="ot">=</span><span class="fu">c</span>((DR)<span class="sc">/</span>(DR<span class="sc">+</span><span class="dv">1</span>),<span class="dv">1</span><span class="sc">-</span>(DR)<span class="sc">/</span>(DR<span class="sc">+</span><span class="dv">1</span>),<span class="dv">0</span>)</span></code></pre></div>
<p>Then from lines 234 to 268 , the rate modifying factors are calculated : Paddy Field coefficient (fPR), Temperature coefficient (fT), Soil Moisture coefficient (fW_2), and Vegetation cover coefficient (fC).</p>
<div class="sourceCode" id="cb39"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># Paddy fields coefficent fPR = 0.4 if the target point is class = 13 , else fPR=1</span></span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># From Shirato and Yukozawa 2004</span></span>
<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-4"><a href="#cb39-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-5"><a href="#cb39-5" aria-hidden="true" tabindex="-1"></a> fPR<span class="ot">=</span>(LU <span class="sc">==</span> <span class="dv">13</span>)<span class="sc">*</span><span class="fl">0.4</span> <span class="sc">+</span> (LU<span class="sc">!=</span><span class="dv">13</span>)<span class="sc">*</span><span class="dv">1</span></span>
<span id="cb39-6"><a href="#cb39-6" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-7"><a href="#cb39-7" aria-hidden="true" tabindex="-1"></a> <span class="co">#Temperature effects per month</span></span>
<span id="cb39-8"><a href="#cb39-8" aria-hidden="true" tabindex="-1"></a> fT<span class="ot">=</span><span class="fu">fT.RothC</span>(Temp[,<span class="dv">2</span>]) </span>
<span id="cb39-9"><a href="#cb39-9" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-10"><a href="#cb39-10" aria-hidden="true" tabindex="-1"></a> <span class="co">#Moisture effects per month . </span></span>
<span id="cb39-11"><a href="#cb39-11" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-12"><a href="#cb39-12" aria-hidden="true" tabindex="-1"></a> fw1func<span class="ot"><-</span><span class="cf">function</span>(P, E, <span class="at">S.Thick =</span> <span class="dv">30</span>, <span class="at">pClay =</span> <span class="fl">32.0213</span>, <span class="at">pE =</span> <span class="dv">1</span>, bare) </span>
<span id="cb39-13"><a href="#cb39-13" aria-hidden="true" tabindex="-1"></a> {</span>
<span id="cb39-14"><a href="#cb39-14" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-15"><a href="#cb39-15" aria-hidden="true" tabindex="-1"></a> M <span class="ot">=</span> P <span class="sc">-</span> E <span class="sc">*</span> pE</span>
<span id="cb39-16"><a href="#cb39-16" aria-hidden="true" tabindex="-1"></a> Acc.TSMD <span class="ot">=</span> <span class="cn">NULL</span></span>
<span id="cb39-17"><a href="#cb39-17" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">2</span><span class="sc">:</span><span class="fu">length</span>(M)) {</span>
<span id="cb39-18"><a href="#cb39-18" aria-hidden="true" tabindex="-1"></a> B <span class="ot">=</span> <span class="fu">ifelse</span>(bare[i] <span class="sc">==</span> <span class="cn">FALSE</span>, <span class="dv">1</span>, <span class="fl">1.8</span>)</span>
<span id="cb39-19"><a href="#cb39-19" aria-hidden="true" tabindex="-1"></a> Max.TSMD <span class="ot">=</span> <span class="sc">-</span>(<span class="dv">20</span> <span class="sc">+</span> <span class="fl">1.3</span> <span class="sc">*</span> pClay <span class="sc">-</span> <span class="fl">0.01</span> <span class="sc">*</span> (pClay<span class="sc">^</span><span class="dv">2</span>)) <span class="sc">*</span> (S.Thick<span class="sc">/</span><span class="dv">23</span>) <span class="sc">*</span> (<span class="dv">1</span><span class="sc">/</span>B)</span>
<span id="cb39-20"><a href="#cb39-20" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[<span class="dv">1</span>] <span class="ot">=</span> <span class="fu">ifelse</span>(M[<span class="dv">1</span>] <span class="sc">></span> <span class="dv">0</span>, <span class="dv">0</span>, M[<span class="dv">1</span>])</span>
<span id="cb39-21"><a href="#cb39-21" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (Acc.TSMD[i <span class="sc">-</span> <span class="dv">1</span>] <span class="sc">+</span> M[i] <span class="sc"><</span> <span class="dv">0</span>) {</span>
<span id="cb39-22"><a href="#cb39-22" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[i] <span class="ot">=</span> Acc.TSMD[i <span class="sc">-</span> <span class="dv">1</span>] <span class="sc">+</span> M[i]</span>
<span id="cb39-23"><a href="#cb39-23" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb39-24"><a href="#cb39-24" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span> (Acc.TSMD[i] <span class="ot">=</span> <span class="dv">0</span>)</span>
<span id="cb39-25"><a href="#cb39-25" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (Acc.TSMD[i] <span class="sc"><=</span> Max.TSMD) {</span>
<span id="cb39-26"><a href="#cb39-26" aria-hidden="true" tabindex="-1"></a> Acc.TSMD[i] <span class="ot">=</span> Max.TSMD</span>
<span id="cb39-27"><a href="#cb39-27" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb39-28"><a href="#cb39-28" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb39-29"><a href="#cb39-29" aria-hidden="true" tabindex="-1"></a> b <span class="ot">=</span> <span class="fu">ifelse</span>(Acc.TSMD <span class="sc">></span> <span class="fl">0.444</span> <span class="sc">*</span> Max.TSMD, <span class="dv">1</span>, (<span class="fl">0.2</span> <span class="sc">+</span> <span class="fl">0.8</span> <span class="sc">*</span> ((Max.TSMD <span class="sc">-</span> </span>
<span id="cb39-30"><a href="#cb39-30" aria-hidden="true" tabindex="-1"></a> Acc.TSMD)<span class="sc">/</span>(Max.TSMD <span class="sc">-</span> <span class="fl">0.444</span> <span class="sc">*</span> Max.TSMD))))</span>
<span id="cb39-31"><a href="#cb39-31" aria-hidden="true" tabindex="-1"></a> b<span class="ot"><-</span><span class="fu">clamp</span>(b,<span class="at">lower=</span><span class="fl">0.2</span>)</span>
<span id="cb39-32"><a href="#cb39-32" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="fu">data.frame</span>(b)) </span>
<span id="cb39-33"><a href="#cb39-33" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb39-34"><a href="#cb39-34" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-35"><a href="#cb39-35" aria-hidden="true" tabindex="-1"></a> fW_2<span class="ot"><-</span> <span class="fu">fw1func</span>(<span class="at">P=</span>(Precip[,<span class="dv">2</span>]), <span class="at">E=</span>(Evp[,<span class="dv">2</span>]), <span class="at">S.Thick =</span> soil.thick, <span class="at">pClay =</span> clay, <span class="at">pE =</span> <span class="dv">1</span>, <span class="at">bare=</span>bare1)<span class="sc">$</span>b </span>
<span id="cb39-36"><a href="#cb39-36" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-37"><a href="#cb39-37" aria-hidden="true" tabindex="-1"></a> <span class="co">#Vegetation Cover effects </span></span>
<span id="cb39-38"><a href="#cb39-38" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb39-39"><a href="#cb39-39" aria-hidden="true" tabindex="-1"></a> fC<span class="ot"><-</span>Cov2[,<span class="dv">2</span>]</span></code></pre></div>
<p>After that, the “xi” variable is calculated as the mean of the product of the four modifying factors.</p>
<div class="sourceCode" id="cb40"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># Set the factors frame for Model calculations</span></span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-3"><a href="#cb40-3" aria-hidden="true" tabindex="-1"></a> xi<span class="ot">=</span><span class="fu">mean</span>(fT<span class="sc">*</span>fW_2<span class="sc">*</span>fC<span class="sc">*</span>fPR)</span></code></pre></div>
<p>Finally, we calculate the “gummi” variable using the “fget_equilibrium_fractions.RothC_input” function. We have already calculated or set the input variables for that function.
The output of the function " Roth_C_equi_analy " is a two element list containing both the soil carbon pools and the carbon input of equilibrium.</p>
<div class="sourceCode" id="cb41"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="co"># RUN THE MODEL </span></span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a> gummi<span class="ot">=</span><span class="fu">fget_equilibrium_fractions.RothC_input</span>(<span class="at">xi=</span>xi,<span class="at">C.tot=</span>SOC,<span class="at">clay=</span>clay, fractI)</span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a> <span class="co"># RUN THE MODEL FROM SOILR</span></span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a> <span class="co">#Model3_spin=RothCModel(t=years,C0=c(DPMptf, RPMptf, BIOptf, HUMptf, FallIOM),In=Cinputs,DR=DR,clay=clay,xi=xi.frame, pass=TRUE) </span></span>
<span id="cb41-7"><a href="#cb41-7" aria-hidden="true" tabindex="-1"></a> <span class="co">#Ct3_spin=getC(Model3_spin)</span></span>
<span id="cb41-8"><a href="#cb41-8" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb41-9"><a href="#cb41-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># Get the final pools of the time series</span></span>
<span id="cb41-10"><a href="#cb41-10" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb41-11"><a href="#cb41-11" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb41-12"><a href="#cb41-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(gummi)</span>
<span id="cb41-13"><a href="#cb41-13" aria-hidden="true" tabindex="-1"></a><span class="er">}</span></span></code></pre></div>
<p>After setting the " Roth_C_equi_analy " function we can now iterate that function over our target points (line 293) .</p>
<div class="sourceCode" id="cb42"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a><span class="do">######### function set up ends###############</span></span>
<span id="cb42-2"><a href="#cb42-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-3"><a href="#cb42-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Iterates over the area of interest</span></span>
<span id="cb42-4"><a href="#cb42-4" aria-hidden="true" tabindex="-1"></a><span class="co">#source("D:/projecte/Rlibs/dataframe_ops.R")</span></span>
<span id="cb42-5"><a href="#cb42-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-6"><a href="#cb42-6" aria-hidden="true" tabindex="-1"></a><span class="do">########for loop starts###############3</span></span>
<span id="cb42-7"><a href="#cb42-7" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">dim</span>(Vector_variables)[<span class="dv">1</span>]) {</span></code></pre></div>
<p>From lines 297-310 we will extract the climate and vegetation cover variables. At line 297 we will create a vector called “Vect”. This variable is a vector of 53 elements containing all the variables we need to run the model over a specific target point. At lines 299-300 we extract from the “Vect” variable the temperature information for the ith target point. At lines 302-303 we extract from the “Vect” variable the precipitation information for the ith target point. At lines 305-306 we extract from the “Vect” variable the potential evapotranspiration information for the ith target point. At lines 308-310 we extract from the “Vect” variable the vegetation cover information for the ith target point.</p>
<div class="sourceCode" id="cb43"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Extract the variables </span></span>
<span id="cb43-2"><a href="#cb43-2" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb43-3"><a href="#cb43-3" aria-hidden="true" tabindex="-1"></a> Vect<span class="ot"><-</span><span class="fu">as.data.frame</span>(Vector_variables[i,])</span>
<span id="cb43-4"><a href="#cb43-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb43-5"><a href="#cb43-5" aria-hidden="true" tabindex="-1"></a> Temp<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">4</span><span class="sc">:</span><span class="dv">15</span>]))</span>
<span id="cb43-6"><a href="#cb43-6" aria-hidden="true" tabindex="-1"></a> Temp<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Temp=</span>Temp[,<span class="dv">1</span>])</span>
<span id="cb43-7"><a href="#cb43-7" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb43-8"><a href="#cb43-8" aria-hidden="true" tabindex="-1"></a> Precip<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">16</span><span class="sc">:</span><span class="dv">27</span>]))</span>
<span id="cb43-9"><a href="#cb43-9" aria-hidden="true" tabindex="-1"></a> Precip<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Precip=</span>Precip[,<span class="dv">1</span>])</span>
<span id="cb43-10"><a href="#cb43-10" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb43-11"><a href="#cb43-11" aria-hidden="true" tabindex="-1"></a> Evp<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">28</span><span class="sc">:</span><span class="dv">39</span>]))</span>
<span id="cb43-12"><a href="#cb43-12" aria-hidden="true" tabindex="-1"></a> Evp<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Evp=</span>Evp[,<span class="dv">1</span>])</span>
<span id="cb43-13"><a href="#cb43-13" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb43-14"><a href="#cb43-14" aria-hidden="true" tabindex="-1"></a> Cov<span class="ot"><-</span><span class="fu">as.data.frame</span>(<span class="fu">t</span>(Vect[<span class="dv">42</span><span class="sc">:</span><span class="dv">53</span>]))</span>
<span id="cb43-15"><a href="#cb43-15" aria-hidden="true" tabindex="-1"></a> Cov1<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Cov=</span>Cov[,<span class="dv">1</span>])</span>
<span id="cb43-16"><a href="#cb43-16" aria-hidden="true" tabindex="-1"></a> Cov2<span class="ot"><-</span><span class="fu">data.frame</span>(<span class="at">Month=</span><span class="dv">1</span><span class="sc">:</span><span class="dv">12</span>, <span class="at">Cov=</span>Cov[,<span class="dv">1</span>])</span></code></pre></div>
<p>To avoid calculus over points with null or odd inputs values, we will introduce and “if” statement at line 314:</p>
<div class="sourceCode" id="cb44"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#Avoid calculus over Na values </span></span>
<span id="cb44-2"><a href="#cb44-2" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb44-3"><a href="#cb44-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (<span class="fu">any</span>(<span class="fu">is.na</span>(Evp[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(Temp[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(SOC_im[i])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(clay_im[i])) <span class="sc">|</span> </span>
<span id="cb44-4"><a href="#cb44-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">any</span>(<span class="fu">is.na</span>(Precip[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(Cov2[,<span class="dv">2</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(Cov1[,<span class="dv">1</span>])) <span class="sc">|</span> <span class="fu">any</span>(<span class="fu">is.na</span>(DR_im[i])) <span class="sc">|</span> </span>
<span id="cb44-5"><a href="#cb44-5" aria-hidden="true" tabindex="-1"></a> (SOC_im[i]<span class="sc"><</span><span class="dv">0</span>) <span class="sc">|</span> (clay_im[i]<span class="sc"><</span><span class="dv">0</span>) ) {C_INPUT_EQ[i,<span class="dv">2</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb44-6"><a href="#cb44-6" aria-hidden="true" tabindex="-1"></a> }<span class="cf">else</span>{</span></code></pre></div>
<p>From line 321 to line 327 we will set the environmental variables for the ith target point.</p>
<div class="sourceCode" id="cb45"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># Set the variables from the images</span></span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb45-3"><a href="#cb45-3" aria-hidden="true" tabindex="-1"></a> soil.thick<span class="ot">=</span><span class="dv">30</span> <span class="co">#Soil thickness (organic layer topsoil), in cm</span></span>
<span id="cb45-4"><a href="#cb45-4" aria-hidden="true" tabindex="-1"></a> SOC<span class="ot"><-</span>SOC_im[i] <span class="co">#Soil organic carbon in Mg/ha </span></span>
<span id="cb45-5"><a href="#cb45-5" aria-hidden="true" tabindex="-1"></a> clay<span class="ot"><-</span>clay_im[i] <span class="co">#Percent clay %</span></span>
<span id="cb45-6"><a href="#cb45-6" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb45-7"><a href="#cb45-7" aria-hidden="true" tabindex="-1"></a> DR<span class="ot"><-</span>DR_im[i] <span class="co"># DPM/RPM (decomplosable vs resistant plant material.)</span></span>
<span id="cb45-8"><a href="#cb45-8" aria-hidden="true" tabindex="-1"></a> bare1<span class="ot"><-</span>(Cov1<span class="sc">></span><span class="fl">0.8</span>) <span class="co"># If the surface is bare or vegetated</span></span>
<span id="cb45-9"><a href="#cb45-9" aria-hidden="true" tabindex="-1"></a> LU<span class="ot"><-</span>LU_im[i]</span></code></pre></div>
<p>At line 330 we will calculate the inert organic carbon with the Falloon method.</p>
<div class="sourceCode" id="cb46"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#IOM using Falloon method</span></span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a> FallIOM<span class="ot">=</span><span class="fl">0.049</span><span class="sc">*</span>SOC<span class="sc">^</span>(<span class="fl">1.139</span>) </span></code></pre></div>
<p>From line 339 to line 342 we will define the maximum and minimum values for the confidence interval for the variables SOC and Clay, in order to estimate the uncertainties.</p>
<div class="sourceCode" id="cb47"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># If you use a SOC uncertainty layer turn on this. First open the layer SOC_UNC </span></span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a> <span class="co">#(it must have the same extent and resolution of the SOC layer)</span></span>
<span id="cb47-3"><a href="#cb47-3" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb47-4"><a href="#cb47-4" aria-hidden="true" tabindex="-1"></a> <span class="co">#SOC_min<-(1-(SOC_UNC/100))*SOC</span></span>
<span id="cb47-5"><a href="#cb47-5" aria-hidden="true" tabindex="-1"></a> <span class="co">#SOC_max<-(1+(SOC_UNC/100))*SOC</span></span>
<span id="cb47-6"><a href="#cb47-6" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb47-7"><a href="#cb47-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># Define SOC min, max Clay min and max. </span></span>
<span id="cb47-8"><a href="#cb47-8" aria-hidden="true" tabindex="-1"></a> SOC_min<span class="ot"><-</span>SOC<span class="sc">*</span><span class="fl">0.8</span></span>
<span id="cb47-9"><a href="#cb47-9" aria-hidden="true" tabindex="-1"></a> SOC_max<span class="ot"><-</span>SOC<span class="sc">*</span><span class="fl">1.2</span></span>
<span id="cb47-10"><a href="#cb47-10" aria-hidden="true" tabindex="-1"></a> clay_min<span class="ot"><-</span>clay<span class="sc">*</span><span class="fl">0.9</span></span>
<span id="cb47-11"><a href="#cb47-11" aria-hidden="true" tabindex="-1"></a> clay_max<span class="ot"><-</span>clay<span class="sc">*</span><span class="fl">1.1</span></span></code></pre></div>
<p>At line 358 we will calculate the “gummi” object by using the “Roth_C_equi_analy” function. The “gummi” object is a list of two elements, the first one is a vector of five elements representing the five soil carbon pools, the second element is the carbon input of equilibrium. Then, at line 364 and 370 we will apply again the “Roth_C_equi_analy” function for the minimum and maximum inputs values, to get the uncertainties.</p>
<div class="sourceCode" id="cb48"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb48-1"><a href="#cb48-1" aria-hidden="true" tabindex="-1"></a> <span class="do">############################################################################## </span></span>
<span id="cb48-2"><a href="#cb48-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># C input equilibrium. (Ceq) + Ceq_MIN + Ceq_MAX are quantified here</span></span>
<span id="cb48-3"><a href="#cb48-3" aria-hidden="true" tabindex="-1"></a> <span class="do">############################################################################## </span></span>
<span id="cb48-4"><a href="#cb48-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb48-5"><a href="#cb48-5" aria-hidden="true" tabindex="-1"></a> <span class="co">#fb<-Roth_C(Cinputs=b,years=years,DPMptf=0, RPMptf=0, BIOptf=0, HUMptf=0, FallIOM=FallIOM,Temp=Temp,Precip=Precip,Evp=Evp,Cov=Cov,Cov1=Cov1,Cov2=Cov2,soil.thick=soil.thick,SOC=SOC,clay=clay,DR=DR,bare1=bare1,LU=LU)</span></span>
<span id="cb48-6"><a href="#cb48-6" aria-hidden="true" tabindex="-1"></a> <span class="co">#fb_t<-fb[1]+fb[2]+fb[3]+fb[4]+fb[5]</span></span>
<span id="cb48-7"><a href="#cb48-7" aria-hidden="true" tabindex="-1"></a> <span class="co">#pool.equi.goodi[i,]=fb</span></span>
<span id="cb48-8"><a href="#cb48-8" aria-hidden="true" tabindex="-1"></a> <span class="co">#m<-(fb_t-FallIOM)/(b)</span></span>
<span id="cb48-9"><a href="#cb48-9" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb48-10"><a href="#cb48-10" aria-hidden="true" tabindex="-1"></a> <span class="co">#Ceq<-(SOC-FallIOM)/m</span></span>
<span id="cb48-11"><a href="#cb48-11" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb48-12"><a href="#cb48-12" aria-hidden="true" tabindex="-1"></a> <span class="co">#Cin.equi$spinup[i]=Ceq;</span></span>
<span id="cb48-13"><a href="#cb48-13" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb48-14"><a href="#cb48-14" aria-hidden="true" tabindex="-1"></a> gummi<span class="ot">=</span><span class="fu">Roth_C_equi_analy</span>(<span class="at">Cinputs=</span>b,<span class="at">Temp=</span>Temp,<span class="at">Precip=</span>Precip,<span class="at">Evp=</span>Evp,<span class="at">Cov2=</span>Cov2,soil.thick,SOC,clay,DR,bare1,LU)</span>
<span id="cb48-15"><a href="#cb48-15" aria-hidden="true" tabindex="-1"></a> Ceq <span class="ot">=</span> gummi[[<span class="dv">2</span>]]</span>
<span id="cb48-16"><a href="#cb48-16" aria-hidden="true" tabindex="-1"></a> pool.equi.mean <span class="ot">=</span> gummi[[<span class="dv">1</span>]]</span>
<span id="cb48-17"><a href="#cb48-17" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb48-18"><a href="#cb48-18" aria-hidden="true" tabindex="-1"></a> <span class="co"># UNCERTAINTIES C input equilibrium (MINIMUM)</span></span>
<span id="cb48-19"><a href="#cb48-19" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb48-20"><a href="#cb48-20" aria-hidden="true" tabindex="-1"></a> gummi<span class="ot">=</span><span class="fu">Roth_C_equi_analy</span>(<span class="at">Cinputs=</span>b,<span class="at">Temp=</span>Temp,<span class="at">Precip=</span>Precip,<span class="at">Evp=</span>Evp,<span class="at">Cov2=</span>Cov2,soil.thick,SOC_min,clay_min,DR,bare1,LU)</span>
<span id="cb48-21"><a href="#cb48-21" aria-hidden="true" tabindex="-1"></a> Ceq_MIN <span class="ot">=</span> gummi[[<span class="dv">2</span>]]</span>
<span id="cb48-22"><a href="#cb48-22" aria-hidden="true" tabindex="-1"></a> pool.equi.min <span class="ot">=</span> gummi[[<span class="dv">1</span>]]</span></code></pre></div>
<p>From line 374 to line 430 we will save all the results in the vector called “C_INPUT_EQ”.</p>
<div class="sourceCode" id="cb49"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a> <span class="co"># UNCERTAINTIES C input equilibrium (MAXIMUM)</span></span>
<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb49-3"><a href="#cb49-3" aria-hidden="true" tabindex="-1"></a> gummi<span class="ot">=</span><span class="fu">Roth_C_equi_analy</span>(<span class="at">Cinputs=</span>b,<span class="at">Temp=</span>Temp,<span class="at">Precip=</span>Precip,<span class="at">Evp=</span>Evp,<span class="at">Cov2=</span>Cov2,soil.thick,SOC_max,clay_max,DR,bare1,LU)</span>
<span id="cb49-4"><a href="#cb49-4" aria-hidden="true" tabindex="-1"></a> Ceq_MAX <span class="ot">=</span> gummi[[<span class="dv">2</span>]]</span>
<span id="cb49-5"><a href="#cb49-5" aria-hidden="true" tabindex="-1"></a> pool.equi.max <span class="ot">=</span> gummi[[<span class="dv">1</span>]]</span>
<span id="cb49-6"><a href="#cb49-6" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb49-7"><a href="#cb49-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># SOC POOLS AFTER 500 YEARS RUN WITH C INPUT EQUILIBRIUM</span></span>
<span id="cb49-8"><a href="#cb49-8" aria-hidden="true" tabindex="-1"></a> good_landuse_classes<span class="ot">=</span><span class="fu">c</span>(<span class="dv">2</span>,<span class="dv">12</span>,<span class="dv">13</span>,<span class="dv">4</span>,<span class="dv">3</span>,<span class="dv">5</span>,<span class="dv">6</span>,<span class="dv">8</span>)</span>
<span id="cb49-9"><a href="#cb49-9" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (LU <span class="sc">%in%</span> good_landuse_classes){</span>
<span id="cb49-10"><a href="#cb49-10" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb49-11"><a href="#cb49-11" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">2</span>]<span class="ot"><-</span>SOC</span>
<span id="cb49-12"><a href="#cb49-12" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">3</span>]<span class="ot"><-</span>Ceq</span>
<span id="cb49-13"><a href="#cb49-13" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">4</span>]<span class="ot"><-</span><span class="fu">sum</span>(pool.equi.mean)</span>
<span id="cb49-14"><a href="#cb49-14" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">5</span>]<span class="ot"><-</span>pool.equi.mean[<span class="dv">1</span>] <span class="co">#DPM</span></span>
<span id="cb49-15"><a href="#cb49-15" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">6</span>]<span class="ot"><-</span>pool.equi.mean[<span class="dv">2</span>] <span class="co">#RPM</span></span>
<span id="cb49-16"><a href="#cb49-16" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">7</span>]<span class="ot"><-</span>pool.equi.mean[<span class="dv">3</span>] <span class="co">#BIO</span></span>
<span id="cb49-17"><a href="#cb49-17" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">8</span>]<span class="ot"><-</span>pool.equi.mean[<span class="dv">4</span>] <span class="co">#HUM</span></span>
<span id="cb49-18"><a href="#cb49-18" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">9</span>]<span class="ot"><-</span>pool.equi.mean[<span class="dv">5</span>] <span class="co">#IOM</span></span>
<span id="cb49-19"><a href="#cb49-19" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">10</span>]<span class="ot"><-</span>Ceq_MIN</span>
<span id="cb49-20"><a href="#cb49-20" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">11</span>]<span class="ot"><-</span>Ceq_MAX</span>
<span id="cb49-21"><a href="#cb49-21" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">12</span>]<span class="ot"><-</span><span class="fu">sum</span>(pool.equi.min)</span>
<span id="cb49-22"><a href="#cb49-22" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">13</span>]<span class="ot"><-</span>pool.equi.min[<span class="dv">1</span>] <span class="co">#DPM</span></span>
<span id="cb49-23"><a href="#cb49-23" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">14</span>]<span class="ot"><-</span>pool.equi.min[<span class="dv">2</span>] <span class="co">#RPM</span></span>
<span id="cb49-24"><a href="#cb49-24" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">15</span>]<span class="ot"><-</span>pool.equi.min[<span class="dv">3</span>] <span class="co">#BIO</span></span>
<span id="cb49-25"><a href="#cb49-25" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">16</span>]<span class="ot"><-</span>pool.equi.min[<span class="dv">4</span>] <span class="co">#HUM</span></span>
<span id="cb49-26"><a href="#cb49-26" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">17</span>]<span class="ot"><-</span>pool.equi.min[<span class="dv">5</span>] <span class="co">#IOM</span></span>
<span id="cb49-27"><a href="#cb49-27" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">18</span>]<span class="ot"><-</span><span class="fu">sum</span>(pool.equi.max)</span>
<span id="cb49-28"><a href="#cb49-28" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">19</span>]<span class="ot"><-</span>pool.equi.max[<span class="dv">1</span>] <span class="co">#DPM </span></span>
<span id="cb49-29"><a href="#cb49-29" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">20</span>]<span class="ot"><-</span>pool.equi.max[<span class="dv">2</span>] <span class="co">#RPM </span></span>
<span id="cb49-30"><a href="#cb49-30" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">21</span>]<span class="ot"><-</span>pool.equi.max[<span class="dv">3</span>] <span class="co">#BIO </span></span>
<span id="cb49-31"><a href="#cb49-31" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">22</span>]<span class="ot"><-</span>pool.equi.max[<span class="dv">4</span>] <span class="co">#HUM </span></span>
<span id="cb49-32"><a href="#cb49-32" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">23</span>]<span class="ot"><-</span>pool.equi.max[<span class="dv">5</span>] <span class="co">#IOM </span></span>
<span id="cb49-33"><a href="#cb49-33" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb49-34"><a href="#cb49-34" aria-hidden="true" tabindex="-1"></a> }<span class="cf">else</span> {</span>
<span id="cb49-35"><a href="#cb49-35" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">2</span>]<span class="ot"><-</span>SOC</span>
<span id="cb49-36"><a href="#cb49-36" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">3</span>]<span class="ot"><-</span>Ceq</span>
<span id="cb49-37"><a href="#cb49-37" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">4</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-38"><a href="#cb49-38" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">5</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-39"><a href="#cb49-39" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">6</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-40"><a href="#cb49-40" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">7</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-41"><a href="#cb49-41" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">8</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-42"><a href="#cb49-42" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">9</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-43"><a href="#cb49-43" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">10</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-44"><a href="#cb49-44" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">11</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-45"><a href="#cb49-45" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">12</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-46"><a href="#cb49-46" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">13</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-47"><a href="#cb49-47" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">14</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-48"><a href="#cb49-48" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">15</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-49"><a href="#cb49-49" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">16</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-50"><a href="#cb49-50" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">17</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-51"><a href="#cb49-51" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">18</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-52"><a href="#cb49-52" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">19</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-53"><a href="#cb49-53" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">20</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-54"><a href="#cb49-54" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">21</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-55"><a href="#cb49-55" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">22</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-56"><a href="#cb49-56" aria-hidden="true" tabindex="-1"></a> C_INPUT_EQ[i,<span class="dv">23</span>]<span class="ot"><-</span><span class="dv">0</span></span>
<span id="cb49-57"><a href="#cb49-57" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb49-58"><a href="#cb49-58" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb49-59"><a href="#cb49-59" aria-hidden="true" tabindex="-1"></a> <span class="fu">print</span>(<span class="fu">c</span>(i,SOC,Ceq))</span>
<span id="cb49-60"><a href="#cb49-60" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb49-61"><a href="#cb49-61" aria-hidden="true" tabindex="-1"></a> <span class="er">}</span> <span class="co"># NA problems</span></span>
<span id="cb49-62"><a href="#cb49-62" aria-hidden="true" tabindex="-1"></a><span class="er">}</span></span>
<span id="cb49-63"><a href="#cb49-63" aria-hidden="true" tabindex="-1"></a><span class="do">###############for loop ends##############</span></span></code></pre></div>
<p>From line 434 to line 455 we will change the names of the columns of the vector files “C_INPUT_EQ” to the variables we want to obtain.</p>
<div class="sourceCode" id="cb50"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb50-1"><a href="#cb50-1" aria-hidden="true" tabindex="-1"></a><span class="co">#rename de columns</span></span>
<span id="cb50-2"><a href="#cb50-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb50-3"><a href="#cb50-3" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">2</span>]<span class="ot">=</span><span class="st">"SOC_FAO"</span></span>
<span id="cb50-4"><a href="#cb50-4" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">3</span>]<span class="ot">=</span><span class="st">"Cinput_EQ"</span></span>
<span id="cb50-5"><a href="#cb50-5" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">4</span>]<span class="ot">=</span><span class="st">"SOC_pedotransfer"</span></span>
<span id="cb50-6"><a href="#cb50-6" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">5</span>]<span class="ot">=</span><span class="st">"DPM_pedotransfer"</span></span>
<span id="cb50-7"><a href="#cb50-7" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">6</span>]<span class="ot">=</span><span class="st">"RPM_pedotransfer"</span></span>
<span id="cb50-8"><a href="#cb50-8" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">7</span>]<span class="ot">=</span><span class="st">"BIO_pedotransfer"</span></span>
<span id="cb50-9"><a href="#cb50-9" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">8</span>]<span class="ot">=</span><span class="st">"HUM_pedotransfer"</span></span>
<span id="cb50-10"><a href="#cb50-10" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">9</span>]<span class="ot">=</span><span class="st">"IOM_pedotransfer"</span></span>
<span id="cb50-11"><a href="#cb50-11" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">10</span>]<span class="ot">=</span><span class="st">"CIneq_min"</span></span>
<span id="cb50-12"><a href="#cb50-12" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">11</span>]<span class="ot">=</span><span class="st">"CIneq_max"</span></span>
<span id="cb50-13"><a href="#cb50-13" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">12</span>]<span class="ot">=</span><span class="st">"SOC_min"</span></span>
<span id="cb50-14"><a href="#cb50-14" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">13</span>]<span class="ot">=</span><span class="st">"DPM_min"</span></span>
<span id="cb50-15"><a href="#cb50-15" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">14</span>]<span class="ot">=</span><span class="st">"RPM_min"</span></span>
<span id="cb50-16"><a href="#cb50-16" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">15</span>]<span class="ot">=</span><span class="st">"BIO_min"</span></span>
<span id="cb50-17"><a href="#cb50-17" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">16</span>]<span class="ot">=</span><span class="st">"HUM_min"</span></span>
<span id="cb50-18"><a href="#cb50-18" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">17</span>]<span class="ot">=</span><span class="st">"IOM_min"</span></span>
<span id="cb50-19"><a href="#cb50-19" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">18</span>]<span class="ot">=</span><span class="st">"SOC_max"</span></span>
<span id="cb50-20"><a href="#cb50-20" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">19</span>]<span class="ot">=</span><span class="st">"DPM_max"</span></span>
<span id="cb50-21"><a href="#cb50-21" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">20</span>]<span class="ot">=</span><span class="st">"RPM_max"</span></span>
<span id="cb50-22"><a href="#cb50-22" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">21</span>]<span class="ot">=</span><span class="st">"BIO_max"</span></span>
<span id="cb50-23"><a href="#cb50-23" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">22</span>]<span class="ot">=</span><span class="st">"HUM_max"</span></span>
<span id="cb50-24"><a href="#cb50-24" aria-hidden="true" tabindex="-1"></a><span class="fu">colnames</span>(C_INPUT_EQ<span class="sc">@</span>data)[<span class="dv">23</span>]<span class="ot">=</span><span class="st">"IOM_max"</span></span></code></pre></div>
<p>Finally, at line 459 we will set the working directory where we are going to savethe output file, and at line 460 we save the vector to an ESRI shapefile file.</p>
<div class="sourceCode" id="cb51"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a><span class="co"># SAVE the Points (shapefile)</span></span>
<span id="cb51-2"><a href="#cb51-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb51-3"><a href="#cb51-3" aria-hidden="true" tabindex="-1"></a><span class="fu">setwd</span>(<span class="st">"D:/TRAINING_MATERIALS_GSOCseq_MAPS_12-11-2020/OUTPUTS/1_SPIN_UP"</span>)</span>
<span id="cb51-4"><a href="#cb51-4" aria-hidden="true" tabindex="-1"></a><span class="fu">writeOGR</span>(C_INPUT_EQ, <span class="st">"."</span>, <span class="st">"SPIN_UP_Country_AOI"</span>, <span class="at">driver=</span><span class="st">"ESRI Shapefile"</span>,<span class="at">overwrite=</span><span class="cn">TRUE</span>)</span></code></pre></div>
</div>
</div>
<div id="warm-up-phase" class="section level2" number="1.3">
<h2><span class="header-section-number">1.3</span> Warm up phase</h2>
<div id="script-number-14a.-roth_c_warm_up_v4.r-no-land-use-change" class="section level3" number="1.3.1">
<h3><span class="header-section-number">1.3.1</span> Script Number 14A. “ROTH_C_WARM_UP_v4.R” No Land use change</h3>
<p>Script number 14 implements the second modeling phase (“Warm up” phase). In this script we will load the stack of different layers generated in script number 11 and the target points. We also will load the output vector of the phase 1 (spin up), the climate layers from script number 2, the NPP layer from script number 5, and the land use layer stack from script number 9. This script runs the Roth C model for 18 years (2000-2018) with the possibility to be modified to 20 years if data is available (2000-2020). The final outputs are SOC stocks of the five C pools of the RothC model (DPM, RPM, BIO, HUM and IOM), and the total SOC stock. This information will be saved to a shapefile vector.</p>
<p><strong>Table 10.2</strong> <em>Script Number 14. Warm Up phase. Inputs and Outputs</em></p>
<p><img src="tables/Table_10.2.png" /></p>
<p>This script runs the spatial RothC model for the warm-up period (from 2001 to 2018). We will provide the script the target points (empty vector layer from Qgis procedure number 1), the Stack layer (from script number 11), the three NPP layers (from script number 5) and the three climate layers generated in script number 2. The output vector layer from script number 13 (Spin up phase) will also be needed.</p>
<div class="sourceCode" id="cb52"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list=</span><span class="fu">ls</span>()) </span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(SoilR)</span>
<span id="cb52-3"><a href="#cb52-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(raster)</span>
<span id="cb52-4"><a href="#cb52-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(rgdal)</span>
<span id="cb52-5"><a href="#cb52-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(soilassessment)</span>
<span id="cb52-6"><a href="#cb52-6" aria-hidden="true" tabindex="-1"></a>working_dir<span class="ot"><-</span><span class="fu">setwd</span>(<span class="st">"C:/TRAINING_MATERIALS_GSOCseq_MAPS_28-09-2020"</span>)</span>
<span id="cb52-7"><a href="#cb52-7" aria-hidden="true" tabindex="-1"></a><span class="co">#Open empty vector</span></span>
<span id="cb52-8"><a href="#cb52-8" aria-hidden="true" tabindex="-1"></a>Vector<span class="ot"><-</span><span class="fu">readOGR</span>(<span class="st">"INPUTS/TARGET_POINTS/target_points_sub.shp"</span>)</span>
<span id="cb52-9"><a href="#cb52-9" aria-hidden="true" tabindex="-1"></a><span class="co">#Open Warm Up Stack</span></span>
<span id="cb52-10"><a href="#cb52-10" aria-hidden="true" tabindex="-1"></a>Stack_Set_warmup<span class="ot"><-</span> <span class="fu">stack</span>(<span class="st">"INPUTS/STACK/Stack_Set_WARM_UP_AOI.tif"</span>)</span>
<span id="cb52-11"><a href="#cb52-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Open Result from SPIN UP PROCESS. A vector with 5 columns , one for each pool</span></span>
<span id="cb52-12"><a href="#cb52-12" aria-hidden="true" tabindex="-1"></a>Spin_up<span class="ot"><-</span><span class="fu">readOGR</span>(<span class="st">"OUTPUTS/1_SPIN_UP/SPIN_UP_County_AOI.shp"</span>)</span>
<span id="cb52-13"><a href="#cb52-13" aria-hidden="true" tabindex="-1"></a>Spin_up<span class="ot"><-</span><span class="fu">as.data.frame</span>(Spin_up)</span>
<span id="cb52-14"><a href="#cb52-14" aria-hidden="true" tabindex="-1"></a><span class="co"># Open Precipitation , temperature, and EVapotranspiration file 20 anios x 12 = 240 layers x 3</span></span>
<span id="cb52-15"><a href="#cb52-15" aria-hidden="true" tabindex="-1"></a>PREC<span class="ot"><-</span><span class="fu">stack</span>(<span class="st">"INPUTS/CRU_LAYERS/Prec_Stack_216_01-18_CRU.tif"</span>)</span>
<span id="cb52-16"><a href="#cb52-16" aria-hidden="true" tabindex="-1"></a>TEMP<span class="ot"><-</span><span class="fu">stack</span>(<span class="st">"INPUTS/CRU_LAYERS/Temp_Stack_216_01-18_CRU.tif"</span>)</span>
<span id="cb52-17"><a href="#cb52-17" aria-hidden="true" tabindex="-1"></a>PET<span class="ot"><-</span><span class="fu">stack</span>(<span class="st">"INPUTS/CRU_LAYERS/PET_Stack_216_01-18_CRU.tif"</span>)</span>
<span id="cb52-18"><a href="#cb52-18" aria-hidden="true" tabindex="-1"></a><span class="co">#Open Mean NPP MIAMI 1981 - 2000</span></span>
<span id="cb52-19"><a href="#cb52-19" aria-hidden="true" tabindex="-1"></a>NPP<span class="ot"><-</span><span class="fu">raster</span>(<span class="st">"INPUTS/NPP/NPP_MIAMI_MEAN_81-00_AOI.tif"</span>)</span>
<span id="cb52-20"><a href="#cb52-20" aria-hidden="true" tabindex="-1"></a>NPP_MEAN_MIN<span class="ot"><-</span><span class="fu">raster</span>(<span class="st">"INPUTS/NPP/NPP_MIAMI_MEAN_81-00_AOI_MIN.tif"</span>)</span>