コード例 #1
0
    def testBasic(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection, graph=graph)
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        # Create a list of dataset infos . . .
        datasetInfos = []

        # npy
        info = DatasetInfo()
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.filePath = self.testNpyFileName
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False
        datasetInfos.append(info)

        # png
        info = DatasetInfo()
        info.location = DatasetInfo.Location.FileSystem
        info.filePath = self.testPngFileName
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False
        datasetInfos.append(info)

        reader.Dataset.setValues(datasetInfos)

        # Read the test files using the data selection operator and verify the contents
        npyData = reader.Image[0][...].wait()
        pngData = reader.Image[1][...].wait()

        # Check the file name output
        print reader.ImageName[0].value
        assert reader.ImageName[0].value == self.testNpyFileName
        assert reader.ImageName[1].value == self.testPngFileName

        # Check raw images
        assert npyData.shape == (10, 11, 1)
        for x in range(npyData.shape[0]):
            for y in range(npyData.shape[1]):
                assert npyData[x, y, 0] == x + y

        assert pngData.shape == (100, 200, 3)
        for x in range(pngData.shape[0]):
            for y in range(pngData.shape[1]):
                for c in range(pngData.shape[2]):
                    assert pngData[x, y, c] == (x + y) % 256
コード例 #2
0
ファイル: testOpDataSelection.py プロジェクト: burcin/ilastik
    def testBasic(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper( OpDataSelection, graph=graph )
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue( os.getcwd() )
        reader.ProjectDataGroup.setValue( 'DataSelection/local_data' )
        
        # Create a list of dataset infos . . .
        datasetInfos = []
        
        # npy
        info = DatasetInfo()
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.filePath = self.testNpyFileName
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False
        datasetInfos.append(info)
        
        # png
        info = DatasetInfo()
        info.location = DatasetInfo.Location.FileSystem
        info.filePath = self.testPngFileName
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False
        datasetInfos.append(info)

        reader.Dataset.setValues(datasetInfos)

        # Read the test files using the data selection operator and verify the contents
        npyData = reader.Image[0][...].wait()
        pngData = reader.Image[1][...].wait()

        # Check the file name output
        print reader.ImageName[0].value
        assert reader.ImageName[0].value == self.testNpyFileName
        assert reader.ImageName[1].value == self.testPngFileName

        # Check raw images
        assert npyData.shape == (10,11,1)
        for x in range(npyData.shape[0]):
            for y in range(npyData.shape[1]):
                assert npyData[x,y,0] == x+y
        
        assert pngData.shape == (100, 200, 3)
        for x in range(pngData.shape[0]):
            for y in range(pngData.shape[1]):
                for c in range(pngData.shape[2]):
                    assert pngData[x,y,c] == (x+y) % 256
コード例 #3
0
    def test_fake_data_source(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection, graph=graph,
                                 operator_kwargs={'forceAxisOrder': False})
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        info = DatasetInfo()
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.filePath = self.testRawDataFileName
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False
        # Use *fake* data source
        info.realDataSource = False
        info.axistags = vigra.defaultAxistags('tczyx')
        info.laneShape = self.imgData.shape
        info.laneDtype = self.imgData.dtype

        reader.Dataset.setValues([info])

        # Verify that now data selection operator returns fake data
        # with expected shape and type
        imgData = reader.Image[0][...].wait()

        assert imgData.shape == self.imgData.shape
        assert imgData.dtype == self.imgData.dtype
        expected_fake_data = numpy.zeros(info.laneShape, dtype=info.laneDtype)
        numpy.testing.assert_array_equal(imgData, expected_fake_data)
コード例 #4
0
    def test_real_data_source(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection, graph=graph,
                                 operator_kwargs={'forceAxisOrder': False})
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        info = DatasetInfo()
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.filePath = self.testRawDataFileName
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False
        #Use real data source
        info.realDataSource = True

        reader.Dataset.setValues([info])

        # Read the test file using the data selection operator and verify the contents
        imgData = reader.Image[0][...].wait()

        assert imgData.shape == self.imgData.shape
        numpy.testing.assert_array_equal(imgData, self.imgData)
コード例 #5
0
    def test_load_single_file_with_list(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={'forceAxisOrder': False})
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        fileNameString = os.path.pathsep.join(self.file_names)
        info = DatasetInfo(filepath=fileNameString)
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False

        reader.Dataset.setValues([info])

        # Read the test files using the data selection operator and verify the contents
        imgData = reader.Image[0][...].wait()
        print('imgData', reader.Image.meta.axistags, reader.Image.meta.original_axistags)

        # Check raw images
        assert imgData.shape == self.imgData3Dct.shape, (imgData.shape, self.imgData3Dct.shape)

        numpy.testing.assert_array_equal(imgData, self.imgData3Dct)
コード例 #6
0
    def testBasic3DcStackFromGlobString(self):
        """Test if stacked 2d 3-channel files are loaded correctly"""
        # For some reason vigra saves 2D+c data compressed in gifs, so skip!
        self.compressedExtensions.append('.gif')
        for fileName in self.imgFileNameGlobs2Dc:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={'forceAxisOrder': False})
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData3Dc = reader.Image[0][...].wait()

            # Check the file name output
            assert reader.ImageName[0].value == fileName
            # Check raw images
            assert imgData3Dc.shape == self.imgData3Dc.shape, (imgData3Dc.shape, self.imgData3Dc.shape)
            # skip this if image was saved compressed:
            if any(x in fileName.lower() for x in self.compressedExtensions):
                print("Skipping raw comparison for compressed data: {}".format(fileName))
                continue
            numpy.testing.assert_array_equal(imgData3Dc, self.imgData3Dc)
