Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Persefone desktop
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
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 desktop
Commits
498dc494
Commit
498dc494
authored
1 year ago
by
xo30xoqa
Browse files
Options
Downloads
Patches
Plain Diff
Fixed the memory leak!! :D
closes #12
parent
6cb1358d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/GUI.jl
+32
-34
32 additions, 34 deletions
src/GUI.jl
src/main.qml
+1
-1
1 addition, 1 deletion
src/main.qml
src/variables.jl
+5
-5
5 additions, 5 deletions
src/variables.jl
with
38 additions
and
40 deletions
src/GUI.jl
+
32
−
34
View file @
498dc494
...
...
@@ -50,44 +50,42 @@ function saveoutput()
end
function
render_map
(
screen
)
global
model
,
mapimage
,
landcovermap
global
model
,
mapimage
launching
[]
&&
return
display
(
screen
,
Figure
()
.
scene
)
# blank screen at launch
println
(
"Updating map"
)
#FIXME repeatedly calling `visualisemap` causes the memory leak
# (regardless of whether individuals are plotted or just the map)
#mapimage[] = visualisemap(model, date[]-Day(1), landcovermap)
empty!
(
mapimage
[])
mapimage
[]
=
vismap
(
model
,
date
[]
-
Day
(
1
),
landcovermap
)
display
(
screen
,
mapimage
[])
end
function
vismap
(
model
::
AgentBasedModel
,
date
=
nothing
,
landcover
=
nothing
)
# load and plot the map
# Note: if the landcover map is supplied, it needs to be rotr90'ed
isnothing
(
landcover
)
&&
(
landcover
=
rotr90
(
load
(
@param
(
world
.
landcovermap
))))
f
=
Figure
()
ax
=
Axis
(
f
[
1
,
1
])
hidedecorations!
(
ax
)
image!
(
f
[
1
,
1
],
landcover
)
ax
.
aspect
=
DataAspect
()
# check if there are individuals and plot them
inds
=
model
.
datatables
[
"individuals"
]
if
iszero
(
size
(
inds
)[
1
])
@debug
"No individual data to map"
return
f
.
scene
end
isnothing
(
date
)
&&
(
date
=
inds
.
Date
[
end
])
for
s
in
unique
(
inds
.
Species
)
points
=
@select
!
(
@subset
(
inds
,
:
Species
.==
s
,
:
Date
.==
date
),
:
X
,
:
Y
)
# The origin in Makie is in the bottom-left rather than in the top-left as
# on the model map, so we have to invert the Y coordinates
@transform
!
(
points
,
:
Y
=
size
(
model
.
landscape
)[
2
]
.-
:
Y
)
scatter!
(
f
[
1
,
1
],
Matrix
{
Float32
}(
points
),
markersize
=
8
)
if
isnothing
(
mapimage
)
# I'm reimplementing `visualisemap()` here, because I need to use Observables
# to keep the figure updated (if I use multiple plots, I get a memory leak,
# see here: https://github.com/MakieOrg/Makie.jl/issues/795)
landcover
=
rotr90
(
load
(
@param
(
world
.
landcovermap
)))
mapimage
=
Figure
()
ax
=
Axis
(
mapimage
[
1
,
1
])
hidedecorations!
(
ax
)
image!
(
mapimage
[
1
,
1
],
landcover
)
ax
.
aspect
=
DataAspect
()
inds
=
@lift
(
@transform
!
(
@subset
(
model
.
datatables
[
"individuals"
],
:
Date
.==
$
date
-
Day
(
1
)),
:
Y
=
size
(
landcover
)[
2
]
.-
:
Y
))
on
(
inds
)
do
i
println
(
"Updated `inds`, length
$
(size(inds[])[1])"
)
end
if
size
(
inds
[])[
1
]
>
0
update_theme!
(
palette
=
(
color
=
cgrad
(
:
seaborn_bright
,
length
(
@param
(
nature
.
targetspecies
))),),
cycle
=
[
:
color
])
for
s
in
@param
(
nature
.
targetspecies
)
points
=
@lift
(
Matrix
{
Float32
}(
@select
!
(
@subset
(
$
inds
,
:
Species
.==
s
),
:
X
,
:
Y
)))
on
(
points
)
do
i
println
(
"Updated `points` of species
$
s"
)
end
scatter!
(
mapimage
[
1
,
1
],
points
,
markersize
=
8
)
end
end
end
f
.
scene
display
(
screen
,
mapimage
.
scene
)
end
function
render_plot
(
screen
)
#FIXME Y axis is too small -> lines not shown?
global
model
...
...
This diff is collapsed.
Click to expand it.
src/main.qml
+
1
−
1
View file @
498dc494
...
...
@@ -204,7 +204,7 @@ Distributed under the MIT license."
onUpdateMakie
:
{
dateText
.
text
=
Julia
.
datestring
();
mapviewport
.
update
();
//
plotviewport.update();
plotviewport
.
update
();
}
signal
showSplash
()
onShowSplash
:
{
...
...
This diff is collapsed.
Click to expand it.
src/variables.jl
+
5
−
5
View file @
498dc494
### PersefoneDesktop - a GUI to the Persefone model of agriculture and ecosystems
###
### This file contains all globals and Observables.
### This file contains all global
variable
s and Observables.
###
## GUI
p
ar
ameter
s
## GUI
v
ar
iable
s
global
model
=
nothing
global
landcovermap
=
nothing
global
runsimulation
=
()
->
nothing
#
global newsimulation = () -> nothing
global
newsimulation
=
()
->
nothing
global
timer
=
nothing
global
mapimage
=
nothing
global
plotimage
=
nothing
const
configfile
=
Observable
(
"guiparams.toml"
)
const
launching
=
Observable
(
false
)
...
...
@@ -21,7 +22,6 @@ const progress = Observable(0.0)
const
delay
=
Observable
(
0.5
)
const
runbuttontext
=
Observable
(
">>"
)
const
runbuttontip
=
Observable
(
"Run"
)
const
mapimage
=
Observable
(
Figure
()
.
scene
)
## configuration parameters
...
...
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