GitLab at IIASA

Commits on Source (2)
...@@ -16,8 +16,8 @@ Depends: R (>= 4.2.1) ...@@ -16,8 +16,8 @@ Depends: R (>= 4.2.1)
Imports: tidyverse, gdxrrw Imports: tidyverse, gdxrrw
License: GPL (>= 3) License: GPL (>= 3)
Encoding: UTF-8 Encoding: UTF-8
LazyData: true LazyData: false
URL: https://www.wur.nl/ URL: https://www.wur.nl/
RoxygenNote: 7.2.1 RoxygenNote: 7.2.2
Suggests: Suggests:
stringr (>= 1.4.1) stringr (>= 1.4.1)
No preview for this file type
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
export(Modes) export(Modes)
export(gdxbinwider) export(gdxbinwider)
export(gdxload)
export(gdxreshape) export(gdxreshape)
export(groupstats) export(groupstats)
export(runFarmDynfromBatch) export(runFarmDynfromBatch)
export(samplr)
export(str_firstLine_replace) export(str_firstLine_replace)
export(str_lastLine_replace) export(str_lastLine_replace)
export(str_line_replace) export(str_line_replace)
export(updateFarmData)
export(writeBatch) export(writeBatch)
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#' #'
#' @docType data #' @docType data
#' #'
#' @usage data(fd2gui); data(fdnl); data(gdxmapping) #' @usage data(samplefd2gui); data(samplefdnl); data(samplegdxmapping)
#' #'
#' @format Objects of class `tbl_df` #' @format Objects of class `tbl_df`
#' #'
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
#' data(fd2gui) #' data(fd2gui)
#' data(fdnl) #' data(fdnl)
#' data(gdxmapping) #' data(gdxmapping)
'fd2gui' #'samplefd2gui'
...@@ -40,7 +40,7 @@ You can install the development version of FarmDynR like so: ...@@ -40,7 +40,7 @@ You can install the development version of FarmDynR like so:
## Workflow ## Workflow
1. Create GDX files with the mappings, global settings per farm, farm data, and weights 1. Create GDX files with the mappings, global settings per farm, farm data, and weights
2. Use `samplr()` to create sample farms based on your selected mapping 2. Use `updateFarmData()` to create sample farms based on your selected mapping
3. Write batch file with `writeBatch()` and run FarmDyn with `runFarmDynfromBatch()` using the created batch file 3. Write batch file with `writeBatch()` and run FarmDyn with `runFarmDynfromBatch()` using the created batch file
- Optional: Create descriptive statistics for reporting with `groupstats()` - Optional: Create descriptive statistics for reporting with `groupstats()`
......
...@@ -33,7 +33,8 @@ You can install the development version of FarmDynR like so: ...@@ -33,7 +33,8 @@ You can install the development version of FarmDynR like so:
1. Create GDX files with the mappings, global settings per farm, farm 1. Create GDX files with the mappings, global settings per farm, farm
data, and weights data, and weights
2. Use `samplr()` to create sample farms based on your selected mapping 2. Use `updateFarmData()` to create sample farms based on your selected
mapping
3. Write batch file with `writeBatch()` and run FarmDyn with 3. Write batch file with `writeBatch()` and run FarmDyn with
`runFarmDynfromBatch()` using the created batch file `runFarmDynfromBatch()` using the created batch file
- Optional: Create descriptive statistics for reporting with - Optional: Create descriptive statistics for reporting with
......
library(dplyr)
library(tidyr)
library(arsenal)
library(gdxrrw)
GAMSDir = "C:/GAMS/40" # Change to your GAMS Version!
igdx(GAMSDir)
set.seed(1234)
abcd <- c(stringi::stri_rand_strings(80,5))
mapping <- rep(LETTERS[5:9], times = c(10, 10, 40, 60, 68))
set.seed(1234)
all_binid <- c(sample(1:187), 'dummy')
set.seed(1234)
item <- c('global', 'yields', 'maxrot', 'misc')
set.seed(1234)
value <- rnorm(15040, mean = 0, sd=100)
a <- data.frame(item,abcd) %>% tibble()
a[a$item=='global',]$abcd[19:20] <- c('soilTypeFirm', 'derogatie')
map2id <- data.frame(all_binid = as.factor(all_binid), grouping = as.factor(mapping))
fadat2gui <- data.frame(all_binid = as.factor(all_binid), a, value=value)
test<- fadat2gui[fadat2gui$item=='global',]$value
#fadat2gui[fadat2gui$all_binid=='dummy',]$item <- 'global'
set.seed(1234)
fadat2gui[fadat2gui$all_binid=='dummy',]$value[sample(nrow(fadat2gui[fadat2gui$all_binid=='dummy',]),3)] <- c(1.6e+303, 1.59e+303, 1.56e+303)
set.seed(1234)
fdnl <- data.frame(all_binid = as.factor(all_binid[1:94]),
year = rep(2017:2020, c(5, 11, 15, 16)),
items = c(stringi::stri_rand_strings(94,5),rep('Weight', 94)),
value = rnorm(94, mean=0, sd=40)
)
set.seed(1234)
fdnl[fdnl$items == 'Weight',]$value <- runif(94, min = 0.01)
write.csv(fadat2gui, 'inst/extdata/GAMS/fadat2gui.csv')
write.csv(fdnl, 'inst/extdata/GAMS/fdnl.csv')
write.csv(map2id, 'inst/extdata/GAMS/map2id.csv')
# Run GAMS
# After running GAMS
fd2gui <- (gdxrrw::rgdx.param("inst/extdata/GAMS/DynRexampledata.gdx", "p_farmData2GUI", names=c("all_binid", 'items', "varias", "value"), compress=FALSE, ts=FALSE,
squeeze=TRUE, useDomInfo = TRUE, check.names = TRUE))
fdnl <- (gdxrrw::rgdx.param("inst/extdata/GAMS/DynRexampledata.gdx", "p_farmData_NL", names=c("all_binid", 'years', "items2", "value"), compress=FALSE, ts=FALSE,
squeeze=TRUE, useDomInfo = TRUE, check.names = TRUE))
gdxmapping <- (rgdx.set("inst/extdata/GAMS/DynRexampledata.gdx", 'map2binid',names = c('all_binid', 'mapping'), compress=FALSE, ts=FALSE,
useDomInfo = TRUE, check.names = TRUE))
save(fd2gui, file = 'data/fd2gui.RData')
save(fdnl, file = 'data/fdnl.RData')
save(gdxmapping, file = 'data/gdxmapping.RData')
groupstats('DynRexampledata.gdx', BINDir="inst/extdata/GAMS/", gdxmap = 'map2binid', mapping = 'mapping', cols = c('d0EfV', 'hXHvI'), w='Weight')
This diff is collapsed.
Set
items 'set of fake items'
all_binid 'fake id numbers'
mapping 'fake mapping used'
map2binid 'fake mapping to fake bin id'
varias 'fake variables used'
year 'fake years'
items2 'fdnl items';
$gdxIn fd2gui.gdx
$load all_binid
$load varias
$load items
Parameter p_farmData2GUI(all_binid, items, varias) 'Fake Random farmdata2gui';
$LOAD p_farmData2GUI
$gdxIn
$gdxIn fdnl.gdx
$load year
$load items2
Parameter p_farmData_NL(all_binid, year, items2) 'Fake Random farmData NL';
$LOAD p_farmData_NL
$gdxIn
$gdxIn map2id.gdx
$LOAD mapping
$LOAD map2binid
execute_unload 'DynRexampledata.gdx'
all_binid
year
items
items2
mapping
map2binid
varias
p_farmData_NL
p_farmData2GUI
* Nothing here is real data, purely fiction
$call csv2gdx fadat2gui.csv id='p_farmData2GUI' index=2,3,4 useHeader=Y colCount=5 value=lastCol
Set
items 'set of fake items'
all_binid 'fake id numbers'
varias 'fake variables used'
$gdxIn fadat2gui.gdx
$load all_binid = Dim1
$load items = Dim2
$load varias = Dim3
Parameter p_farmData2GUI(all_binid, items, varias) 'Fake Random farmdata2gui';
$load p_farmData2GUI
$gdxIn
execute_unloaddi "fd2gui.gdx"
all_binid
items
varias
p_farmData2GUI
\ No newline at end of file
"","all_binid","year","items","value"
"1","28",2017,"7cbcr",-43.1016849103772
"2","80",2017,"d0EfV",-129.326085316925
"3","150",2017,"hXHvI",-10.1949861061814
"4","101",2017,"pHGBE",1.18071321285919
"5","111",2017,"JI92D",23.7709509644205
"6","137",2018,"oWup2",2.36540672715187
"7","133",2018,"SGIVB",16.5359557894818
"8","166",2018,"lCGzo",-43.9108869828168
"9","144",2018,"YeJcK",28.4470102908176
"10","132",2018,"VfUFl",28.7555491941657
"11","98",2018,"4JiV9",10.0660427611587
"12","103",2018,"VUkAq",54.290977446071
"13","90",2018,"r2J0E",16.1787388511443
"14","70",2018,"hJV3Z",10.5745707935175
"15","79",2018,"7t0m5",10.7217561657479
"16","116",2018,"WN4Jf",17.4772230815793
"17","14",2019,"vT8XC",42.4049562194946
"18","126",2019,"tOJ9t",18.0876158611486
"19","62",2019,"At886",26.5279446274826
"20","4",2019,"VI1Jk",-45.4549421596334
"21","178",2019,"2ZHC8",-14.8199006836847
"22","149",2019,"K98R2",59.0787835916988
"23","40",2019,"i6w7D",-48.9561500205502
"24","93",2019,"uwH7n",10.3227354958442
"25","122",2019,"kuzwU",16.2001122173407
"26","181",2019,"HFVUJ",39.032132872378
"27","66",2019,"xd7Qu",-13.9550694615964
"28","123",2019,"Tubdr",6.3450175796505
"29","48",2019,"VyKTM",-70.5302026616461
"30","108",2019,"cjZyZ",13.5438418839962
"31","131",2019,"RE5qE",-26.6626011823709
"32","87",2020,"zbzNY",-9.54586497310576
"33","41",2020,"QZQD5",-47.5106112982878
"34","115",2020,"dQ4nK",15.3974128707431
"35","72",2020,"kahQL",26.6631806261792
"36","42",2020,"lQY7I",-12.1845555783094
"37","43",2020,"TLb4x",73.0004425634518
"38","2",2020,"1qdJk",26.8223748227035
"39","117",2020,"dz7so",37.9453029302061
"40","173",2020,"opjyd",81.9761200668364
"41","49",2020,"eWJlW",-26.0445443695014
"42","102",2020,"jJPCz",32.3447709138517
"43","51",2020,"ZHBkZ",39.4632245581825
"44","134",2020,"vdhTq",-0.246831843628001
"45","147",2020,"Q1GK8",12.7620943172765
"46","143",2020,"UnKVU",-40.4728761096738
"47","57",2020,"nZ6oZ",18.8067019090556
"48","136",2017,"DkJUz",-28.0388132651639
"49","26",2017,"QFDgy",32.5473145010597
"50","160",2017,"TlZxn",-32.4572313597109
"51","8",2017,"WaGH4",12.7758994839784
"52","96",2017,"YG0aW",-33.860906126545
"53","22",2018,"q1bG7",-9.8305271651493
"54","35",2018,"6k03k",-62.1143604442184
"55","155",2018,"MlNn1",5.13736131703013
"56","157",2018,"VoXGL",39.4177355761947
"57","86",2018,"MQumj",7.32990092268766
"58","141",2018,"HSHho",-70.6491685372183
"59","10",2018,"ePxFb",-24.8213478646377
"60","55",2018,"kh7dJ",66.2417214799494
"61","135",2018,"LyXRw",72.3922154233551
"62","120",2018,"SBzYl",-47.0014707204854
"63","109",2018,"ugPP9",-14.6681303531056
"64","25",2019,"CBPLp",14.1450179570915
"65","3",2019,"CrO9L",12.7662488347159
"66","83",2019,"MQBev",-23.1982795607761
"67","50",2019,"jsxCT",-38.1311480778763
"68","180",2019,"NN1vP",-7.17714347782484
"69","175",2019,"xGWyM",40.3923285977721
"70","156",2019,"J2fv2",0.945064596856353
"71","174",2019,"Ck8hz",-25.961128783356
"72","20",2019,"wajUl",-20.1749688819276
"73","162",2019,"0YSKp",64.5756598183345
"74","63",2019,"yeEoi",-17.8783924502265
"75","71",2019,"yGsUI",30.5270704445326
"76","61",2019,"Ol6Qe",58.868747447432
"77","140",2019,"IC06D",17.7465961474966
"78","145",2019,"7gBzw",-16.8688748028076
"79","170",2020,"gjjeA",-1.60006504824295
"80","184",2020,"vZX1M",-19.6911987291155
"81","27",2020,"gPkmZ",49.1086846925101
"82","76",2020,"Bl5cP",-5.98214260977569
"83","153",2020,"moxDr",61.9993353592985
"84","159",2020,"PVm8P",-22.4645014152525
"85","60",2020,"fuL6v",-25.8846900252944
"86","65",2020,"C3QLH",5.72528636201707
"87","36",2020,"fmRvG",0.967545919642049
"88","187",2020,"eNvja",-20.1780609832348
"89","19",2020,"oskVz",-63.2558723972136
"90","9",2020,"Ysdc2",1.20265685021672
"91","30",2020,"Fmzxk",-28.6630679628281
"92","114",2020,"gFbZ3",43.3044382190448
"93","17",2020,"NtOWA",-38.1074181975717
"94","167",2020,"BXOcZ",45.0593091603663
"95","28",2017,"Weight",0.12256637719227
"96","80",2017,"Weight",0.626076410766691
"97","150",2017,"Weight",0.613181985551491
"98","101",2017,"Weight",0.627145647259895
"99","111",2017,"Weight",0.862306229721289
"100","137",2018,"Weight",0.64390749923652
"101","133",2018,"Weight",0.0194007987924851
"102","166",2018,"Weight",0.240225000954233
"103","144",2018,"Weight",0.66942292064894
"104","132",2018,"Weight",0.519108629929833
"105","98",2018,"Weight",0.696655378865544
"106","103",2018,"Weight",0.549525087233633
"107","90",2018,"Weight",0.289906247754116
"108","70",2018,"Weight",0.924199149433989
"109","79",2018,"Weight",0.299392681852914
"110","116",2018,"Weight",0.83892267187126
"111","14",2019,"Weight",0.293361051820684
"112","126",2019,"Weight",0.274152572201565
"113","62",2019,"Weight",0.194855561761651
"114","4",2019,"Weight",0.239903651422355
"115","178",2019,"Weight",0.32344633028144
"116","149",2019,"Weight",0.309666437022388
"117","40",2019,"Weight",0.167455542867538
"118","93",2019,"Weight",0.0495959588699043
"119","122",2019,"Weight",0.226611545595806
"120","181",2019,"Weight",0.812492566935252
"121","66",2019,"Weight",0.530440571310464
"122","123",2019,"Weight",0.915511584342457
"123","48",2019,"Weight",0.833031596401706
"124","108",2019,"Weight",0.0553125606663525
"125","131",2019,"Weight",0.461530567600857
"126","87",2020,"Weight",0.272534805147443
"127","41",2020,"Weight",0.311625480996445
"128","115",2020,"Weight",0.512233801372349
"129","72",2020,"Weight",0.189285246198997
"130","42",2020,"Weight",0.762073929097969
"131","43",2020,"Weight",0.209235557252541
"132","2",2020,"Weight",0.266221720466856
"133","117",2020,"Weight",0.992228913353756
"134","173",2020,"Weight",0.809278816911392
"135","49",2020,"Weight",0.557800254831091
"136","102",2020,"Weight",0.649942033137195
"137","51",2020,"Weight",0.318706064007711
"138","134",2020,"Weight",0.625601006150246
"139","147",2020,"Weight",0.336472473982722
"140","143",2020,"Weight",0.506977498221677
"141","57",2020,"Weight",0.680323582014535
"142","136",2017,"Weight",0.490141326759476
"143","26",2017,"Weight",0.251489539071918
"144","160",2017,"Weight",0.767805189690553
"145","8",2017,"Weight",0.0830420812685043
"146","96",2017,"Weight",0.316589735841844
"147","22",2018,"Weight",0.720099025908858
"148","35",2018,"Weight",0.509500453025103
"149","155",2018,"Weight",0.161468969357666
"150","157",2018,"Weight",0.508894153276924
"151","86",2018,"Weight",0.499021313819103
"152","141",2018,"Weight",0.753688195061404
"153","10",2018,"Weight",0.182903325683437
"154","55",2018,"Weight",0.849908486332279
"155","135",2018,"Weight",0.866185493699741
"156","120",2018,"Weight",0.0514387024287134
"157","109",2018,"Weight",0.324010333772749
"158","25",2019,"Weight",0.0236124397651292
"159","3",2019,"Weight",0.246635469414759
"160","83",2019,"Weight",0.709429671103135
"161","50",2019,"Weight",0.315013809571974
"162","180",2019,"Weight",0.513462090010289
"163","175",2019,"Weight",0.0611301531433128
"164","156",2019,"Weight",0.568924141575117
"165","174",2019,"Weight",0.130265385296661
"166","20",2019,"Weight",0.893908017864451
"167","162",2019,"Weight",0.0244809831748717
"168","63",2019,"Weight",0.785289892617147
"169","71",2019,"Weight",0.0990617196378298
"170","61",2019,"Weight",0.523998081004247
"171","140",2019,"Weight",0.39042402068153
"172","145",2019,"Weight",0.0793519723485224
"173","170",2020,"Weight",0.327437977979425
"174","184",2020,"Weight",0.671810443112627
"175","27",2020,"Weight",0.927136471604463
"176","76",2020,"Weight",0.47719062393764
"177","153",2020,"Weight",0.151189189779107
"178","159",2020,"Weight",0.548827057466842
"179","60",2020,"Weight",0.204212905331515
"180","65",2020,"Weight",0.899594684322365
"181","36",2020,"Weight",0.395604786833283
"182","187",2020,"Weight",0.317762071881443
"183","19",2020,"Weight",0.168428376368247
"184","9",2020,"Weight",0.89722399106482
"185","30",2020,"Weight",0.174729842578527
"186","114",2020,"Weight",0.901420350193512
"187","17",2020,"Weight",0.142737413134892
"188","167",2020,"Weight",0.140297992839478
$call csv2gdx fdnl.csv id='p_farmData_NL' index=2,3,4 useHeader=Y colCount=5 value=lastCol
Set
items 'set of fake items'
all_binid 'fake id numbers'
* mapping 'fake mapping used'
* map2binid 'fake mapping to fake bin id'
* varias 'fake variables used'
year 'fake years'
items2 'items of fdnl';
$gdxIn fdnl.gdx
$load all_binid = Dim1
$load year = Dim2
$load items2 = Dim3
Parameter p_farmData_NL(all_binid, year, items2) 'Fake Random farmData NL';
$load p_farmData_NL
$gdxIn
execute_unload "fdnl.gdx"
all_binid
items2
year
p_farmData_NL
\ No newline at end of file