Skip to content

Commit f0e97f3

Browse files
committed
Update PlantBiophysics variables names See VEZY/PlantBiophysics.jl#63
1 parent a3abf9e commit f0e97f3

9 files changed

Lines changed: 224 additions & 229 deletions

File tree

examples/ToyMultiScalePlantTutorial/ToyPlantSimulation1.jl

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
function get_n_leaves(node::MultiScaleTreeGraph.Node)
88
root = MultiScaleTreeGraph.get_root(node)
9-
nleaves = length(MultiScaleTreeGraph.traverse(root, x->1, symbol="Leaf"))
9+
nleaves = length(MultiScaleTreeGraph.traverse(root, x -> 1, symbol="Leaf"))
1010
return nleaves
1111
end
1212

@@ -19,7 +19,7 @@ struct ToyCustomInternodeEmergence{T} <: AbstractOrgan_EmergenceModel
1919
leaves_max_surface_area::T
2020
end
2121

22-
ToyCustomInternodeEmergence(;TT_emergence=300.0, carbon_internode_creation_cost=200.0, leaf_surface_area=3.0, leaves_max_surface_area=100.0) = ToyCustomInternodeEmergence(TT_emergence, carbon_internode_creation_cost, leaf_surface_area, leaves_max_surface_area)
22+
ToyCustomInternodeEmergence(; TT_emergence=300.0, carbon_internode_creation_cost=200.0, leaf_surface_area=3.0, leaves_max_surface_area=100.0) = ToyCustomInternodeEmergence(TT_emergence, carbon_internode_creation_cost, leaf_surface_area, leaves_max_surface_area)
2323

