本文整理汇总了Python中thunder.rdds.fileio.seriesloader.SeriesLoader.fromStack方法的典型用法代码示例。如果您正苦于以下问题:Python SeriesLoader.fromStack方法的具体用法?Python SeriesLoader.fromStack怎么用?Python SeriesLoader.fromStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thunder.rdds.fileio.seriesloader.SeriesLoader
的用法示例。
在下文中一共展示了SeriesLoader.fromStack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_roundtrip_tst
# 需要导入模块: from thunder.rdds.fileio.seriesloader import SeriesLoader [as 别名]
# 或者: from thunder.rdds.fileio.seriesloader.SeriesLoader import fromStack [as 别名]
def _run_roundtrip_tst(self, testCount, arrays, blockSize):
print "Running TestSeriesBinaryWriteFromStack roundtrip test #%d" % testCount
insubdir = os.path.join(self.outputdir, 'input%d' % testCount)
os.mkdir(insubdir)
outsubdir = os.path.join(self.outputdir, 'output%d' % testCount)
#os.mkdir(outsubdir)
for aryCount, array in enumerate(arrays):
# array.tofile always writes in column-major order...
array.tofile(os.path.join(insubdir, "img%02d.stack" % aryCount))
# ... but we will read and interpret these as though they are in row-major order
dims = list(arrays[0].shape)
dims.reverse()
underTest = SeriesLoader(self.sc)
underTest.saveFromStack(insubdir, outsubdir, dims, blockSize=blockSize, datatype=str(arrays[0].dtype))
series = underTest.fromStack(insubdir, dims, datatype=str(arrays[0].dtype))
roundtripped_series = underTest.fromBinary(outsubdir)
roundtripped = roundtripped_series.collect()
direct = series.collect()
expecteddtype = str(smallest_float_type(arrays[0].dtype))
assert_equals(expecteddtype, roundtripped_series.dtype)
assert_equals(expecteddtype, series.dtype)
assert_equals(expecteddtype, str(roundtripped[0][1].dtype))
assert_equals(expecteddtype, str(direct[0][1].dtype))
with open(os.path.join(outsubdir, "conf.json"), 'r') as fp:
# check that binary series file data type *matches* input stack data type (not yet converted to float)
# at least according to conf.json
conf = json.load(fp)
assert_equals(str(arrays[0].dtype), conf["valuetype"])
for ((serieskeys, seriesvalues), (directkeys, directvalues)) in zip(roundtripped, direct):
assert_equals(directkeys, serieskeys)
assert_equals(directvalues, seriesvalues)
for seriesidx, seriesval in enumerate(seriesvalues):
#print "seriesidx: %d; serieskeys: %s; seriesval: %g" % (seriesidx, serieskeys, seriesval)
# flip indices again for row vs col-major insanity
arykeys = list(serieskeys)
arykeys.reverse()
msg = "Failure on test #%d, time point %d, indices %s" % (testCount, seriesidx, str(tuple(arykeys)))
try:
assert_almost_equal(arrays[seriesidx][tuple(arykeys)], seriesval, places=4)
except AssertionError, e:
raise AssertionError(msg, e)