Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Simon, Wolfram
CiFoS_Crops
Commits
fd00228b
Commit
fd00228b
authored
Feb 23, 2022
by
Simon, Wolfram
Browse files
did some data consistency check and resolved issue #39 on cifos-ModelEU repository
parent
61cb9659
Changes
1
Hide whitespace changes
Inline
Side-by-side
R_to_SQL_database/Cifos_Model_Data_EU.R
View file @
fd00228b
...
...
@@ -2822,13 +2822,14 @@ write_csv(dat_dist, "Input_data/dat_dist.csv")
if
(
Sys.getenv
(
"USERNAME"
)
==
"wacke003"
){
localGit
=
"C:/Users/wacke003/Git/cifos-model.eu/"
}
else
{
localGit
=
"
C
:/
Wolfram_Admin/GAMS/EU_model_frmSep21/cifos-model_eu
/"
localGit
=
"
D
:/
GAMS/EU_model_Feb2022
/"
}
excel_file
=
paste
(
localGit
,
"European_CiFoS_model_data.xlsx"
,
sep
=
""
)
FertNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"FertNutr"
)
AnimalNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"Animal_Feed_Nutr"
)
HumanNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"Human_Food_Nutr"
)
CropNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"Crop_Nutrient"
)
tmp
=
FertNutr
%>%
...
...
@@ -2850,3 +2851,90 @@ tmp = FertNutr %>%
write_csv
(
tmp
,
"Input_data/FertNutr.csv"
)
# class_FamGustavson ------------------------------------------------------
# Issue#39 in repo Cifos-Model-EU: THOMASs:
# Also, I noticed that there are more products than ProcRaw+ProcOut in the class_FamGustavson sheet.
# This does not matter, we just need to remember that $loaddc will not work on the GP(FamG,AllProd) mapping set.
class_FamGustavson
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"class_FamGustavson"
)
processing
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"Processing_Fraction"
)
# Gettting a vector for procout and procraw
fun_vec
=
function
(
col
){
processing
%>%
select
(
col
)
%>%
distinct
()
%>%
rename
(
"Product"
=
col
)
}
procout
=
fun_vec
(
"proc_out"
)
procraw
=
fun_vec
(
"proc_raw"
)
procout_raw
=
bind_rows
(
procout
,
procraw
)
procout_raw
%>%
nrow
()
# All the procouts+procraws count to 334 (with duplicates)
procout_raw_dist
=
procout_raw
%>%
distinct
()
procout_raw_dist
%>%
nrow
()
# All the procouts+procraws count to 313 (without duplicates)\
nrow
(
class_FamGustavson
)
# 326
# 326-313=13
# There are 13 more Products in class_FamGustavson$Product than in proc_out+proc_raw from the processing sheet
# Final class_FamGustavson sheet
class_FamGustavsonv23_2_22
=
procout_raw_dist
%>%
left_join
(
class_FamGustavson
,
by
=
"Product"
)
write_csv
(
class_FamGustavsonv23_2_22
,
"Input_data/class_FamGustavsonv23_2_22.csv"
)
# Consistency checks -----------------------------------------------------
# Loading data where Products occur
class_FamGustavson
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"class_FamGustavson"
)
FertNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"FertNutr"
)
AnimalNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"Animal_Feed_Nutr"
)
HumanNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"Human_Food_Nutr"
)
CropNutr
=
readxl
::
read_excel
(
excel_file
,
sheet
=
"Crop_Nutrient"
)
# This corresponds to AllProd (procout+procraw)
procout_raw_dist
# Are all the elements of procout+procraw in the related sheets?
# All values of animal nutrition that are not in loss fraction
Fun_Consist
=
function
(
ref_dat
=
procout_raw_dist
,
col_ref
,
nest_dat
){
nest_dat
$
Product
[
!
nest_dat
$
Product
%in%
ref_dat
$
Product
]
}
# All elemetns in animal nutrition are in the proc_raw or procout
Fun_Consist
(
nest_dat
=
AnimalNutr
)
#character(0)
Fun_Consist
(
nest_dat
=
HumanNutr
)
#character(0)
Fun_Consist
(
nest_dat
=
FertNutr
)
#character(0)
Fun_Consist
(
nest_dat
=
class_FamGustavson
)
#character(0)
CropNutr
$
crop_cifos
[
!
CropNutr
$
crop_cifos
%in%
procout_raw_dist
$
Product
]
#character(0)
# Vice versa checking: are all the products that are in the child sheets of processing in processing?
Fun_Consist_child
=
function
(
nest_dat
=
procout_raw_dist
,
ref_dat
){
nest_dat
$
Product
[
!
nest_dat
$
Product
%in%
ref_dat
$
Product
]
}
Fun_Consist_child
(
ref_dat
=
AnimalNutr
)
#"pearl_millet_beer" "sorghum_beer" "flax_fiber_and_tow" "seed_cotton_fibres"
# "tobacco_leaves" "barley_beer" "other_fibres" "tobacco"
Fun_Consist_child
(
ref_dat
=
HumanNutr
)
#all proc_raw are missing
Fun_Consist_child
(
ref_dat
=
class_FamGustavson
)
#character(0)
Fun_Consist_child
(
ref_dat
=
FertNutr
)
#character(0)
Fun_Consist
(
nest_dat
=
HumanNutr
)
#character(0)
Fun_Consist
(
nest_dat
=
FertNutr
)
#character(0)
Fun_Consist
(
nest_dat
=
class_FamGustavson
)
#character(0)
CropNutr
$
crop_cifos
[
!
CropNutr
$
crop_cifos
%in%
procout_raw_dist
$
Product
]
#character(0)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment