def test_simpleBlockExtraction(self): for params in TestBlockExtraction.PARAMS: strategy = SimpleBlockingStrategy([1]*len(params.aryshape)) # dummy splits; not used here n = reduce(lambda x, y: x*y, params.aryshape) ary = arange(n, dtype='int16').reshape(params.aryshape) key, val = strategy.extractBlockFromImage(ary, params.blockslices, params.timepoint, params.ntimepoints) expectedSlices = [slice(params.timepoint, params.timepoint+1, 1)] + list(params.blockslices) expectedAry = expand_dims(ary[params.blockslices], axis=0) assert_equals(params.timepoint, key.temporalKey) assert_equals(params.ntimepoints, key.origShape[0]) assert_equals(tuple(params.aryshape), tuple(key.origShape[1:])) assert_equals(tuple(expectedSlices), tuple(key.imgSlices)) assert_true(array_equal(expectedAry, val))
def test_fromStackToSeriesWithPack(self): ary = arange(8, dtype=dtypeFunc('int16')).reshape((2, 4)) filename = os.path.join(self.outputdir, "test.stack") ary.tofile(filename) image = ImagesLoader(self.sc).fromStack(filename, dims=(4, 2)) strategy = SimpleBlockingStrategy.generateFromBlockSize(image, "150M") series = image.toBlocks(strategy).toSeries() seriesVals = series.collect() seriesAry = series.pack() # check ordering of keys assert_equals((0, 0), seriesVals[0][0]) # first key assert_equals((1, 0), seriesVals[1][0]) # second key assert_equals((2, 0), seriesVals[2][0]) assert_equals((3, 0), seriesVals[3][0]) assert_equals((0, 1), seriesVals[4][0]) assert_equals((1, 1), seriesVals[5][0]) assert_equals((2, 1), seriesVals[6][0]) assert_equals((3, 1), seriesVals[7][0]) # check dimensions tuple is reversed from numpy shape assert_equals(ary.shape[::-1], series.dims.count) # check that values are in original order collectedVals = array([kv[1] for kv in seriesVals], dtype=dtypeFunc('int16')).ravel() assert_true(array_equal(ary.ravel(), collectedVals)) # check that packing returns transpose of original array assert_true(array_equal(ary.T, seriesAry))
def _run_tst_splitCalc(blockSize, image, expectedSplits, expectedSize, testIdx=-1): strategy = SimpleBlockingStrategy.generateFromBlockSize(image, blockSize) splits = strategy.splitsPerDim avgSize = strategy.calcAverageBlockSize() assert_equals(tuple(expectedSplits), tuple(splits), msg="Failure in test %i, expected splits %s != actual splits %s" % (testIdx, tuple(expectedSplits), tuple(splits))) assert_true(isclose(expectedSize, avgSize, rtol=0.001), msg="Failure in test %i, expected avg size %g not close to actual size %g" % (testIdx, expectedSize, avgSize))
def test_roundtripConvertToSeries(self): imagepath = findSourceTreeDir("utils/data/fish/images") images = ImagesLoader(self.sc).fromTif(imagepath) strategy = SimpleBlockingStrategy.generateFromBlockSize(images, blockSize=76 * 20) self._run_tst_roundtripConvertToSeries(images, strategy)