コード例 #7
0
    def testBasic3DstacksFromFileList(self):
        for ext, fileNames in list(self.imgFileLists2D.items()):
            fileNameString = os.path.pathsep.join(fileNames)
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={'forceAxisOrder': False})
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo(filepath=fileNameString)
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData3D = reader.Image[0][...].wait()

            # Check raw images
            assert imgData3D.shape == self.imgData3D.shape, (imgData3D.shape, self.imgData3D.shape)
            # skip this if image was saved compressed:
            if any(x.strip('.') in ext.lower() for x in self.compressedExtensions):
                print("Skipping raw comparison for compressed data: {}".format(ext))
                continue
            numpy.testing.assert_array_equal(imgData3D, self.imgData3D)
コード例 #8
0
    def testBasic3DWrongAxes(self):
        """Test if 3D file with intentionally wrong axes is rejected """
        for fileName in self.imgFileNames3D:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={'forceAxisOrder': False})
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False
            info.axistags = vigra.defaultAxistags('tzyc')

            try:
                reader.Dataset.setValues([info])
                assert False, "Should have thrown an exception!"
            except DatasetConstraintError:
                pass
            except:
                assert False, "Should have thrown a DatasetConstraintError!"
コード例 #9
0
    def testBasic3D(self):
        """Test if plane 2d files are loaded correctly"""
        for fileName in self.imgFileNames3D:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={'forceAxisOrder': False})
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData3D = reader.Image[0][...].wait()

            # Check the file name output
            assert reader.ImageName[0].value == fileName
            # Check raw images
            assert imgData3D.shape == self.imgData3D.shape, (imgData3D.shape, self.imgData3D.shape)
            # skip this if image was saved compressed:
            numpy.testing.assert_array_equal(imgData3D, self.imgData3D)
