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
df23cc87
Commit
df23cc87
authored
3 months ago
by
Marco Matthies
Browse files
Options
Downloads
Patches
Plain Diff
Fix AquaCrop cropfield setup when there are not enough data points
parent
c912735d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/crop/aquacrop.jl
+18
-7
18 additions, 7 deletions
src/crop/aquacrop.jl
test/crop_tests.jl
+1
-1
1 addition, 1 deletion
test/crop_tests.jl
with
19 additions
and
8 deletions
src/crop/aquacrop.jl
+
18
−
7
View file @
df23cc87
...
@@ -108,6 +108,8 @@ end
...
@@ -108,6 +108,8 @@ end
function
make_aquacrop_cropfield
(
croptype
::
CropType
,
function
make_aquacrop_cropfield
(
croptype
::
CropType
,
model
::
SimulationModel
,
model
::
SimulationModel
,
soiltype
::
SoilType
)
soiltype
::
SoilType
)
# TODO: put this constant somewhere else?
MIN_DATASET_LEN
=
366
# TODO: get this mapping for soil types from a CSV file?
# TODO: get this mapping for soil types from a CSV file?
soiltype_to_aquacrop
=
Dict
(
soiltype
=>
replace
(
string
(
soiltype
),
"_"
=>
" "
)
soiltype_to_aquacrop
=
Dict
(
soiltype
=>
replace
(
string
(
soiltype
),
"_"
=>
" "
)
for
soiltype
in
instances
(
SoilType
))
for
soiltype
in
instances
(
SoilType
))
...
@@ -118,10 +120,19 @@ function make_aquacrop_cropfield(croptype::CropType,
...
@@ -118,10 +120,19 @@ function make_aquacrop_cropfield(croptype::CropType,
start_daynum
=
daynumber
(
model
.
weather
,
start_date
)
start_daynum
=
daynumber
(
model
.
weather
,
start_date
)
end_daynum
=
daynumber
(
model
.
weather
,
end_date
)
end_daynum
=
daynumber
(
model
.
weather
,
end_date
)
dayrange
=
start_daynum
:
end_daynum
dayrange
=
start_daynum
:
end_daynum
input_Tmin
=
@view
model
.
weather
.
mintemp
[
dayrange
]
numdays
=
length
(
dayrange
)
input_Tmax
=
@view
model
.
weather
.
maxtemp
[
dayrange
]
if
numdays
>=
MIN_DATASET_LEN
input_ETo
=
@view
model
.
weather
.
evapotranspiration
[
dayrange
]
input_Tmin
=
@view
model
.
weather
.
mintemp
[
dayrange
]
input_Rain
=
@view
model
.
weather
.
precipitation
[
dayrange
]
input_Tmax
=
@view
model
.
weather
.
maxtemp
[
dayrange
]
input_ETo
=
@view
model
.
weather
.
evapotranspiration
[
dayrange
]
input_Rain
=
@view
model
.
weather
.
precipitation
[
dayrange
]
else
# Append fake data so that there are always more than MIN_DATASET_LEN datapoints
input_Tmin
=
append!
(
model
.
weather
.
mintemp
[
dayrange
],
fill
(
10.0
,
MIN_DATASET_LEN
-
numdays
))
input_Tmax
=
append!
(
model
.
weather
.
maxtemp
[
dayrange
],
fill
(
16.0
,
MIN_DATASET_LEN
-
numdays
))
input_ETo
=
append!
(
model
.
weather
.
evapotranspiration
[
dayrange
],
fill
(
1.0
,
MIN_DATASET_LEN
-
numdays
))
input_Rain
=
append!
(
model
.
weather
.
precipitation
[
dayrange
],
fill
(
1.0
,
MIN_DATASET_LEN
-
numdays
))
end
# Generate the keyword object for the AquaCrop simulation
# Generate the keyword object for the AquaCrop simulation
kwargs
=
(
kwargs
=
(
...
@@ -163,8 +174,8 @@ mutable struct CropState <: AbstractCropState
...
@@ -163,8 +174,8 @@ mutable struct CropState <: AbstractCropState
soiltype
::
SoilType
soiltype
::
SoilType
cropstate
::
AquaCrop
.
AquaCropField
cropstate
::
AquaCrop
.
AquaCropField
function
CropState
(
croptype
::
CropType
,
soiltype
::
SoilType
,
function
CropState
(
croptype
::
CropType
,
model
::
SimulationModel
,
model
::
SimulationModel
,
height
::
Tlength
=
0.0
cm
)
soiltype
::
SoilType
,
height
::
Tlength
=
0.0
cm
)
aquacrop_cropfield
=
make_aquacrop_cropfield
(
croptype
,
model
,
soiltype
)
aquacrop_cropfield
=
make_aquacrop_cropfield
(
croptype
,
model
,
soiltype
)
return
new
(
croptype
,
height
,
soiltype
,
aquacrop_cropfield
)
return
new
(
croptype
,
height
,
soiltype
,
aquacrop_cropfield
)
end
end
...
@@ -180,7 +191,7 @@ function isharvestable(cs::CropState)
...
@@ -180,7 +191,7 @@ function isharvestable(cs::CropState)
return
!
ismissing
(
stage
)
&&
stage
==
0
return
!
ismissing
(
stage
)
&&
stage
==
0
end
end
makecropstate
(
croptype
::
CropType
,
model
::
SimulationModel
,
soiltype
::
SoilType
)
=
makecropstate
(
croptype
::
CropType
,
model
::
SimulationModel
,
soiltype
::
SoilType
)
=
CropState
(
croptype
,
soiltype
,
model
)
CropState
(
croptype
,
model
,
soiltype
)
function
setsoiltype!
(
cs
::
CropState
,
soiltype
::
SoilType
)
function
setsoiltype!
(
cs
::
CropState
,
soiltype
::
SoilType
)
# TODO: this does not affect the actual soil type of the state of
# TODO: this does not affect the actual soil type of the state of
# the aquacrop simulation
# the aquacrop simulation
...
...
This diff is collapsed.
Click to expand it.
test/crop_tests.jl
+
1
−
1
View file @
df23cc87
...
@@ -65,7 +65,7 @@ end
...
@@ -65,7 +65,7 @@ end
pixels
=
[(
0
,
0
)]
pixels
=
[(
0
,
0
)]
farmer
=
0
farmer
=
0
soiltype
=
Ps
.
sand
soiltype
=
Ps
.
sand
fp
=
FarmPlot
(
id
,
pixels
,
farmer
,
soiltype
,
PsAC
.
CropState
(
ct
,
soiltype
,
model
))
fp
=
FarmPlot
(
id
,
pixels
,
farmer
,
soiltype
,
PsAC
.
CropState
(
ct
,
model
,
soiltype
))
@test
fp
isa
FarmPlot
@test
fp
isa
FarmPlot
@test
fp
.
cropstate
isa
PsAC
.
CropState
@test
fp
.
cropstate
isa
PsAC
.
CropState
@test
croptype
(
fp
)
isa
PsAC
.
CropType
@test
croptype
(
fp
)
isa
PsAC
.
CropType
...
...
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