Ejemplo n.º 1
0
def test_count_pixels():
    scene_path = path("data/test_povray/scene.bmp")
    scene_box_path = path("data/test_povray/scene_box.bmp")
    
    rgb_colors = [[0, 170, 0], 
                  [170, 170, 0], 
                  [255, 0, 0], 
                  [255, 170, 0], 
                  [255, 201, 5], 
                  [0, 0, 255], 
                  [255, 170, 0], 
                  [0, 0, 255], 
                  [255, 201, 5], 
                  [170, 255, 255], 
                  [170, 255, 255]]
    
    import tempfile
    povray_results_directory = path(tempfile.mkdtemp(suffix='_povray_results'))
    result_path = povray_results_directory.joinpath('scene_res.csv')
    normalized_scene_path = povray_results_directory.joinpath('normalized_scene.bmp')
    normalize = True
    post_processing.count_pixels(scene_path=scene_path, scene_box_path=scene_box_path, rgb_colors=rgb_colors, result_path=result_path, normalize=normalize, normalized_scene_path=normalized_scene_path)
    expected_result_array = np.array([['scene.bmp', 0, 28526, 375, 2253, 25, 83, 2959, 122786]], dtype=object)    
    result_array = pandas.read_csv(result_path).values
    np.testing.assert_equal(result_array, expected_result_array)
Ejemplo n.º 2
0
    def changeExtension(self, extension=None):
        """
        Change to a new extension.

        :param extension: can be "mini", "3d", "tissue", "plant"
        """
        self.removeDocksWidgets()

        filename = 'oalab.py'
        conf = path(get_openalea_home_dir()) / filename
        if extension in ["mini", "3d", "tissue", "plant"]:
            filename = ('oalab_' + extension + '.py')
            conf = path(get_openalea_home_dir()) / filename
        if not conf.exists():
            with conf.open('w') as f:
                # TODO : auto generate config file
                # f.write(self._config.generate_config_file())
                if extension == "mini":
                    f.write(config_file_mini)
                elif extension == "3d":
                    f.write(config_file_3d)
                elif extension == "tissue":
                    f.write(config_file_tissue)
                elif extension == "plant":
                    f.write(config_file_plant)
                else:
                    f.write(config_file_default)

        self.session.load_config_file(filename=filename,
                                      path=get_openalea_home_dir())
        self.setWidgets(self.controller)
Ejemplo n.º 3
0
    def changeExtension(self, extension=None):
        """
        Change to a new extension.

        :param extension: can be "mini", "3d", "tissue", "plant"
        """
        self.removeDocksWidgets()

        filename = 'oalab.py'
        conf = path(get_openalea_home_dir()) / filename
        if extension in ["mini", "3d", "tissue", "plant"]:
            filename = ('oalab_' + extension + '.py')
            conf = path(get_openalea_home_dir()) / filename
        if not conf.exists():
            with conf.open('w') as f:
                # TODO : auto generate config file
                # f.write(self._config.generate_config_file())
                if extension == "mini":
                    f.write(config_file_mini)
                elif extension == "3d":
                    f.write(config_file_3d)
                elif extension == "tissue":
                    f.write(config_file_tissue)
                elif extension == "plant":
                    f.write(config_file_plant)
                else:
                    f.write(config_file_default)

        self.session.load_config_file(filename=filename, path=get_openalea_home_dir())
        self.setWidgets(self.controller)
Ejemplo n.º 4
0
def test_count_pixels():
    scene_path = path("data/test_povray/scene.bmp")
    scene_box_path = path("data/test_povray/scene_box.bmp")
    
    rgb_colors = [[0, 170, 0], 
                  [170, 170, 0], 
                  [255, 0, 0], 
                  [255, 170, 0], 
                  [255, 201, 5], 
                  [0, 0, 255], 
                  [255, 170, 0], 
                  [0, 0, 255], 
                  [255, 201, 5], 
                  [170, 255, 255], 
                  [170, 255, 255]]
    
    import tempfile
    povray_results_directory = path(tempfile.mkdtemp(suffix='_povray_results'))
    result_path = povray_results_directory.joinpath('scene_res.csv')
    normalized_scene_path = povray_results_directory.joinpath('normalized_scene.bmp')
    normalize = True
    post_processing.count_pixels(scene_path=scene_path, scene_box_path=scene_box_path, rgb_colors=rgb_colors, result_path=result_path, normalize=normalize, normalized_scene_path=normalized_scene_path)
    expected_result_array = np.array([['scene.bmp', 0, 28526, 375, 2253, 25, 83, 2959, 122786]], dtype=object)    
    result_array = pandas.read_csv(result_path).values
    np.testing.assert_equal(result_array, expected_result_array)
