@@ -4,6 +4,7 @@ gapfill_from_old_data <- function(survey_form,
4
4
save_to_env = FALSE ,
5
5
parameters = c(" bulk_density" ,
6
6
" organic_carbon_total" ,
7
+ " n_total" ,
7
8
" organic_layer_weight" ,
8
9
" coarse_fragment_vol" ,
9
10
" part_size_clay" ,
@@ -408,6 +409,7 @@ gapfill_from_old_data <- function(survey_form,
408
409
assertthat :: assert_that(
409
410
identical(parameters , c(" bulk_density" ,
410
411
" organic_carbon_total" ,
412
+ " n_total" ,
411
413
" organic_layer_weight" ,
412
414
" coarse_fragment_vol" ,
413
415
" part_size_clay" ,
@@ -460,13 +462,15 @@ gapfill_from_old_data <- function(survey_form,
460
462
select(unique_layer_repetition ,
461
463
bulk_density ,
462
464
organic_carbon_total ,
465
+ n_total ,
463
466
organic_layer_weight ,
464
467
coarse_fragment_vol ,
465
468
part_size_clay ,
466
469
part_size_silt ,
467
470
part_size_sand ) %> %
468
471
rename(bulk_density_afscdb = bulk_density ,
469
472
organic_carbon_total_afscdb = organic_carbon_total ,
473
+ n_total_afscdb = n_total ,
470
474
organic_layer_weight_afscdb = organic_layer_weight ,
471
475
coarse_fragment_vol_afscdb = coarse_fragment_vol ,
472
476
part_size_clay_afscdb = part_size_clay ,
@@ -504,6 +508,16 @@ gapfill_from_old_data <- function(survey_form,
504
508
organic_carbon_total = coalesce(
505
509
.data $ organic_carbon_total ,
506
510
.data $ organic_carbon_total_afscdb )) %> %
511
+ # N total
512
+ mutate(
513
+ n_total_source = case_when(
514
+ ! is.na(n_total_source ) ~ n_total_source ,
515
+ ! is.na(.data $ n_total ) ~ " som (same year)" ,
516
+ ! is.na(.data $ n_total_afscdb ) ~ " FSCDB.LII (2012)" ,
517
+ TRUE ~ NA_character_ ),
518
+ n_total = coalesce(
519
+ .data $ n_total ,
520
+ .data $ n_total_afscdb )) %> %
507
521
# Organic layer weight
508
522
mutate(
509
523
organic_layer_weight_source = case_when(
@@ -570,6 +584,27 @@ gapfill_from_old_data <- function(survey_form,
570
584
filter(is.na(.data $ unique_survey_so_som )) %> %
571
585
select(- unique_survey_so_som , - unique_layer_repetition )
572
586
587
+ # Some Romanian records were missing in both databases,
588
+ # but the partner confirmed that they should be inserted.
589
+
590
+ layers_to_check <- c(" 52_2009_13_M12_3" ,
591
+ " 52_2009_13_M24_3" ,
592
+ " 52_2009_13_M48_3" )
593
+
594
+ if (all(! layers_to_check %in% df $ unique_layer_repetition )) {
595
+
596
+ assertthat :: assert_that(
597
+ all(layers_to_check %in% so_som_afscdb $ unique_layer_repetition ))
598
+
599
+ so_som_missing_records <- rbind(
600
+ so_som_missing_records ,
601
+ so_som_afscdb %> %
602
+ filter(unique_layer_repetition %in% layers_to_check ) %> %
603
+ select(- unique_survey_so_som , - unique_layer_repetition )
604
+ )
605
+ }
606
+
607
+
573
608
# If there are any unique surveys in afscdb which are missing in so_som
574
609
575
610
if (nrow(so_som_missing_records ) > 0 ) {
@@ -656,6 +691,7 @@ gapfill_from_old_data <- function(survey_form,
656
691
" Record inserted from FSCDB.LII." ),
657
692
bulk_density_afscdb = bulk_density ,
658
693
organic_carbon_total_afscdb = organic_carbon_total ,
694
+ n_total_afscdb = n_total ,
659
695
organic_layer_weight_afscdb = organic_layer_weight ,
660
696
coarse_fragment_vol_afscdb = coarse_fragment_vol ,
661
697
part_size_clay_afscdb = part_size_clay ,
@@ -747,7 +783,7 @@ gapfill_from_old_data <- function(survey_form,
747
783
n_total_orig ,
748
784
origin_merged , origin_merge_info ,
749
785
750
- bulk_density_afscdb , organic_carbon_total_afscdb ,
786
+ bulk_density_afscdb , organic_carbon_total_afscdb , n_total_afscdb ,
751
787
organic_layer_weight_afscdb , coarse_fragment_vol_afscdb ,
752
788
part_size_clay_afscdb , part_size_silt_afscdb ,
753
789
part_size_sand_afscdb )
@@ -789,15 +825,17 @@ gapfill_from_old_data <- function(survey_form,
789
825
code_plot = ifelse(code_country == 58 & code_plot == 2255 ,
790
826
255 ,
791
827
code_plot )) %> %
792
- mutate(repetition = ifelse(code_country == 58 & code_plot == 2188 ,
793
- 2 ,
794
- plot_id ),
795
- plot_id = ifelse(code_country == 58 & code_plot == 2188 ,
796
- " 58_188" ,
797
- plot_id ),
798
- code_plot = ifelse(code_country == 58 & code_plot == 2188 ,
799
- 188 ,
800
- code_plot )) %> %
828
+ # do not apply this because then, there seem to be two profiles
829
+ # with 58_188 as plot_id
830
+ # mutate(repetition = ifelse(code_country == 58 & code_plot == 2188,
831
+ # 2,
832
+ # repetition),
833
+ # plot_id = ifelse(code_country == 58 & code_plot == 2188,
834
+ # "58_188",
835
+ # plot_id),
836
+ # code_plot = ifelse(code_country == 58 & code_plot == 2188,
837
+ # 188,
838
+ # code_plot)) %>%
801
839
mutate(
802
840
unique_survey = paste0(code_country , " _" ,
803
841
survey_year , " _" ,
@@ -1173,6 +1211,7 @@ gapfill_from_old_data <- function(survey_form,
1173
1211
assertthat :: assert_that(
1174
1212
identical(parameters , c(" bulk_density" ,
1175
1213
" organic_carbon_total" ,
1214
+ " n_total" ,
1176
1215
" organic_layer_weight" ,
1177
1216
" coarse_fragment_vol" ,
1178
1217
" part_size_clay" ,
@@ -1223,10 +1262,12 @@ gapfill_from_old_data <- function(survey_form,
1223
1262
select(unique_layer_repetition_s1_som ,
1224
1263
bulk_density ,
1225
1264
organic_carbon_total ,
1265
+ n_total ,
1226
1266
organic_layer_weight ,
1227
1267
coarse_fragment_vol ) %> %
1228
1268
rename(bulk_density_fscdb = bulk_density ,
1229
1269
organic_carbon_total_fscdb = organic_carbon_total ,
1270
+ n_total_fscdb = n_total ,
1230
1271
organic_layer_weight_fscdb = organic_layer_weight ,
1231
1272
coarse_fragment_vol_fscdb = coarse_fragment_vol ),
1232
1273
by = join_by(" unique_layer_repetition" ==
@@ -1262,6 +1303,16 @@ gapfill_from_old_data <- function(survey_form,
1262
1303
organic_carbon_total = coalesce(
1263
1304
.data $ organic_carbon_total ,
1264
1305
.data $ organic_carbon_total_fscdb )) %> %
1306
+ # N total
1307
+ mutate(
1308
+ n_total_source = case_when(
1309
+ ! is.na(n_total_source ) ~ n_total_source ,
1310
+ ! is.na(.data $ n_total ) ~ " som (same year)" ,
1311
+ ! is.na(.data $ n_total_fscdb ) ~ " FSCDB.LI (2002)" ,
1312
+ TRUE ~ NA_character_ ),
1313
+ n_total = coalesce(
1314
+ .data $ n_total ,
1315
+ .data $ n_total_fscdb )) %> %
1265
1316
# Organic layer weight
1266
1317
mutate(
1267
1318
organic_layer_weight_source = case_when(
@@ -1365,6 +1416,7 @@ gapfill_from_old_data <- function(survey_form,
1365
1416
other_obs = " Record inserted from FSCDB.LI." ,
1366
1417
bulk_density_fscdb = bulk_density ,
1367
1418
organic_carbon_total_fscdb = organic_carbon_total ,
1419
+ n_total_fscdb = n_total ,
1368
1420
organic_layer_weight_fscdb = organic_layer_weight ,
1369
1421
coarse_fragment_vol_fscdb = coarse_fragment_vol ,
1370
1422
part_size_clay_fscdb = part_size_clay ,
@@ -1428,6 +1480,7 @@ gapfill_from_old_data <- function(survey_form,
1428
1480
coarse_fragment_vol_orig , organic_layer_weight_orig ,
1429
1481
organic_carbon_total_orig ,
1430
1482
n_total_orig , bulk_density_fscdb , organic_carbon_total_fscdb ,
1483
+ n_total_fscdb ,
1431
1484
organic_layer_weight_fscdb , coarse_fragment_vol_fscdb )
1432
1485
1433
1486
assertthat :: assert_that(all(names(df ) == names(s1_som_fscdb_to_add )))
0 commit comments