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

Fspm wheat tillers #8

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
20 changes: 19 additions & 1 deletion src/alinea/adel/adel_dynamic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
""" Prototype adel model that uses mtg edition functions"""
import pandas

from openalea.mtg import MTG
from alinea.adel.astk_interface import AdelWheat
from alinea.adel.mtg_editions import find_metamers, add_plant, add_vegetative_metamer, new_mtg_factory, update_organ_elements
from alinea.adel.mtg_editions import find_metamers, add_axe, add_plant, add_vegetative_metamer, new_mtg_factory, update_organ_elements
from alinea.adel.AdelR import plantSample
from alinea.adel.mtg_interpreter import mtg_interpreter, transform_geom

Expand All @@ -26,13 +28,29 @@ def build_stand(self):
axis_properties=ms_properties)
return g

def add_tiller(self, g, label='T1', plant_number=1):
add_axe(g, label, plant_number)
return g


def add_metamer(self, g, plant=1, axe='MS'):
vid_plant, vid_axe, metamers = find_metamers(g, plant, axe)
nff = g.property('nff')[vid_axe]
num_metamer = len(metamers)
df = self.phytoT(axe)
m = df.loc[df['n'] == num_metamer, :].to_dict('list')
metamer_properties = {'L_shape': m['Ll'][0]}
if 'index_relative_to_MS_phytomer' in self.devT['dimT']:
dfd = pandas.DataFrame(self.devT['axeT']).merge(
pandas.DataFrame(self.devT['dimT'])).loc[:, (
'id_plt', 'id_axis', 'index_phytomer',
'index_relative_to_MS_phytomer')]
metamer_properties.update({'index_relative_to_MS_phytomer':
dfd.set_index(['id_plt', 'id_axis',
'index_phytomer']).loc[
(plant, axe,
num_metamer), 'index_relative_to_MS_phytomer']})

ntop = nff - num_metamer + 1
shape_key = None
lctype = int(m['Lindex'][0])
Expand Down
31 changes: 30 additions & 1 deletion src/alinea/adel/astk_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Class instanciating a wheat canopy and complying to astk canopy interface
"""

import pandas

from alinea.adel.AdelR import setAdel, RunAdel, genGeoAxe, checkAxeDyn, getAxeT, \
getPhenT, getPhytoT, saveRData
Expand Down Expand Up @@ -104,12 +105,40 @@ def timing(delay, steps, weather, start_date):
dt=delay) if not i % delay else TimeControlSet(
dt=0) for i in range(steps))

def setup_canopy(self, age=10):
def setup_canopy(self, age=None):
""" Create a canopy of a given age

Args:
age: thermal time age of the canopy (simce emergence 1).
If None (default) a full grown canopy is returned (TT = last
ligulation + 300)

Returns:

"""

if age is None:
axT = pandas.DataFrame(self.devT['axeT'])
phenT = pandas.DataFrame(self.devT['phenT'])
axT = axT.loc[axT['TT_stop_axis'] == 'NA']
axT = axT.merge(phenT)
TT_last_col = (axT['TT_col_phytomer1'] + axT['dTT_col_phytomer']).max()
age = TT_last_col + 300


self.new_stand(age=age)

if self.duplicate is None:
canopy = RunAdel(age, self.pars, adelpars=self.run_adel_pars)
# add index_relative_to_MS_phytomer to parameters
if 'index_relative_to_MS_phytomer' in self.devT['dimT']:
dfd = pandas.DataFrame(self.devT['axeT']).merge(
pandas.DataFrame(self.devT['dimT'])).loc[:, (
'id_plt', 'id_axis', 'index_phytomer',
'index_relative_to_MS_phytomer')]
canopy = pandas.DataFrame(canopy).merge(dfd.rename(
columns={'id_plt': 'plant', 'id_axis': 'axe_id',
'index_phytomer': 'numphy'})).to_dict('list')
stand = zip(self.positions, self.plant_azimuths)
g = self.build_mtg(canopy, stand,
aborting_tiller_reduction=self.aborting_tiller_reduction)
Expand Down
5 changes: 4 additions & 1 deletion src/alinea/adel/mtg_editions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# ==============================================================================
""" new mtg edition function (should be integrated in new mtg"""
# TODO add to adel dressdyn
from openalea.mtg.traversal import iter_mtg
from alinea.adel.newmtg import internode_elements, sheath_elements, blade_elements, convert, properties_from_dict, adel_metamer
from openalea.mtg import MTG, fat_mtg
Expand Down Expand Up @@ -523,7 +524,9 @@ def new_mtg_factory(parameters, metamer_factory=adel_metamer, leaf_sectors=1,
components = metamer_factory(Lsect=leaf_sectors, shape_key=xysr_key,
elongation=elongation, leaves=leaves[species],
**args)
args = {'L_shape': args.get('L_shape')}
args = {'L_shape': args.get('L_shape'),
'index_relative_to_MS_phytomer': args.get(
'index_relative_to_MS_phytomer')}
#
metamer_properties = args
internode, sheath, blade = None, None, None
Expand Down
4 changes: 3 additions & 1 deletion src/alinea/adel/newmtg.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ def mtg_factory(parameters, metamer_factory=adel_metamer, leaf_sectors=1,
components = metamer_factory(Lsect=leaf_sectors, shape_key=xysr_key,
elongation=elongation,
leaves=leaves[species], **args)
args = {'L_shape': args.get('L_shape')}
args = {'L_shape': args.get('L_shape'),
'index_relative_to_MS_phytomer': args.get(
'index_relative_to_MS_phytomer')}
#
label = 'metamer' + str(num_metamer)
new_metamer = g.add_component(vid_axe, edge_type='/', label=label,
Expand Down