コード例 #10
0
ファイル: testOpDataSelection.py プロジェクト: burcin/ilastik
    def testProjectLocalData(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper( OpDataSelection, graph=graph )
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue( os.getcwd() )
        reader.ProjectDataGroup.setValue( 'DataSelection/local_data' )
        
        # Create a list of dataset infos . . .
        datasetInfos = []

        # From project
        info = DatasetInfo()
        info.location = DatasetInfo.Location.ProjectInternal
        info.filePath = "This string should be ignored..."
        info._datasetId = 'dataset1' # (Cheating a bit here...)
        info.invertColors = False
        info.convertToGrayscale = False
        datasetInfos.append(info)

        reader.Dataset.setValues(datasetInfos)

        projectInternalData = reader.Image[0][...].wait()
        
        assert projectInternalData.shape == self.pngData.shape
        assert (projectInternalData == self.pngData).all()
コード例 #11
0
    def testBasic3DcStackFromGlobString(self):
        """Test if stacked 2d 3-channel files are loaded correctly"""
        # For some reason vigra saves 2D+c data compressed in gifs, so skip!
        self.compressedExtensions.append('.gif')
        for fileName in self.imgFileNameGlobs2Dc:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph)
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData3Dc = reader.Image[0][...].wait()

            # Check the file name output
            assert reader.ImageName[0].value == fileName
            # Check raw images
            assert imgData3Dc.shape == self.imgData3Dc.shape
            # skip this if image was saved compressed:
            if any(x in fileName.lower() for x in self.compressedExtensions):
                print("Skipping raw comparison for compressed data: {}".format(
                    fileName))
                continue
            numpy.testing.assert_array_equal(imgData3Dc, self.imgData3Dc)
コード例 #12
0
    def testBasic3DstacksFromFileList(self):
        for ext, fileNames in self.imgFileLists2D.items():
            fileNameString = os.path.pathsep.join(fileNames)
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph)
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo(filepath=fileNameString)
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData3D = reader.Image[0][...].wait()

            # Check raw images
            assert imgData3D.shape == self.imgData3D.shape
            # skip this if image was saved compressed:
            if any(
                    x.strip('.') in ext.lower()
                    for x in self.compressedExtensions):
                print("Skipping raw comparison for compressed data: {}".format(
                    ext))
                continue
            numpy.testing.assert_array_equal(imgData3D, self.imgData3D)
コード例 #13
0
    def testBasic2D(self):
        """Test if plane 2d files are loaded correctly"""
        for fileName in self.imgFileNames2D:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph)
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData2D = reader.Image[0][...].wait()

            # Check the file name output
            assert reader.ImageName[0].value == fileName
            # Check raw images
            assert imgData2D.shape == self.imgData2D.shape
            # skip this if image was saved compressed:
            if any(x in fileName.lower() for x in self.compressedExtensions):
                print("Skipping raw comparison for compressed data: {}".format(fileName))
                continue
            numpy.testing.assert_array_equal(imgData2D, self.imgData2D)
コード例 #14
0
    def testBasic3DWrongAxes(self):
        """Test if 3D file with intentionally wrong axes is rejected """
        for fileName in self.imgFileNames3D:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph)
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False
            info.axistags = vigra.defaultAxistags('tzyc')

            try:
                reader.Dataset.setValues([info])
                assert False, "Should have thrown an exception!"
            except DatasetConstraintError:
                pass
            except:
                assert False, "Should have thrown a DatasetConstraintError!"
コード例 #15
0
    def testProjectLocalData(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection, graph=graph)
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        # Create a list of dataset infos . . .
        datasetInfos = []

        # From project
        info = DatasetInfo()
        info.location = DatasetInfo.Location.ProjectInternal
        info.filePath = "This string should be ignored..."
        info._datasetId = 'dataset1'  # (Cheating a bit here...)
        info.invertColors = False
        info.convertToGrayscale = False
        datasetInfos.append(info)

        reader.Dataset.setValues(datasetInfos)

        projectInternalData = reader.Image[0][...].wait()

        assert projectInternalData.shape == self.imgData3Dc.shape
        assert (projectInternalData == self.imgData3Dc).all()
