Пример #1
0
def test_graph_is_frozen():
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK, sort=True)

    assert_array_equal(
        graph.nodes_at_link, [[0, 1], [1, 2], [0, 3], [1, 4], [2, 5], [3, 4], [4, 5]]
    )

    with pytest.raises(ValueError):
        graph.nodes_at_link[0] = [1, 0]
Пример #2
0
def test_graph_can_thaw():
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK, sort=True)

    assert_array_equal(
        graph.nodes_at_link, [[0, 1], [1, 2], [0, 3], [1, 4], [2, 5], [3, 4], [4, 5]]
    )

    with graph.thawed():
        graph.nodes_at_link[0] = [1, 0]
    assert_array_equal(
        graph.nodes_at_link, [[1, 0], [1, 2], [0, 3], [1, 4], [2, 5], [3, 4], [4, 5]]
    )
Пример #3
0
def test_nodes_at_patch_ccw():
    """Test nodes at patch with rotational sorting."""
    graph = Graph((NODE_Y, NODE_X),
                  links=NODES_AT_LINK,
                  patches=LINKS_AT_PATCH)

    assert_array_equal(graph.nodes_at_patch, [[4, 3, 0, 1], [5, 4, 1, 2]])
Пример #4
0
def test_links_at_patch_ccw():
    """Test links at patch with rotational sorting."""
    graph = Graph((NODE_Y, NODE_X),
                  links=NODES_AT_LINK,
                  patches=LINKS_AT_PATCH)

    assert_array_equal(graph.links_at_patch, [[3, 5, 2, 0], [4, 6, 3, 1]])
Пример #5
0
def test_graph_link_dirs_at_node():
    """Test links directions at nodes without rotational sorting."""
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK)

    assert_array_equal(graph.link_dirs_at_node,
                       [[-1, -1, 0], [-1, -1, 1], [-1, 1, 0], [-1, 1, 0],
                        [-1, 1, 1], [1, 1, 0]])
Пример #6
0
def test_graph_links_at_node():
    """Test links at nodes without rotational sorting."""
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK)

    assert_array_equal(
        graph.links_at_node,
        [[0, 2, -1], [1, 3, 0], [4, 1, -1], [5, 2, -1], [6, 5, 3], [6, 4, -1]])
Пример #7
0
    def write_output(self):
        """Write output to file as a netCDF.

        Filenames will have the value of ``"output_filename"`` from the
        input file or parameter dictionary as the first part of the file
        name and the model run iteration as the second part of the
        filename.
        """
        self.calculate_cumulative_change()
        filename = self._out_file_name + str(self.iteration).zfill(4) + ".nc"
        self._output_files.append(filename)
        try:
            write_raster_netcdf(filename,
                                self.grid,
                                names=self.output_fields,
                                format="NETCDF4")
        except NotImplementedError:
            graph = Graph.from_dict({
                "y_of_node": self.grid.y_of_node,
                "x_of_node": self.grid.x_of_node,
                "nodes_at_link": self.grid.nodes_at_link,
            })

            for field_name in self.output_fields:

                graph._ds.__setitem__(field_name,
                                      ("node", self.grid.at_node[field_name]))

            graph.to_netcdf(path=filename, mode="w", format="NETCDF4")

        self.run_output_writers()
Пример #8
0
def test_create_graph_with_links():
    """Create a graph of connected nodes."""
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK)

    assert_array_almost_equal(graph.x_of_node, [0., 1., 2., 0., 1., 2.])
    assert_array_almost_equal(graph.y_of_node, [0., 0., 0., 1., 1., 1.])
    assert_array_almost_equal(
        graph.nodes_at_link,
        [[0, 1], [1, 2], [0, 3], [1, 4], [2, 5], [3, 4], [4, 5]])
Пример #9
0
def test_graph_link_tails():
    """Test nodes at link tails."""
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK)

    assert_array_equal(graph.node_at_link_tail, [0, 1, 0, 1, 2, 3, 4])
Пример #10
0
def test_graph_link_heads():
    """Test nodes at link heads."""
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK)

    assert_array_equal(graph.node_at_link_head, [1, 2, 3, 4, 5, 4, 5])
Пример #11
0
def test_create_graph_with_nodes():
    """Create a graph of unconnected nodes."""
    graph = Graph((NODE_Y, NODE_X))

    assert_array_almost_equal(graph.x_of_node, [0., 1., 2., 0., 1., 2.])
    assert_array_almost_equal(graph.y_of_node, [0., 0., 0., 1., 1., 1.])
Пример #12
0
def test_graph_nodes_property():
    graph = Graph((NODE_Y, NODE_X), links=NODES_AT_LINK, sort=True)
    assert_array_equal(graph.nodes, [0, 1, 2, 3, 4, 5])
    with pytest.raises(ValueError):
        graph.nodes[0] = 99
Пример #13
0
def test_create_graph_with_nodes():
    """Create a graph of unconnected nodes."""
    graph = Graph((NODE_Y, NODE_X), sort=True)

    assert_array_almost_equal(graph.x_of_node, [0.0, 1.0, 2.0, 0.0, 1.0, 2.0])
    assert_array_almost_equal(graph.y_of_node, [0.0, 0.0, 0.0, 1.0, 1.0, 1.0])