Skip to content

Commit

Permalink
Merge pull request #23 from openalea-incubator/Port_python_3
Browse files Browse the repository at this point in the history
conversion using 2to3
  • Loading branch information
christian34 authored Nov 25, 2021
2 parents a1375b6 + 6801a21 commit 5de395f
Show file tree
Hide file tree
Showing 83 changed files with 1,723 additions and 1,456 deletions.
21 changes: 16 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,31 @@ Installation with conda
=======================

Create an environment:

conda create -n adel -c openalea openalea.plantgl boost=1.66
conda create -n adel -c conda-forge python=3.8 ipython numpy=1.20 pandas rpy2 scipy setuptools=49.6 path -y


Activate the environment:

[source] activate adel

Install the different packages

conda install -c conda-forge rpy2
conda install -c fredboudon -c conda-forge openalea.plantgl openalea.mtg -y

Install openalea.Deploy

conda install -c anaconda -c openalea openalea.mtg openalea.visualea openalea.core openalea.components numpy scipy matplotlib pandas pil
.. code-block:: console
git clone https://github.com/openalea/deploy.git
cd deploy
python setup.py install
cd
Install adel

python setup.py develop
.. code-block:: console
git clone -b Port_python_3 https://github.com/openalea-incubator/adel.git
cd adel
python setup.py develop
22 changes: 11 additions & 11 deletions example/compute_rel_interception_from_one_leaf_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
earT_filepath,
lamina2D_filepath,
laminaCurv_filepath,
params_filepath) = map(pj, [DATA_IN_DIR] * 5,
params_filepath) = list(map(pj, [DATA_IN_DIR] * 5,
['dimT.csv', 'earT.csv', 'lamina2D.RData',
'laminaCurv.RData', 'params.py'])
'laminaCurv.RData', 'params.py']))

params = imp.load_source('params', params_filepath)

(dimT, earT) = map(pandas.read_csv, (dimT_filepath, earT_filepath))
(dimT, earT) = list(map(pandas.read_csv, (dimT_filepath, earT_filepath)))

earT_grouped = earT.groupby(['Code', 'id_plt'])

for Linc in (0, 0.5, 1):
angle_of_incidence = Linc * 90
print 'angle_of_incidence', angle_of_incidence
print('angle_of_incidence', angle_of_incidence)

metamers_parameters = []

Expand All @@ -53,7 +53,7 @@
L_spike = earT_group['L_spike'][earT_group.first_valid_index()]

index_phytomer_ntop = [1]
metamers_parameters_group = pandas.DataFrame(columns=dimT.columns, index=range(len(index_phytomer_ntop)))
metamers_parameters_group = pandas.DataFrame(columns=dimT.columns, index=list(range(len(index_phytomer_ntop))))
metamers_parameters_group['id_plt'] = id_plt_global
metamers_parameters_group['index_phytomer_ntop'] = index_phytomer_ntop
metamers_parameters_group['L_blade'] = dimT_group['L_blade'].tolist()
Expand All @@ -80,7 +80,7 @@
metamers_parameters_group['axe_id'] = 'MS' # Note: to adapt if tillers are provided
metamers_parameters_group['ms_insertion'] = 0 # Note: to adapt if tillers are provided
# order numphy from base to top
metamers_parameters_group['numphy'] = range(1, len(metamers_parameters_group) + 1)
metamers_parameters_group['numphy'] = list(range(1, len(metamers_parameters_group) + 1))
# add missing mandatory data (does like adel)
metamers_parameters_group['Laz'] = [180 for i in range(len(metamers_parameters_group))] #leaf azimuth
metamers_parameters_group['LcType'] = metamers_parameters_group['ntop'] # selector for first level in leaf db
Expand Down Expand Up @@ -114,7 +114,7 @@
metamers_parameters = pandas.concat(metamers_parameters, ignore_index=True)

metamers_parameters_filepath = pj(DATA_OUT_DIR, 'metamers_parameters' + str(angle_of_incidence) + '.csv')
print 'Save Adel parameters to ', metamers_parameters_filepath
print('Save Adel parameters to ', metamers_parameters_filepath)
metamers_parameters.to_csv(metamers_parameters_filepath, na_rep='NA', index=False)

