Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PLUM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Land Use Lab
PLUM
Commits
14252e98
Commit
14252e98
authored
5 years ago
by
R0slyn
Browse files
Options
Downloads
Patches
Plain Diff
Script tweaks for Frances for generating shock.csv files when creating scenarios.
parent
a33e4a82
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
data/shockDistributions.csv
+8
-8
8 additions, 8 deletions
data/shockDistributions.csv
scripts/createShockFiles.R
+35
-29
35 additions, 29 deletions
scripts/createShockFiles.R
with
43 additions
and
37 deletions
data/shockDistributions.csv
+
8
−
8
View file @
14252e98
...
@@ -2,22 +2,22 @@ shock,pname,min,max,type
...
@@ -2,22 +2,22 @@ shock,pname,min,max,type
protectionism,TRADE_BARRIER_MULTIPLIER,0.1,0.2,additive
protectionism,TRADE_BARRIER_MULTIPLIER,0.1,0.2,additive
protectionism ,TRANSPORT_COST,0.5,1,multiplicative
protectionism ,TRANSPORT_COST,0.5,1,multiplicative
protectionism ,TRANSPORT_LOSSES,0.05,0.1,additive
protectionism ,TRANSPORT_LOSSES,0.05,0.1,additive
automation,TRANSPORT_COST,-0.
2
5,-0.5,multiplicative
automation,TRANSPORT_COST,-0.5,-0.
2
5,multiplicative
automation,TRANSPORT_LOSSES,-0.
05
,-0.
1
,additive
automation,TRANSPORT_LOSSES,-0.
1
,-0.
05
,additive
automation,TECHNOLOGY_CHANGE_ANNUAL_RATE,0.002,0.004,additive
automation,TECHNOLOGY_CHANGE_ANNUAL_RATE,0.002,0.004,additive
automation,MEAT_EFFICIENCY,0.025,0.05,additive
automation,MEAT_EFFICIENCY,0.025,0.05,additive
automation,FERTILISER_COST_PER_T,-0.
2
5,-0.5,multiplicative
automation,FERTILISER_COST_PER_T,-0.5,-0.
2
5,multiplicative
automation,OTHER_INTENSITY_COST,-0.
2
5,-0.5,multiplicative
automation,OTHER_INTENSITY_COST,-0.5,-0.
2
5,multiplicative
automation,IRRIG_COST_MULTIPLIER,-0.
2
5,-0.5,additive
automation,IRRIG_COST_MULTIPLIER,-0.5,-0.
2
5,additive
automation,IRRIG_EFF_MULTIPLIER,0.1,0.2,additive
automation,IRRIG_EFF_MULTIPLIER,0.1,0.2,additive
diet,RUMINANT_CHANGE_ANNUAL_RATE,0.4,0.6,additive
diet,RUMINANT_CHANGE_ANNUAL_RATE,0.4,0.6,additive
diet,MONOGASTRIC_CHANGE_ANNUAL_RATE,0.4,0.6,additive
diet,MONOGASTRIC_CHANGE_ANNUAL_RATE,0.4,0.6,additive
cyber,TRANSPORT_COST,0.5,1,multiplicative
cyber,TRANSPORT_COST,0.5,1,multiplicative
cyber,TRANSPORT_LOSSES,0.1,0.2,additive
cyber,TRANSPORT_LOSSES,0.1,0.2,additive
cyber,TECHNOLOGY_CHANGE_ANNUAL_RATE,-0.00
2
,-0.00
4
,additive
cyber,TECHNOLOGY_CHANGE_ANNUAL_RATE,-0.00
4
,-0.00
2
,additive
cyber,MEAT_EFFICIENCY,-0.0
2
5,-0.05,additive
cyber,MEAT_EFFICIENCY,-0.05,-0.0
2
5,additive
cyber,FERTILISER_COST_PER_T,0.25,0.5,multiplicative
cyber,FERTILISER_COST_PER_T,0.25,0.5,multiplicative
cyber,OTHER_INTENSITY_COST,0.25,0.5,multiplicative
cyber,OTHER_INTENSITY_COST,0.25,0.5,multiplicative
cyber,IRRIG_COST_MULTIPLIER,0.25,0.5,additive
cyber,IRRIG_COST_MULTIPLIER,0.25,0.5,additive
cyber,IRRIG_EFF_MULTIPLIER,-0.
1
,-0.
2
,additive
cyber,IRRIG_EFF_MULTIPLIER,-0.
2
,-0.
1
,additive
financial,FINANCIAL_SPECULATION_MULTIPLIER,0.5,1,additive
financial,FINANCIAL_SPECULATION_MULTIPLIER,0.5,1,additive
This diff is collapsed.
Click to expand it.
scripts/createShockFiles.R
+
35
−
29
View file @
14252e98
...
@@ -9,28 +9,36 @@ createShockFile = function(scenario){
...
@@ -9,28 +9,36 @@ createShockFile = function(scenario){
#setting all parameters to default values. If parameters are changed according to ssp then pull value from samp table, if not
#setting all parameters to default values. If parameters are changed according to ssp then pull value from samp table, if not
#set as default same as in config file or to a value that makes no change
#set as default same as in config file or to a value that makes no change
paramValues
=
data.table
(
Year
=
seq
(
2010
,
2100
,
1
),
##This creates the shocks.csv table that PLUM needs to read in to update the parameter values over time
trendYearValue
=
c
(
rep
(
0
,
16
),
seq
(
0.2
,
1
,
0.2
),
rep
(
1
,
70
)),
##the parameters below and their order must match the order of the method in PLUM in ModelConfig readInShocksFile()
TRADE_BARRIER_MULTIPLIER
=
scenario
[,
TRADE_BARRIER_MULTIPLIER
],
##if the parameter has a baseline value as specified in the scenario table then use that otherwise use the PLUM default value
TRANSPORT_COST
=
scenario
[,
TRANSPORT_COST
],
##as in ModelConfig
TECHNOLOGY_CHANGE_ANNUAL_RATE
=
scenario
[,
TECHNOLOGY_CHANGE_ANNUAL_RATE
],
paramValues
=
data.table
(
Year
=
seq
(
2010
,
2100
,
1
),
MEAT_EFFICIENCY
=
scenario
[,
MEAT_EFFICIENCY
],
trendYearValue
=
c
(
rep
(
0
,
scenarioTable
[
i
,
SHOCK_START_YEAR
]
-2010
),
FERTILISER_COST_PER_T
=
scenario
[,
FERTILISER_COST_PER_T
],
seq
(
0
,
1
,
1
/
scenarioTable
[
i
,
SHOCK_END_YEAR
-
SHOCK_START_YEAR
]),
OTHER_INTENSITY_COST
=
scenario
[,
OTHER_INTENSITY_COST
],
rep
(
1
,
2100
-
scenarioTable
[
i
,
SHOCK_END_YEAR
])),
TRANSPORT_LOSSES
=
0.05
,
TRADE_BARRIER_MULTIPLIER
=
scenario
[,
if
(
exists
(
"TRADE_BARRIER_MULTIPLIER"
))
TRADE_BARRIER_MULTIPLIER
else
1.0
],
IRRIG_COST_MULTIPLIER
=
1.0
,
TRANSPORT_COST
=
scenario
[,
if
(
exists
(
"TRANSPORT_COST"
))
TRANSPORT_COST
else
0.1
],
RUMINANT_CHANGE_ANNUAL_RATE
=
0.0
,
TECHNOLOGY_CHANGE_ANNUAL_RATE
=
scenario
[,
if
(
exists
(
"TECHNOLOGY_CHANGE_ANNUAL_RATE"
))
TECHNOLOGY_CHANGE_ANNUAL_RATE
else
0.002
],
MONOGASTRIC_CHANGE_ANNUAL_RATE
=
0.0
,
MEAT_EFFICIENCY
=
scenario
[,
if
(
exists
(
"MEAT_EFFICIENCY"
))
MEAT_EFFICIENCY
else
1.0
],
IRRIG_EFF_MULTIPLIER
=
1.0
,
FERTILISER_COST_PER_T
=
scenario
[,
if
(
exists
(
"FERTILISER_COST_PER_T"
))
FERTILISER_COST_PER_T
else
1.4
],
FINANCIAL_SPECULATION_MULTIPLIER
=
1.0
)
OTHER_INTENSITY_COST
=
scenario
[,
if
(
exists
(
"OTHER_INTENSITY_COST"
))
OTHER_INTENSITY_COST
else
0.8
],
TRANSPORT_LOSSES
=
scenario
[,
if
(
exists
(
"TRANSPORT_LOSSES"
))
TRANSPORT_LOSSES
else
0.05
],
IRRIG_COST_MULTIPLIER
=
scenario
[,
if
(
exists
(
"IRRIG_COST_MULTIPLIER"
))
IRRIG_COST_MULTIPLIER
else
1.0
],
RUMINANT_CHANGE_ANNUAL_RATE
=
scenario
[,
if
(
exists
(
"RUMINANT_CHANGE_ANNUAL_RATE"
))
RUMINANT_CHANGE_ANNUAL_RATE
else
0.0
],
MONOGASTRIC_CHANGE_ANNUAL_RATE
=
scenario
[,
if
(
exists
(
"MONOGASTRIC_CHANGE_ANNUAL_RATE"
))
MONOGASTRIC_CHANGE_ANNUAL_RATE
else
0.0
],
IRRIG_EFF_MULTIPLIER
=
scenario
[,
if
(
exists
(
"IRRIG_EFF_MULTIPLIER"
))
IRRIG_EFF_MULTIPLIER
else
1.0
],
FINANCIAL_SPECULATION_MULTIPLIER
=
scenario
[,
if
(
exists
(
"FINANCIAL_SPECULATION_MULTIPLIER"
))
FINANCIAL_SPECULATION_MULTIPLIER
else
1.0
]
)
paramValues
[,
names
(
paramValues
)
:=
lapply
(
.SD
,
as.numeric
)]
paramValues
[,
names
(
paramValues
)
:=
lapply
(
.SD
,
as.numeric
)]
##This decides if and when a cyber shock or financial shock will happen according to the shockProbabilities.csv table and the SSP
shocksHappen
=
data.table
(
SSP_Scenario
=
scenario
[,
SSP_SCENARIO
],
Scenario
=
scenario
[,
Scenario
],
Year
=
seq
(
2010
,
2100
,
1
),
shocksHappen
=
data.table
(
SSP_Scenario
=
scenario
[,
SSP_SCENARIO
],
Scenario
=
scenario
[,
Scenario
],
Year
=
seq
(
2010
,
2100
,
1
),
climate
=
as.logical
(
rbinom
(
91
,
size
=
1
,
prob
=
shockProbs
[
ssp
==
substr
(
scenario
[,
SSP_SCENARIO
],
1
,
4
),
climate
])),
cyber
=
as.logical
(
rbinom
(
91
,
size
=
1
,
prob
=
shockProbs
[
ssp
==
substr
(
scenario
[,
SSP_SCENARIO
],
1
,
4
),
cyber
])),
cyber
=
as.logical
(
rbinom
(
91
,
size
=
1
,
prob
=
shockProbs
[
ssp
==
substr
(
scenario
[,
SSP_SCENARIO
],
1
,
4
),
cyber
])),
financial
=
as.logical
(
rbinom
(
91
,
size
=
1
,
prob
=
shockProbs
[
ssp
==
substr
(
scenario
[,
SSP_SCENARIO
],
1
,
4
),
financial
])))
financial
=
as.logical
(
rbinom
(
91
,
size
=
1
,
prob
=
shockProbs
[
ssp
==
substr
(
scenario
[,
SSP_SCENARIO
],
1
,
4
),
financial
])))
##this creates the table for the shocksRecords.csv file. so contains only the shock value, hence where no shock the value is 0
shockValues
=
data.table
(
Year
=
rep
(
seq
(
2010
,
2100
,
1
),
6
),
shock
=
rep
(
c
(
"protectionism"
,
"automation"
,
"diet"
,
"cyber"
,
"climate"
,
"financial"
),
each
=
91
),
shockValues
=
data.table
(
Year
=
rep
(
seq
(
2010
,
2100
,
1
),
6
),
shock
=
rep
(
c
(
"protectionism"
,
"automation"
,
"diet"
,
"cyber"
,
"climate"
,
"financial"
),
each
=
91
),
TRADE_BARRIER_MULTIPLIER
=
0
,
TRADE_BARRIER_MULTIPLIER
=
0
,
TRANSPORT_COST
=
0
,
TRANSPORT_COST
=
0
,
...
@@ -45,14 +53,16 @@ createShockFile = function(scenario){
...
@@ -45,14 +53,16 @@ createShockFile = function(scenario){
IRRIG_EFF_MULTIPLIER
=
0
,
IRRIG_EFF_MULTIPLIER
=
0
,
FINANCIAL_SPECULATION_MULTIPLIER
=
0
)
FINANCIAL_SPECULATION_MULTIPLIER
=
0
)
##add trend values to shocks.csv file by drawing a random value from the distributions file for each parameter for the type of trend
for
(
trendType
in
c
(
"protectionism"
,
"automation"
,
"diet"
)){
for
(
trendType
in
c
(
"protectionism"
,
"automation"
,
"diet"
)){
if
(
as.logical
(
rbinom
(
1
,
size
=
1
,
prob
=
shockProbs
[
ssp
==
substr
(
scenario
[,
SSP_SCENARIO
],
1
,
4
),
get
(
trendType
)]))){
if
(
as.logical
(
rbinom
(
1
,
size
=
1
,
prob
=
shockProbs
[
ssp
==
substr
(
scenario
[,
SSP_SCENARIO
],
1
,
4
),
get
(
trendType
)]))){
for
(
paramName
in
shockDistFile
[
shock
==
trendType
]
$
pname
){
for
(
paramName
in
shockDistFile
[
shock
==
trendType
]
$
pname
){
#draw a random parameter value from the distribution file
randomValue
=
drawValue
(
trendType
,
paramName
)
randomValue
=
drawValue
(
trendType
,
paramName
)
#put in records table
#put in records table
shockValues
[
shock
==
trendType
,
c
(
paramName
)
:=
randomValue
*
paramValues
[,
trendYearValue
]]
shockValues
[
shock
==
trendType
,
c
(
paramName
)
:=
randomValue
*
paramValues
[,
trendYearValue
]]
##add the value to the shocks.csv table and adjust depending on whether multiplicative or additive, also adjust value
##according to year of implementation
if
(
shockDistFile
[
shock
==
trendType
&
pname
==
paramName
]
$
type
==
'additive'
){
if
(
shockDistFile
[
shock
==
trendType
&
pname
==
paramName
]
$
type
==
'additive'
){
paramValues
[,
c
(
paramName
)
:=
get
(
paramName
)
+
randomValue
*
trendYearValue
]
paramValues
[,
c
(
paramName
)
:=
get
(
paramName
)
+
randomValue
*
trendYearValue
]
}
}
...
@@ -63,9 +73,9 @@ createShockFile = function(scenario){
...
@@ -63,9 +73,9 @@ createShockFile = function(scenario){
}
}
}
}
##do the same as above for individual year shocks, don't adjust by implementation year as cyber shocks and financial shocks are single year occurances
for
(
year
in
paramValues
[,
Year
]){
for
(
year
in
paramValues
[,
Year
]){
for
(
shockType
in
names
(
shocksHappen
)[
4
:
6
]){
for
(
shockType
in
names
(
shocksHappen
)[
4
:
5
]){
if
(
shocksHappen
[
Year
==
year
,
get
(
shockType
)]){
if
(
shocksHappen
[
Year
==
year
,
get
(
shockType
)]){
for
(
paramName
in
shockDistFile
[
shock
==
shockType
]
$
pname
){
for
(
paramName
in
shockDistFile
[
shock
==
shockType
]
$
pname
){
...
@@ -85,7 +95,9 @@ createShockFile = function(scenario){
...
@@ -85,7 +95,9 @@ createShockFile = function(scenario){
}
}
}
}
#if negative set to zero, or need to change shock distributions so zero can't happen
#if negative set to zero
for
(
col
in
names
(
paramValues
))
set
(
paramValues
,
i
=
which
(
paramValues
[[
col
]]
<
0
),
j
=
col
,
value
=
0
)
for
(
col
in
names
(
paramValues
))
set
(
paramValues
,
i
=
which
(
paramValues
[[
col
]]
<
0
),
j
=
col
,
value
=
0
)
ensDir
=
file.path
(
scenario
[,
Ensemble
],
scenario
[,
Scenario
])
ensDir
=
file.path
(
scenario
[,
Ensemble
],
scenario
[,
Scenario
])
...
@@ -102,14 +114,8 @@ createShockFile = function(scenario){
...
@@ -102,14 +114,8 @@ createShockFile = function(scenario){
drawValue
<-
function
(
shockType
,
paramName
){
drawValue
<-
function
(
shockType
,
paramName
){
randomValue
=
runif
(
1
,
abs
(
shockDistFile
[
shock
==
shockType
&
pname
==
paramName
]
$
min
),
runif
(
1
,
shockDistFile
[
shock
==
shockType
&
pname
==
paramName
]
$
min
,
abs
(
shockDistFile
[
shock
==
shockType
&
pname
==
paramName
]
$
max
))
shockDistFile
[
shock
==
shockType
&
pname
==
paramName
]
$
max
)
if
(
shockDistFile
[
shock
==
shockType
&
pname
==
paramName
]
$
min
<
0
){
randomValue
=
randomValue
*
-1
}
randomValue
}
}
plumDirectory
=
"/exports/csce/eddie/geos/groups/LURG/models/PLUM"
plumDirectory
=
"/exports/csce/eddie/geos/groups/LURG/models/PLUM"
...
...
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