Exemplo n.º 1
0
    def __init__(self, model, events): 
        PyDynamics.Dynamics.__init__(self, model, events)
        valeur_python = convert.to_pyvalue( events )
        if "modelname" in valeur_python.keys() :
            self.m_name = valeur_python["modelname"]
        print ""
        print "-----------------------------------------------"
	print "-------- ", self.m_name, " : __init__ --------------"            
        self.m_choix = 1

        print "valeur python de events : ", valeur_python
        print "lecture des elements  1 a 1 : "
        for k,v in valeur_python.iteritems() :
            print "key : ", k, "value : ", v

        self.conditions = valeur_python

        pm = load_package_manager()
        node_factory = pm[self.conditions['openalea_pkgname']][self.conditions['openalea_nodename']]
        self.eval = function(node_factory)
        # /!\ on suppose l'unicité des noms entre paramètres et attributs des ports
        self.eval_args = dict([(d['name'],-1.) for d in node_factory.inputs])
        self.out_names = [d['name'] for d in node_factory.outputs]
        self.outputs = self.eval(**self.eval_args)
        for k in self.conditions.keys() :
            if k in self.eval_args.keys() :        
                self.eval_args[k] = self.conditions[k]

        if "delay" in valeur_python.keys() :
            self.p_delay = valeur_python["delay"]
            print "Le 'delay' est de : ", self.p_delay 
        else : 
            self.p_delay = 1.0

        print ""
Exemplo n.º 2
0
    def __init__(self, model, events):
        PyDynamics.Dynamics.__init__(self, model, events)
        # get init partameters
        self.conditions = convert.to_pyvalue(events)

        pm = load_package_manager()
        node_factory = pm[self.conditions['openalea_pkgname']][
            self.conditions['openalea_nodename']]
        self.eval = function(node_factory)
        # /!\ on suppose l'unicite des noms entre parametres et attributs des ports
        self.eval_args = dict([(d['name'], -1.) for d in node_factory.inputs])
        self.out_names = [d['name'] for d in node_factory.outputs]
        self.outputs = self.eval(**self.eval_args)
        # set model parameters, if any
        for k in self.conditions.keys():
            if k in self.eval_args.keys():
                self.eval_args[k] = self.conditions[k]

        if "delay" in self.conditions.keys():
            self.p_delay = self.conditions["delay"]
            print "Le 'delay' est de : ", self.p_delay
        else:
            self.p_delay = 1.0

        print ""
Exemplo n.º 3
0
    def __init__(self, model, events):
        PyDynamics.Dynamics.__init__(self, model, events)
        # get init partameters
        self.conditions = convert.to_pyvalue(events)

        pm = load_package_manager()
        node_factory = pm[self.conditions['openalea_pkgname']][
            self.conditions['openalea_nodename']]
        self.eval = function(node_factory)
        # /!\ on suppose l'unicite des noms entre parametres et attributs des ports
        self.eval_args = dict([(d['name'], -1.) for d in node_factory.inputs])
        self.out_names = [d['name'] for d in node_factory.outputs]
        self.outputs = self.eval(**self.eval_args)
        # set model parameters, if any
        for k in self.conditions.keys():
            if k in self.eval_args.keys():
                self.eval_args[k] = self.conditions[k]

        if "delay" in self.conditions.keys():
            self.p_delay = self.conditions["delay"]
            print("Le 'delay' est de : ", self.p_delay)
        else:
            self.p_delay = 1.0

        print("")
Exemplo n.º 4
0
from openalea.core.alea import load_package_manager, function
import alinea.phenomenal.phenomenal_config as pconf

pm = load_package_manager()
node_factory = pm['alinea.phenomenal.macros']['side_binarisation']
node_factory2 = pm['alinea.phenomenal.macros']['top_binarisation']
side_binarisation = function(node_factory)
top_binarisation = function(node_factory2)

p = pconf.getconfig()
opts_sv = pconf.sidebinarisation_options(p).values()
opts_tv = pconf.topbinarisation_options(p).values()


def side_bin(file):
    return side_binarisation(file, *opts_sv)[0]
    
    
res = top_binarisation(file, *opts_tv)[0]
from sys import argv,stdout,stdin
from openalea.aml import MTG, VtxList, Trunk, Feature
from openalea.core.alea import load_package_manager, function
from numpy import mean, array

pm = load_package_manager()
nf = pm['__my package__']['twosethistogram']
histogram = function(nf)

#get mtg file name
#mfile=argv[1]
mfile='ModelMTG.mtg'

