Esempio n. 1
0
 def testSaveLoadRecipe(self):
     from pyphant.core.CompositeWorker import CompositeWorker
     from pyphant.core.WorkerRegistry import WorkerRegistry
     from itertools import chain
     recipe = CompositeWorker(annotations={'foo':42.0, 'bar':u'Hääh?'})
     wreg = WorkerRegistry.getInstance()
     workerInfos = [t.workerInfos for t in wreg.getToolBoxInfoList()]
     for wInfo in chain(*workerInfos):
         worker = wInfo.createWorker()
         recipe.addWorker(worker)
     with H5FH(self.path, 'w') as handler:
         handler.saveRecipe(recipe)
     with H5FH(self.path, 'r') as handler:
         loadedRecipe = handler.loadRecipe()
     loadedWorkers = loadedRecipe.getWorkers()
     workers = recipe.getWorkers()
     self.assertEqual(len(loadedWorkers), len(workers))
     workerNames = [w.name for w in workers]
     loadedWorkerNames = [w.name for w in loadedWorkers]
     for name in loadedWorkerNames:
         self.assertTrue(name in workerNames)
     self.assertEqual(recipe._annotations, loadedRecipe._annotations)
Esempio n. 2
0
 def testSaveLoadRecipe(self):
     from pyphant.core.CompositeWorker import CompositeWorker
     from pyphant.core.WorkerRegistry import WorkerRegistry
     from itertools import chain
     recipe = CompositeWorker(annotations={'foo': 42.0, 'bar': u'Hääh?'})
     wreg = WorkerRegistry.getInstance()
     workerInfos = [t.workerInfos for t in wreg.getToolBoxInfoList()]
     for wInfo in chain(*workerInfos):
         worker = wInfo.createWorker()
         recipe.addWorker(worker)
     with H5FH(self.path, 'w') as handler:
         handler.saveRecipe(recipe)
     with H5FH(self.path, 'r') as handler:
         loadedRecipe = handler.loadRecipe()
     loadedWorkers = loadedRecipe.getWorkers()
     workers = recipe.getWorkers()
     self.assertEqual(len(loadedWorkers), len(workers))
     workerNames = [w.name for w in workers]
     loadedWorkerNames = [w.name for w in loadedWorkers]
     for name in loadedWorkerNames:
         self.assertTrue(name in workerNames)
     self.assertEqual(recipe._annotations, loadedRecipe._annotations)
Esempio n. 3
0
# import all necessary classes
from pyphant.core.CompositeWorker import CompositeWorker
from ImageProcessing.ImageLoaderWorker import ImageLoaderWorker
from ImageProcessing.Gradient import Gradient
from Statistics.Histogram import Histogram

# create a recipe aka CompositeWorker
recipe = CompositeWorker()

# instantiate an ImageLoader worker, insert it into the recipe
# and set the filename parameter
loader = ImageLoaderWorker()
recipe.addWorker(loader)
loader.paramFilename.value = "1.5.01.tiff"

# instantiate a Gradient worker, insert it into the recipe
# and connect it to the ImageLoader worker
gradient = Gradient()
recipe.addWorker(gradient)
gradient.getSockets()[0].insert(loader.getPlugs()[0])

# instantiate a Histogram worker, insert it into the recipe,
# set its bins parameter and connect it to the Gradient worker
histogram = Histogram()
recipe.addWorker(histogram)
histogram.paramBins.value = 50
histogram.getSockets()[0].insert(gradient.getPlugs()[0])

# request the result from the Histogram worker's plug
result = histogram.getPlugs()[0].getResult()
print result.data.mean()