本文整理汇总了Python中pyphant.core.DataContainer.FieldContainer.seal方法的典型用法代码示例。如果您正苦于以下问题:Python FieldContainer.seal方法的具体用法?Python FieldContainer.seal怎么用?Python FieldContainer.seal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyphant.core.DataContainer.FieldContainer
的用法示例。
在下文中一共展示了FieldContainer.seal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CoverageTestCase
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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)
示例2: gradientWorker
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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
示例3: testNonUniformAxes
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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: testSeal
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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
示例5: testUnits
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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'))
示例6: testDeepcopy
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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)
示例7: testDateTime
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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))
示例8: FieldContainerTestCase
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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()
示例9: invert
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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
示例10: testUnits
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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'))
示例11: testUnicodeFields
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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))
示例12: testInvert
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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())
示例13: find
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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
示例14: loadImageAsGreyScale
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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
示例15: testFindExtrPoint
# 需要导入模块: from pyphant.core.DataContainer import FieldContainer [as 别名]
# 或者: from pyphant.core.DataContainer.FieldContainer import seal [as 别名]
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())