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
84b933f8
Commit
84b933f8
authored
5 months ago
by
Marco Matthies
Browse files
Options
Downloads
Patches
Plain Diff
AquaCrop: wrap interface code in WrapAquaCrop submodule
parent
e5e3a07a
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/crop/aquacrop.jl
+25
-0
25 additions, 0 deletions
src/crop/aquacrop.jl
src/crop/cropmodels.jl
+4
-4
4 additions, 4 deletions
src/crop/cropmodels.jl
test/crop_tests.jl
+5
-4
5 additions, 4 deletions
test/crop_tests.jl
with
34 additions
and
8 deletions
src/crop/aquacrop.jl
+
25
−
0
View file @
84b933f8
module
WrapAquaCrop
# Persefone.jl wrapper for AquaCrop.jl
# Use different name from `AquaCrop` to avoid name clash
import
AquaCrop
import
AquaCrop
using
Persefone
:
AnnualDate
,
cm
,
SimulationModel
import
Persefone
:
stepagent!
,
croptype
,
cropname
,
cropheight
,
cropcover
,
cropyield
,
sow!
,
harvest!
,
isharvestable
using
Unitful
:
@u_str
# We can't use Length{Float64} as that is a Union type
# We can't use Length{Float64} as that is a Union type
const
Tlength
=
typeof
(
1.0
cm
)
const
Tlength
=
typeof
(
1.0
cm
)
...
@@ -68,3 +91,5 @@ function harvest!(cs::AquaCropState, model::SimulationModel)
...
@@ -68,3 +91,5 @@ function harvest!(cs::AquaCropState, model::SimulationModel)
# TODO: implement this
# TODO: implement this
return
0.0
u
"g/m^2"
return
0.0
u
"g/m^2"
end
end
end
# module WrapAquaCrop
This diff is collapsed.
Click to expand it.
src/crop/cropmodels.jl
+
4
−
4
View file @
84b933f8
...
@@ -21,11 +21,11 @@ function initcropmodel(cropmodel::AbstractString, cropdirectory::AbstractString)
...
@@ -21,11 +21,11 @@ function initcropmodel(cropmodel::AbstractString, cropdirectory::AbstractString)
crops
=
Dict
(
name
=>
SimpleCrop
.
CropType
(
ct
.
name
,
ct
.
group
,
ct
.
minsowdate
,
ct
.
maxsowdate
)
crops
=
Dict
(
name
=>
SimpleCrop
.
CropType
(
ct
.
name
,
ct
.
group
,
ct
.
minsowdate
,
ct
.
maxsowdate
)
for
(
name
,
ct
)
in
crops_almass
)
for
(
name
,
ct
)
in
crops_almass
)
elseif
cropmodel
==
"aquacrop"
elseif
cropmodel
==
"aquacrop"
Tcroptype
=
AquaCropType
Tcroptype
=
WrapAquaCrop
.
AquaCropType
Tcropstate
=
AquaCropState
Tcropstate
=
WrapAquaCrop
.
AquaCropState
# TODO: temporarily using ALMaSS crop types
# TODO: temporarily using ALMaSS crop types
crops_almass
=
ALMaSS
.
readcropparameters
(
cropdirectory
)
crops_almass
=
ALMaSS
.
readcropparameters
(
cropdirectory
)
crops
=
Dict
(
name
=>
AquaCropType
(
ct
.
name
,
ct
.
group
,
ct
.
minsowdate
,
ct
.
maxsowdate
)
crops
=
Dict
(
name
=>
WrapAquaCrop
.
AquaCropType
(
ct
.
name
,
ct
.
group
,
ct
.
minsowdate
,
ct
.
maxsowdate
)
for
(
name
,
ct
)
in
crops_almass
)
for
(
name
,
ct
)
in
crops_almass
)
else
else
error
(
"initcropmodel: no implementation for crop model '
$
cropmodel'"
)
error
(
"initcropmodel: no implementation for crop model '
$
cropmodel'"
)
...
@@ -81,7 +81,7 @@ function makecropstate(model::SimulationModel)
...
@@ -81,7 +81,7 @@ function makecropstate(model::SimulationModel)
0.0
m
0.0
m
)
)
elseif
@param
(
crop
.
cropmodel
)
==
"aquacrop"
elseif
@param
(
crop
.
cropmodel
)
==
"aquacrop"
cs
=
AquaCropState
(
model
.
crops
[
"natural grass"
],
0.0
cm
)
cs
=
WrapAquaCrop
.
AquaCropState
(
model
.
crops
[
"natural grass"
],
0.0
cm
)
else
else
Base
.
error
(
"Unhandled crop model '
$
(@param(crop.cropmodel))' in makecropstate()."
)
Base
.
error
(
"Unhandled crop model '
$
(@param(crop.cropmodel))' in makecropstate()."
)
end
end
...
...
This diff is collapsed.
Click to expand it.
test/crop_tests.jl
+
5
−
4
View file @
84b933f8
...
@@ -57,14 +57,15 @@ end
...
@@ -57,14 +57,15 @@ end
end
end
@testset
"Submodule AquaCrop"
begin
@testset
"Submodule AquaCrop"
begin
ct
=
Ps
.
AquaCropType
(
"olive tree"
,
"no_crop_group"
,
AnnualDate
(
4
,
1
),
AnnualDate
(
5
,
1
))
PsAC
=
Ps
.
WrapAquaCrop
ct
=
PsAC
.
AquaCropType
(
"olive tree"
,
"no_crop_group"
,
AnnualDate
(
4
,
1
),
AnnualDate
(
5
,
1
))
id
=
0
id
=
0
pixels
=
[(
0
,
0
)]
pixels
=
[(
0
,
0
)]
farmer
=
0
farmer
=
0
fp
=
FarmPlot
(
id
,
pixels
,
farmer
,
Ps
.
AquaCropState
(
ct
))
fp
=
FarmPlot
(
id
,
pixels
,
farmer
,
Ps
AC
.
AquaCropState
(
ct
))
@test
fp
isa
FarmPlot
@test
fp
isa
FarmPlot
@test
fp
isa
FarmPlot
{
Ps
.
AquaCropState
}
@test
fp
isa
FarmPlot
{
Ps
AC
.
AquaCropState
}
@test
croptype
(
fp
)
isa
Ps
.
AquaCropType
@test
croptype
(
fp
)
isa
Ps
AC
.
AquaCropType
@test
cropname
(
fp
)
isa
String
@test
cropname
(
fp
)
isa
String
@test
cropheight
(
fp
)
isa
Length
{
Float64
}
@test
cropheight
(
fp
)
isa
Length
{
Float64
}
@test
cropcover
(
fp
)
isa
Float64
@test
cropcover
(
fp
)
isa
Float64
...
...
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