Ejemplo n.º 5
0
def test_post_processing():
    adel_output_path = path('data/test_stand/adel_output.csv')

    import tempfile
    global_postprocessing_file_path = path(
        tempfile.mktemp(prefix='global_postprocessing', suffix='.csv'))
    peraxis_postprocessing_file_path = path(
        tempfile.mktemp(prefix='peraxis_postprocessing', suffix='.csv'))

    # launch the postprocessing
    (global_postprocessing_file_path,
     peraxis_postprocessing_file_path,
     intermediate_results_file_path)= \
        post_processing(adel_output_path,
                        3,
                        0.013824884792626729,
                        global_postprocessing_file_path,
                        peraxis_postprocessing_file_path)

    expected_results_dir_path = path('data/test_stand')
    # check intermediate results
    intermediate_results_array = \
        pandas.read_csv(intermediate_results_file_path).values
    intermediate_results_array = np.delete(intermediate_results_array, 2,
                                           1).astype(float)
    expected_intermediate_results_array = \
        pandas.read_csv(expected_results_dir_path/'intermediate.csv').values
    expected_intermediate_results_array = np.delete(
        expected_intermediate_results_array, 2, 1).astype(float)
    np.testing.assert_allclose(intermediate_results_array,
                               expected_intermediate_results_array,
                               relative_tolerance, absolute_tolerance)

    # check per axis post processing results
    peraxis_postprocessing_results_array = pandas.read_csv(
        peraxis_postprocessing_file_path).values
    peraxis_postprocessing_results_array = np.delete(
        peraxis_postprocessing_results_array, [0, 2], 1).astype(float)
    expected_peraxis_postprocessing_results_array = pandas.read_csv(
        expected_results_dir_path / 'peraxis_postprocessing.csv').values
    expected_peraxis_postprocessing_results_array = np.delete(
        expected_peraxis_postprocessing_results_array, [0, 2], 1).astype(float)
    np.testing.assert_allclose(peraxis_postprocessing_results_array,
                               expected_peraxis_postprocessing_results_array,
                               relative_tolerance, absolute_tolerance)

    # check global post processing results
    global_postprocessing_results_array = pandas.read_csv(
        global_postprocessing_file_path).values
    global_postprocessing_results_array = np.delete(
        global_postprocessing_results_array, 0, 1).astype(float)
    expected_global_postprocessing_results_array = pandas.read_csv(
        expected_results_dir_path / 'global_postprocessing.csv').values
    expected_global_postprocessing_results_array = np.delete(
        expected_global_postprocessing_results_array, 0, 1).astype(float)
    np.testing.assert_allclose(global_postprocessing_results_array,
                               expected_global_postprocessing_results_array,
                               relative_tolerance, absolute_tolerance)
def test_get_data():
    res = run(('openalea.data file', 'get_data'), inputs={'package': 'alinea.caribu.data', 'filename': 'filterT.can'}, pm=pm)
    assert path(res[0]).basename() == 'filterT.can'
    res = run(('openalea.data file', 'get_data'), inputs={'package': 'openalea.core', 'filename': 'test_image.npy'}, pm=pm)
    assert path(res[0]).basename() == 'test_image.npy'
    res = run(('openalea.data file', 'get_data'), inputs={'package': 'vplants.fractalysis', 'filename': 'mango_f21_L.bgeom'}, pm=pm)
    assert path(res[0]).basename() == 'mango_f21_L.bgeom'
    res = run(('openalea.data file', 'get_data'), inputs={'package': 'openalea.stat_tool', 'filename': 'meri1.his'}, pm=pm)
    assert res[0] == None
Ejemplo n.º 7
0
def showOpenFileDialog(extension=None, where=None, parent=None):
    if extension is None:
        extension = ""

    if where is not None:
        my_path = path(str(where)).abspath().splitpath()[0]
    else:
        my_path = path(settings.get_project_dir())
    logger.debug("Search to open file with extension " + extension + " from " + my_path)
    fname = QtGui.QFileDialog.getOpenFileName(parent, 'Select File to open',
                                              my_path, "All (*);;Scripts Files (%s)" % extension)
    return fname
Ejemplo n.º 8
0
def test_shared_data_browser():
    res = run(('openalea.misc.test','shared_data_browser'), {}, pm=pm)
    assert res == []
    res = run(('openalea.misc', 'SharedDataBrowser'), inputs={'package': 'openalea.stat_tool', 'filename': 'meri1.his'}, pm=pm)
    assert path(res[0]).basename() == 'meri1.his'
    res = run(('openalea.misc', 'SharedDataBrowser'), inputs={'package': 'vplants.sequence_analysis', 'filename': 'cafe_ortho1.seq'}, pm=pm)
    assert path(res[0]).basename() == 'cafe_ortho1.seq'
    res = run(('openalea.misc', 'SharedDataBrowser'), inputs={'package': 'alinea.caribu', 'filename': 'filterT.can'}, pm=pm)
    assert path(res[0]).basename() == 'filterT.can'
    res = run(('openalea.misc', 'SharedDataBrowser'),inputs={'package': 'numpy', 'filename': 'something.something'}, pm=pm)
    assert res[0] == None
    res = run(('openalea.misc', 'SharedDataBrowser'),inputs={'package': 'alinea.adel.data', 'filename': 'dimTSoissons.csv'}, pm=pm)
    assert res[0] == None
def test_to_csv():
    tmp_filepath = tempfile.mkstemp()[1]
    res = run(('openalea.pandas.io', 'to_csv'),
              inputs={
                  'dataframe': expected_df,
                  'path_or_buf': tmp_filepath,
                  'index': False
              },
              pm=pm)
    df = pandas.read_csv(path(res[0]))
    np.testing.assert_allclose(df.values, expected_df.values,
                               relative_tolerance, absolute_tolerance)
    path(tmp_filepath).remove()
Ejemplo n.º 10
0
def showOpenFileDialog(extension=None, where=None, parent=None):
    if extension is None:
        extension = ""

    if where is not None:
        my_path = path(str(where)).abspath().splitpath()[0]
    else:
        my_path = path(settings.get_project_dir())
    logger.debug("Search to open file with extension " + extension + " from " +
                 my_path)
    fname = QtGui.QFileDialog.getOpenFileName(
        parent, 'Select File to open', my_path,
        "All (*);;Scripts Files (%s)" % extension)
    return fname
