Skip to content
Snippets Groups Projects
Commit 6cb1358d authored by xo30xoqa's avatar xo30xoqa
Browse files

Can now save output to file

closes #10
parent c01b89cc
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
julia_version = "1.9.3" julia_version = "1.9.3"
manifest_format = "2.0" manifest_format = "2.0"
project_hash = "9170528eea0c39d465f2660dd18c961dc469bd3c" project_hash = "75d54abf5eeb3f6918bd64a71e5b724e43cc9f03"
[[deps.AbstractFFTs]] [[deps.AbstractFFTs]]
deps = ["LinearAlgebra"] deps = ["LinearAlgebra"]
...@@ -1411,11 +1411,11 @@ version = "2.7.2" ...@@ -1411,11 +1411,11 @@ version = "2.7.2"
[[deps.Persefone]] [[deps.Persefone]]
deps = ["Agents", "ArgParse", "CSV", "CairoMakie", "DataFrames", "DataFramesMeta", "Dates", "Distributed", "FileIO", "GeoArrays", "ImageMagick", "Logging", "LoggingExtras", "Pkg", "Random", "Serialization", "StableRNGs", "StatsBase", "TOML", "Test", "TiffImages"] deps = ["Agents", "ArgParse", "CSV", "CairoMakie", "DataFrames", "DataFramesMeta", "Dates", "Distributed", "FileIO", "GeoArrays", "ImageMagick", "Logging", "LoggingExtras", "Pkg", "Random", "Serialization", "StableRNGs", "StatsBase", "TOML", "Test", "TiffImages"]
git-tree-sha1 = "389b532a6c7343ce8a8c5842a7949f98330b4d49" git-tree-sha1 = "88ace44808fa1050135c13c31baec6c94ba14f38"
repo-rev = "master" repo-rev = "master"
repo-url = "../model" repo-url = "../model"
uuid = "039acd1d-2a07-4b33-b082-83a1ff0fd136" uuid = "039acd1d-2a07-4b33-b082-83a1ff0fd136"
version = "0.3.2" version = "0.3.5"
[[deps.Pixman_jll]] [[deps.Pixman_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LLVMOpenMP_jll", "Libdl"] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "LLVMOpenMP_jll", "Libdl"]
......
...@@ -5,6 +5,7 @@ version = "0.1.0" ...@@ -5,6 +5,7 @@ version = "0.1.0"
[deps] [deps]
Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4" CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964" DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
function loadsimulation(filename) function loadsimulation(filename)
global model global model, landcovermap
@emit showSplash() @emit showSplash()
fn = convert(filename, String) fn = convert(filename, String)
startswith(fn, "file://") && (fn = fn[8:end]) startswith(fn, "file://") && (fn = fn[8:end])
...@@ -36,13 +36,23 @@ function Base.convert(s::QString, ::Type{<:AbstractString}) ...@@ -36,13 +36,23 @@ function Base.convert(s::QString, ::Type{<:AbstractString})
s2 s2
end end
#TODO saveoutput() function saveoutput()
global model
println("Saving output to file")
if !@param(core.csvoutput) #override preference
for output in model.dataoutputs
CSV.write(joinpath(@param(core.outdir), output.name*".csv"),
model.datatables[output.name])
end
end
visualiseoutput(model)
GLMakie.activate!() # visualiseoutput() switches to Cairo
end
function render_map(screen) function render_map(screen)
global model, mapimage, landcovermap global model, mapimage, landcovermap
launching[] && return display(screen, Figure().scene) # blank screen at launch launching[] && return display(screen, Figure().scene) # blank screen at launch
println("Updating map") println("Updating map")
#FIXME I'm not sure date-1 is the real fix
#FIXME repeatedly calling `visualisemap` causes the memory leak #FIXME repeatedly calling `visualisemap` causes the memory leak
# (regardless of whether individuals are plotted or just the map) # (regardless of whether individuals are plotted or just the map)
#mapimage[] = visualisemap(model, date[]-Day(1), landcovermap) #mapimage[] = visualisemap(model, date[]-Day(1), landcovermap)
...@@ -54,7 +64,7 @@ end ...@@ -54,7 +64,7 @@ end
function vismap(model::AgentBasedModel,date=nothing,landcover=nothing) function vismap(model::AgentBasedModel,date=nothing,landcover=nothing)
# load and plot the map # load and plot the map
# Note: if the landcover map is supplied, it needs to be rotr90'ed # Note: if the landcover map is supplied, it needs to be rotr90'ed
isnothing(landcover) && (landcover = load(@param(world.landcovermap))) isnothing(landcover) && (landcover = rotr90(load(@param(world.landcovermap))))
f = Figure() f = Figure()
ax = Axis(f[1,1]) ax = Axis(f[1,1])
hidedecorations!(ax) hidedecorations!(ax)
...@@ -79,7 +89,7 @@ function vismap(model::AgentBasedModel,date=nothing,landcover=nothing) ...@@ -79,7 +89,7 @@ function vismap(model::AgentBasedModel,date=nothing,landcover=nothing)
end end
function render_plot(screen) function render_plot(screen)
#FIXME causes segfault when called during a simulation? #FIXME Y axis is too small -> lines not shown?
global model global model
launching[] && return display(screen, Figure().scene) # blank screen at launch launching[] && return display(screen, Figure().scene) # blank screen at launch
println("Updating plot") println("Updating plot")
...@@ -121,6 +131,7 @@ function activateqmlfunctions() ...@@ -121,6 +131,7 @@ function activateqmlfunctions()
@qmlfunction previousstep @qmlfunction previousstep
@qmlfunction datestring @qmlfunction datestring
@qmlfunction writeconfig @qmlfunction writeconfig
@qmlfunction saveoutput
end end
""" """
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
module PersefoneDesktop module PersefoneDesktop
using using
CSV,
QML, QML,
TOML, TOML,
Dates, Dates,
......
...@@ -5,16 +5,17 @@ ...@@ -5,16 +5,17 @@
@resumable function createlaunchfunction() @resumable function createlaunchfunction()
global model, landcovermap global model, landcovermap
Ps = Persefone
running[] = false running[] = false
progress[] = 0.0 progress[] = 0.0
@yield 1 @yield 1
model = initialise(configfile[]) model = initialise(configfile[])
@yield 1 @yield 1
model.date -= Day(1)
Persefone.outputdata(model, true) # record data before run starts
model.date += Day(1)
landcovermap = rotr90(load(@param(world.landcovermap))) landcovermap = rotr90(load(@param(world.landcovermap)))
date[] = model.date date[] = model.date
launching[] = false launching[] = false
println("Model initialised (resumable).")
end end
function nextstep() function nextstep()
......
...@@ -30,15 +30,11 @@ ApplicationWindow { ...@@ -30,15 +30,11 @@ ApplicationWindow {
} }
Action { Action {
text: "&Load Saved State" text: "&Load Saved State"
onTriggered: { onTriggered: { loadFileChooser.open() }
loadFileChooser.open()
}
} }
Action { Action {
text: "&Save Current State" text: "&Save Current State"
onTriggered: { onTriggered: { saveFileChooser.open() }
saveFileChooser.open()
}
} }
MenuSeparator { } MenuSeparator { }
Action { Action {
...@@ -52,8 +48,10 @@ ApplicationWindow { ...@@ -52,8 +48,10 @@ ApplicationWindow {
text: "Show &Population Graph" text: "Show &Population Graph"
onTriggered: { populationGraph.visible = true } onTriggered: { populationGraph.visible = true }
} }
Action { text: "Save &Graphical Output" } Action {
Action { text: "Save &CSV Output" } text: "Save &Simulation Output"
onTriggered: { Julia.saveoutput() }
}
} }
Menu { Menu {
title: "&Help" title: "&Help"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment