def test_network_skimming(self):
        # graph
        g = Graph()
        g.load_from_disk(test_graph)
        g.set_graph(cost_field="distance", skim_fields=None)
        # None implies that only the cost field will be skimmed

        # skimming results
        res = SkimResults()
        res.prepare(g)

        aux_res = MultiThreadedNetworkSkimming()
        aux_res.prepare(g, res)
        _ = skimming_single_origin(26, g, res, aux_res, 0)

        skm = NetworkSkimming(g, res)
        skm.execute()

        tot = np.nanmax(res.skims.distance[:, :])

        if tot > 10e10:
            self.fail(
                "Skimming was not successful. At least one np.inf returned.")

        if skm.report:
            self.fail("Skimming returned an error:" + str(skm.report))
    def test_network_skimming(self):
        # graph
        g = Graph()
        g.load_from_disk(test_graph)
        g.set_graph(cost_field='distance', skim_fields=None)
        # None implies that only the cost field will be skimmed

        # skimming results
        res = SkimResults()
        res.prepare(g)

        aux_res = MultiThreadedNetworkSkimming()
        aux_res.prepare(g, res)
        a = skimming_single_origin(26, g, res, aux_res, 0)

        skm = NetworkSkimming(g, res)
        skm.execute()

        tot = np.nanmax(res.skims.distance[:, :])

        if tot > 10e10:
            self.fail('Skimming was not successful. At least one np.inf returned.')

        if skm.report:
            self.fail('Skimming returned an error:' + str(skm.report))
    def test_skimming_single_origin(self):

        g = Graph()
        g.load_from_disk(test_graph)
        g.set_graph(cost_field="distance")
        g.set_skimming("distance")

        origin = np.random.choice(g.centroids[:-1], 1)[0]

        # skimming results
        res = SkimResults()
        res.prepare(g)
        aux_result = MultiThreadedNetworkSkimming()
        aux_result.prepare(g, res)

        a = skimming_single_origin(origin, g, res, aux_result, 0)
        tot = np.sum(res.skims.distance[origin, :])
        if tot > 10e10:
            self.fail(
                "Skimming was not successful. At least one np.inf returned for origin {}."
                .format(origin))

        if a != origin:
            self.fail("Skimming returned an error: {} for origin {}".format(
                a, origin))
    def test_skimming_single_origin(self):

        origin = 1

        # graph
        g = Graph()
        g.load_from_disk(test_graph)
        g.set_graph(cost_field="distance", skim_fields=None)
        # g.block_centroid_flows = False
        # None implies that only the cost field will be skimmed

        # skimming results
        res = SkimResults()
        res.prepare(g)
        aux_result = MultiThreadedNetworkSkimming()
        aux_result.prepare(g, res)

        a = skimming_single_origin(origin, g, res, aux_result, 0)
        tot = np.sum(res.skims.distance[origin, :])
        if tot > 10e10:
            self.fail(
                "Skimming was not successful. At least one np.inf returned.")

        if a != origin:
            self.fail("Skimming returned an error: " + a)
    def test_network_skimming(self):

        self.network.build_graphs()
        graph = self.network.graphs['c']
        graph.set_graph(cost_field="distance")
        graph.set_skimming("distance")
        graph.set_blocked_centroid_flows(False)

        # skimming results
        res = SkimResults()
        res.prepare(graph)
        aux_res = MultiThreadedNetworkSkimming()
        aux_res.prepare(graph, res)
        _ = skimming_single_origin(12, graph, res, aux_res, 0)

        skm = NetworkSkimming(graph)
        skm.execute()

        tot = np.nanmax(skm.results.skims.distance[:, :])
        if tot > np.sum(graph.cost):
            self.fail(
                "Skimming was not successful. At least one np.inf returned.")

        if skm.report:
            self.fail("Skimming returned an error:" + str(skm.report))

        skm.save_to_project('tEst_Skimming')

        if not os.path.isfile(
                os.path.join(self.proj_dir, 'matrices', 'test_skimming.omx')):
            self.fail('Did not save project to project')

        matrices = self.project.matrices
        mat = matrices.get_record('TEsT_Skimming')
        self.assertEqual(mat.name, 'tEst_Skimming',
                         'Matrix record name saved wrong')
        self.assertEqual(mat.file_name, 'tEst_Skimming.omx',
                         'matrix file_name saved  wrong')
        self.assertEqual(mat.cores, 1,
                         'matrix saved number of matrix cores wrong')
        self.assertEqual(mat.procedure, 'Network skimming',
                         'Matrix saved wrong procedure name')
        self.assertEqual(mat.procedure_id, skm.procedure_id,
                         'Procedure ID saved  wrong')
        self.assertEqual(mat.timestamp, skm.procedure_date,
                         'Procedure ID saved  wrong')