Exemple #1
0
    def setupOutputs(self):
        file_paths = self.expandGlobStrings(self.GlobString.value)
        for filename in file_paths:
            if os.path.splitext(
                    filename)[1].lower() not in OpTiffReader.TIFF_EXTS:
                raise OpTiffSequenceReader.WrongFileTypeError(filename)

        num_files = len(file_paths)
        if num_files == 0:
            self.Output.disconnect()
            self.Output.meta.NOTREADY = True
            return

        self.Output.connect(self._opStacker.Output)
        try:
            opFirstImg = OpTiffReader(parent=self)
            opFirstImg.Filepath.setValue(file_paths[0])
            slice_axes = opFirstImg.Output.meta.getAxisKeys()
            opFirstImg.cleanUp()
        except RuntimeError as e:
            logger.error(str(e))
            raise OpTiffSequenceReader.FileOpenError(file_paths[0])

        if self.SequenceAxis.ready():
            new_axis = self.SequenceAxis.value
            assert len(new_axis) == 1
            assert new_axis in 'tzyxc'
        else:
            # Try to pick an axis that doesn't already exist in each tiff
            for new_axis in 'tzc0':
                if new_axis not in slice_axes:
                    break

            if new_axis == '0':
                # All axes used already.
                # Stack across first existing axis
                new_axis = slice_axes[0]

        self._opStacker.Images.resize(0)
        self._opStacker.Images.resize(num_files)
        self._opStacker.AxisFlag.setValue(new_axis)

        for opReader in self._readers:
            opReader.cleanUp()

        self._readers = []
        for filename, stacker_slot in zip(file_paths, self._opStacker.Images):
            opReader = OpTiffReader(parent=self)
            try:
                opReader.Filepath.setValue(filename)
            except RuntimeError as e:
                logger.error(str(e))
                raise OpTiffSequenceReader.FileOpenError(file_paths[0])
            else:
                stacker_slot.connect(opReader.Output)
                self._readers.append(opReader)
    def setupOutputs(self):
        file_paths = self.expandGlobStrings(self.GlobString.value)
        for filename in file_paths:
            if os.path.splitext(filename)[1].lower() not in OpTiffReader.TIFF_EXTS:
                raise OpTiffSequenceReader.WrongFileTypeError(filename)

        num_files = len(file_paths)
        if num_files == 0:
            self.Output.disconnect()
            self.Output.meta.NOTREADY = True
            return

        self.Output.connect(self._opStacker.Output)
        try:
            opFirstImg = OpTiffReader(parent=self)
            opFirstImg.Filepath.setValue(file_paths[0])
            slice_axes = opFirstImg.Output.meta.getAxisKeys()
            opFirstImg.cleanUp()
        except RuntimeError as e:
            logger.error(str(e))
            raise OpTiffSequenceReader.FileOpenError(file_paths[0])

        if self.SequenceAxis.ready():
            new_axis = self.SequenceAxis.value
            assert len(new_axis) == 1
            assert new_axis in "tzyxc"
        else:
            # Try to pick an axis that doesn't already exist in each tiff
            for new_axis in "tzc0":
                if new_axis not in slice_axes:
                    break

            if new_axis == "0":
                # All axes used already.
                # Stack across first existing axis
                new_axis = slice_axes[0]

        self._opStacker.Images.resize(0)
        self._opStacker.Images.resize(num_files)
        self._opStacker.AxisFlag.setValue(new_axis)

        for opReader in self._readers:
            opReader.cleanUp()

        self._readers = []
        for filename, stacker_slot in zip(file_paths, self._opStacker.Images):
            opReader = OpTiffReader(parent=self)
            try:
                opReader.Filepath.setValue(filename)
            except RuntimeError as e:
                logger.error(str(e))
                raise OpTiffSequenceReader.FileOpenError(file_paths[0])
            else:
                stacker_slot.connect(opReader.Output)
                self._readers.append(opReader)
    def test_basic(self):
        opSource = OpArrayPiper(graph=self.graph)
        opSource.Input.setValue(self.testData)

        opData = OpArrayCache(graph=self.graph)
        opData.blockShape.setValue(self.testData.shape)
        opData.Input.connect(opSource.Output)

        filepath = os.path.join(self._tmpdir, 'multipage.tiff')
        logger.debug("writing to: {}".format(filepath))

        opExport = OpExportMultipageTiff(graph=self.graph)
        opExport.Filepath.setValue(filepath)
        opExport.Input.connect(opData.Output)

        # Run the export
        opExport.run_export()

        opReader = OpTiffReader(graph=self.graph)
        try:
            opReader.Filepath.setValue(filepath)

            # Re-order before comparing
            opReorderAxes = OpReorderAxes(graph=self.graph)
            try:
                opReorderAxes.AxisOrder.setValue(self._axisorder)
                opReorderAxes.Input.connect(opReader.Output)

                readData = opReorderAxes.Output[:].wait()
                logger.debug("Expected shape={}".format(self.testData.shape))
                logger.debug("Read shape={}".format(readData.shape))

                assert opReorderAxes.Output.meta.shape == self.testData.shape, \
                    "Exported files were of the wrong shape or number."
                assert (opReorderAxes.Output[:].wait() == self.testData.view( numpy.ndarray )).all(), \
                    "Exported data was not correct"
            finally:
                opReorderAxes.cleanUp()
        finally:
            opReader.cleanUp()
    def test_basic(self):
        opSource = OpArrayPiper(graph=self.graph)
        opSource.Input.setValue( self.testData )
        
        opData = OpArrayCache( graph=self.graph )
        opData.blockShape.setValue( self.testData.shape )
        opData.Input.connect( opSource.Output )
        
        filepath = os.path.join( self._tmpdir, 'multipage.tiff' )
        logger.debug( "writing to: {}".format(filepath) )
        
        opExport = OpExportMultipageTiff(graph=self.graph)
        opExport.Filepath.setValue( filepath )
        opExport.Input.connect( opData.Output )

        # Run the export
        opExport.run_export()

        opReader = OpTiffReader( graph=self.graph )
        try:
            opReader.Filepath.setValue( filepath )
    
            # Re-order before comparing
            opReorderAxes = OpReorderAxes( graph=self.graph )
            try:
                opReorderAxes.AxisOrder.setValue( self._axisorder )
                opReorderAxes.Input.connect( opReader.Output )
                
                readData = opReorderAxes.Output[:].wait()
                logger.debug("Expected shape={}".format( self.testData.shape ) )
                logger.debug("Read shape={}".format( readData.shape ) )
                
                assert opReorderAxes.Output.meta.shape == self.testData.shape, \
                    "Exported files were of the wrong shape or number."
                assert (opReorderAxes.Output[:].wait() == self.testData.view( numpy.ndarray )).all(), \
                    "Exported data was not correct"
            finally:
                opReorderAxes.cleanUp()
        finally:
            opReader.cleanUp()