def agronomicplot(nplants=None, length=None, width=None, sowing_density=None, plant_density=None, inter_row=None, noise=0, convunit=100, center_scene=True):
Expand Down Expand Up @@ -186,7 +186,7 @@ def agronomicplot(nplants=None, length=None, width=None, sowing_density=None, pl
db, discard = fit.fit_leaves(db, NUMBER_OF_LONGITUDINAL_DIVISIONS)

# set the rotation angle of the plant on itself. Permits to randomize the orientation of each leaf.
stand = zip(positions, [0 for i in range(len(positions))])
stand = list(zip(positions, [0 for i in range(len(positions))]))
g = mtg_factory(metamers_parameters.to_dict('list'), adel_metamer, leaf_db = db, stand = stand)
#add geometry
g = mtg_interpreter(g)
Expand All @@ -203,7 +203,7 @@ def agronomicplot(nplants=None, length=None, width=None, sowing_density=None, pl
columns=['adel_label', 'star', 'exposed_area'])

caribu_out_filepath = pj(DATA_OUT_DIR, 'caribu_out' + str(angle_of_incidence) + '.csv')
print 'Save caribu output to', caribu_out_filepath
print('Save caribu output to', caribu_out_filepath)
caribu_out.to_csv(caribu_out_filepath, na_rep='NA', index=False)

# Calculate the star for each class of metamers (metamer1, metamer2, metamer3, etc).
Expand All @@ -224,8 +224,8 @@ def agronomicplot(nplants=None, length=None, width=None, sowing_density=None, pl
pandas.concat([mean_star_per_phytomer_pre, mean_star_per_phytomer],
ignore_index=True)

print 'Save mean star per phytomer to', mean_star_per_phytomer_filepath
print('Save mean star per phytomer to', mean_star_per_phytomer_filepath)
mean_star_per_phytomer.to_csv(mean_star_per_phytomer_filepath, na_rep='NA', index=False)

tps2 = time.clock()
print 'Execution time: ', tps2 - tps1
print('Execution time: ', tps2 - tps1)
10 changes: 5 additions & 5 deletions example/example_leaf_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Imports for wheat
try:
import cPickle as pickle
import pickle as pickle
except:
import pickle
from alinea.adel.newmtg import move_properties, adel_ids
Expand Down Expand Up @@ -48,7 +48,7 @@
for canopy_iter in canopy_timing:
if canopy_iter:
date = canopy_iter.value.index[-1]
print date
print(date)

# Grow wheat
g = adel.grow(g, canopy_iter.value)
Expand All @@ -59,21 +59,21 @@

# Save variables
for plant in recorders:
for lf, recorder in recorders[plant].iteritems():
for lf, recorder in recorders[plant].items():
recorder.update_vids_with_labels(adel_ids = adel_ids(g))
recorder.record_only_leaf_data(g, date, degree_days = canopy_iter.value.degree_days[-1])

scene = plot3d(g)
Viewer.display(scene)

for plant in recorders:
for recorder in recorders[plant].itervalues():
for recorder in recorders[plant].values():
recorder.create_dataframe_only_leaf_data()

leaves = ['F%d' % lf for lf in range(13)]
fig, axs = plt.subplots(3, 3)
for plant in recorders:
for recorder in recorders[plant].itervalues():
for recorder in recorders[plant].values():
data = recorder.data
axs[0][0].plot(data.degree_days, data.leaf_area)
axs[0][0].set_ylabel('leaf area (cm2)', fontsize = 18)
Expand Down
4 changes: 2 additions & 2 deletions example/reconstruction_digit.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
stand = AgronomicStand(sowing_density=500, plant_density=500, inter_row=0.15, noise=0.03)
adel = AdelDress(dimT=dimT, leaves=leaves, stand=stand)
g = adel.canopy(nplants=10, species = {'soissons':0.5, 'cap_horn':0.5}, relative_inclination = {'soissons':1.5, 'cap_horn':1})
print [v for k, v in g.property('species').iteritems() if k in g.vertices(1)]
print adel.plot_statistics(g)
print([v for k, v in g.property('species').items() if k in g.vertices(1)])
print(adel.plot_statistics(g))

2 changes: 1 addition & 1 deletion example/test_adelR.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run_adel(dd):
out = canL2canS(RcanT,srdb)
out_df = DataFrame(out)
return out_df
out_dfs = map(run_adel, [dd, dd + 100])
out_dfs = list(map(run_adel, [dd, dd + 100]))
concat_df = concat(out_dfs, ignore_index=True)
domain_area = 1
axis_df = postprocessing.axis_statistics(concat_df, domain_area)
Expand Down
104 changes: 52 additions & 52 deletions example/test_newmtg.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
from alinea.adel.newmtg import *
from alinea.adel.mtg_interpreter import *
import openalea.plantgl.all as pgl
from alinea.adel.AdelR import devCsv,setAdel,RunAdel,genGeoLeaf,genGeoAxe
import alinea.adel.fitting as fitting

import alinea.adel.data as data
from openalea.core.path import path as Path


def adelR(nplants,dd):
devT = devCsv('./data/axeTCa0N.csv','./data/dimTCa0N.csv','./data/phenTCa0N.csv','./data/earTCa0N.csv','./data/ssi2sen.csv')
geoLeaf = genGeoLeaf()
geoAxe = genGeoAxe()
pars = setAdel(devT,geoLeaf,geoAxe,nplants)
cantable = RunAdel(dd,pars)
return pars,cantable

def leaves_db(dlevel=9):
import cPickle as Pickle
d = data.__path__[0]
fn = r'%s/leaves_simple.db'%str(d)
f = open(fn)
leaves = Pickle.load(f)
f.close()
leaves,discard = fitting.fit_leaves(leaves, dlevel)
return leaves

#from openalea.mtg import mtg2axialtree
#affichage : aller voir __str__dans mtg.py
#dp = {'plant':[1,1,1,1,1], 'axe' : [0,0,1,1,2], 'numphy': [1,2,1,2,1], 'Laz': [0,180,90,180,180],'Einc':[0,0,45,-45,45], 'El': [1,1,1,1,1],'Ev':[1,1,1,1,1], 'Esen':[0,0,0,0,0], 'Ed':[0.1,0.1,0.1,0.1,0.1]}
#dp = {'plant':[1,1,1,1,1], 'axe' : [0,0,1,1,2], 'numphy': [1,2,1,2,1], 'Laz': [0,180,90,180,0],'Einc':[0,0,45,-30,45], 'El': [1,1,1,1,1],'Ev':[1,1,1,1,1], 'Esen':[0,0,0,0,0], 'Ed':[0.1,0.1,0.1,0.1,0.1]}
#g=mtg_factory(dp,adel_metamer)
#g.display()

#more test
p,d= adelR(1,1000)
leaves=leaves_db()
g=mtg_factory(d,adel_metamer,leaves=leaves, stand=[((0,0,0),0),((10,0,0),90), ((0,10,0), 0)])
g=mtg_interpreter(g)
scene = plot3d(g)
pgl.Viewer.display(scene)
#
def test_leaf_shape():
""" test leaf positioning/ inclination """
d = {'plant':[1,1],'axe_id':['MS','T1'],'ms_insertion':[0,1],'numphy':[1,1],
'Laz': [0,90], 'Ll' :[3,3], 'Lv' :[3,3] , 'Lsen':[0,0], 'L_shape':[3,3], 'Lw_shape':[.3,.3], 'Linc':[0,0],
'Einc':[0,45],'El':[1,1],'Ev':[1,1],'Esen':[0,0],'Ed': [0.1,0.1]}
g=mtg_factory(d,adel_metamer,leaf_db=leaves_db())
g=mtg_interpreter(g)
scene = plot3d(g)
pgl.Viewer.display(scene)
from alinea.adel.newmtg import *
from alinea.adel.mtg_interpreter import *
import openalea.plantgl.all as pgl
from alinea.adel.AdelR import devCsv,setAdel,RunAdel,genGeoLeaf,genGeoAxe
import alinea.adel.fitting as fitting

import alinea.adel.data as data
from pathlib import Path


def adelR(nplants,dd):
devT = devCsv('./data/axeTCa0N.csv','./data/dimTCa0N.csv','./data/phenTCa0N.csv','./data/earTCa0N.csv','./data/ssi2sen.csv')
geoLeaf = genGeoLeaf()
geoAxe = genGeoAxe()
pars = setAdel(devT,geoLeaf,geoAxe,nplants)
cantable = RunAdel(dd,pars)
return pars,cantable

def leaves_db(dlevel=9):
import pickle as Pickle
d = data.__path__[0]
fn = r'%s/leaves_simple.db'%str(d)
f = open(fn)
leaves = Pickle.load(f)
f.close()
leaves,discard = fitting.fit_leaves(leaves, dlevel)
return leaves

#from openalea.mtg import mtg2axialtree
#affichage : aller voir __str__dans mtg.py
#dp = {'plant':[1,1,1,1,1], 'axe' : [0,0,1,1,2], 'numphy': [1,2,1,2,1], 'Laz': [0,180,90,180,180],'Einc':[0,0,45,-45,45], 'El': [1,1,1,1,1],'Ev':[1,1,1,1,1], 'Esen':[0,0,0,0,0], 'Ed':[0.1,0.1,0.1,0.1,0.1]}
#dp = {'plant':[1,1,1,1,1], 'axe' : [0,0,1,1,2], 'numphy': [1,2,1,2,1], 'Laz': [0,180,90,180,0],'Einc':[0,0,45,-30,45], 'El': [1,1,1,1,1],'Ev':[1,1,1,1,1], 'Esen':[0,0,0,0,0], 'Ed':[0.1,0.1,0.1,0.1,0.1]}
#g=mtg_factory(dp,adel_metamer)
#g.display()

#more test
p,d= adelR(1,1000)
leaves=leaves_db()
g=mtg_factory(d,adel_metamer,leaves=leaves, stand=[((0,0,0),0),((10,0,0),90), ((0,10,0), 0)])
g=mtg_interpreter(g)
scene = plot3d(g)
pgl.Viewer.display(scene)
#
def test_leaf_shape():
""" test leaf positioning/ inclination """
d = {'plant':[1,1],'axe_id':['MS','T1'],'ms_insertion':[0,1],'numphy':[1,1],
'Laz': [0,90], 'Ll' :[3,3], 'Lv' :[3,3] , 'Lsen':[0,0], 'L_shape':[3,3], 'Lw_shape':[.3,.3], 'Linc':[0,0],
'Einc':[0,45],'El':[1,1],'Ev':[1,1],'Esen':[0,0],'Ed': [0.1,0.1]}
g=mtg_factory(d,adel_metamer,leaf_db=leaves_db())
g=mtg_interpreter(g)
scene = plot3d(g)
pgl.Viewer.display(scene)
return(g)
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ build_requires = python >= 2.6
python-devel >= 2.6
python-setuptools >= 0.6
python-OpenAlea.Deploy >= 0.9
provides = %{name} = %{version}
obsoletes = %{name} < %{version}
provides = %%{name} = %%{version}
obsoletes = %%{name} < %%{version}
doc_files = AUTHORS.txt ChangeLog.txt README.txt LICENSE.txt
python = /usr/bin/python
packager = OpenAlea Consortium
16 changes: 7 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# -*- coding: iso-8859-15 -*-


import os, sys
import os, sys
from setuptools import setup, find_packages
from openalea.deploy.metainfo import read_metainfo
pj = os.path.join


# Reads the metainfo file
metadata = read_metainfo('metainfo.ini', verbose=True)
for key,value in metadata.iteritems():
for key,value in metadata.items():
exec("%s = '%s'" % (key, value))


Expand All @@ -28,21 +28,19 @@
version=version,
description=description,
long_description=long_description,
authors=authors,
authors_email=authors_email,
author=authors,
author_email=authors_email,
url=url,
license=license,

namespace_packages = [namespace],
create_namespaces = True,

py_modules = [],
# pure python packages
packages= find_packages('src'),
# python packages directory
package_dir= {'': 'src'},
namespace_packages=['alinea'],


# Namespace packages creation by deploy
# Add package platform libraries if any
include_package_data=True,
package_data = {'' : ['*.RData', '*.R', '*.8', '*.h', '*.str','*.txt', '*.l', '*.map', '*.csv', '*.png'],},
Expand Down
Loading

0 comments on commit 5de395f

Please sign in to comment.