Ejemplo n.º 11
0
 def __init__(self, camera = {'type':'perspective', 'distance':1., 'fov':45.,  'xc':0., 'yc':0., 'azimuth':0, 'zenith':0.}, image_width = 320, image_height = 280, background = (0,0,0), light_position = (10,0,10), light_color=(1,1,1), working_dir = None):
     """ Setup a Povray instance
     
     :Parameters:
         - camera: a dict of parameters for positioning the camera
             - distance: distance from the position of the camera to the look_at point
             - fov : angle corresponding to the width of the image
             - xc, yc : coordinates of the center of the scene
             - azimuth: angle in degree around the vertical axis. az=0. is equialent to have the width of the image align to X direction of the scene
             - zenith: angle between the view direction and the vertical
         - image_width: width of the final image in pixel
         - image_height: height of the final image in pixel
         - working_dir: A directory for storing povary files. If None, (default),  a temporary directory will be created and removed onece the instance is deleted
         
     """
 
     try: 
         if working_dir is not None:
             self.wdir=path(path(working_dir).abspath())
             if not self.wdir.exists():
                 self.wdir.mkdir() 
             self.cleanup_wdir = False
         else:
             # build a temporary directory
             self.wdir = path(tempfile.mkdtemp())
             self.cleanup_wdir = True
     except:
         raise PovRayError("PovRay can't create its working directory : check for read/write permission or security level")
     
     if platform.system() is 'Windows':
         self.cmdline = 'pvengine +FN +I%s +H%d +W%d -d /exit'
     else:
         self.cmdline = 'povray +FN +I%s +H%d +W%d'
         
     
     self.image_width = image_width
     self.image_height = image_height
     self.camera = camera
     self.light_position = light_position
     self.light_color = light_color
     self.background = background
     
     self.soil = False
     self.rendered_image_path = None
     self.tesselator = pgl.Tesselator()
     
     #to be removed once cv_camera has been properly integrated
     self.user_camera = None
Ejemplo n.º 12
0
 def __init__(self, camera = {'type':'perspective', 'distance':1., 'fov':45.,  'xc':0., 'yc':0., 'azimuth':0, 'zenith':0.}, image_width = 320, image_height = 280, background = (0,0,0), light_position = (10,0,10), light_color=(1,1,1), working_dir = None):
     """ Setup a Povray instance
     
     :Parameters:
         - camera: a dict of parameters for positioning the camera
             - distance: distance from the position of the camera to the look_at point
             - fov : angle corresponding to the width of the image
             - xc, yc : coordinates of the center of the scene
             - azimuth: angle in degree around the vertical axis. az=0. is equialent to have the width of the image align to X direction of the scene
             - zenith: angle between the view direction and the vertical
         - image_width: width of the final image in pixel
         - image_height: height of the final image in pixel
         - working_dir: A directory for storing povary files. If None, (default),  a temporary directory will be created and removed onece the instance is deleted
         
     """
 
     try: 
         if working_dir is not None:
             self.wdir=path(path(working_dir).abspath())
             if not self.wdir.exists():
                 self.wdir.mkdir() 
             self.cleanup_wdir = False
         else:
             # build a temporary directory
             self.wdir = path(tempfile.mkdtemp())
             self.cleanup_wdir = True
     except:
         raise PovRayError("PovRay can't create its working directory : check for read/write permission or security level")
     
     if platform.system() is 'Windows':
         self.cmdline = 'pvengine +FN +I%s +H%d +W%d -d /exit'
     else:
         self.cmdline = 'povray +FN +I%s +H%d +W%d'
         
     
     self.image_width = image_width
     self.image_height = image_height
     self.camera = camera
     self.light_position = light_position
     self.light_color = light_color
     self.background = background
     
     self.soil = False
     self.rendered_image_path = None
     self.tesselator = pgl.Tesselator()
     
     #to be removed once cv_camera has been properly integrated
     self.user_camera = None
Ejemplo n.º 13
0
def simulation(lsystem_filename, nb_plants):

    # write AleaPars.h
    fn = path(lsystem_filename)
    dir = fn.dirname()

    param_fn = dir / "AleaPars.h"
    s = '\n#define NB_PLANTS %d\n' % nb_plants
    f = open(param_fn, "w")
    f.write(s)
    f.close()

    view_file = 'view.v'
    leaf_file = 'leaf.a'
    color_file = 'color.map'
    result_file = 'result.str'
    cmd = "cpfg -g -h**o -str %s %s %s %s -m %s" % (
        result_file, fn.basename(), view_file, leaf_file, color_file)
    print cmd
    curdir = os.getcwd()
    print dir
    os.chdir(dir)
    os.system(cmd)
    os.chdir(curdir)
    result_file = dir / result_file
    if not result_file.exists():
        result_file = dir / '100plants' / 'bid050.str'

    f = open(result_file)
    s = f.read()
    s = s.replace('\n', '')
    f.close()
    return s
Ejemplo n.º 14
0
    def __init__(self, name=None, project='', dir='.', release='0.1'):

        self.name = name  # e.g. name = PlantGL
        self.package = name.lower()  # e.g. name = plantgl
        self.dir = dir
        self.pkg_dir = path(dir) / self.package
        self.languages = ['python']
        self.project = project.lower()
        self.release = release

        self.check_project()

        self.metainfo = {
            'PACKAGE':
            self.package,
            'PACKAGE_NAME':
            self.name,
            'PROJECT':
            self.project,
            'DEFAULT_PROJECT':
            self.project if self.project else 'openalea',
            'PROJECT_NAME':
            self.project_name[self.project] if self.project else '',
            'FULL_NAME':
            self.project_name[self.project] + '.' +
            self.name if self.project else self.name,
            'RELEASE':
            self.release,
        }
