예제 #1
0
    def test(self):
        # Define the files we'll be making
        testProjectName = 'test_project.ilp'
        # Clean up: Remove the test data files we created last time (just in case)
        for f in [testProjectName]:
            try:
                os.remove(f)
            except:
                pass

        # Create an empty project
        with h5py.File(testProjectName) as testProject:
            testProject.create_dataset("ilastikVersion", data=0.6)

            # Create an operator to work with and give it some input
            graph = Graph()
            operatorToSave = OpFeatureSelection(graph=graph)

            # Configure scales
            scales = [0.1, 0.2, 0.3, 0.4, 0.5]
            operatorToSave.Scales.setValue(scales)

            # Configure feature types
            featureIds = ['GaussianSmoothing', 'LaplacianOfGaussian']
            operatorToSave.FeatureIds.setValue(featureIds)

            # All False (no features selected)
            selectionMatrix = numpy.zeros((2, 5), dtype=bool)

            # Change a few to True
            selectionMatrix[0, 0] = True
            selectionMatrix[1, 0] = True
            selectionMatrix[0, 2] = True
            selectionMatrix[1, 4] = True
            operatorToSave.SelectionMatrix.setValue(selectionMatrix)

            # Serialize!
            serializer = FeatureSelectionSerializer(operatorToSave,
                                                    'FeatureSelections')
            serializer.serializeToHdf5(testProject, testProjectName)

            assert (
                testProject['FeatureSelections/Scales'].value == scales).all()
            assert (testProject['FeatureSelections/FeatureIds'].value ==
                    featureIds).all()
            assert (testProject['FeatureSelections/SelectionMatrix'].value ==
                    selectionMatrix).all()

            # Deserialize into a fresh operator
            operatorToLoad = OpFeatureSelection(graph=graph)
            deserializer = FeatureSelectionSerializer(operatorToLoad,
                                                      'FeatureSelections')
            deserializer.deserializeFromHdf5(testProject, testProjectName)

            assert (operatorToLoad.Scales.value == scales).all()
            assert (operatorToLoad.FeatureIds.value == featureIds).all()
            assert (
                operatorToLoad.SelectionMatrix.value == selectionMatrix).all()

        os.remove(testProjectName)
    def test(self):    
        # Define the files we'll be making    
        testProjectName = 'test_project.ilp'
        # Clean up: Remove the test data files we created last time (just in case)
        for f in [testProjectName]:
            try:
                os.remove(f)
            except:
                pass
    
        # Create an empty project
        with h5py.File(testProjectName, 'w') as testProject:
            testProject.create_dataset("ilastikVersion", data=b"1.0.0")
            
            # Create an operator to work with and give it some input
            graph = Graph()
            operatorToSave = OpFeatureSelection(graph=graph)

            scales = operatorToSave.Scales.value
            featureIds = operatorToSave.FeatureIds.value

            # All False (no features selected)
            selectionMatrix = operatorToSave.MinimalFeatures
        
            # Change a few to True
            selectionMatrix[0,0] = True
            selectionMatrix[1,1] = True
            selectionMatrix[2,2] = True
            selectionMatrix[3,3] = True
            selectionMatrix[4,4] = True
            selectionMatrix[5,5] = True
            operatorToSave.SelectionMatrix.setValue(selectionMatrix)
            
            # Serialize!
            serializer = FeatureSelectionSerializer(operatorToSave, 'FeatureSelections')
            serializer.serializeToHdf5(testProject, testProjectName)

        with h5py.File(testProjectName, 'r') as testProject:
            file_feature_ids = numpy.asarray(list(map(lambda s: s.decode('utf-8'), testProject['FeatureSelections/FeatureIds'].value)))
            
            assert (testProject['FeatureSelections/Scales'].value == scales).all()
            assert (file_feature_ids == featureIds).all()
            assert (testProject['FeatureSelections/SelectionMatrix'].value == selectionMatrix).all()
        
            # Deserialize into a fresh operator
            operatorToLoad = OpFeatureSelection(graph=graph)

            deserializer = FeatureSelectionSerializer(operatorToLoad, 'FeatureSelections')
            deserializer.deserializeFromHdf5(testProject, testProjectName)
            assert operatorToLoad.FeatureIds.value == getFeatureIdOrder(), \
                "Feature IDs were deserialized to a strange order!"
            
            assert isinstance(operatorToLoad.Scales.value, list)
            assert isinstance(operatorToLoad.FeatureIds.value, list)

            assert (operatorToLoad.Scales.value == scales)
            assert (operatorToLoad.FeatureIds.value == featureIds)
            assert (operatorToLoad.SelectionMatrix.value == selectionMatrix).all()

        os.remove(testProjectName)
    def test(self):    
        # Define the files we'll be making    
        testProjectName = 'test_project.ilp'
        # Clean up: Remove the test data files we created last time (just in case)
        for f in [testProjectName]:
            try:
                os.remove(f)
            except:
                pass
    
        # Create an empty project
        with h5py.File(testProjectName) as testProject:
            testProject.create_dataset("ilastikVersion", data=0.6)
            
            # Create an operator to work with and give it some input
            graph = Graph()
            operatorToSave = OpFeatureSelection(graph=graph, filter_implementation='Original')
        
            # Configure scales        
            scales = [0.1, 0.2, 0.3, 0.4, 0.5]
            operatorToSave.Scales.setValue(scales)
        
            # Configure feature types
            featureIds = [ 'GaussianSmoothing',
                           'LaplacianOfGaussian' ]
            operatorToSave.FeatureIds.setValue(featureIds)
        
            # All False (no features selected)
            selectionMatrix = numpy.zeros((2, 5), dtype=bool)
        
            # Change a few to True
            selectionMatrix[0,0] = True
            selectionMatrix[1,0] = True
            selectionMatrix[0,2] = True
            selectionMatrix[1,4] = True
            operatorToSave.SelectionMatrix.setValue(selectionMatrix)
            
            # Serialize!
            serializer = FeatureSelectionSerializer(operatorToSave, 'FeatureSelections')
            serializer.serializeToHdf5(testProject, testProjectName)
            
            assert (testProject['FeatureSelections/Scales'].value == scales).all()
            assert (testProject['FeatureSelections/FeatureIds'].value == featureIds).all()
            assert (testProject['FeatureSelections/SelectionMatrix'].value == selectionMatrix).all()
        
            # Deserialize into a fresh operator
            operatorToLoad = OpFeatureSelection(graph=graph, filter_implementation='Original')
            deserializer = FeatureSelectionSerializer(operatorToLoad, 'FeatureSelections')
            deserializer.deserializeFromHdf5(testProject, testProjectName)
            
            assert isinstance(operatorToLoad.Scales.value, list)
            assert isinstance(operatorToLoad.FeatureIds.value, list)

            assert (operatorToLoad.Scales.value == scales)
            assert (operatorToLoad.FeatureIds.value == featureIds)
            assert (operatorToLoad.SelectionMatrix.value == selectionMatrix).all()

        os.remove(testProjectName)
