Esempio n. 1
0
    def test(self):
        graph = Graph()
        op = OpTiledVolumeReader(graph=graph)
        op.DescriptionFilePath.setValue(
            self.data_setup.TRANSPOSED_VOLUME_DESCRIPTION_FILE)
        op.tiled_volume.TEST_MODE = True

        roi = numpy.array([(10, 150, 100), (30, 550, 550)])
        roi_t = numpy.array([tuple(reversed(roi[0])), tuple(reversed(roi[1]))])

        result_out_t = op.Output(*roi_t).wait()
        result_out = result_out_t.transpose()

        # We expect a channel dimension to be added automatically...
        assert (result_out_t.shape == roi_t[1] - roi_t[0]).all()

        ref_path_comp = PathComponents(self.data_setup.REFERENCE_VOL_PATH)
        with h5py.File(ref_path_comp.externalPath, 'r') as f:
            ref_data = f[ref_path_comp.internalPath][:]

        expected = ref_data[roiToSlice(*roi)]

        #numpy.save('/tmp/expected.npy', expected)
        #numpy.save('/tmp/result_out.npy', result_out)

        # We can't expect the pixels to match exactly because compression was used to create the tiles...
        assert (expected == result_out).all()
    def __init__(self, *args, **kwargs):
        super(OpCachedTiledVolumeReader, self).__init__(*args, **kwargs)
        self._opReader = OpTiledVolumeReader(parent=self)
        self._opReader.DescriptionFilePath.connect(self.DescriptionFilePath)

        self.UncachedOutput.connect(self._opReader.Output)

        self._opCache = OpBlockedArrayCache(parent=self)
        self._opCache.Input.connect(self._opReader.Output)
        self._opCache.fixAtCurrent.setValue(False)

        self.CachedOutput.connect(self._opCache.Output)