Ejemplo n.º 15
0
def simulation(lsystem_filename, nb_plants):
    
    # write AleaPars.h
    fn = path(lsystem_filename)
    dir = fn.dirname()

    param_fn = dir / "AleaPars.h"
    s = '\n#define NB_PLANTS %d\n'%nb_plants
    f = open(param_fn, "w")
    f.write(s)
    f.close()

    view_file = 'view.v'
    leaf_file = 'leaf.a'
    color_file = 'color.map'
    result_file = 'result.str'
    cmd = "cpfg -g -h**o -str %s %s %s %s -m %s" % (result_file, fn.basename(), view_file, leaf_file, color_file)
    print cmd
    curdir = os.getcwd()
    print dir
    os.chdir(dir)
    os.system(cmd)
    os.chdir(curdir)
    result_file = dir / result_file
    if not result_file.exists():
        result_file = dir/'100plants'/'bid050.str'
        
    f = open(result_file)
    s = f.read()
    s = s.replace('\n','')
    f.close()
    return s
Ejemplo n.º 16
0
    def __call__(self, pov_file, povdir, wait):

        path_ini = os.path.abspath(os.getcwd())
        if win32api:
            dir = pov_file[:-len(pov_file.split('\\')[-1]) -
                           1]  #path du fichier .pov d'origine
            name = pov_file.split('\\')[-1].split('.')[0]
            #os.system('copy '+win32api.GetShortPathName(pov_file)+' '+win32api.GetShortPathName(povdir))  #copie du fichier pov dans le bin de povray pas necessaire : avec short paths peut executer diretcement
            os.chdir(povdir)
            os.system(
                'pvengine.exe /RENDER ' + join(win32api.GetShortPathName(dir),
                                               pov_file.split('\\')[-1])
            )  #short name pour le path, mais pas le nom de fichier pour conserver noms'd'image complets
            ext = '.bmp'
        else:
            _pov_file = path(pov_file)
            dir = _pov_file.dirname()
            name = _pov_file.namebase

            os.chdir(dir)
            cmdline = 'povray +I%s' % (pov_file)
            ext = '.png'

        time.sleep(wait)  #temps d'attente en secondes entre 2 simulations
        os.chdir(path_ini)

        return join(dir, name + ext)
Ejemplo n.º 17
0
def test_mtglpy_topvine():
    fn = path('vinemtg_n.lpy')
    if not fn.exists():
        return

    l = Lsystem(str(fn))
    parameters = {}
    parameters['carto_file'] = 'geom_n.dat'
    parameters['picle_file'] = 'vine_n.dat'
    parameters['TTfin'] = None

    #l.context().updateNamespace(parameters)

    c_iter = l.getLastIterationNb()
    nbstep = l.derivationLength - c_iter
    tree = l.iterate(l.axiom, c_iter, nbstep)

    scene = l.sceneInterpretation(tree)

    mtg = lpy2mtg(tree, l, scene)

    print(len(mtg))
    axial_tree = AxialTree()
    axial_tree = mtg2lpy(mtg, l, axial_tree)

    g = lpy2mtg(axial_tree, l, scene)

    assert len(g) == len(mtg)
    #axial_tree = mtg2axialtree(mtg, scale, parameters, axial_tree)

    # Check
    assert True
    return mtg, tree, axial_tree
Ejemplo n.º 18
0
 def save_as(self):
     project = self.project()
     if project:
         p = path(self.showNewProjectDialog(default_name=None, text="Select name to save project")).abspath()
         projectdir, name = p.splitpath()
         if name:
             project.save_as(projectdir, name)
Ejemplo n.º 19
0
    def _update_available_project_menu(self):
        """
        Discover all projects and generate an action for each one.
        Then connect this action to _on_open_project_triggered
        """
        self.menu_available_projects.clear()
        self.action_available_project.clear()

        all_projects = {}  # dict parent dir -> list of Project objects
        for project in projects():
            all_projects.setdefault(project.projectdir, []).append(project)

        home = path(get_default_home_dir())
        for projectdir, _projects in all_projects.iteritems():
            relpath = home.relpathto(projectdir)
            label = unicode(relpath)
            menu = QtGui.QMenu(label, self.menu_available_projects)
            for project in sorted(_projects, key=lambda project: project.label):
                icon = obj_icon(project, default=DEFAULT_PROJECT_ICON, paths=[project.path])
                action = QtGui.QAction(icon, project.label, self.menu_available_projects)
                action.triggered.connect(self._on_open_project_triggered)
                menu.addAction(action)
                self.action_available_project[action] = project
            self.menu_available_projects.addMenu(menu)
        return self.menu_available_projects
Ejemplo n.º 20
0
    def find_vlab_dir(self, directory, recursive=True):
        """
        Find in a directory vlab specification file.

        Search recursivly is recursive is True

        :return: a list of pkgreader instances
        """

        spec_files = set()
        if(not os.path.isdir(directory)):
            logger.error("Not a directory", directory, repr(directory))
            # self.log.add("Not a directory", directory, repr(directory))
            return []

        p = path(directory).abspath()
        spec_name = '*specifications'
        # search for wralea.py
        if(recursive and SEARCH_OUTSIDE_ENTRY_POINTS):
            spec_files.update(p.walkfiles(spec_name))
        else:
            spec_files.update(p.glob(spec_name))

        for f in spec_files:
            logger.info("Package Manager : found  VLAB %s" % p)
            # self.log.add("Package Manager : found  VLAB %s" % p)

        return list(map(self.get_pkgreader, spec_files))
