コード例 #1
0
ファイル: TestGradient.py プロジェクト: scre583/pyphant1
 def testUnits(self):
     data = (np.arange(0, 256, .01)).reshape((80, 320))
     image = FieldContainer(data, unit=Quantity('1 mJ'))
     for dim in image.dimensions:
         dim.unit = Quantity('1 cm')
     image.seal()
     gradient = Gradient()
     result = gradient.gradientWorker(image)
     self.assertEqual(result.dimensions, image.dimensions)
     self.assertEqual(result.unit, Quantity('1 mJ / cm'))
コード例 #2
0
ファイル: TestGradient.py プロジェクト: zklaus/pyphant1
 def testUnits(self):
     from ImageProcessing.Gradient import Gradient
     from pyphant.core.DataContainer import FieldContainer
     from pyphant.quantities import Quantity
     data = (numpy.arange(0, 256, .01)).reshape((80, 320))
     image = FieldContainer(data, unit=Quantity('1 mJ'))
     for dim in image.dimensions:
         dim.unit = Quantity('1 cm')
     image.seal()
     gradient = Gradient()
     result = gradient.gradientWorker(image)
     self.assertEqual(result.dimensions, image.dimensions)
     self.assertEqual(result.unit, Quantity('1 mJ / cm'))
コード例 #3
0
ファイル: TestGradient.py プロジェクト: scre583/pyphant1
 def testNonUniformAxes(self):
     im = np.array(
         [
             [0., 1., 2.],
             [30., 10., 50.],
             [8., 9., 6.],
             [-10., 0., 22.]
             ]
         )
     x = FieldContainer(np.array([1., 10., 200.]), unit=Quantity('1 m'))
     y = FieldContainer(np.array([0., 2., 4., 8.]), unit=Quantity('1 cm'))
     fc = FieldContainer(im, unit=Quantity('5 V'), dimensions=[y, x])
     fc.seal()
     grad_y, grad_x = np.gradient(fc.data)
     grad_y /= np.gradient(y.data).reshape((4, 1))
     grad_x /= np.gradient(x.data).reshape((1, 3))
     grad_y = FieldContainer(
         grad_y, unit=fc.unit / y.unit,
         dimensions=copy.deepcopy(fc.dimensions)
         )
     grad_x = FieldContainer(
         grad_x, unit=fc.unit / x.unit,
         dimensions=copy.deepcopy(fc.dimensions)
         )
     grad_x = grad_x.inUnitsOf(grad_y)
     expected_result = FieldContainer(
         (grad_x.data ** 2 + grad_y.data ** 2) ** 0.5,
         unit=copy.deepcopy(grad_y.unit),
         dimensions=copy.deepcopy(fc.dimensions)
         )
     result = Gradient().gradientWorker(fc)
     self.assertEqual(expected_result, result)
コード例 #4
0
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()