本文整理汇总了Python中thunder.rdds.fileio.imagesloader.ImagesLoader.saveAsBinarySeries方法的典型用法代码示例。如果您正苦于以下问题:Python ImagesLoader.saveAsBinarySeries方法的具体用法?Python ImagesLoader.saveAsBinarySeries怎么用?Python ImagesLoader.saveAsBinarySeries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thunder.rdds.fileio.imagesloader.ImagesLoader
的用法示例。
在下文中一共展示了ImagesLoader.saveAsBinarySeries方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_tstSaveAsBinarySeries
# 需要导入模块: from thunder.rdds.fileio.imagesloader import ImagesLoader [as 别名]
# 或者: from thunder.rdds.fileio.imagesloader.ImagesLoader import saveAsBinarySeries [as 别名]
def _run_tstSaveAsBinarySeries(self, testidx, narys_, valdtype, groupingdim_):
"""Pseudo-parameterized test fixture, allows reusing existing spark context
"""
paramstr = "(groupingdim=%d, valuedtype='%s')" % (groupingdim_, valdtype)
arys, aryshape, arysize = _generate_test_arrays(narys_, dtype_=valdtype)
dims = aryshape[:]
outdir = os.path.join(self.outputdir, "anotherdir%02d" % testidx)
images = ImagesLoader(self.sc).fromArrays(arys)
images.saveAsBinarySeries(outdir, groupingDim=groupingdim_)
ndims = len(aryshape)
# prevent padding to 4-byte boundaries: "=" specifies no alignment
unpacker = struct.Struct('=' + 'h'*ndims + dtype(valdtype).char*narys_)
def calcExpectedNKeys():
tmpshape = list(dims[:])
del tmpshape[groupingdim_]
return prod(tmpshape)
expectednkeys = calcExpectedNKeys()
def byrec(f_, unpacker_, nkeys_):
rec = True
while rec:
rec = f_.read(unpacker_.size)
if rec:
allrecvals = unpacker_.unpack(rec)
yield allrecvals[:nkeys_], allrecvals[nkeys_:]
outfilenames = glob.glob(os.path.join(outdir, "*.bin"))
assert_equals(dims[groupingdim_], len(outfilenames))
for outfilename in outfilenames:
with open(outfilename, 'rb') as f:
nkeys = 0
for keys, vals in byrec(f, unpacker, ndims):
nkeys += 1
assert_equals(narys_, len(vals))
for validx, val in enumerate(vals):
assert_equals(arys[validx][keys], val, "Expected %g, got %g, for test %d %s" %
(arys[validx][keys], val, testidx, paramstr))
assert_equals(expectednkeys, nkeys)
confname = os.path.join(outdir, "conf.json")
assert_true(os.path.isfile(confname))
with open(os.path.join(outdir, "conf.json"), 'r') as fconf:
import json
conf = json.load(fconf)
assert_equals(outdir, conf['input'])
assert_equals(tuple(dims), tuple(conf['dims']))
assert_equals(len(aryshape), conf['nkeys'])
assert_equals(narys_, conf['nvalues'])
assert_equals(valdtype, conf['valuetype'])
assert_equals('int16', conf['keytype'])
assert_true(os.path.isfile(os.path.join(outdir, 'SUCCESS')))
示例2: test_roundtripConvertToSeries
# 需要导入模块: from thunder.rdds.fileio.imagesloader import ImagesLoader [as 别名]
# 或者: from thunder.rdds.fileio.imagesloader.ImagesLoader import saveAsBinarySeries [as 别名]
def test_roundtripConvertToSeries(self):
imagepath = TestImagesUsingOutputDir._findSourceTreeDir("utils/data/fish/tif-stack")
outdir = os.path.join(self.outputdir, "fish-series-dir")
images = ImagesLoader(self.sc).fromMultipageTif(imagepath)
series = images.toSeries(blockSize=76*20)
series_ary = series.pack()
images.saveAsBinarySeries(outdir, blockSize=76*20)
converted_series = SeriesLoader(self.sc).fromBinary(outdir)
converted_series_ary = converted_series.pack()
assert_equals((76, 87, 2), series.dims.count)
assert_equals((20, 76, 87, 2), series_ary.shape)
assert_true(array_equal(series_ary, converted_series_ary))