Ejemplo n.º 21
0
    def _update_available_project_menu(self):
        """
        Discover all projects and generate an action for each one.
        Then connect this action to _on_open_project_triggered
        """
        self.menu_available_projects.clear()
        self.action_available_project.clear()

        all_projects = {}  # dict parent dir -> list of Project objects
        for project in projects():
            all_projects.setdefault(project.projectdir, []).append(project)

        home = path(get_default_home_dir())
        for projectdir, _projects in all_projects.iteritems():
            relpath = home.relpathto(projectdir)
            label = unicode(relpath)
            menu = QtGui.QMenu(label, self.menu_available_projects)
            for project in sorted(_projects,
                                  key=lambda project: project.label):
                icon = obj_icon(project,
                                default=DEFAULT_PROJECT_ICON,
                                paths=[project.path])
                action = QtGui.QAction(icon, project.label,
                                       self.menu_available_projects)
                action.triggered.connect(self._on_open_project_triggered)
                menu.addAction(action)
                self.action_available_project[action] = project
            self.menu_available_projects.addMenu(menu)
        return self.menu_available_projects
Ejemplo n.º 22
0
def test_full():
    data = path(scanalea.__path__[0]) / '..' / '..'
    datadir = data / 'share' / 'INRIA_maize' / 'finemesh'
    files = datadir.glob('*.ply')

    report = pd.read_csv(datadir / 'report.txt',
                         sep=' *',
                         header=None,
                         names=['Date', 'num'],
                         infer_datetime_format=True)

    report = report.sort('Date')

    # bad option to  do the trick...
    def fun(x):
        return [f for f in files if ('_' + str(x) + '_') in f][0]

    report['filename'] = report['num'].map(fun)

    scenes = [read(fn) for fn in report['filename']]
    shapes = [
        normalised(scenes[xx][0], (xx / 5, xx % 5., 0),
                   (xx * 10, 80, (xx * 30) % 255)) for xx in range(len(scenes))
    ]

    scene = Scene(shapes)
    return scene
Ejemplo n.º 23
0
 def get_file(f):
     exts = ['.png', '.jpg', '.tif']
     fn = f.splitext()[0]
     for ext in exts:
         _f = path(fn + ext)
         if _f.exists():
             return _f
Ejemplo n.º 24
0
def test_mtglpy_topvine():
    fn = path('vinemtg_n.lpy')
    if not fn.exists():
        return

    l = Lsystem(str(fn))
    parameters = {}
    parameters['carto_file'] = 'geom_n.dat'
    parameters['picle_file'] = 'vine_n.dat'
    parameters['TTfin'] = None

    #l.context().updateNamespace(parameters)

    c_iter = l.getLastIterationNb()
    nbstep = l.derivationLength - c_iter
    tree = l.iterate(l.axiom,c_iter,nbstep)

    scene = l.sceneInterpretation(tree)

    mtg = lpy2mtg(tree, l, scene)

    print len(mtg)
    axial_tree = AxialTree()
    axial_tree = mtg2lpy(mtg, l, axial_tree)

    g = lpy2mtg(axial_tree, l, scene)

    assert len(g) == len(mtg)
    #axial_tree = mtg2axialtree(mtg, scale, parameters, axial_tree)
    
    # Check
    assert True
    return mtg, tree, axial_tree
Ejemplo n.º 25
0
 def showNewProjectDialog(self, default_name=None, text=None, parent=None):
     my_path = path(settings.get_project_dir())
     if default_name:
         my_path = my_path / default_name
     if not text:
         text = 'Select name to create project'
     fname = QtGui.QFileDialog.getSaveFileName(parent, text, my_path)
     return fname
Ejemplo n.º 26
0
 def load_controls(self, filename=None):
     if not filename:
         filename = QtGui.QFileDialog.getOpenFileName(self, 'Select python file')
     if filename:
         if path(filename).exists():
             self.model()._manager.clear()
             code = file(filename, 'r').read()
             exec(code)
Ejemplo n.º 27
0
    def find_all_wralea(self):
        """
        Find on the system all wralea.py files

        :return : a list of file paths
        """

        files = set()
        directories = self.get_wralea_path()
        recursive = True
        if not SEARCH_OUTSIDE_ENTRY_POINTS:
            recursive = False
        if recursive:
            files = set(f.abspath() for p in directories for f in path(p).walkfiles('*wralea*.py'))
        else:
            files = set(f.abspath() for p in directories for f in path(p).glob('*wralea*.py'))
        return files
Ejemplo n.º 28
0
def glob(directory, pattern):
    """Return a list of path that match the pattern

    :param pattern: a pattern to glob
    :return: a list of paths that match the pattern
    """
    ret = path.path(directory).glob(pattern)
    return ret,
Ejemplo n.º 29
0
 def showNewProjectDialog(self, default_name=None, text=None, parent=None):
     my_path = path(settings.get_project_dir())
     if default_name:
         my_path = my_path / default_name
     if not text:
         text = 'Select name to create project'
     fname = QtGui.QFileDialog.getSaveFileName(parent, text, my_path)
     return fname
Ejemplo n.º 30
0
def glob(directory,pattern):
    """Return a list of path that match the pattern

    :param pattern: a pattern to glob
    :return: a list of paths that match the pattern
    """
    ret = path.path(directory).glob(pattern)
    return ret,
Ejemplo n.º 31
0
def tutorials():
    from openalea.core.path import path
    try:
        from openalea import oalab
        from openalea.deploy.shared_data import shared_data
    except ImportError:
        return []
    else:
        oalab_dir = shared_data(oalab)
        return [path(oalab_dir)]
Ejemplo n.º 32
0
def create_project_shortcut():
    """
    Create a shortcut/symlink inside project directory to oalab.share directory.
    Permit to access to oalab examples simpler.
    """
    project_dir = get_project_dir()
    project_link_name = path(project_dir) / "oalab_examples"
    if not project_link_name.exists():
        oalab_dir = shared_data(oalab)
        symlink(oalab_dir, project_link_name)
Ejemplo n.º 33
0
 def __call__(self):
     from openalea.core.path import path
     try:
         from openalea import oalab
         from openalea.deploy.shared_data import shared_data
     except ImportError:
         return []
     else:
         oalab_dir = shared_data(oalab)
         return [path(oalab_dir)]
