Esempio n. 1
0
    def test_debug(self):
        """
        Test the debugging output of the CT
        """
        self.setup()
        test_file = "ct_test_debug.txt"
        sys.stdout = open(test_file, "w")

        self.ct = topopy.ContourTree(debug=True,
                                     short_circuit=True,
                                     graph=self.graph)
        self.ct.build(self.X, self.Y)

        self.ct = topopy.ContourTree(debug=True,
                                     short_circuit=False,
                                     graph=self.graph)
        self.ct.build(self.X, self.Y)

        sys.stdout.close()

        lines = [
            "Graph Preparation:",
            "Split Tree Computation:",
            "Join Tree Computation:",
            "Networkx Tree construction:",
            "Networkx Tree construction:",
            "Processing Tree:",
            "Processing Tree:",
            "Identifying branches:",
            "Condensing Graph: ",
            "Sorting Nodes:",
            "Graph Preparation:",
            "Split Tree Computation:",
            "Join Tree Computation:",
            "Networkx Tree construction:",
            "Networkx Tree construction:",
            "Processing Tree:",
            "Processing Tree:",
            "Identifying branches:",
            "Condensing Graph:",
            "Sorting Nodes:",
        ]

        with open(test_file, "r") as fp:
            debug_output = fp.read()
            for line in lines:
                self.assertIn(line, debug_output)

        os.remove(test_file)
        # Restore stdout
        sys.stdout = sys.__stdout__
Esempio n. 2
0
    def setup(self):
        """
        Setup function will create a fixed point set and parameter
        settings for testing different aspects of this library.
        """
        self.X = generate_test_grid_2d(40)
        self.Y = gerber(self.X)

        self.norm_x = {}
        scaler = sklearn.preprocessing.MinMaxScaler()
        self.norm_x["feature"] = scaler.fit_transform(np.atleast_2d(self.X))
        self.norm_x["zscore"] = sklearn.preprocessing.scale(self.X,
                                                            axis=0,
                                                            with_mean=True,
                                                            with_std=True,
                                                            copy=True)
        self.norm_x["none"] = self.X

        # Methods covered here:
        # __init__
        # build
        # __set_data
        self.graph = ngl.EmptyRegionGraph(max_neighbors=10)
        self.ct = topopy.ContourTree(graph=self.graph, debug=False)
        self.ct.build(self.X, self.Y)
Esempio n. 3
0
    def test_no_short_circuit(self):
        """
        Test the build process of the ContourTree
        """
        self.setup()
        self.ct = topopy.ContourTree(graph=self.graph, short_circuit=False)
        self.ct.build(self.X, self.Y)

        self.assertEqual(
            71,
            len(self.ct.superNodes),
            "The 2D Gerber test function should have 71 " +
            "nodes in its contour tree.",
        )
        self.assertEqual(
            70,
            len(self.ct.superArcs),
            "The 2D Gerber test function should have 70 " +
            "arcs in its contour tree.",
        )