Пример #1
0
    def _applyPattern(self):
        globStrings = self.patternEdit.text()
        H5EXTS = OpStreamingH5N5SequenceReaderM.H5EXTS
        N5EXTS = OpStreamingH5N5SequenceReaderM.N5EXTS
        filenames = []
        # see if some glob strings include HDF5 and/or N5 files
        globStrings = globStrings.split(os.path.pathsep)
        pcs = [PathComponents(x) for x in globStrings]
        is_h5_n5 = [x.extension in (H5EXTS + N5EXTS) for x in pcs]

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

        filenames.extend(OpStackLoader.expandGlobStrings(globStrings))

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

        try:
            OpStreamingH5N5SequenceReaderM.checkGlobString(h5GlobStrings)
            filenames.extend(
                "{}/{}".format(external, internal)
                for external, internal in zip(
                    *OpStreamingH5N5SequenceReaderM.expandGlobStrings(
                        h5GlobStrings)))
        except (
                OpStreamingH5N5SequenceReaderM.WrongFileTypeError,
                OpStreamingH5N5SequenceReaderM.SameFileError,
                OpStreamingH5N5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingH5N5SequenceReaderM.InternalPlaceholderError,
        ):
            pass
        self._updateFileList(filenames)
Пример #2
0
    def _applyPattern(self):
        globStrings = self.patternEdit.text()
        H5EXTS = OpStreamingH5N5SequenceReaderM.H5EXTS
        N5EXTS = OpStreamingH5N5SequenceReaderM.N5EXTS
        filenames = []
        # see if some glob strings include HDF5 and/or N5 files
        globStrings = globStrings.split(os.path.pathsep)
        pcs = [PathComponents(x) for x in globStrings]
        is_h5_n5 = [x.extension in (H5EXTS + N5EXTS) for x in pcs]

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

        filenames.extend(OpStackLoader.expandGlobStrings(globStrings))

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

        try:
            OpStreamingH5N5SequenceReaderM.checkGlobString(h5GlobStrings)
            filenames.extend(
                "{}/{}".format(external, internal)
                for external, internal
                in zip(*OpStreamingH5N5SequenceReaderM.expandGlobStrings(h5GlobStrings))
            )
        except (
                OpStreamingH5N5SequenceReaderM.WrongFileTypeError,
                OpStreamingH5N5SequenceReaderM.SameFileError,
                OpStreamingH5N5SequenceReaderM.NoExternalPlaceholderError,
                OpStreamingH5N5SequenceReaderM.InternalPlaceholderError):
            pass
        self._updateFileList(filenames)
Пример #3
0
    def _attemptOpenAsH5N5Stack(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:
            OpStreamingH5N5SequenceReaderS.checkGlobString(filePath)
        except OpStreamingH5N5SequenceReaderS.WrongFileTypeError:
            return ([], None)
        except (
                OpStreamingH5N5SequenceReaderS.NoInternalPlaceholderError,
                OpStreamingH5N5SequenceReaderS.NotTheSameFileError,
                OpStreamingH5N5SequenceReaderS.ExternalPlaceholderError,
        ):
            isSingleFile = False

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

        assert not (isMultiFile and isSingleFile)

        if isSingleFile is True:
            opReader = OpStreamingH5N5SequenceReaderS(parent=self)
        elif isMultiFile is True:
            opReader = OpStreamingH5N5SequenceReaderM(parent=self)

        try:
            opReader.SequenceAxis.connect(self.SequenceAxis)
            opReader.GlobString.setValue(filePath)
            return ([opReader], opReader.OutputImage)
        except (OpStreamingH5N5SequenceReaderM.WrongFileTypeError,
                OpStreamingH5N5SequenceReaderS.WrongFileTypeError):
            return ([], None)
    def test_globStringValidity(self):
        """Check whether globStrings are correctly verified"""
        testGlobString = "/tmp/test.h5"
        with self.assertRaises(
                OpStreamingH5N5SequenceReaderS.NoInternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test.n5"
        with self.assertRaises(
                OpStreamingH5N5SequenceReaderS.NoInternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test.h5/a" + os.pathsep + "/tmp/test2.h5/a"
        with self.assertRaises(
                OpStreamingH5N5SequenceReaderS.NotTheSameFileError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test.n5/a" + os.pathsep + "/tmp/test2.n5/a"
        with self.assertRaises(
                OpStreamingH5N5SequenceReaderS.NotTheSameFileError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test*.h5/a" + os.pathsep + "/tmp/test*.h5/a"
        with self.assertRaises(
                OpStreamingH5N5SequenceReaderS.ExternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test*.n5/a" + os.pathsep + "/tmp/test*.n5/a"
        with self.assertRaises(
                OpStreamingH5N5SequenceReaderS.ExternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

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

        validGlobStrings = [
            "/tmp/test.h5/*",
            "/tmp/test.h5/data1" + os.pathsep + "/tmp/test.h5/data2",
            "/tmp/test.h5/data*",
            "/tmp/test.n5/*",
            "/tmp/test.n5/data1" + os.pathsep + "/tmp/test.n5/data2",
            "/tmp/test.n5/data*",
        ]

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

        self.assertTrue(True)
    def test_globStringValidity(self):
        """Check whether globStrings are correctly verified"""
        testGlobString = "/tmp/test.h5"
        with self.assertRaises(OpStreamingH5N5SequenceReaderS.NoInternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test.n5"
        with self.assertRaises(OpStreamingH5N5SequenceReaderS.NoInternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test.h5/a" + os.pathsep + "/tmp/test2.h5/a"
        with self.assertRaises(OpStreamingH5N5SequenceReaderS.NotTheSameFileError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test.n5/a" + os.pathsep + "/tmp/test2.n5/a"
        with self.assertRaises(OpStreamingH5N5SequenceReaderS.NotTheSameFileError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test*.h5/a" + os.pathsep + "/tmp/test*.h5/a"
        with self.assertRaises(OpStreamingH5N5SequenceReaderS.ExternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

        testGlobString = "/tmp/test*.n5/a" + os.pathsep + "/tmp/test*.n5/a"
        with self.assertRaises(OpStreamingH5N5SequenceReaderS.ExternalPlaceholderError):
            OpStreamingH5N5SequenceReaderS.checkGlobString(testGlobString)

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

        validGlobStrings = [
            "/tmp/test.h5/*",
            "/tmp/test.h5/data1" + os.pathsep + "/tmp/test.h5/data2",
            "/tmp/test.h5/data*",
            "/tmp/test.n5/*",
            "/tmp/test.n5/data1" + os.pathsep + "/tmp/test.n5/data2",
            "/tmp/test.n5/data*",
        ]

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

        self.assertTrue(True)