Ejemplo n.º 34
0
    def _raw_data(self, mimedata, mimetype_in, mimetype_out):
        """
        'text/uri-list' -> list of paths
        'openalealab/data' -> name
        """

        if mimetype_in == 'text/uri-list':
            return [path(url.toLocalFile()) for url in mimedata.urls()]
        elif mimetype_in == 'openalealab/data':
            return mimedata.data('openalealab/data')
Ejemplo n.º 35
0
def create_project_shortcut():
    """
    Create a shortcut/symlink inside project directory to oalab.share directory.
    Permit to access to oalab examples simpler.
    """
    project_dir = get_project_dir()
    project_link_name = path(project_dir)/"oalab_examples"
    if not project_link_name.exists():
        oalab_dir = shared_data(oalab)
        symlink(oalab_dir,project_link_name)
def test_get_data():
    res = run(
        ("openalea.data file", "get_data"), inputs={"package": "alinea.caribu.data", "filename": "filterT.can"}, pm=pm
    )
    assert path(res[0]).basename() == "filterT.can"
    res = run(
        ("openalea.data file", "get_data"), inputs={"package": "openalea.core", "filename": "test_image.npy"}, pm=pm
    )
    assert path(res[0]).basename() == "test_image.npy"
    res = run(
        ("openalea.data file", "get_data"),
        inputs={"package": "vplants.fractalysis", "filename": "mango_f21_L.bgeom"},
        pm=pm,
    )
    assert path(res[0]).basename() == "mango_f21_L.bgeom"
    res = run(
        ("openalea.data file", "get_data"), inputs={"package": "openalea.stat_tool", "filename": "meri1.his"}, pm=pm
    )
    assert res[0] == None
Ejemplo n.º 37
0
def qt4(directory = path('qt4'), name='qt4'):

    zip_name = path('..')/name + '.zip'

    patterns = ['*2.5.dylib', '*.py', '*.api', '*.so',  '*.txt', '*safe', '*INFO',  '*.4.dylib'] 

    curdir = path(os.curdir).abspath()
    os.chdir(directory)

    zf=zipfile.ZipFile(zip_name,compression=zipfile.ZIP_DEFLATED,mode='w')

    d = path('.')
    for pattern in patterns:
        for fn in d.walkfiles(pattern):
            print 'add ', fn
            zf.write(fn)

    zf.close()
    os.chdir(curdir)
Ejemplo n.º 38
0
 def decode(self, raw_data, mimetype_in, mimetype_out, **kwds):
     """
     raw_data: list of urls
     """
     if mimetype_in == 'text/uri-list':
         for url in raw_data:
             local_file = path(url)
             return local_file, dict(path=local_file, name=local_file.namebase)
     else:
         return None, {}
Ejemplo n.º 39
0
 def save_as(self):
     project = self.project()
     if project:
         p = path(
             self.showNewProjectDialog(
                 default_name=None,
                 text="Select name to save project")).abspath()
         projectdir, name = p.splitpath()
         if name:
             project.save_as(projectdir, name)
Ejemplo n.º 40
0
    def __call__(self, inputs):
        """
        :param input: list of input values 
        :returns: the path string
        """

        fname = str(inputs[0])
        d = path.path(fname)
        d.basename()
        self.set_caption(str('.../'+d.basename()))
        return (fname, )
Ejemplo n.º 41
0
def test_python_dict():
    obj1 = {'test1': True, 'test2': 42, 'test3': 'ok'}
    filename = path("temp.py")
    saver = GenericSaver()
    saver.save(obj1, filename)
    loader = PythonLoader()
    obj2 = loader.load(filename)
    assert obj1 == obj2

    if filename.exists():
        os.remove(filename)
def test_python_dict():
    obj1 = {'test1': True, 'test2': 42, 'test3': 'ok'}
    filename = path("temp.py")
    saver = CPickleSaver()
    saver.save(obj1, filename)
    loader = CPickleLoader()
    obj2 = loader.load(filename)
    assert obj1 == obj2

    if filename.exists():
        os.remove(filename)
def test_python_int():
    obj1 = 42
    filename = path("temp.py")
    saver = CPickleSaver()
    saver.save(obj1, filename)
    loader = CPickleLoader()
    obj2 = loader.load(filename)
    assert obj1 == obj2

    if filename.exists():
        os.remove(filename)
def test_python_str():
    obj1 = "this is a beautifull test text"
    filename = path("temp.py")
    saver = CPickleSaver()
    saver.save(obj1, filename)
    loader = CPickleLoader()
    obj2 = loader.load(filename)
    assert obj1 == obj2

    if filename.exists():
        os.remove(filename)
Ejemplo n.º 45
0
    def __call__(self, inputs):
        """
        :param input: list of input values 
        :returns: the path string
        """

        fname = str(inputs[0])
        d = path.path(fname)
        d.basename()
        self.set_caption(str('.../' + d.basename()))
        return (fname, )
Ejemplo n.º 46
0
def test_python_int():
    obj1 = 42
    filename = path("temp.py")
    saver = GenericSaver()
    saver.save(obj1, filename)
    loader = PythonLoader()
    obj2 = loader.load(filename)
    assert obj1 == obj2

    if filename.exists():
        os.remove(filename)
Ejemplo n.º 47
0
def test_python_str():
    obj1 = "this is a beautifull test text"
    filename = path("temp.py")
    saver = GenericSaver()
    saver.save(obj1, filename)
    loader = GenericLoader()
    obj2 = loader.load(filename)
    assert obj1 == obj2

    if filename.exists():
        os.remove(filename)
