当前位置: 首页>>代码示例>>Python>>正文


Python DataContainer.FieldContainer类代码示例

本文整理汇总了Python中pyphant.core.DataContainer.FieldContainer的典型用法代码示例。如果您正苦于以下问题:Python FieldContainer类的具体用法?Python FieldContainer怎么用?Python FieldContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FieldContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CoverageTestCase

class CoverageTestCase(unittest.TestCase):
    def setUp(self):
        from pyphant.core.DataContainer import FieldContainer
        data = numpy.arange(0, 256, 1).reshape((16, 16))
        self.image = FieldContainer(data, unit=1e10)
        self.image.seal()

    def testRatiosUpToTenPercentError(self):
        delta = .1
        from ImageProcessing.CoverageWorker import CoverageWorker
        from ImageProcessing import FEATURE_COLOR, BACKGROUND_COLOR
        from pyphant.quantities import Quantity
        cworker = CoverageWorker()
        for rho1Fac in [0.1, 0.25, 0.5, 1.0, 1.5, 2.0, 5.0, 10.0]:
            rho1 = '%s mC / m ** 3' % (3000. * rho1Fac, )
            rho2 = '3 C / m ** 3'
            cworker.paramRho1.value = rho1
            cworker.paramRho2.value = rho2
            rho1 = Quantity(rho1)
            rho2 = Quantity(rho2)
            for ratio in numpy.arange(0.0, 1.01, 0.01):
                cworker.paramW1.value = '%s%%' % (ratio * 100., )
                result = cworker.threshold(self.image)
                self.assertEqual(result.dimensions, self.image.dimensions)
                stuff1 = numpy.where(result.data == FEATURE_COLOR,
                                     True, False).sum()
                stuff2 = numpy.where(result.data == BACKGROUND_COLOR,
                                     True, False).sum()
                self.assertEqual(stuff1 + stuff2, result.data.size)
                stuff1 = (stuff1 * rho1).inUnitsOf('C / m ** 3').value
                stuff2 = (stuff2 * rho2).inUnitsOf('C / m ** 3').value
                actualRatio = stuff1 / (stuff1 + stuff2)
                self.assertTrue(abs(ratio - actualRatio) <= delta)
开发者ID:GitEdit,项目名称:pyphant1,代码行数:33,代码来源:TestCoverage.py

示例2: gradientWorker

    def gradientWorker(self, image, subscriber=0):
        d0 = image.dimensions[0]
        dims = [d0] + [d.inUnitsOf(d0) for d in image.dimensions[1:]]
        data = image.data.astype(float)
        gradient = np.gradient(data)
        magnitude = np.zeros_like(data)
        for i, (dim, grad) in enumerate(zip(dims, gradient)):
            shape = [1, ] * len(dims)
            shape[i] = dim.data.shape[0]
            grad /= np.gradient(dim.data).reshape(shape)
            magnitude += grad ** 2
        magnitude = np.sqrt(magnitude)

        longname = "Gradient"
        from pyphant.core.DataContainer import FieldContainer
        result = FieldContainer(
            magnitude,
            image.unit / d0.unit,
            None,
            copy.deepcopy(image.mask),
            copy.deepcopy(image.dimensions),
            longname,
            image.shortname,
            copy.deepcopy(image.attributes),
            False)
        result.seal()
        return result
开发者ID:GitEdit,项目名称:pyphant1,代码行数:27,代码来源:Gradient.py

示例3: testNonUniformAxes

 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)
开发者ID:GitEdit,项目名称:pyphant1,代码行数:32,代码来源:TestGradient.py

示例4: testCommaSeparated

 def testCommaSeparated(self):
     section = self.field1d[[1, 3, 7],]
     afoot = FieldContainer(numpy.array([0.2, 0.4, 0.8]), longname="voltage", shortname="U", unit="1V")
     afoot.dimensions[0] = self.xDim[[1, 3, 7],]
     self.assertEqual(section, afoot)
     section = self.field1d[[[1, 3, 7]]]
     self.assertEqual(section, afoot)
开发者ID:juliameier,项目名称:pyphant1,代码行数:7,代码来源:TestDataContainer.py

示例5: testLoadOneRowDep

 def testLoadOneRowDep(self):
     result = self.load('onerow_dep.fmf')
     t = FieldContainer(numpy.array([1.0]), unit=Quantity('1 s'),
                        shortname='t', longname='time')
     s = FieldContainer(numpy.array([5.0]), unit=Quantity('1 m'),
                        shortname='s', longname='distance')
     s.dimensions[0] = deepcopy(t)
     self.checkExpected([t, s], result)
开发者ID:zklaus,项目名称:pyphant1,代码行数:8,代码来源:TestLoadFMF.py

示例6: testCompleteRightOpenIntervall

 def testCompleteRightOpenIntervall(self):
     dim = self.xDim
     intStart = dim.data.min() * dim.unit
     intEnd = dim.data.max() * dim.unit
     unitname = dim.unit.unit.name()
     section = self.field1d["%.4f%s:%.4f%s" % (intStart.value, unitname, intEnd.value, unitname)]
     afoot = FieldContainer(numpy.linspace(0.1, 0.9, 9), longname="voltage", shortname="U", unit="1V")
     afoot.dimensions[0] = self.xDim[0:-1]
     self.assertEqual(section, afoot)
