コード例 #1
0
ファイル: generate_movie.py プロジェクト: jvail/vmango
def generate_bgeom(step=None):
    from openalea.lpy import Lsystem
    import os
    print('Scene generator launched')
    l = Lsystem(
        lsysfile, {
            'RESOLUTION': 2,
            'daystep': 1,
            'TIMEBAR': False,
            'LEAFY': True,
            'WITH_INFLO': True,
            'EXPORT_TO_MTG': False
        })

    if step is None:
        firststep = 0
        nbsteps = l.derivationLength
    else:
        firststep = step
        nbsteps = step + 1

    open(stepfile, 'w').write(str(nbsteps))
    if not os.path.exists(workingrep): os.makedirs(workingrep)
    for step in range(firststep, nbsteps):
        if step == firststep: lstring = l.derive(firststep + 1)
        else: lstring = l.derive(lstring, step, 1)
        lscene = l.sceneInterpretation(lstring)
        fname = join(workingrep, bgeomfile.format(str(step).zfill(4)))
        lscene.save(tempbgeomfile)
        os.rename(tempbgeomfile, fname)
        print("Scene", step, "generated ...")
コード例 #2
0
def run_lgrass(scenario_id=1,
               inputs_dir_path='inputs',
               outputs_dir_path='outputs'):
    """ Run lgrass.lpy file from external script

    :param str inputs_dir_path: the path to the input files (meteo, list of simulations...)
    :param str outputs_dir_path: the path to the outputs files
    :param int scenario_id: the index of the scenario to be run from the list of simulations CSV file

    """

    # Scenario to be run
    scenarii_df = pd.read_csv(os.path.join('inputs', 'plan_simulation.csv'),
                              index_col='Scenario')
    scenario = scenarii_df.loc[scenario_id].to_dict()
    scenario_name = scenario['name']

    # Update parameters of flowering model
    flowering_model = lgrass.flowering_functions.FloweringFunctions()
    flowering_model.param.__dict__.update(
        (k, scenario[k])
        for k in set(scenario).intersection(flowering_model.param.__dict__))

    # Load lsystem
    lpy_filename = os.path.join(lgrass.__path__[0], "lgrass.lpy")
    lsystem = Lsystem(lpy_filename)

    # Update parameters
    lsystem.option_profile = "plateau"
    lsystem.flowering_model = flowering_model
    lsystem.derivationLength = int(scenario['derivationLength'])
    lsystem.option_tallage = scenario['option_tallage']
    lsystem.option_senescence = scenario['option_senescence']
    lsystem.option_floraison = scenario['option_floraison']
    lsystem.meteo_path = os.path.join(inputs_dir_path,
                                      scenario['meteo_filename'])
    lsystem.sowing_date = scenario['sowing_date']
    lsystem.site = scenario['site']
    lsystem.output_induction_file_name = '{}_induction'.format(scenario_name)
    lsystem.output_organ_lengths_file_name = '{}_organ_lengths'.format(
        scenario_name)
    lsystem.cutting_dates = [] if pd.isna(scenario['cutting_dates']) \
        else [scenario['cutting_dates']] if isinstance(scenario['cutting_dates'], int) \
        else [int(i) for i in scenario['cutting_dates'].split("_")]
    lsystem.ParamP[0]['C'] = scenario['value_C']
    lsystem.ParamP[0]['Premiecroiss'] = scenario['Premiecroiss']
    lsystem.ParamP[0]['PS_compensation_point'] = scenario[
        'PS_compensation_point']
    if outputs_dir_path:
        lsystem.OUTPUTS_DIRPATH = outputs_dir_path

    # Run the lsystem
    try:
        lsystem.derive(
        )  # permet le declenchement de la fonction "End" du script lpy
        lsystem.clear()
    except Exception as e:
        print(e)