Ejemplo n.º 48
0
    def template_scons(self):
        ''' Build default SConstruct and SConscript files. '''
        files = self.sconsfiles()
        tpl_files = []
        for f in files:
            if not f.exists() or f.size == 0:
                if 'wrapper' in f:
                    tpl_file = path(__file__).dirname()/'template_SConscript_wrapper.txt'
                else:
                    tpl_file = path(__file__).dirname()/'template_'+f.namebase+'.txt'
                tpl_files.append((f, tpl_file))
            
        for f, tpl in tpl_files:
            txt = Template(open(tpl).read())
            txt = txt.substitute(**self.metainfo)

            print "Creating a template version for %s ..." % ( f, )
            py_file = open(f, "w")
            py_file.write(txt)
            py_file.close()
Ejemplo n.º 49
0
 def add_wf_item(self, item, *args, **kwargs):
     try:
         prov_path = os.path.join(self.localpath,
                                  str(item["workflow"]) + '.json')
         with open(prov_path, 'a+') as fp:
             json.dump(item, fp, indent=4)
     except:
         prov_path = path(settings.get_openalea_home_dir()
                          ) / 'provenance' / 'wf_provenance.json'
         print('Fail to open prov files. - Now write prov in : ', prov_path)
         with open(prov_path, 'a+') as fp:
             json.dump(item, fp, indent=4)
Ejemplo n.º 50
0
def test_post_processing():
    adel_output_path = path('data/test_stand/adel_output.csv')
    
    import tempfile
    global_postprocessing_file_path = path(tempfile.mktemp(prefix='global_postprocessing', suffix='.csv'))
    peraxis_postprocessing_file_path = path(tempfile.mktemp(prefix='peraxis_postprocessing', suffix='.csv'))
    
    # launch the postprocessing
    (global_postprocessing_file_path, 
     peraxis_postprocessing_file_path,
     intermediate_results_file_path)= \
        post_processing(adel_output_path, 
                        3, 
                        0.013824884792626729,
                        global_postprocessing_file_path,
                        peraxis_postprocessing_file_path)
        
    expected_results_dir_path = path('data/test_stand')
    # check intermediate results
    intermediate_results_array = \
        pandas.read_csv(intermediate_results_file_path).values
    intermediate_results_array = np.delete(intermediate_results_array, 2, 1).astype(float)
    expected_intermediate_results_array = \
        pandas.read_csv(expected_results_dir_path/'intermediate.csv').values
    expected_intermediate_results_array = np.delete(expected_intermediate_results_array, 2, 1).astype(float)
    np.testing.assert_allclose(intermediate_results_array, expected_intermediate_results_array, relative_tolerance, absolute_tolerance)
    
    # check per axis post processing results
    peraxis_postprocessing_results_array = pandas.read_csv(peraxis_postprocessing_file_path).values
    peraxis_postprocessing_results_array = np.delete(peraxis_postprocessing_results_array, [0, 2], 1).astype(float)
    expected_peraxis_postprocessing_results_array = pandas.read_csv(expected_results_dir_path/'peraxis_postprocessing.csv').values
    expected_peraxis_postprocessing_results_array = np.delete(expected_peraxis_postprocessing_results_array, [0, 2], 1).astype(float)
    np.testing.assert_allclose(peraxis_postprocessing_results_array, expected_peraxis_postprocessing_results_array, relative_tolerance, absolute_tolerance)
    
    # check global post processing results
    global_postprocessing_results_array = pandas.read_csv(global_postprocessing_file_path).values
    global_postprocessing_results_array = np.delete(global_postprocessing_results_array, 0, 1).astype(float)
    expected_global_postprocessing_results_array = pandas.read_csv(expected_results_dir_path/'global_postprocessing.csv').values
    expected_global_postprocessing_results_array = np.delete(expected_global_postprocessing_results_array, 0, 1).astype(float)
    np.testing.assert_allclose(global_postprocessing_results_array, expected_global_postprocessing_results_array, relative_tolerance, absolute_tolerance)
Ejemplo n.º 51
0
def povray(scene, 
           pov_file = './scene.pov', 
           camera_distance=1., fov=45., width=320, height=280, 
           domain = ((-.5,-.5),(.5,.5)), 
           azimuth=0., zenith= 0., camera_type = 'perspective', 
           soil=False, 
           povray_cmd='povray'):
    """    
     !!!! Deprecated function, use alinea.povray.Povray class instead !!!! 
    
    Compute povray files based both on a scene and its stand box.

    :Parameters:
        - scene: a plantgl scene
        - camera distance: distance from the position of the camera to the look_at point
        - angle : angle corresponding to the width of the image
        - width: width of the final image in pixel
        - height: height of the final image in pixel
        - domain: scene pattern used by caribu
        - azimuth: angle in degree around the vertical axis. az=0. is equialent to have the width of the image align to X direction of the scene
        - zenith: angle between the view direction and the vertical
        - camera type: perspective, orthographic or fisheye
        - soil: add a soil to the scene
        - povray cmd : the path of the povray exe
    """
    
    f = path(pov_file)
    namebase = f.namebase
    ext = f.ext
    dirname = f.dirname()
    
    xc=0.5*(domain[0][0]+domain[1][0])
    yc=0.5*(domain[0][1]+domain[1][1])

    camera = {'type':camera_type, 'distance':camera_distance, 'fov':fov,  'xc':xc, 'yc':yc, 'azimuth':azimuth, 'zenith':zenith}
    
    pov = PovRay(camera=camera, image_width=width, image_height=height, working_dir=str(dirname))
    
    pov.render(scene, namebase + ext)
    image_name = pov.rendered_image_path
    
    d3D = domain3D(domain, scene)
    scene_box = pgl.Scene()
    scene_box.add(stand_box(d3D))
    f_box = namebase + '_box' + ext
    pov.render(scene_box, f_box)
    image_name_box = pov.rendered_image_path

    return image_name, image_name_box

        
        
Ejemplo n.º 52
0
def povray(scene,
           pov_file = './scene.pov',
           camera_distance=1., fov=45., width=320, height=280,
           domain = ((-.5,-.5),(.5,.5)),
           azimuth=0., zenith= 0., camera_type = 'perspective',
           soil=False,
           povray_cmd='povray'):
    """
     !!!! Deprecated function, use alinea.povray.Povray class instead !!!!

    Compute povray files based both on a scene and its stand box.

    :Parameters:
        - scene: a plantgl scene
        - camera distance: distance from the position of the camera to the look_at point
        - angle : angle corresponding to the width of the image
        - width: width of the final image in pixel
        - height: height of the final image in pixel
        - domain: scene pattern used by caribu
        - azimuth: angle in degree around the vertical axis. az=0. is equialent to have the width of the image align to X direction of the scene
        - zenith: angle between the view direction and the vertical
        - camera type: perspective, orthographic or fisheye
        - soil: add a soil to the scene
        - povray cmd : the path of the povray exe
    """

    f = path(pov_file)
    namebase = f.namebase
    ext = f.ext
    dirname = f.dirname()

    xc=0.5*(domain[0][0]+domain[1][0])
    yc=0.5*(domain[0][1]+domain[1][1])

    camera = {'type':camera_type, 'distance':camera_distance, 'fov':fov,  'xc':xc, 'yc':yc, 'azimuth':azimuth, 'zenith':zenith}

    pov = PovRay(camera=camera, image_width=width, image_height=height, working_dir=str(dirname))

    pov.render(scene, namebase + ext)
    image_name = pov.rendered_image_path

    d3D = domain3D(domain, scene)
    scene_box = pgl.Scene()
    scene_box.add(stand_box(d3D))
    f_box = namebase + '_box' + ext
    pov.render(scene_box, f_box)
    image_name_box = pov.rendered_image_path

    return image_name, image_name_box

        
        
Ejemplo n.º 53
0
def vlab_object(directory, pkgmanager):
    """
    Create an openalea package from a vlab object.
    First, read the specification file and parse it.
    Create the list of data, the list of editors,
    and the list of programs.
    Build the graph of dependencies.
    Compute the layout of the graph.
    Create a package with data and a composite node.

    """
    directory = path(directory)
    obj = VlabObject2(directory, pkgmanager)
    return obj
Ejemplo n.º 54
0
    def __init__(self):
        import traceback
        traceback.print_stack(file=sys.__stdout__)

        self._project = None
        self._is_proj = False
        self._debug = False
        self.gui = True

        self.tmpdir = path(get_openalea_tmp_dir())

        self._config = MainConfig()
        self.extension = None

        self.applet = {}
        self.manager = {}

        self.package_manager = package_manager
        self.control_manager = ControlManager()
        self.project_manager = ProjectManager()
        self.plugin_manager = PluginManager()
        self.plugin_instance_manager = PluginInstanceManager()

        self.manager['control'] = self.control_manager
        self.manager['package'] = self.package_manager
        self.manager['project'] = self.project_manager
        self.manager['plugin'] = self.plugin_manager
        self.manager['plugin_instance'] = self.plugin_instance_manager

        self.world = World()

        self.interpreter = interpreter()

        # Hack if interpreter is an object from class TerminalInteractiveShell
        if not hasattr(self.interpreter, "shell"):
            self.interpreter.shell = self.interpreter
        if hasattr(self.interpreter.shell, "events"):
            self.interpreter.shell.events.register("post_execute", self.add_to_history)
        else:
            print("You need ipython >= 2.0 to use history.")

#         self.project_manager.set_shell(self.interpreter.shell)

        self.interpreter.locals['session'] = self

        self.old_syspath = sys.path

        self.load_default()

        self.__class__.instantiated = True
Ejemplo n.º 55
0
def read_image_path(urls, mimetype_in, mimetype_out):

    if isinstance(urls, basestring):
        urls = [urls]
    for url in urls:
        url = path(url)
        if url.exists():
            try:
                data = imread(url)
            except Exception, e:
                e = MimeConversionError(url, mimetype_in, mimetype_out, e)
                raise e
            else:
                return data, {}
Ejemplo n.º 56
0
    def template_doc(self):
        files = self.docfiles()
        tpl_files = []
        for f in files:
            if not f.exists() or f.size == 0:
                tpl_file = path(__file__).dirname()/'template_'+f.namebase+'.txt'
                tpl_files.append((f, tpl_file))

        for f, tpl in tpl_files:
            txt = Template(open(tpl).read())
            txt = txt.substitute(self.metainfo)
            print "Creating a template version for %s ..." % ( f, )
            py_file = open(f, "w")
            py_file.write(txt)
            py_file.close()
Ejemplo n.º 57
0
def qt4_dev (directory=path('qt4-dev'), name='qt4_dev'):

    zip_name = path('..')/name + '.zip'
    curdir = path(os.curdir).abspath()
    os.chdir(directory)

    zf=zipfile.ZipFile(zip_name,compression=zipfile.ZIP_DEFLATED,mode='w')

    dirs = {}
    dirs['EGG-INFO'] = ['*']
    dirs['include'] = ['*']
    dirs['bin'] = ['*']
    dirs['sip'] = ['*']
    dirs['lib'] = ['*.4.dylib', '*2.5.dylib']

    for dir, patterns in dirs.iteritems():
        d = path(dir)
        for pattern in patterns:
            for fn in d.walkfiles(pattern):
                print 'add ', fn
                zf.write(fn)

    zf.close()
    os.chdir(curdir)