开发者ID:juliameier,项目名称:pyphant1,代码行数:9,代码来源:TestDataContainer.py

示例7: testRegionIndex

 def testRegionIndex(self):
     section = self.field1d[1:4]
     afoot = FieldContainer(numpy.linspace(0.2, 0.4, 3), longname="voltage", shortname="U", unit="1V")
     afoot.dimensions[0] = self.xDim[1:4]
     self.assertEqual(section, afoot)
     section = self.field1d[1:-1]
     afoot = FieldContainer(numpy.linspace(0.2, 0.9, 8), longname="voltage", shortname="U", unit="1V")
     afoot.dimensions[0] = self.xDim[1:-1]
     self.assertEqual(section, afoot)
开发者ID:juliameier,项目名称:pyphant1,代码行数:9,代码来源:TestDataContainer.py

示例8: testSeal

 def testSeal(self):
     field = FieldContainer(self.testData, 1, longname=self.longname, shortname=self.shortname)
     field.seal()
     self.assertNotEqual(field.id, None)
     self.assertNotEqual(field.hash, None)
     try:
         field.data = scipy.array([1, 2, 3])
     except TypeError, e:
         pass
开发者ID:juliameier,项目名称:pyphant1,代码行数:9,代码来源:TestDataContainer.py

示例9: testUnits

 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'))
开发者ID:GitEdit,项目名称:pyphant1,代码行数:10,代码来源:TestGradient.py

示例10: FieldContainerTestCase

class FieldContainerTestCase(unittest.TestCase):
    def setUp(self):
        data = NPArray([10.0, -103.5, 1000.43, 0.0, 10.0])
        unit = PQ('3s')
        error = NPArray([0.1, 0.2, 4.5, 0.1, 0.2])
        longname = u'Test: FieldContainer H5FileHandler'
        shortname = u'TestH5FC'
        attributes = {'custom1':u'testing1...', 'custom2':u'testing2...'}
        self.fc = FieldContainer(data, unit, error, None, None, longname,
                                 shortname, attributes)
        self.fc.seal()
开发者ID:GitEdit,项目名称:pyphant1,代码行数:11,代码来源:TestH5FileHandler.py

示例11: testDeepcopy

 def testDeepcopy(self):
     field = FieldContainer(self.testData, 1, longname=self.longname, shortname=self.shortname)
     copiedField = copy.deepcopy(field)
     self.assertEqual(field, copiedField)
     field.seal()
     copiedField.seal()
     self.assertEqual(field, copiedField)
     # equal because only real data is considered:
     self.assertEqual(field.hash, copiedField.hash)
     # unique due to timestamp in dimension ids:
     self.assertNotEqual(field.id, copiedField.id)
开发者ID:juliameier,项目名称:pyphant1,代码行数:11,代码来源:TestDataContainer.py

示例12: testDateTime

 def testDateTime(self):
     """Test the correct saving and  restoring of object arrays composed from datetime objects."""
     objectArray = numpy.array([datetime.datetime.now() for i in range(10)])
     objectField = FieldContainer(objectArray,longname=u"timestamp",
                                 shortname='t')
     objectField.seal()
     self.eln.createGroup(self.eln.root,'testObjectFields')
     saveField(self.eln,self.eln.root.testObjectFields,objectField)
     restoredField = loadField(self.eln,self.eln.root.testObjectFields)
     for i,j in zip(restoredField.data.tolist(),objectField.data.tolist()):
         self.assertEqual(i,j,'Expected %s but got %s!' % (j,i))
开发者ID:GitEdit,项目名称:pyphant1,代码行数:11,代码来源:TestPyTablesPersister.py

示例13: invert

 def invert(self, image, subscriber=0):
     max = scipy.amax(image.data)
     min = scipy.amin(image.data)
     data = max + min - image.data
     from pyphant.core.DataContainer import FieldContainer
     result = FieldContainer(data, unit=image.unit,
                             dimensions=copy.deepcopy(image.dimensions),
                             mask=copy.deepcopy(image.mask),
                             error=copy.deepcopy(image.error),
                             longname=image.longname,
                             shortname=image.shortname)
     result.seal()
     return result
开发者ID:GitEdit,项目名称:pyphant1,代码行数:13,代码来源:InvertWorker.py

示例14: testUnits

 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'))
开发者ID:gclos,项目名称:pyphant1,代码行数:13,代码来源:TestGradient.py

示例15: testUnicodeFields

 def testUnicodeFields(self):
     self.field.seal()
     unicodeArray = numpy.array([u'Hallo World!',u'Hallo Wörld!'])
     unicodeField = FieldContainer(unicodeArray,longname=u"blabla",
                                 shortname=self.shortname,
                                 unit = 1,
                                 attributes = self.attributes
                                 )
     unicodeField.seal()
     self.eln.createGroup(self.eln.root,'testUnicodeFields')
     saveField(self.eln,self.eln.root.testUnicodeFields,unicodeField)
     restoredField = loadField(self.eln,self.eln.root.testUnicodeFields)
     self.assertEqual(restoredField,unicodeField,
                      "Restored unicode string is %s (%s) but is expected to be %s (%s)." % (restoredField.data,restoredField.data.dtype,unicodeField.data,unicodeField.data.dtype))
开发者ID:GitEdit,项目名称:pyphant1,代码行数:14,代码来源:TestPyTablesPersister.py


注:本文中的pyphant.core.DataContainer.FieldContainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。