m=MTG(mfile)
branches=VtxList(Scale=2)
nodes=VtxList(Scale=3)
rat= len(nodes) / float(len(branches))
stdout.write('\nNode:Branch ratio is %.2f\n' % (rat))

numsegs=[] # as limited by MAXGROW
flushlen=[] # this is what is provided by budvigour, but not limited by MAXGROW
for n in nodes[4:len(nodes)]: #skip first there nodes as they are set to INITIALNODES
	fl=Feature(n,'FlushLen')
	nc=Feature(n,'NumSegs')
	if fl >0:
		flushlen.append(fl)
		numsegs.append(nc)
stdout.write('Mean actual flush len %.2f %.2f - %.2f (%i) \n' % (mean(numsegs),min(numsegs),max(numsegs),len(numsegs)))
stdout.write('Mean potential        %.2f %.2f - %.2f (%i) \n' % (mean(flushlen),min(flushlen),max(flushlen),len(flushlen)))

nbins=10
Exemplo n.º 6
0
import pickle

from  openalea.core import alea

pm = alea.load_package_manager()

def subdataflow():
    factory = pm['openalea.tutorial.multiprocess']['x+1']
    f = alea.function(factory)
    return f()[0]

def test0():
    l  = pm.search_node('int')
    n = l[0]
    pickle.dumps(n.instantiate())

def test1():
    pickle.dumps(subdataflow())

def test2():
    sdf = subdataflow()
    pickle.dumps(sdf.dataflow)

def test3():
    sdf = subdataflow()
    pickle.dumps(sdf.algo)

def check(node):
    d = node.__getstate__()
    for k, v in d.iteritems():
        try:
Exemplo n.º 7
0
def json_convert(package_name, module_name):
    ''' convert openalea metainfo package and module in json
    
    parameters:
    -----------
       package_name: name of package to convert (type:string)
       module_name : name of python module of package (type:string)
    
    Return:
    -------
       print of metainformation in json according to IPM schema

    '''
    pm = alea.load_package_manager()

    factory = pm[package_name]
    name = module_name

    def DSS(factory):
        """Transform package meta-information in Ordered Dict"""
        identifier = NotImplemented
        name = factory.name
        description = factory.metainfo['description']  # optional no ask by ipm
        version = factory.metainfo['version']
        Authors = factory.metainfo['authors']
        url = factory.metainfo['url']
        languages = NotImplemented
        organization = {
            "name": factory.metainfo["institutes"],
            "country": NotImplemented,
            "address": NotImplemented,
            "postal_code": NotImplemented,
            "city": NotImplemented,
            "email": NotImplemented,
            "url": NotImplemented
        }
        license = factory.metainfo['license']  # optional no ask by ipm

        return OrderedDict(identifier=identifier,
                           name=name,
                           description=description,
                           version=version,
                           Authors=Authors,
                           url=url,
                           languages=languages,
                           organization=organization,
                           license=license)

    def DSSModel(factory, name):
        """Transform a factory into an OrderedDict"""
        name = factory[name].name
        identifier = NotImplemented
        version = NotImplemented
        type_of_decision = NotImplemented
        type_of_output = NotImplemented
        description_URL = NotImplemented
        description = factory[name].description
        citation = NotImplemented
        execution = {
            "type": NotImplemented,
            "endpoints": NotImplemented,
            "form_method": NotImplemented,
            "content_type": NotImplemented,
            "input_schema": factory[name].get_writer()
        }
        inputs = factory[name].inputs
        authors = [{
            "name": factory[name].get_authors(),
            "email": NotImplemented,
            "organization": factory.metainfo["institutes"]
        }]
        pests = NotImplemented
        crops = NotImplemented
        keywords = NotImplemented
        output = {
            "warning_status_interpretation":
            NotImplemented,
            "result_parameters": [{
                "id":
                NotImplemented,
                "title":
                factory[name].outputs[0]['name'],
                "description":
                factory[name].outputs[0]['desc']
            }]
        }
        valid_spatial = {
            "countries": NotImplemented,
            "geoJson": NotImplemented
        }

        return OrderedDict(name=name,
                           identifier=identifier,
                           version=version,
                           type_of_decision=type_of_decision,
                           type_of_output=type_of_output,
                           description_URL=description_URL,
                           description=description,
                           citation=citation,
                           execution=execution,
                           input=inputs,
                           authors=authors,
                           pests=pests,
                           crops=crops,
                           keywords=keywords,
                           output=output,
                           valid_spatial=valid_spatial)

    print json.dumps({
        "DSS": DSS(factory),
        "models": [DSSModel(factory, name)]
    },
                     indent=4,
                     sort_keys=True,
                     cls=MyEncoder)