Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
remind
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jerome Hilaire
remind
Commits
1a895f74
Commit
1a895f74
authored
4 years ago
by
Johannes Koch
Browse files
Options
Downloads
Patches
Plain Diff
Refactor policyCosts script
parent
998771da
No related branches found
No related tags found
1 merge request
!147
Refactor policyCosts script
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/output/comparison/policyCosts.R
+25
-25
25 additions, 25 deletions
scripts/output/comparison/policyCosts.R
with
25 additions
and
25 deletions
scripts/output/comparison/policyCosts.R
+
25
−
25
View file @
1a895f74
...
...
@@ -20,20 +20,20 @@
suppressPackageStartupMessages
(
library
(
tidyverse
))
# TODO: Loading magclass shouldn't actually be necessary... but running on the
# cluster without doing so throws an error...
suppressPackageStartupMessages
(
library
(
magclass
))
# Function defintions
get_run_names
<-
function
(
filepaths
)
{
# The run names are found between a "/" and the time-stamp of the run.
run_names
<-
str_match
(
filepaths
,
pattern
=
"^.*\\/(.*)(_....-..-..*)$"
)[,
2
]
# If for some reason there isn't a time-stamp, return the name of the folder
if
(
any
(
is.na
(
run_names
)))
{
run_names
<-
str_match
(
filepaths
,
pattern
=
"^.*\\/(.*)\\/.*$"
)[,
2
]
}
return
(
run_names
)
rm_timestamp
<-
function
(
strings
,
name_timestamp_seperator
=
"_"
,
timestamp_format
=
"%Y-%m-%d_%H.%M.%S"
)
{
# Get regex pattern of timestamp
regex_timestamp
<-
gsub
(
"%[mdHMS]"
,
"\\\\d{2}"
,
timestamp_format
)
regex_timestamp
<-
gsub
(
"%Y"
,
"\\\\d{4}"
,
regex_timestamp
)
regex_timestamp
<-
paste0
(
name_timestamp_seperator
,
regex_timestamp
)
# Substitute timestamps with nothing (thereby removing them)
my_strings_wo_timeStamp
<-
sub
(
regex_timestamp
,
""
,
strings
)
return
(
my_strings_wo_timeStamp
)
}
policy_costs_pdf
<-
function
(
policy_costs
,
fileName
=
"PolicyCost.pdf"
)
{
...
...
@@ -113,21 +113,21 @@ policy_costs_pdf <- function(policy_costs, fileName="PolicyCost.pdf") {
}
# Check for an object called "source_include". If found, that means, this script
# is being called from another (output.R most likely), and the input variable
s
#
are
already in the environment. If not found,
the input variables are
given
# default values, and made over-writable with command line
values
.
# is being called from another (output.R most likely), and the input variable
#
"outputdirs" is
already in the environment. If not found,
"outputdirs" is
given
# default values, and made over-writable with
the
command line.
if
(
!
exists
(
"source_include"
))
{
# Set default value
outputdirs
<-
c
(
"../../
femulator_hq/remind_runs_lab/base_allT_lab_0point7
_2020-03-
12
_09.3
6.25
"
,
"../../
femulator_hq/remind_runs_lab/base_allT_lab_0point95
_2020-03-
16
_1
5
.3
5.20
"
,
"../../
femulator_hq/remind_runs_lab/base_allT_lab_0point7_2020-03-12_09.36.25
"
,
"../../
femulator_hq/remind_runs_lab/base_allT_lab_0point8
_2020-0
3
-1
2_09.36.24
"
)
outputdirs
<-
c
(
"../../
../output/default
_2020-03-
03
_09.3
8.01
"
,
"../../
../output/default_slim
_2020-03-
03
_1
1
.3
7.51
"
,
"../../
../output/sa_emu_3_2_2020-03-13_16.41.08
"
,
"../../
../output/sa_emu_1_posYIntercept_posSlope
_2020-0
4
-1
4_11.08.07
"
)
# Make over-writtable from command line
lucode
::
readArgs
(
"outputdirs"
)
}
# Check that
the input variable
"outputdirs" has an even number of entries.
# Check that "outputdirs" has an even number of entries.
if
(
length
(
outputdirs
)
%%
2
!=
0
)
{
cat
(
paste0
(
crayon
::
red
(
"\nERROR: "
),
"The number of directories is not even!\n"
))
cat
(
"Remember, the order in which you choose the directories should be:\n"
)
...
...
@@ -141,14 +141,14 @@ pol_gdxs <- paste0(outputdirs[seq(1,length(outputdirs),2)], "/fulldata.gdx")
ref_gdxs
<-
paste0
(
outputdirs
[
seq
(
2
,
length
(
outputdirs
),
2
)],
"/fulldata.gdx"
)
# Get run names
pol_names
<-
get_run_
name
s
(
pol_gdxs
)
ref_names
<-
get_run_
name
s
(
ref_gdxs
)
pol_names
<-
rm_timestamp
(
basename
(
dir
name
(
pol_gdxs
)
))
ref_names
<-
rm_timestamp
(
basename
(
dir
name
(
ref_gdxs
)
))
# Define pol-ref, policyCost pair names
pc_pairs
<-
paste0
(
pol_names
,
"_w.r.t_"
,
ref_names
)
# If scrpit was called from output.R, check with user if the pol-ref pairs
are the
# ones he wanted.
# If
this
scrpit was called from output.R, check with user if the pol-ref pairs
#
are the
ones he wanted.
if
(
exists
(
"source_include"
))
{
cat
(
crayon
::
blue
(
"\nPlease confirm the set-up:\n"
))
cat
(
"From the order with which you selected the directories, the following policy-cost curves will be created:\n"
)
...
...
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