Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sap flow per cordon #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/figs/paper_figs.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def plot_figure_14():
m_df = pd.merge(obs_grouped, sims)

x = m_df['west'].values + m_df['east'].values
y = m_df['sapWest'].values + m_df['sapEast'].values
y = m_df['arm2'].values + m_df['arm1'].values

x_index = np.isfinite(x)
y_index = np.isfinite(y)
Expand All @@ -674,8 +674,8 @@ def plot_figure_14():
ax.xaxis.grid(which='minor', zorder=0)
ax.yaxis.grid(which='major', zorder=0)

ax.plot(sims.index, sims.sapEast, c='r', linewidth=1)
ax.plot(sims.index, sims.sapWest, c='b', linewidth=1)
ax.plot(sims.index, sims['arm1'], c='r', linewidth=1)
ax.plot(sims.index, sims['arm2'], c='b', linewidth=1)

ax.plot(obs_df.index, obs_df['east'], label='East', color='red',
marker='o', markeredgecolor='none', alpha=0.1)
Expand Down
5 changes: 2 additions & 3 deletions example/gdc_can1_grapevine/sim.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""This is an example on running HydroShoot on a potted grapevine with a
simple shoot architecture.
"""This is an example on running HydroShoot on a Geneva Double Curtain grapevine with.
"""

from os import getcwd
Expand Down Expand Up @@ -37,4 +36,4 @@
# Run HydroShoot
# =============================================================================

model.run(g, str(getcwd()) + '/', scene)
model.run(g, str(getcwd()) + '/', scene, sapflow_per_cordon=True)
2 changes: 1 addition & 1 deletion example/gdc_can2_grapevine/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
# Run HydroShoot
# =============================================================================

model.run(g, str(getcwd()) + '/', scene)
model.run(g, str(getcwd()) + '/', scene, sapflow_per_cordon=True)
2 changes: 1 addition & 1 deletion example/gdc_can3_grapevine/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
# Run HydroShoot
# =============================================================================

model.run(g, str(getcwd()) + '/', scene)
model.run(g, str(getcwd()) + '/', scene, sapflow_per_cordon=True)
34 changes: 19 additions & 15 deletions src/hydroshoot/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
from hydroshoot.params import Params


def run(g, wd, scene=None, write_result=True, **kwargs):
def run(g, wd, scene=None, write_result=True, sapflow_per_cordon=False, **kwargs):
"""
Calculates leaf gas and energy exchange in addition to the hydraulic structure of an individual plant.

:Parameters:
- **g**: a multiscale tree graph object
- **wd**: string, working directory
- **scene**: PlantGl scene
- **sapflow_per_cordon**: to return simulated sapflow per cordon if `True`, otherwise (default `False`) to return
only total sapflow of the whole plant
- **kwargs** can include:
- **psi_soil**: [MPa] predawn soil water potential
- **gdd_since_budbreak**: [°Cd] growing degree-day since bubreak
Expand Down Expand Up @@ -100,8 +102,9 @@ def run(g, wd, scene=None, write_result=True, **kwargs):
print 'GDD since budbreak = %d °Cd' % gdd_since_budbreak

# Determination of perennial structure arms (for grapevine)
# arm_vid = {g.node(vid).label: g.node(vid).components()[0]._vid for vid in g.VtxList(Scale=2) if
# g.node(vid).label.startswith('arm')}
if sapflow_per_cordon:
arm_vid = {g.node(vid).label: g.node(vid).components()[0]._vid for vid in g.VtxList(Scale=2) if
g.node(vid).label.startswith('arm')}

# Soil reservoir dimensions (inter row, intra row, depth) [m]
soil_dimensions = params.soil.soil_dimensions
Expand Down Expand Up @@ -280,9 +283,11 @@ def run(g, wd, scene=None, write_result=True, **kwargs):
# Simulations
# ==============================================================================

sapflow = []
# sapEast = []
# sapWest = []
if sapflow_per_cordon:
sapflow = {k: [] for k in arm_vid.keys()}
else:
sapflow = {'E': []}

an_ls = []
rg_ls = []
psi_stem = {}
Expand Down Expand Up @@ -358,9 +363,11 @@ def run(g, wd, scene=None, write_result=True, **kwargs):
architecture.mtg_save(g, scene, output_path)

# Plot stuff..
sapflow.append(g.node(vid_collar).Flux)
# sapEast.append(g.node(arm_vid['arm1']).Flux)
# sapWest.append(g.node(arm_vid['arm2']).Flux)
if sapflow_per_cordon:
for cordon in sapflow.keys():
sapflow[cordon].append(g.node(arm_vid[cordon]).Flux)
else:
sapflow['E'].append(g.node(vid_collar).Flux)

an_ls.append(g.node(vid_collar).FluxC)

Expand Down Expand Up @@ -389,9 +396,7 @@ def run(g, wd, scene=None, write_result=True, **kwargs):

# Write output
# Plant total transpiration
sapflow = [flow * time_conv * 1000. for flow in sapflow]

# sapEast, sapWest = [np.array(flow) * time_conv * 1000. for i, flow in enumerate((sapEast, sapWest))]
sapflow = {k: [flow * time_conv * 1000. for flow in cordon_flow] for k, cordon_flow in sapflow.items()}

# Median leaf temperature
t_ls = [np.median(Tlc_dict[date].values()) for date in meteo.time]
Expand All @@ -402,12 +407,11 @@ def run(g, wd, scene=None, write_result=True, **kwargs):
results_dict = {
'Rg': rg_ls,
'An': an_ls,
'E': sapflow,
# 'sapEast': sapEast,
# 'sapWest': sapWest,
'Tleaf': t_ls
}

results_dict.update(sapflow)

# Results DataFrame
results_df = DataFrame(results_dict, index=meteo.time)

Expand Down