예제 #4
0
    def test(self):
        # Define the files we'll be making
        testProjectName = "test_project.ilp"
        # Clean up: Remove the test data files we created last time (just in case)
        for f in [testProjectName]:
            try:
                os.remove(f)
            except:
                pass

        # Create an empty project
        with h5py.File(testProjectName, "w") as testProject:
            testProject.create_dataset("ilastikVersion", data=b"1.0.0")

            # Create an operator to work with and give it some input
            graph = Graph()
            operatorToSave = OpFeatureSelection(graph=graph)

            scales = operatorToSave.Scales.value
            featureIds = operatorToSave.FeatureIds.value

            # All False (no features selected)
            selectionMatrix = operatorToSave.MinimalFeatures

            # Change a few to True
            selectionMatrix[0, 0] = True
            selectionMatrix[1, 1] = True
            selectionMatrix[2, 2] = True
            selectionMatrix[3, 3] = True
            selectionMatrix[4, 4] = True
            selectionMatrix[5, 5] = True
            operatorToSave.SelectionMatrix.setValue(selectionMatrix)

            # Serialize!
            serializer = FeatureSelectionSerializer(operatorToSave,
                                                    "FeatureSelections")
            serializer.serializeToHdf5(testProject, testProjectName)

        with h5py.File(testProjectName, "r") as testProject:
            file_feature_ids = numpy.asarray(
                list(
                    map(lambda s: s.decode("utf-8"),
                        testProject["FeatureSelections/FeatureIds"].value)))

            assert (
                testProject["FeatureSelections/Scales"].value == scales).all()
            assert (file_feature_ids == featureIds).all()
            assert (testProject["FeatureSelections/SelectionMatrix"].value ==
                    selectionMatrix).all()

            # Deserialize into a fresh operator
            operatorToLoad = OpFeatureSelection(graph=graph)

            deserializer = FeatureSelectionSerializer(operatorToLoad,
                                                      "FeatureSelections")
            deserializer.deserializeFromHdf5(testProject, testProjectName)
            assert (operatorToLoad.FeatureIds.value == getFeatureIdOrder()
                    ), "Feature IDs were deserialized to a strange order!"

            assert isinstance(operatorToLoad.Scales.value, list)
            assert isinstance(operatorToLoad.FeatureIds.value, list)

            assert operatorToLoad.Scales.value == scales
            assert operatorToLoad.FeatureIds.value == featureIds
            assert (
                operatorToLoad.SelectionMatrix.value == selectionMatrix).all()

        os.remove(testProjectName)
    def test(self):
        # Define the files we'll be making
        testProjectName = 'test_project.ilp'
        # Clean up: Remove the test data files we created last time (just in case)
        for f in [testProjectName]:
            try:
                os.remove(f)
            except:
                pass

        # Create an empty project
        with h5py.File(testProjectName, 'w') as testProject:
            testProject.create_dataset("ilastikVersion", data="1.0.0")

            # Create an operator to work with and give it some input
            graph = Graph()
            operatorToSave = OpFeatureSelection(
                graph=graph, filter_implementation='Original')

            scales = operatorToSave.Scales.value
            featureIds = operatorToSave.FeatureIds.value

            # All False (no features selected)
            selectionMatrix = operatorToSave.SelectionMatrix.value.copy()

            # Change a few to True
            selectionMatrix[0, 0] = True
            selectionMatrix[1, 1] = True
            selectionMatrix[2, 2] = True
            selectionMatrix[3, 3] = True
            selectionMatrix[4, 4] = True
            selectionMatrix[5, 5] = True
            operatorToSave.SelectionMatrix.setValue(selectionMatrix)

            # Serialize!
            serializer = FeatureSelectionSerializer(operatorToSave,
                                                    'FeatureSelections')
            serializer.serializeToHdf5(testProject, testProjectName)

        with h5py.File(testProjectName, 'r') as testProject:
            assert (
                testProject['FeatureSelections/Scales'].value == scales).all()
            assert (testProject['FeatureSelections/FeatureIds'].value ==
                    featureIds).all()
            assert (testProject['FeatureSelections/SelectionMatrix'].value ==
                    selectionMatrix).all()

            # Deserialize into a fresh operator
            operatorToLoad = OpFeatureSelection(
                graph=graph, filter_implementation='Original')

            deserializer = FeatureSelectionSerializer(operatorToLoad,
                                                      'FeatureSelections')
            deserializer.deserializeFromHdf5(testProject, testProjectName)
            assert operatorToLoad.FeatureIds.value == getFeatureIdOrder(), \
                "Feature IDs were deserialized to a strange order!"

            assert isinstance(operatorToLoad.Scales.value, list)
            assert isinstance(operatorToLoad.FeatureIds.value, list)

            assert (operatorToLoad.Scales.value == scales)
            assert (operatorToLoad.FeatureIds.value == featureIds)
            assert (
                operatorToLoad.SelectionMatrix.value == selectionMatrix).all()

        os.remove(testProjectName)