Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Persefone.jl
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Persefone
Persefone.jl
Commits
aa25f0e9
Commit
aa25f0e9
authored
2 years ago
by
xo30xoqa
Browse files
Options
Downloads
Patches
Plain Diff
Wrote the `setupdatadir()` function, changed `setting()` to `param()`
parent
f1637a80
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/core/input.jl
+21
-9
21 additions, 9 deletions
src/core/input.jl
src/core/output.jl
+40
-0
40 additions, 0 deletions
src/core/output.jl
src/core/simulation.jl
+3
-3
3 additions, 3 deletions
src/core/simulation.jl
with
64 additions
and
12 deletions
src/core/input.jl
+
21
−
9
View file @
aa25f0e9
...
...
@@ -3,7 +3,7 @@
### This file includes functions for configuring the model and reading in map files.
###
## Note:
some
of this code was adapted from the GeMM model
## Note:
much
of this code was adapted from the GeMM model
by Leidinger et al.
## (https://github.com/CCTB-Ecomods/gemm/blob/master/src/input.jl)
let
settings
::
Dict
{
String
,
Dict
{
String
,
Any
}}
...
...
@@ -15,15 +15,27 @@ let settings::Dict{String, Dict{String, Any}}
global
function
initsettings
(
configfile
::
String
)
settings
=
getsettings
(
configfile
)
end
"""
setting
(domain
,
param)
param
(domainparam)
Return a configuration parameter from the global settings.
Domain may be any of "
core
", "
ecology
", "
farm
", or "
crop
".
The argument should be in the form `"
<
domain
>.<
parameter
>
"`,
for example `param("
core
.
outdir
")`. Possible values for
<domain> are "
core
", "
ecology
", "
farm
", or "
crop
".
"""
global
function
param
(
domainparam
::
String
)
domain
,
paramname
=
split
(
domainparam
,
"."
)
settings
[
domain
][
paramname
]
end
"""
astoml(io)
Print all settings in TOML format to the given output stream.
"""
global
function
setting
(
domain
::
String
,
param
::
String
)
settings
[
domain
][
param
]
global
function
astoml
(
stream
::
IO
=
stdout
)
TOML
.
print
(
stream
,
settings
)
end
end
...
...
@@ -94,11 +106,11 @@ function parsecommandline()
arg_type
=
String
required
=
false
"--loglevel"
,
"-l"
help
=
"
amount of logging
:
\"
debug
\"
,
\"
normal
\"
, or
\"
errors
\"
"
help
=
"
verbosity
:
\"
debug
\"
,
\"
normal
\"
, or
\"
errors
\"
"
arg_type
=
String
required
=
false
"--quietmode"
,
"-q"
help
=
"
quiet mode. D
on't print output to screen
.
"
help
=
"
d
on't print output to screen"
action
=
:
store_true
"--runtime"
,
"-r"
help
=
"duration in days that the simulation will run"
...
...
@@ -118,5 +130,5 @@ end
Read in a TIFF map file and return it as an array.
"""
function
readtiffmapfile
(
filename
)
#TODO
#TODO
this requires GeoArrays
end
This diff is collapsed.
Click to expand it.
src/core/output.jl
+
40
−
0
View file @
aa25f0e9
### Persephone - a socio-economic-ecological model of European agricultural landscapes.
###
### This file includes functions for saving the model output.
###
## Note: some of this code was adapted from the GeMM model by Leidinger et al.
## (https://github.com/CCTB-Ecomods/gemm/blob/master/src/output.jl)
"""
setupdatadir()
Creates the output directory and copies relevant files into it.
"""
function
setupdatadir
()
# Check whether the output directory already exists and handle conflicts
if
isdir
(
param
(
"core.outdir"
))
@warn
"The chosen output directory
$
(param("
core
.
outdir
")) already exists."
println
(
"Type 'yes' to overwrite this directory. Otherwise, the simulation will abort."
)
print
(
"Overwrite? "
)
answer
=
readline
()
(
answer
!=
"yes"
)
&&
Base
.
error
(
"Output directory exists, will not overwrite. Aborting."
)
else
mkpath
(
param
(
"core.outdir"
))
end
@info
"Setting up output directory
$
(param("
core
.
outdir
"))"
# Export a copy of the current parameter settings to the output folder.
# This can be used to replicate this exact run in future, and also
# records the current time and git commit.
open
(
joinpath
(
param
(
"core.outdir"
),
basename
(
param
(
"core.configfile"
))),
"w"
)
do
f
println
(
f
,
"#
\n
# --- Persephone configuration parameters ---"
)
println
(
f
,
"# This file was generated automatically."
)
println
(
f
,
"# Simulation run on
$
(string(Dates.format(Dates.now(), "
d
u
Y
HH
:
MM
:
SS
"))),"
)
println
(
f
,
"# with git commit
$
(read(`git rev-parse HEAD`, String))#
\n
"
)
astoml
(
f
)
end
# Copy the map file to the output folder
mapf
=
param
(
"core.mapfile"
)
!
(
isfile
(
mapf
))
&&
@error
"The map file
$(mapf)
doesn't exist."
cp
(
mapf
,
joinpath
(
param
(
"core.outdir"
),
basename
(
mapf
)),
force
=
true
)
end
This diff is collapsed.
Click to expand it.
src/core/simulation.jl
+
3
−
3
View file @
aa25f0e9
...
...
@@ -5,8 +5,8 @@
function
initsim
(
config
::
String
)
initsettings
(
config
)
Random
.
seed!
(
setting
(
"core
"
,
"
seed"
))
#TODO create output folder
Random
.
seed!
(
param
(
"core
.
seed"
))
setupdatadir
()
#TODO create world
end
...
...
@@ -22,7 +22,7 @@ end
function
simulate
(
config
::
String
=
paramfile
)
initsim
(
config
)
for
day
in
1
:
setting
(
"core
"
,
"
runtime"
)
for
day
in
1
:
param
(
"core
.
runtime"
)
stepsim
()
end
finalisesim
()
...
...
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