Пример #1
0
    def _applyPattern(self):
        globStrings = encode_from_qstring(self.patternEdit.text())
        H5EXTS = OpStreamingHdf5SequenceReaderM.H5EXTS
        filenames = []
        # see if some glob strings include HDF5 files
        globStrings = globStrings.split(os.path.pathsep)
        pcs = [PathComponents(x) for x in globStrings]
        ish5 = [x.extension in H5EXTS for x in pcs]

        h5GlobStrings = os.path.pathsep.join(
            [x for x, y in zip(globStrings, ish5) if y is True])
        globStrings = os.path.pathsep.join(
            [x for x, y in zip(globStrings, ish5) if y is False])

        filenames.extend(OpStackLoader.expandGlobStrings(globStrings))

        try:
            OpStreamingHdf5SequenceReaderS.checkGlobString(h5GlobStrings)
            # OK, if nothing raised there is a single h5 file in h5GlobStrings:
            pathComponents = PathComponents(
                h5GlobStrings.split(os.path.pathsep)[0])
            h5file = h5py.File(pathComponents.externalPath, mode='r')
            filenames.extend(
                "{}/{}".format(pathComponents.externalPath, internal)
                for internal in OpStreamingHdf5SequenceReaderS.
                expandGlobStrings(h5file, h5GlobStrings))
        except (OpStreamingHdf5SequenceReaderS.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderS.NotTheSameFileError,
                OpStreamingHdf5SequenceReaderS.NoInternalPlaceholderError,
                OpStreamingHdf5SequenceReaderS.ExternalPlaceholderError):
            pass

        try:
            OpStreamingHdf5SequenceReaderM.checkGlobString(h5GlobStrings)
            filenames.extend(
                "{}/{}".format(external, internal)
                for external, internal in zip(
                    *OpStreamingHdf5SequenceReaderM.expandGlobStrings(
                        h5GlobStrings)))
        except (OpStreamingHdf5SequenceReaderM.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderM.SameFileError,
                OpStreamingHdf5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            pass

        self._updateFileList(filenames)
    def _applyPattern(self):
        globStrings = self.patternEdit.text()
        H5EXTS = OpStreamingHdf5SequenceReaderM.H5EXTS
        filenames = []
        # see if some glob strings include HDF5 files
        globStrings = globStrings.split(os.path.pathsep)
        pcs = [PathComponents(x) for x in globStrings]
        ish5 = [x.extension in H5EXTS for x in pcs]

        h5GlobStrings = os.path.pathsep.join([x for x, y in zip(globStrings, ish5) if y is True])
        globStrings = os.path.pathsep.join([x for x, y in zip(globStrings, ish5) if y is False])

        filenames.extend(OpStackLoader.expandGlobStrings(globStrings))

        try:
            OpStreamingHdf5SequenceReaderS.checkGlobString(h5GlobStrings)
            # OK, if nothing raised there is a single h5 file in h5GlobStrings:
            pathComponents = PathComponents(h5GlobStrings.split(os.path.pathsep)[0])
            h5file = h5py.File(pathComponents.externalPath, mode='r')
            filenames.extend(
                "{}/{}".format(pathComponents.externalPath, internal)
                for internal in OpStreamingHdf5SequenceReaderS.expandGlobStrings(h5file, h5GlobStrings))
        except (
                OpStreamingHdf5SequenceReaderS.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderS.NotTheSameFileError,
                OpStreamingHdf5SequenceReaderS.NoInternalPlaceholderError,
                OpStreamingHdf5SequenceReaderS.ExternalPlaceholderError):
            pass

        try:
            OpStreamingHdf5SequenceReaderM.checkGlobString(h5GlobStrings)
            filenames.extend(
                "{}/{}".format(external, internal)
                for external, internal
                in zip(*OpStreamingHdf5SequenceReaderM.expandGlobStrings(h5GlobStrings))
            )
        except (
                OpStreamingHdf5SequenceReaderM.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderM.SameFileError,
                OpStreamingHdf5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            pass

        self._updateFileList(filenames)
Пример #3
0
    def _attemptOpenAsHdf5Stack(self, filePath):
        if not ('*' in filePath or os.path.pathsep in filePath):
            return ([], None)

        # Now use the .checkGlobString method of the stack readers
        isSingleFile = True
        try:
            OpStreamingHdf5SequenceReaderS.checkGlobString(filePath)
        except OpStreamingHdf5SequenceReaderS.WrongFileTypeError:
            return ([], None)
        except (OpStreamingHdf5SequenceReaderS.NoInternalPlaceholderError,
                OpStreamingHdf5SequenceReaderS.NotTheSameFileError,
                OpStreamingHdf5SequenceReaderS.ExternalPlaceholderError):
            isSingleFile = False

        isMultiFile = True
        try:
            OpStreamingHdf5SequenceReaderM.checkGlobString(filePath)
        except (OpStreamingHdf5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingHdf5SequenceReaderM.SameFileError,
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            isMultiFile = False

        assert (not (isMultiFile and isSingleFile))

        if isSingleFile is True:
            opReader = OpStreamingHdf5SequenceReaderS(parent=self)
        elif isMultiFile is True:
            opReader = OpStreamingHdf5SequenceReaderM(parent=self)

        try:
            opReader.SequenceAxis.connect(self.SequenceAxis)
            opReader.GlobString.setValue(filePath)
            return ([opReader], opReader.OutputImage)
        except (OpStreamingHdf5SequenceReaderM.WrongFileTypeError,
                OpStreamingHdf5SequenceReaderS.WrongFileTypeError):
            return ([], None)
        else:
            return ([], None)
    def test_3d_vigra_along_t(self):
        """Test if 3d volumes generated through vigra are recognized correctly"""
        # Prepare some data set for this case
        data = numpy.random.randint(0, 255,
                                    (10, 15, 50, 100, 3)).astype(numpy.uint8)

        axistags = vigra.defaultAxistags('zyxc')
        expected_axistags = vigra.defaultAxistags('tzyxc')

        op = OpStreamingHdf5SequenceReaderM(graph=self.graph)

        with tempdir() as d:
            try:
                for sliceIndex, tSlice in enumerate(data):
                    testDataFileName = '{path}/test-{index:02d}.h5'.format(
                        path=d, index=sliceIndex)
                    # Write the dataset to an hdf5 file
                    # (Note: Don't use vigra to do this, which may reorder the axes)
                    h5File = h5py.File(testDataFileName)
                    try:
                        h5File.create_group('volume')

                        h5File['volume'].create_dataset("subvolume",
                                                        data=tSlice)
                        # Write the axistags attribute
                        current_path = 'volume/subvolume'
                        h5File[current_path].attrs[
                            'axistags'] = axistags.toJSON()
                    finally:
                        h5File.close()

                # Read the data with an operator
                hdf5GlobString = "{path}/test-*.h5/volume/subvolume".format(
                    path=d)
                op.SequenceAxis.setValue('t')
                op.GlobString.setValue(hdf5GlobString)

                assert op.OutputImage.ready()
                assert op.OutputImage.meta.axistags == expected_axistags
                numpy.testing.assert_array_equal(
                    op.OutputImage[0:2, 5:10, 20:50, 40:70].wait(),
                    data[0:2, 5:10, 20:50, 40:70])
            finally:
                op.cleanUp()
    def test_globStringValidity(self):
        """Check whether globStrings are correctly verified"""
        testGlobString = '/tmp/test.h5/somedata'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderM.NoExternalPlaceholderError):
            OpStreamingHdf5SequenceReaderM.checkGlobString(testGlobString)

        testGlobString = '/tmp/test.jpg/*'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderM.WrongFileTypeError):
            OpStreamingHdf5SequenceReaderM.checkGlobString(testGlobString)

        testGlobString = '/tmp/test.h5/data' + os.pathsep + '/tmp/test.h5/data2'
        with self.assertRaises(OpStreamingHdf5SequenceReaderM.SameFileError):
            OpStreamingHdf5SequenceReaderM.checkGlobString(testGlobString)

        testGlobString = '/tmp/test-*.h5/data*'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            OpStreamingHdf5SequenceReaderM.checkGlobString(testGlobString)

        testGlobString = '/tmp/test-0.h5/data' + os.pathsep + '/tmp/test-1.h5/data*'
        with self.assertRaises(
                OpStreamingHdf5SequenceReaderM.InternalPlaceholderError):
            OpStreamingHdf5SequenceReaderM.checkGlobString(testGlobString)

        validGlobStrings = [
            '/tmp/test-*.h5/data',
            '/tmp/test-1.h5/data1' + os.pathsep + '/tmp/test-2.h5/data1',
        ]

        for testGlobString in validGlobStrings:
            OpStreamingHdf5SequenceReaderM.checkGlobString(testGlobString)
        # Implicit test for validity; test fails if an exception is raised
        self.assertTrue(True)