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
 def setUp(self):
     self.composite = CompositeWorker()
     self.worker1 = TestCompositeDummyWorker(self.composite)
     self.worker1.getParam('name').value = 'worker1'
     self.worker2 = TestCompositeDummyWorker(self.composite)
     self.worker2.getParam('name').value = 'worker2'
Esempio n. 4
0
 def setUp(self):
     self.composite = CompositeWorker()
     self.worker1 = ThresholdingWorker(self.composite)
     self.worker1.getParam('name').value = 'worker1'
     self.worker2 = ThresholdingWorker(self.composite)
     self.worker2.getParam('name').value = 'worker2'
Esempio n. 5
0
from pyphant.core.CompositeWorker import CompositeWorker
from pyphant.core.H5FileHandler import H5FileHandler

# create a recipe
recipe = CompositeWorker()
# ... fill the recipe (e.g. Listing 1)

# save it
with H5FileHandler('quicktour_api.h5', 'w') as handler:
    handler.saveRecipe(recipe, saveResults=True)

# load a recipe
with H5FileHandler('quicktour_api.h5', 'r') as handler:
    recipe = handler.loadRecipe()
Esempio n. 6
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()