2424
PlantSimEngine.inputs_(m::ToyCustomInternodeEmergence) = (TT_cu=0.0, carbon_stock=0.0)
2525
PlantSimEngine.outputs_(m::ToyCustomInternodeEmergence) = (TT_cu_emergence=0.0, carbon_organ_creation_consumed=0.0)
@@ -32,14 +32,14 @@ function PlantSimEngine.run!(m::ToyCustomInternodeEmergence, models, status, met
3232
if leaves_surface_area > m.leaves_max_surface_area
3333
return nothing
3434
end
35-
35+
3636
# if not enough carbon, no organ creation
3737
if status.carbon_stock < m.carbon_internode_creation_cost
3838
return nothing
3939
end
40-
41-
if length(MultiScaleTreeGraph.children(status.node)) == 2 &&
42-
status.TT_cu - status.TT_cu_emergence >= m.TT_emergence
40+
41+
if length(MultiScaleTreeGraph.children(status.node)) == 2 &&
42+
status.TT_cu - status.TT_cu_emergence >= m.TT_emergence
4343
status_new_internode = add_organ!(status.node, sim_object, "<", "Internode", 2, index=1)
4444
add_organ!(status_new_internode.node, sim_object, "+", "Leaf", 2, index=1)
4545
add_organ!(status_new_internode.node, sim_object, "+", "Leaf", 2, index=1)
@@ -60,8 +60,8 @@ PlantSimEngine.@process "resource_stock_computation" verbose = false
6060
struct ToyStockComputationModel <: AbstractResource_Stock_ComputationModel
6161
end
6262

63-
PlantSimEngine.inputs_(::ToyStockComputationModel) =
64-
(carbon_captured=0.0,carbon_organ_creation_consumed=0.0)
63+
PlantSimEngine.inputs_(::ToyStockComputationModel) =
64+
(carbon_captured=0.0, carbon_organ_creation_consumed=0.0)
6565

6666
PlantSimEngine.outputs_(::ToyStockComputationModel) = (carbon_stock=-Inf,)
6767

@@ -78,7 +78,7 @@ PlantSimEngine.ObjectDependencyTrait(::Type{<:ToyStockComputationModel}) = Plant
7878

7979
PlantSimEngine.@process "leaf_carbon_capture" verbose = false
8080

81-
struct ToyLeafCarbonCaptureModel<: AbstractLeaf_Carbon_CaptureModel end
81+
struct ToyLeafCarbonCaptureModel <: AbstractLeaf_Carbon_CaptureModel end
8282

8383
function PlantSimEngine.inputs_(::ToyLeafCarbonCaptureModel)
8484
NamedTuple()#(TT_cu=-Inf)
@@ -88,53 +88,53 @@ function PlantSimEngine.outputs_(::ToyLeafCarbonCaptureModel)
8888
(carbon_captured=0.0,)
8989
end
9090

91-
function PlantSimEngine.run!(::ToyLeafCarbonCaptureModel, models, status, meteo, constants, extra)
92-
# very crude approximation with LAI of 1 and constant PPFD
93-
status.carbon_captured = 200.0 *(1.0 - exp(-0.2))
91+
function PlantSimEngine.run!(::ToyLeafCarbonCaptureModel, models, status, meteo, constants, extra)
92+
# very crude approximation with LAI of 1 and constant aPPFD
93+
status.carbon_captured = 200.0 * (1.0 - exp(-0.2))
9494
end
9595

9696
PlantSimEngine.ObjectDependencyTrait(::Type{<:ToyLeafCarbonCaptureModel}) = PlantSimEngine.IsObjectIndependent()
9797
PlantSimEngine.TimeStepDependencyTrait(::Type{<:ToyLeafCarbonCaptureModel}) = PlantSimEngine.IsTimeStepIndependent()
9898

9999
mapping = Dict(
100-
"Scene" => ToyDegreeDaysCumulModel(),
101-
"Plant" => (
102-
MultiScaleModel(
103-
model=ToyStockComputationModel(),
104-
mapped_variables=[
105-
:carbon_captured=>["Leaf"],
106-
:carbon_organ_creation_consumed=>["Internode"]
107-
],
100+
"Scene" => ToyDegreeDaysCumulModel(),
101+
"Plant" => (
102+
MultiScaleModel(
103+
model=ToyStockComputationModel(),
104+
mapped_variables=[
105+
:carbon_captured => ["Leaf"],
106+
:carbon_organ_creation_consumed => ["Internode"]
107+
],
108108
),
109-
Status(carbon_stock = 0.0)
109+
Status(carbon_stock=0.0)
110110
),
111-
"Internode" => (
111+
"Internode" => (
112112
MultiScaleModel(
113113
model=ToyCustomInternodeEmergence(),#TT_emergence=20.0),
114114
mapped_variables=[:TT_cu => "Scene",
115-
PreviousTimeStep(:carbon_stock)=>"Plant"],
116-
),
115+
PreviousTimeStep(:carbon_stock) => "Plant"],
116+
),
117117
Status(carbon_organ_creation_consumed=0.0),
118118
),
119-
"Leaf" => ( ToyLeafCarbonCaptureModel(),),
119+
"Leaf" => (ToyLeafCarbonCaptureModel(),),
120120
)
121121

122-
mtg = MultiScaleTreeGraph.Node(MultiScaleTreeGraph.NodeMTG("/", "Scene", 1, 0))
122+
mtg = MultiScaleTreeGraph.Node(MultiScaleTreeGraph.NodeMTG("/", "Scene", 1, 0))
123123
#MultiScaleTreeGraph.Node(mtg, MultiScaleTreeGraph.NodeMTG("/", "Soil", 1, 1))
124-
plant = MultiScaleTreeGraph.Node(mtg, MultiScaleTreeGraph.NodeMTG("+", "Plant", 1, 1))
125-
126-
internode1 = MultiScaleTreeGraph.Node(plant, MultiScaleTreeGraph.NodeMTG("/", "Internode", 1, 2))
127-
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
128-
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
124+
plant = MultiScaleTreeGraph.Node(mtg, MultiScaleTreeGraph.NodeMTG("+", "Plant", 1, 1))
125+
126+
internode1 = MultiScaleTreeGraph.Node(plant, MultiScaleTreeGraph.NodeMTG("/", "Internode", 1, 2))
127+
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
128+
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
129+
130+
internode2 = MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("<", "Internode", 1, 2))
131+
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
132+
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
129133

130-
internode2 = MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("<", "Internode", 1, 2))
131-
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
132-
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
133134

135+
meteo_day = CSV.read(joinpath(pkgdir(PlantSimEngine), "examples/meteo_day.csv"), DataFrame, header=18)
134136

135-
meteo_day = CSV.read(joinpath(pkgdir(PlantSimEngine), "examples/meteo_day.csv"), DataFrame, header=18)
136-
137-
outs = run!(mtg, mapping, meteo_day)
138-
mtg
137+
outs = run!(mtg, mapping, meteo_day)
138+
mtg
139139

140-
length(MultiScaleTreeGraph.traverse(mtg,x->x, symbol="Leaf"))
140+
length(MultiScaleTreeGraph.traverse(mtg, x -> x, symbol="Leaf"))

