Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiFoS_Crops
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simon, Wolfram
CiFoS_Crops
Commits
3d8c7be4
Commit
3d8c7be4
authored
3 years ago
by
Simon, Wolfram
Browse files
Options
Downloads
Patches
Plain Diff
externalized the functions. Fixed the forage.
parent
98a1f089
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SPAM_Data_Transformation/SPAM2010_ADM0_SOILagri_AEZ_SpatialEx.R
+7
-47
7 additions, 47 deletions
...ata_Transformation/SPAM2010_ADM0_SOILagri_AEZ_SpatialEx.R
with
7 additions
and
47 deletions
SPAM_Data_Transformation/SPAM2010_ADM0_SOILagri_AEZ_SpatialEx.R
+
7
−
47
View file @
3d8c7be4
...
...
@@ -11,49 +11,8 @@ easypackages::packages(c("tidyverse", 'sf', 'raster','sp', 'spatialEco',
"rlist"
,
"largeList"
,
"snow"
,
"foreign"
,
"reshape2"
,
"margrittr"
,
"stringi"
))
# Functions ---------------------------------------------------------------
# Functions loading dbf SPAM files
FUNload_list_dbf_SPAM
<-
function
(
path
,
type
)
{
pattern
<-
switch
(
type
,
"harv"
=
"_H_"
,
"phys"
=
"_A_"
,
"prod"
=
"_P_"
)
path
<-
list.files
(
path
=
path
,
full.names
=
TRUE
,
pattern
=
pattern
)
l_dbf
<-
lapply
(
path
,
foreign
::
read.dbf
)
names
(
l_dbf
)
<-
basename
(
path
)
return
(
l_dbf
)
}
# Functions loading dbf veggie and nuts Monfreda files
FUNload_list_monfreda
<-
function
(
path
,
type
)
{
pattern
<-
switch
(
type
,
"harv"
=
"_HarvestedAreaHectares"
,
"phys"
=
"_HarvestedAreaHectares"
,
"prod"
=
"_Production"
)
path
<-
list.files
(
path
=
path
,
full.names
=
TRUE
,
pattern
=
pattern
)
l_csv
<-
lapply
(
path
,
read.csv
)
names
(
l_csv
)
<-
basename
(
path
)
return
(
l_csv
)
}
# # Functions loading dbf forage Monfreda files
# FUNload_list_forage <- function(path, type) {
# pattern <- switch (type,
# "harv" = "_HarvestedAreaHectares",
# "phys" = "_HarvestedAreaHectares",
# "prod" = "_Production")
# path <- list.files(path = path,
# full.names = TRUE,
# pattern = pattern)
# l_csv <- lapply(path, read.csv)
# names(l_csv) <- basename(path)
# return(l_csv)
# }
# Sourcing functions from external R script
source
(
"Functions_cifos/function_collection.R"
)
# Load data --------------------------------------------------------------
SPAMdbf_harv
=
FUNload_list_dbf_SPAM
(
path
=
"C:/Users/simon083/OneDrive - Wageningen University & Research/PhD_WJS/Academic/RQ1/Data_analysis/Spatial_mod/Modified_scripts/R/CifoS_Crop/Input_data/DBF_ADM0_AEZ_Soilagri_exctraction/SPAM2010"
,
type
=
"harv"
)
...
...
@@ -93,8 +52,8 @@ SPAM2010_ZONES_exdbf = df_rec %>%
'H.dbf'
=
'H'
)))
%>%
dplyr
::
select
(
-
Rec_type
)
write_csv
(
SPAM2010_ZONES_exdbf
,
here
(
"Input_data"
,
"SPAM2010_ADM0_AEZ_Soilagri_exdbf_global.csv"
))
#
SPAM2010_ZONES_exdbf =read_csv(here("Input_data", "SPAM2010_
adm1
_exdbf_global.csv"))
write_csv
(
SPAM2010_ZONES_exdbf
,
here
::
here
(
"Input_data"
,
"SPAM2010_ADM0_AEZ_Soilagri_exdbf_global.csv"
))
SPAM2010_ZONES_exdbf
=
read_csv
(
here
::
here
(
"Input_data"
,
"SPAM2010_
ADM0_AEZ_Soilagri
_exdbf_global.csv"
))
# Monfreda data ----------------------------------------------------------------
# Load data --------------------------------------------------------------
...
...
@@ -128,8 +87,8 @@ monf_dat = monf_rec %>%
dplyr
::
select
(
-
c
(
Rec_type
,
stats
))
%>%
mutate
(
tech_type
=
'A'
)
#add a tech type all together ("A") -> Monfreda has no distinction btw tech types like SPAM does.
write_csv
(
monf_dat
,
here
(
"Input_data"
,
"Monfreda2008_ADM0_AEZ_Soilagri_excsv_global.csv"
))
# SPAM2010_ZONES_exdbf
=read_csv(here("Input_data", "
SPAM2010_adm1_exdbf
_global.csv"))
write_csv
(
monf_dat
,
here
::
here
(
"Input_data"
,
"Monfreda2008_ADM0_AEZ_Soilagri_excsv_global.csv"
))
monf_dat
=
read_csv
(
here
::
here
(
"Input_data"
,
"
Monfreda2008_ADM0_AEZ_Soilagri_excsv
_global.csv"
))
# vector containing all different category names
# nuts
...
...
@@ -219,6 +178,7 @@ Forage_nuts_veg_spam = SPAM2010_global_ZONES %>%
bind_rows
(
.
,
forageCrop_dat
,
forageGrass_dat
)
write_csv
(
Forage_nuts_veg_spam
,
here
(
"Input_data"
,
"SPAM2010_global_nuts_veg_adm0_aez_soilagri_forage.csv"
))
Forage_nuts_veg_spam
=
read_csv
(
here
::
here
(
"Input_data"
,
"SPAM2010_global_nuts_veg_adm0_aez_soilagri_forage.csv"
))
# Subsetting -------------------------------------------------------------
EU_iso3
=
c
(
"AUT"
,
"BEL"
,
"BGR"
,
"HRV"
,
"CZE"
,
"DNK"
,
"EST"
,
"FIN"
,
"FRA"
,
"DEU"
,
"GRC"
,
"HUN"
,
"IRL"
,
"ITA"
,
"LVA"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment