Beispiel #1
0
def main():
    import sys
    filename = sys.argv[1]
    from pyphant.core import KnowledgeManager
    km = KnowledgeManager.KnowledgeManager.getInstance()
    import os.path
    km.registerURL("file://" + os.path.realpath(filename))
    import tables
    h5 = tables.openFile(filename, 'r+')
    from pyphant.core import PyTablesPersister
    recipe = PyTablesPersister.loadRecipe(h5)
    executionOrders = PyTablesPersister.loadExecutionOrders(h5)
    h5.close()
    from pyphant.core.Emd5Src import Emd5Src
    for order in executionOrders:
        for socket, emd5 in order[0].iteritems():
            sSpec = socket.split('.')
            w = recipe.getWorker(sSpec[0])
            s = getattr(w, sSpec[-1])
            src = Emd5Src(recipe)
            src.paramEmd5.value = emd5
            if s.isFull():
                s.pullPlug()
            s.insert(src.plugGetDataContainer)
        pSpec = order[1][0].split('.')
        d = recipe.getWorker(pSpec[0])
        plug = getattr(d, pSpec[1])
        res = plug.getResult()
        res.seal()
        h5 = tables.openFile(filename, 'r+')
        PyTablesPersister.saveResult(res, h5)
        h5.close()
Beispiel #2
0
 def testEmd5Source(self):
     """Retrieves the previously registered FieldContainer via the
     Emd5Source and checks for equality."""
     #Predict result
     from pyphant.core.Emd5Src import Emd5Src
     s = Emd5Src()
     s.paramEmd5.value = self.V.id
     result = s.plugGetDataContainer.getResult()
     self.assertEqual(result, self.V)
Beispiel #3
0
def batch(recipe, input, plug, longname, dobatch=True, temporary=False):
    """
    Runs the same recipe multiple times for different input data.
    The return value is either a SampleContainer similar to input
    with 'emd5' column replaced by results or the resulting
    DataContainer from plug, if dobatch is set to False.
    recipe -- CompositeWorker instance
    input -- SampleContainer with 'emd5' column or any DataContainer if
             dobatch is set to False
    plug -- plug contained in recipe to get output from
            (there has to be exactly one open socket in recipe
            ascending from plug)
    longname -- longname of resulting SampleContainer, works only for
                dobatch == True
    dobatch -- if set to False, input is treated as a single data source
    temporary -- whether to register results temporarily, only applies when
                 dobatch is set to True
    """
    socket = recipe.getOpenSocketsForPlug(plug)[0]
    from pyphant.core.Emd5Src import Emd5Src
    DummyWorker = Emd5Src()
    socket.insert(DummyWorker.getPlugs()[0])
    DummyWorker.paramSelectby.value = u"enter emd5"
    from pyphant.core.KnowledgeManager import KnowledgeManager
    km = KnowledgeManager.getInstance()
    if dobatch:
        import copy
        output = copy.deepcopy(input)
        index = 0
        for emd5 in input['emd5'].data:
            DummyWorker.paramEnteremd5.value = emd5
            resultDC = plug.getResult()
            km.registerDataContainer(resultDC, temporary=temporary)
            output['emd5'].data[index] = resultDC.id
            index += 1
        output.longname = longname
        output.seal()
    else:
        km.registerDataContainer(input)
        DummyWorker.paramEnteremd5.value = input.id
        output = plug.getResult()
    socket.pullPlug()
    return output
 def _initWorkerRep(self):
     try:
         # adds Emd5Src worker to WorkerRepository
         from pyphant.core.Emd5Src import Emd5Src
         Emd5Src()
         self._workerRepository = WorkerRepository.WorkerRepository(
             self, self.ID_WINDOW_RIGHT, wx.DefaultPosition,
             wx.Size(220, -1))
         self._workerRepository.Expand(self._workerRepository.RootItem)
     except:
         import sys
         self._wxPyphantApp._logger.error(
             u"An exception occured while loading the toolboxes.",
             exc_info=sys.exc_info())
         wx.MessageBox(
             "An error has occurred while importing "\
             "the toolboxes.\nPlease investigate the logfile "\
             "for further details.\nThe logfile is located at %s\n"\
             "You may also try to update and restart wxPyphant."\
             % os.path.join(LOGDIR, 'pyphant.log'),
             "Toolbox Error!")
         self._workerRepository = wx.TreeCtrl(self)