examples/ToyMultiScalePlantTutorial/ToyPlantSimulation2.jl

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
function get_root_end_node(node::MultiScaleTreeGraph.Node)
1010
root = MultiScaleTreeGraph.get_root(node)
11-
return MultiScaleTreeGraph.traverse(root, x->x, symbol="Root", filter_fun = MultiScaleTreeGraph.isleaf)
11+
return MultiScaleTreeGraph.traverse(root, x -> x, symbol="Root", filter_fun=MultiScaleTreeGraph.isleaf)
1212
end
1313

1414
function get_roots_count(node::MultiScaleTreeGraph.Node)
1515
root = MultiScaleTreeGraph.get_root(node)
16-
return length(MultiScaleTreeGraph.traverse(root, x->x, symbol="Root"))
16+
return length(MultiScaleTreeGraph.traverse(root, x -> x, symbol="Root"))
1717
end
1818

1919
function get_n_leaves(node::MultiScaleTreeGraph.Node)
2020
root = MultiScaleTreeGraph.get_root(node)
21-
nleaves = length(MultiScaleTreeGraph.traverse(root, x->1, symbol="Leaf"))
21+
nleaves = length(MultiScaleTreeGraph.traverse(root, x -> 1, symbol="Leaf"))
2222
return nleaves
2323
end
2424

@@ -32,10 +32,10 @@ struct ToyCustomInternodeEmergence{T} <: AbstractOrgan_EmergenceModel
3232
water_leaf_threshold::T
3333
end
3434

35-
ToyCustomInternodeEmergence(;TT_emergence=300.0, carbon_internode_creation_cost=200.0, leaf_surface_area=3.0,leaves_max_surface_area=100.0,
36-
water_leaf_threshold=30.0) = ToyCustomInternodeEmergence(TT_emergence, carbon_internode_creation_cost, leaf_surface_area, leaves_max_surface_area, water_leaf_threshold)
35+
ToyCustomInternodeEmergence(; TT_emergence=300.0, carbon_internode_creation_cost=200.0, leaf_surface_area=3.0, leaves_max_surface_area=100.0,
36+
water_leaf_threshold=30.0) = ToyCustomInternodeEmergence(TT_emergence, carbon_internode_creation_cost, leaf_surface_area, leaves_max_surface_area, water_leaf_threshold)
3737

38-
PlantSimEngine.inputs_(m::ToyCustomInternodeEmergence) = (TT_cu=0.0,water_stock=0.0, carbon_stock=0.0)
38+
PlantSimEngine.inputs_(m::ToyCustomInternodeEmergence) = (TT_cu=0.0, water_stock=0.0, carbon_stock=0.0)
3939
PlantSimEngine.outputs_(m::ToyCustomInternodeEmergence) = (TT_cu_emergence=0.0, carbon_organ_creation_consumed=0.0)
4040