コード例 #16
0
    def testBasic3D(self):
        """Test if plane 2d files are loaded correctly"""
        for fileName in self.imgFileNames3D:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection, graph=graph)
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData3D = reader.Image[0][...].wait()

            # Check the file name output
            assert reader.ImageName[0].value == fileName
            # Check raw images
            assert imgData3D.shape == self.imgData3D.shape
            # skip this if image was saved compressed:
            numpy.testing.assert_array_equal(imgData3D, self.imgData3D)
コード例 #17
0
    def test_load_single_file_with_list(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection,
                                 graph=graph,
                                 operator_kwargs={'forceAxisOrder': False})
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        fileNameString = os.path.pathsep.join(self.file_names)
        info = DatasetInfo(filepath=fileNameString)
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False

        reader.Dataset.setValues([info])

        # Read the test files using the data selection operator and verify the contents
        imgData = reader.Image[0][...].wait()
        print('imgData', reader.Image.meta.axistags,
              reader.Image.meta.original_axistags)

        # Check raw images
        assert imgData.shape == self.imgData3Dct.shape, (
            imgData.shape, self.imgData3Dct.shape)

        numpy.testing.assert_array_equal(imgData, self.imgData3Dct)
コード例 #18
0
    def testBasic2D(self):
        """Test if plane 2d files are loaded correctly"""
        for fileName in self.imgFileNames2D:
            graph = lazyflow.graph.Graph()
            reader = OperatorWrapper(OpDataSelection,
                                     graph=graph,
                                     operator_kwargs={'forceAxisOrder': False})
            reader.ProjectFile.setValue(self.projectFile)
            reader.WorkingDirectory.setValue(os.getcwd())
            reader.ProjectDataGroup.setValue('DataSelection/local_data')

            info = DatasetInfo()
            # Will be read from the filesystem since the data won't be found in the project file.
            info.location = DatasetInfo.Location.ProjectInternal
            info.filePath = fileName
            info.internalPath = ""
            info.invertColors = False
            info.convertToGrayscale = False

            reader.Dataset.setValues([info])

            # Read the test files using the data selection operator and verify the contents
            imgData2D = reader.Image[0][...].wait()

            # Check the file name output
            assert reader.ImageName[0].value == fileName
            # Check raw images
            assert imgData2D.shape == self.imgData2D.shape
            # skip this if image was saved compressed:
            if any(x in fileName.lower() for x in self.compressedExtensions):
                print("Skipping raw comparison for compressed data: {}".format(
                    fileName))
                continue
            numpy.testing.assert_array_equal(imgData2D, self.imgData2D)
コード例 #19
0
    def test_load_single_file_with_glob(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection, graph=graph)
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        info = DatasetInfo(filepath=self.glob_string)
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False

        reader.Dataset.setValues([info])

        # Read the test files using the data selection operator and verify the contents
        imgData = reader.Image[0][...].wait()

        # Check raw images
        assert imgData.shape == self.imgData3Dct.shape

        numpy.testing.assert_array_equal(imgData, self.imgData3Dct)
コード例 #20
0
    def test_load_single_file_with_glob(self):
        graph = lazyflow.graph.Graph()
        reader = OperatorWrapper(OpDataSelection, graph=graph)
        reader.ProjectFile.setValue(self.projectFile)
        reader.WorkingDirectory.setValue(os.getcwd())
        reader.ProjectDataGroup.setValue('DataSelection/local_data')

        info = DatasetInfo(filepath=self.glob_string)
        # Will be read from the filesystem since the data won't be found in the project file.
        info.location = DatasetInfo.Location.ProjectInternal
        info.internalPath = ""
        info.invertColors = False
        info.convertToGrayscale = False

        reader.Dataset.setValues([info])

        # Read the test files using the data selection operator and verify the contents
        imgData = reader.Image[0][...].wait()

        # Check raw images
        assert imgData.shape == self.imgData3Dct.shape

        numpy.testing.assert_array_equal(imgData, self.imgData3Dct)