コード例 #3
0
def test_run(overwrite_desired_data=False):
    lpy_filename = os.path.join(lgrass.__path__[0], "lgrass.lpy")
    lsys = Lsystem(lpy_filename)
    axiom = lsys.axiom

    lsys.meteo_path = os.path.join(INPUTS_DIRPATH, 'meteo_file.csv')
    lsys.INPUTS_DIRPATH = INPUTS_DIRPATH
    lsys.OUTPUTS_DIRPATH = OUTPUTS_DIRPATH
    lsys.GRAPHS_DIRPATH = GRAPHS_DIRPATH
    lsys.derivationLength = NSTEP
    lsys.DureeExp = NSTEP
    lsys.option_tallage = True
    lsys.option_senescence = True
    lsys.option_floraison = True
    lsys.option_caribu = 'Off'
    lsys.option_tiller_regression = False
    lsys.option_mophogenetic_regulation_by_carbone = False
    lsys.derive(axiom, NSTEP)

    # convert the outputs to Pandas dataframe
    surface_biomass = pd.read_csv(lsys.chemin_fichier1.name)
    evol = pd.read_csv(lsys.chemin_fichier2.name)
    output_induction_file_path = os.path.join(OUTPUTS_DIRPATH,
                                              'output_induction.csv')
    output_induction = pd.read_csv(output_induction_file_path)
    output_organ_lengths_file_path = os.path.join(OUTPUTS_DIRPATH,
                                                  'output_organ_lengths.csv')
    output_organ_lengths = pd.read_csv(output_organ_lengths_file_path)

    # # compare outputs
    compare_actual_to_desired(OUTPUTS_DIRPATH, surface_biomass,
                              DESIRED_SORTIE_SURFACE_BIOMASS_FILENAME,
                              lsys.chemin_fichier1.name,
                              overwrite_desired_data)
    compare_actual_to_desired(OUTPUTS_DIRPATH, evol,
                              DESIRED_SERIE_FOLIAIRE_FILENAME,
                              lsys.chemin_fichier2.name,
                              overwrite_desired_data)
    compare_actual_to_desired(OUTPUTS_DIRPATH, output_induction,
                              DESIRED_OUTPUT_INDUCTION_FILENAME,
                              output_induction_file_path,
                              overwrite_desired_data)
    compare_actual_to_desired(OUTPUTS_DIRPATH, output_organ_lengths,
                              DESIRED_OUTPUT_ORGAN_LENGTHS_FILENAME,
                              output_organ_lengths_file_path,
                              overwrite_desired_data)

    if overwrite_desired_data:
        print("New desired files written")
    else:
        print("Test passed successfully")
コード例 #4
0
def generate_bgeom(step=None, endstep=None):
    from openalea.lpy import Lsystem
    import os
    print('Scene generator launched')
    l = Lsystem(
        lsysfile, {
            'SEED': 0,
            'TREE': 0,
            'RESOLUTION': 2,
            'TIMESTEP': 1,
            'TIMEBAR': False,
            'LEAFY': True,
            'WITH_INFLO': True,
            'TEXTURE': True,
            'GENERALIZEDCYLINDER': True,
            'WITH_GLM': True,
            'FRUIT_MODEL': False,
            'GLM_RESTRICTION': None,
            '_GLM_TYPE': 3,
            'EXPORT_TO_MTG': False
        })

    if step is None:
        firststep = 0
        endstep = l.derivationLength
    else:
        firststep = step
        if endstep is None:
            endstep = l.derivationLength
        else:
            assert endstep < l.derivationLength

    open(stepfile, 'w').write(str(endstep))
    if not os.path.exists(workingrep): os.makedirs(workingrep)
    for step in range(firststep, endstep):
        if step == firststep: lstring = l.derive(firststep + 1)
        else: lstring = l.derive(lstring, step, 1)
        lscene = l.sceneInterpretation(lstring)
        fname = join(workingrep, bgeomfile.format(str(step).zfill(4)))
        lscene.save(tempbgeomfile)
        os.rename(tempbgeomfile, fname)
        print("Scene", step, "generated ...")
コード例 #5
0
ファイル: generate_fruitsimu.py プロジェクト: jvail/vmango
def generate(seed = 0, tree = 0, fdist = 4, regenerate = False):
    from openalea.lpy import Lsystem
    import os
    rep = glob.glob(pattern.format(tree, seed, '*' , fdist))
    if len(rep) == 2 and not regenerate: 
        print('Do not regenerate', seed, tree, fdist)
        return True
    l = Lsystem(lsysfile,{'RESOLUTION' : 1, 'daystep' : 30, 'TIMEBAR' : False, 'LEAFY' : True, 'WITH_INFLO' : True, 'EXPORT_TO_MTG' : False, 'TREE' : tree, 'SEED' : seed, 'FRUITBRANCHSIZE' : fdist})
    if l.tree_load:
        print('Generate', seed, tree, fdist)
        try:
            lstring = l.derive()
            return True
        except:
            return False
    else :
        print('Not loaded tree', tree)
        return False