4141
function PlantSimEngine.run!(m::ToyCustomInternodeEmergence, models, status, meteo, constants=nothing, sim_object=nothing)
@@ -46,7 +46,7 @@ function PlantSimEngine.run!(m::ToyCustomInternodeEmergence, models, status, met
4646
if leaves_surface_area > m.leaves_max_surface_area
4747
return nothing
4848
end
49-
49+
5050
# if water levels are low, prioritise roots
5151
if status.water_stock < m.water_leaf_threshold
5252
return nothing
@@ -56,9 +56,9 @@ function PlantSimEngine.run!(m::ToyCustomInternodeEmergence, models, status, met
5656
if status.carbon_stock < m.carbon_internode_creation_cost
5757
return nothing
5858
end
59-
60-
if length(MultiScaleTreeGraph.children(status.node)) == 2 &&
61-
status.TT_cu - status.TT_cu_emergence >= m.TT_emergence
59+
60+
if length(MultiScaleTreeGraph.children(status.node)) == 2 &&
61+
status.TT_cu - status.TT_cu_emergence >= m.TT_emergence
6262
status_new_internode = add_organ!(status.node, sim_object, "<", "Internode", 2, index=1)
6363
add_organ!(status_new_internode.node, sim_object, "+", "Leaf", 2, index=1)
6464
add_organ!(status_new_internode.node, sim_object, "+", "Leaf", 2, index=1)
@@ -104,15 +104,15 @@ struct ToyRootGrowthModel{T} <: AbstractRoot_GrowthModel
104104
root_max_len::Int
105105
end
106106

107-
PlantSimEngine.inputs_(::ToyRootGrowthModel) = (water_stock=0.0,carbon_stock=0.0,)
107+
PlantSimEngine.inputs_(::ToyRootGrowthModel) = (water_stock=0.0, carbon_stock=0.0,)
108108
PlantSimEngine.outputs_(::ToyRootGrowthModel) = (carbon_root_creation_consumed=0.0,)
109109

110110
function PlantSimEngine.run!(m::ToyRootGrowthModel, models, status, meteo, constants=nothing, extra=nothing)
111111
if status.water_stock < m.water_threshold && status.carbon_stock > m.carbon_root_creation_cost
112-
112+
113113
root_end = get_root_end_node(status.node)
114-
115-
if length(root_end) != 1
114+
115+
if length(root_end) != 1
116116
throw(AssertionError("Couldn't find MTG leaf node with symbol \"Root\""))
117117
end
118118
root_len = get_roots_count(root_end[1])
@@ -135,10 +135,10 @@ struct ToyStockComputationModel <: AbstractResource_Stock_ComputationModel
135135
end
136136
#status.water_stock += meteo.precipitations * root_water_assimilation_ratio
137137

138-
PlantSimEngine.inputs_(::ToyStockComputationModel) =
139-
(water_absorbed=0.0,carbon_captured=0.0,carbon_organ_creation_consumed=0.0,carbon_root_creation_consumed=0.0)
138+
PlantSimEngine.inputs_(::ToyStockComputationModel) =
139+
(water_absorbed=0.0, carbon_captured=0.0, carbon_organ_creation_consumed=0.0, carbon_root_creation_consumed=0.0)
140140

141-
PlantSimEngine.outputs_(::ToyStockComputationModel) = (water_stock=-Inf,carbon_stock=-Inf)
141+
PlantSimEngine.outputs_(::ToyStockComputationModel) = (water_stock=-Inf, carbon_stock=-Inf)
142142

143143
function PlantSimEngine.run!(m::ToyStockComputationModel, models, status, meteo, constants=nothing, extra=nothing)
144144
status.water_stock += sum(status.water_absorbed) #- status.water_transpiration
@@ -158,7 +158,7 @@ PlantSimEngine.ObjectDependencyTrait(::Type{<:ToyStockComputationModel}) = Plant
158158

159159
PlantSimEngine.@process "leaf_carbon_capture" verbose = false
160160

161-
struct ToyLeafCarbonCaptureModel<: AbstractLeaf_Carbon_CaptureModel end
161+
struct ToyLeafCarbonCaptureModel <: AbstractLeaf_Carbon_CaptureModel end
162162

163163
function PlantSimEngine.inputs_(::ToyLeafCarbonCaptureModel)
164164
NamedTuple()#(TT_cu=-Inf)
@@ -168,70 +168,68 @@ function PlantSimEngine.outputs_(::ToyLeafCarbonCaptureModel)
168168
(carbon_captured=0.0,)
169169
end
170170

171-
function PlantSimEngine.run!(::ToyLeafCarbonCaptureModel, models, status, meteo, constants, extra)
172-
# very crude approximation with LAI of 1 and constant PPFD
173-
status.carbon_captured = 200.0 *(1.0 - exp(-0.2))
171+
function PlantSimEngine.run!(::ToyLeafCarbonCaptureModel, models, status, meteo, constants, extra)
172+
# very crude approximation with LAI of 1 and constant aPPFD
173+
status.carbon_captured = 200.0 * (1.0 - exp(-0.2))
174174
end
175175

176176
PlantSimEngine.ObjectDependencyTrait(::Type{<:ToyLeafCarbonCaptureModel}) = PlantSimEngine.IsObjectIndependent()
177177
PlantSimEngine.TimeStepDependencyTrait(::Type{<:ToyLeafCarbonCaptureModel}) = PlantSimEngine.IsTimeStepIndependent()
178178

179179
mapping = Dict(
180-
"Scene" => ToyDegreeDaysCumulModel(),
181-
"Plant" => (
182-
MultiScaleModel(
183-
model=ToyStockComputationModel(),
184-
mapped_variables=[
185-
:carbon_captured=>["Leaf"],
186-
:water_absorbed=>["Root"],
187-
:carbon_root_creation_consumed=>["Root"],
188-
:carbon_organ_creation_consumed=>["Internode"]
189-
190-
],
180+
"Scene" => ToyDegreeDaysCumulModel(),
181+
"Plant" => (
182+
MultiScaleModel(
183+
model=ToyStockComputationModel(),
184+
mapped_variables=[
185+
:carbon_captured => ["Leaf"],
186+
:water_absorbed => ["Root"],
187+
:carbon_root_creation_consumed => ["Root"],
188+
:carbon_organ_creation_consumed => ["Internode"]],
191189
),
192-
Status(water_stock = 0.0, carbon_stock = 0.0)
190+
Status(water_stock=0.0, carbon_stock=0.0)
193191
),
194-
"Internode" => (
192+
"Internode" => (
195193
MultiScaleModel(
196194
model=ToyCustomInternodeEmergence(),#TT_emergence=20.0),
197195
mapped_variables=[:TT_cu => "Scene",
198-
PreviousTimeStep(:water_stock)=>"Plant",
199-
PreviousTimeStep(:carbon_stock)=>"Plant"],
200-
),
196+
PreviousTimeStep(:water_stock) => "Plant",
197+
PreviousTimeStep(:carbon_stock) => "Plant"],
198+
),
201199
Status(carbon_organ_creation_consumed=0.0),
202200
),
203-
"Root" => ( MultiScaleModel(
201+
"Root" => (MultiScaleModel(
204202
model=ToyRootGrowthModel(10.0, 50.0, 10),
205-
mapped_variables=[PreviousTimeStep(:carbon_stock)=>"Plant",
206-
PreviousTimeStep(:water_stock)=>"Plant"],
207-
),
208-
ToyWaterAbsorptionModel(),
209-
Status(carbon_root_creation_consumed=0.0, root_water_assimilation=1.0),
210-
),
211-
"Leaf" => ( ToyLeafCarbonCaptureModel(),),
203+
mapped_variables=[PreviousTimeStep(:carbon_stock) => "Plant",
204+
PreviousTimeStep(:water_stock) => "Plant"],
205+
),
206+
ToyWaterAbsorptionModel(),
207+
Status(carbon_root_creation_consumed=0.0, root_water_assimilation=1.0),
208+
),
209+
"Leaf" => (ToyLeafCarbonCaptureModel(),),
212210
)
213211

214-
mtg = MultiScaleTreeGraph.Node(MultiScaleTreeGraph.NodeMTG("/", "Scene", 1, 0))
212+
mtg = MultiScaleTreeGraph.Node(MultiScaleTreeGraph.NodeMTG("/", "Scene", 1, 0))
213+
214+
plant = MultiScaleTreeGraph.Node(mtg, MultiScaleTreeGraph.NodeMTG("+", "Plant", 1, 1))
215215

216-
plant = MultiScaleTreeGraph.Node(mtg, MultiScaleTreeGraph.NodeMTG("+", "Plant", 1, 1))
217-
218-
internode1 = MultiScaleTreeGraph.Node(plant, MultiScaleTreeGraph.NodeMTG("/", "Internode", 1, 2))
219-
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
220-
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
216+
internode1 = MultiScaleTreeGraph.Node(plant, MultiScaleTreeGraph.NodeMTG("/", "Internode", 1, 2))
217+
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
218+
MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
221219

222-
internode2 = MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("<", "Internode", 1, 2))
223-
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
224-
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
220+
internode2 = MultiScaleTreeGraph.Node(internode1, MultiScaleTreeGraph.NodeMTG("<", "Internode", 1, 2))
221+
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
222+
MultiScaleTreeGraph.Node(internode2, MultiScaleTreeGraph.NodeMTG("+", "Leaf", 1, 2))
223+
224+
plant_root_start = MultiScaleTreeGraph.Node(
225+
plant,
226+
MultiScaleTreeGraph.NodeMTG("+", "Root", 1, 3),
227+
)
225228

226-
plant_root_start = MultiScaleTreeGraph.Node(
227-
plant,
228-
MultiScaleTreeGraph.NodeMTG("+", "Root", 1, 3),
229-
)
229+
meteo_day = CSV.read(joinpath(pkgdir(PlantSimEngine), "examples/meteo_day.csv"), DataFrame, header=18)
230230

231-
meteo_day = CSV.read(joinpath(pkgdir(PlantSimEngine), "examples/meteo_day.csv"), DataFrame, header=18)
232-
233-
outs = run!(mtg, mapping, meteo_day)
234-
mtg
231+
outs = run!(mtg, mapping, meteo_day)
232+
mtg
235233

236234

237-
length(MultiScaleTreeGraph.traverse(mtg,x->x, symbol="Leaf"))
235+
length(MultiScaleTreeGraph.traverse(mtg, x -> x, symbol="Leaf"))

0 commit comments

Comments
 (0)