• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python DataContainer.FieldContainer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testInvert

 def testInvert(self):
     from ImageProcessing.InvertWorker import InvertWorker
     from pyphant.core.DataContainer import FieldContainer
     from pyphant.quantities import Quantity
     data = numpy.ones((100, 100), dtype='uint8') * 112
     data[0][0] = 0
     image = FieldContainer(data)
     for dim in image.dimensions:
         dim.unit = Quantity('1 cm')
     image.seal()
     invert = InvertWorker()
     result = invert.invert(image)
     self.assertEqual(result.dimensions, image.dimensions)
     expected = numpy.zeros((100, 100), dtype='uint8')
     expected[0][0] = 112
     self.assertTrue((result.data == expected).all())
开发者ID:GitEdit,项目名称:pyphant1,代码行数:16,代码来源:TestInvert.py


示例17: find

 def find(self, image, subscriber=0):
     newdata = self.findExtrema(image.data)
     longname = "FindLocalExtrema"
     from pyphant.core.DataContainer import FieldContainer
     result = FieldContainer(
         newdata,
         copy.deepcopy(image.unit),
         copy.deepcopy(image.error),
         copy.deepcopy(image.mask),
         copy.deepcopy(image.dimensions),
         longname,
         image.shortname,
         copy.deepcopy(image.attributes),
         False)
     result.seal()
     return result
开发者ID:gclos,项目名称:pyphant1,代码行数:16,代码来源:FindLocalExtrema.py


示例18: loadImageAsGreyScale

 def loadImageAsGreyScale(self, subscriber=0):
     import os
     import re
     from scipy.misc import imread
     import numpy
     from pyphant.core.DataContainer import FieldContainer
     from pyphant.quantities import Quantity
     path = os.path.realpath(self.paramPath.value)
     if os.path.isfile(path):
         path = os.path.dirname(path)
     pattern = re.compile(self.paramRegex.value)
     filenames = filter(
         lambda x: pattern.match(x) is not None, os.listdir(path)
         )
     filenames.sort()
     filenames = [os.path.join(path, fname) for fname in filenames]
     print path
     zClip = self.getClip(self.paramZClip.value)
     filenames = filenames[zClip[0]:zClip[1]]
     assert len(filenames) >= 1
     yClip = self.getClip(self.paramYClip.value)
     xClip = self.getClip(self.paramXClip.value)
     dtype = self.paramDtype.value
     data = []
     for i, fn in enumerate(filenames):
         subscriber %= 1 + 99 * i / len(filenames)
         data.append(imread(fn, True)[yClip[0]:yClip[1], xClip[0]:xClip[1]])
     data = numpy.array(data, dtype=dtype)
     axes = ['z', 'y', 'x']
     dimensions = [
         self.getDimension(a, data.shape[i]) for i, a in enumerate(axes)
         ]
     try:
         unit = Quantity(self.paramFieldUnit.value)
     except AttributeError:
         unit = self.paramFieldUnit.value
     longname = self.paramLongname.value
     shortname = self.paramShortname.value
     image = FieldContainer(
         data=data, dimensions=dimensions, unit=unit,
         longname=longname, shortname=shortname,
         attributes={'yFactor':Quantity(self.paramDy.value),
                     'xFactor':Quantity(self.paramDx.value)}
         )
     image.seal()
     subscriber %= 100
     return image
开发者ID:gclos,项目名称:pyphant1,代码行数:47,代码来源:LoadZStack.py


示例19: testFindExtrPoint

 def testFindExtrPoint(self):
     from ImageProcessing.FindLocalExtrema import FindLocalExtrema
     from pyphant.core.DataContainer import FieldContainer
     from pyphant.quantities import Quantity
     data = numpy.ones((100, 100), dtype='uint8') * 112
     data[10][20] = 255
     image = FieldContainer(data)
     for dim in image.dimensions:
         dim.unit = Quantity('2 mum')
     image.seal()
     fle = FindLocalExtrema()
     fle.paramExcolor.value = 1
     result = fle.find(image)
     self.assertEqual(result.dimensions, image.dimensions)
     expected = numpy.zeros((100, 100), dtype='uint8')
     expected[10][20] = 1
     self.assertTrue((result.data == expected).all())
开发者ID:gclos,项目名称:pyphant1,代码行数:17,代码来源:TestLocalExtrema.py


示例20: add_noise

 def add_noise(self, input_fc, subscriber=0):
     width = parseFCUnit(self.paramWidth.value)
     scale = float(width / input_fc.unit)
     noisy_data = input_fc.data + normal(
         scale=scale, size=input_fc.data.shape
         )
     output_fc = FieldContainer(
         data=noisy_data,
         unit=deepcopy(input_fc.unit),
         dimensions=deepcopy(input_fc.dimensions),
         longname=input_fc.longname + u" with noise",
         shortname=input_fc.shortname,
         error=deepcopy(input_fc.error),
         mask=deepcopy(input_fc.mask),
         attributes=deepcopy(input_fc.attributes)
         )
     output_fc.seal()
     return output_fc
开发者ID:GitEdit,项目名称:pyphant1,代码行数:18,代码来源:api004.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pypika.Query类代码示例发布时间:2022-05-27
下一篇:
Python core.DataContainer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap