diff --git a/src/alinea/adel/adel_dynamic.py b/src/alinea/adel/adel_dynamic.py index d4195501..8458fea5 100644 --- a/src/alinea/adel/adel_dynamic.py +++ b/src/alinea/adel/adel_dynamic.py @@ -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 @@ -26,6 +28,11 @@ 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] @@ -33,6 +40,17 @@ def add_metamer(self, g, plant=1, axe='MS'): 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]) diff --git a/src/alinea/adel/astk_interface.py b/src/alinea/adel/astk_interface.py index c139abdc..b398e53a 100644 --- a/src/alinea/adel/astk_interface.py +++ b/src/alinea/adel/astk_interface.py @@ -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 @@ -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) diff --git a/src/alinea/adel/mtg_editions.py b/src/alinea/adel/mtg_editions.py index addec648..111861b6 100644 --- a/src/alinea/adel/mtg_editions.py +++ b/src/alinea/adel/mtg_editions.py @@ -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 @@ -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 diff --git a/src/alinea/adel/newmtg.py b/src/alinea/adel/newmtg.py index ce33d277..55904beb 100644 --- a/src/alinea/adel/newmtg.py +++ b/src/alinea/adel/newmtg.py @@ -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,