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
fbe32017
Commit
fbe32017
authored
3 months ago
by
Marco Matthies
Browse files
Options
Downloads
Patches
Plain Diff
Implement Base.show for the model landscape (Matrix{Pixel})
parent
f8622f0d
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
Project.toml
+1
-0
1 addition, 0 deletions
Project.toml
src/world/landscape.jl
+36
-0
36 additions, 0 deletions
src/world/landscape.jl
test/landscape_tests.jl
+7
-0
7 additions, 0 deletions
test/landscape_tests.jl
with
44 additions
and
0 deletions
Project.toml
+
1
−
0
View file @
fbe32017
...
@@ -17,6 +17,7 @@ GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
...
@@ -17,6 +17,7 @@ GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
Logging
=
"56ddb016-857b-54e1-b83d-db4d58db5568"
Logging
=
"56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras
=
"e6f89c97-d47a-5376-807f-9c37f3926c36"
LoggingExtras
=
"e6f89c97-d47a-5376-807f-9c37f3926c36"
Pkg
=
"44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Pkg
=
"44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Printf
=
"de0858da-6303-5e67-8744-51eddeeeb8d7"
Random
=
"9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Random
=
"9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Serialization
=
"9e88b42a-f829-5b0c-bbe9-9e923198166b"
Serialization
=
"9e88b42a-f829-5b0c-bbe9-9e923198166b"
StableRNGs
=
"860ef19b-820b-49d6-a774-d7a799459cd3"
StableRNGs
=
"860ef19b-820b-49d6-a774-d7a799459cd3"
...
...
This diff is collapsed.
Click to expand it.
src/world/landscape.jl
+
36
−
0
View file @
fbe32017
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
### This file manages the landscape maps that underlie the model.
### This file manages the landscape maps that underlie the model.
###
###
using
Printf
## IMPORTANT: do not change the order of this enum, or initlandscape() will break!
## IMPORTANT: do not change the order of this enum, or initlandscape() will break!
"The land cover classes encoded in the Mundialis Sentinel data."
"The land cover classes encoded in the Mundialis Sentinel data."
@enum
LandCover
nodata
forest
grass
water
builtup
soil
agriculture
@enum
LandCover
nodata
forest
grass
water
builtup
soil
agriculture
...
@@ -29,6 +31,40 @@ Pixel(landcover::LandCover, fieldid::Union{Missing,Int64}) =
...
@@ -29,6 +31,40 @@ Pixel(landcover::LandCover, fieldid::Union{Missing,Int64}) =
Pixel
(
landcover
,
fieldid
,
Vector
{
Management
}(),
Vector
{
Int64
}(),
Vector
{
Int64
}())
Pixel
(
landcover
,
fieldid
,
Vector
{
Management
}(),
Vector
{
Int64
}(),
Vector
{
Int64
}())
Pixel
(
landcover
::
LandCover
)
=
Pixel
(
landcover
,
missing
)
Pixel
(
landcover
::
LandCover
)
=
Pixel
(
landcover
,
missing
)
function
Base.show
(
io
::
IO
,
::
MIME
"text/plain"
,
mat
::
T
)
where
T
<:
AbstractMatrix
{
Pixel
}
max_fieldid
=
maximum
(
skipmissing
(
map
(
x
->
getfield
(
x
,
:
fieldid
),
mat
));
init
=
0
)
println
(
io
,
"Matrix{Pixel}:"
)
println
(
io
,
" LandCover:"
)
nrow
,
ncol
=
size
(
mat
)
for
i
in
axes
(
mat
,
1
)
print
(
io
,
" "
)
for
j
in
axes
(
mat
,
2
)
charid
=
uppercase
(
first
(
string
(
mat
[
i
,
j
]
.
landcover
)))
fieldid
=
if
ismissing
(
mat
[
i
,
j
]
.
fieldid
)
repeat
(
" "
,
ndigits
(
max_fieldid
))
else
@sprintf
(
"%*s"
,
ndigits
(
max_fieldid
),
mat
[
i
,
j
]
.
fieldid
)
end
print
(
io
,
charid
,
fieldid
,
" "
)
end
println
(
io
)
end
# print legend
legend
=
join
(
map
(
x
->
"
$
(uppercase(first(string(x)))) =
$
x"
,
instances
(
Persefone
.
LandCover
)),
", "
)
println
(
io
,
"Legend: "
,
legend
)
# print number of unique animals, events, territories
nanimals
=
length
(
unique
(
reduce
(
vcat
,
map
(
x
->
getfield
(
x
,
:
animals
),
mat
))))
nevents
=
length
(
unique
(
reduce
(
vcat
,
map
(
x
->
getfield
(
x
,
:
events
),
mat
))))
nterritories
=
length
(
unique
(
reduce
(
vcat
,
map
(
x
->
getfield
(
x
,
:
territories
),
mat
))))
println
(
io
,
"Num. unique animals : "
,
nanimals
)
println
(
io
,
"Num. unique events : "
,
nevents
)
print
(
io
,
"Num. unique territories: "
,
nterritories
)
# no newline on last line of output
return
nothing
end
"""
"""
FarmEvent
FarmEvent
...
...
This diff is collapsed.
Click to expand it.
test/landscape_tests.jl
+
7
−
0
View file @
fbe32017
...
@@ -19,6 +19,13 @@
...
@@ -19,6 +19,13 @@
@test
length
(
Ps
.
farmplot
((
800
,
800
),
model
)
.
pixels
)
==
4049
@test
length
(
Ps
.
farmplot
((
800
,
800
),
model
)
.
pixels
)
==
4049
end
end
@testset
"Utility functions"
begin
model
=
inittestmodel
()
iobuf
=
IOBuffer
()
show
(
iobuf
,
MIME
"text/plain"
(),
model
.
landscape
)
@test
length
(
take!
(
iobuf
))
>
0
end
@testset
"Event system"
begin
@testset
"Event system"
begin
model
=
inittestmodel
()
model
=
inittestmodel
()
createevent!
(
model
,
[(
1
,
1
),
(
1
,
2
),
(
1
,
3
),
(
2
,
1
),
(
2
,
3
)],
Ps
.
tillage
)
createevent!
(
model
,
[(
1
,
1
),
(
1
,
2
),
(
1
,
3
),
(
2
,
1
),
(
2
,
3
)],
Ps
.
tillage
)
...
...
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