Ejemplo n.º 1
0
def test_geometric_distance_distribution():
    res = Grid.SmallTestGrid().geometric_distance_distribution(3)[0]
    exp = np.array([0.3333, 0.4667, 0.2])
    assert np.allclose(res, exp, atol=1e-04)

    res = Grid.SmallTestGrid().geometric_distance_distribution(3)[1]
    exp = np.array([0., 0.1616, 0.3231, 0.4847])
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 2
0
def test_geometric_distance_distribution():
    res = Grid.SmallTestGrid().geometric_distance_distribution(3)[0]
    exp = np.array([0.3333, 0.4667, 0.2])
    assert np.allclose(res, exp, atol=1e-04)

    res = Grid.SmallTestGrid().geometric_distance_distribution(3)[1]
    exp = np.array([0., 9.317, 18.6339, 27.9509])
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 3
0
def test_grid():
    res = Grid.SmallTestGrid().grid()["lat"]
    exp = np.array([0., 5., 10., 15., 20., 25.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)

    res = Grid.SmallTestGrid().grid()["lon"]
    exp = np.array([2.5, 5., 7.5, 10., 12.5, 15.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 4
0
def test_RegularGrid():
    res = Grid.RegularGrid(time_seq=np.arange(2),
                           space_grid=np.array([[0., 5.], [1., 2.]]),
                           silence_level=2).sequence(0)
    exp = np.array([0., 0., 5., 5.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)

    res = Grid.RegularGrid(time_seq=np.arange(2),
                           space_grid=np.array([[0., 5.], [1., 2.]]),
                           silence_level=2).sequence(1)
    exp = np.array([1., 2., 1., 2.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 5
0
def test_angular_distance():
    res = Grid.SmallTestGrid().angular_distance().round(2)
    exp = np.array(
        [[0., 0.1, 0.19, 0.29, 0.39, 0.48], [0.1, 0., 0.1, 0.19, 0.29, 0.39],
         [0.19, 0.1, 0., 0.1, 0.19, 0.29], [0.29, 0.19, 0.1, 0., 0.1, 0.19],
         [0.39, 0.29, 0.19, 0.1, 0., 0.1], [0.48, 0.39, 0.29, 0.19, 0.1, 0.]],
        dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 6
0
def test_euclidean_distance():
    res = Grid.SmallTestGrid().euclidean_distance().round(2)
    exp = np.array([[0., 5.59, 11.18, 16.77, 22.36, 27.95],
                    [5.59, 0., 5.59, 11.18, 16.77, 22.36],
                    [11.18, 5.59, 0., 5.59, 11.18, 16.77],
                    [16.77, 11.18, 5.59, 0., 5.59, 11.18],
                    [22.36, 16.77, 11.18, 5.59, 0., 5.59],
                    [27.95, 22.36, 16.77, 11.18, 5.59, 0.]], dtype=np.float32)
    assert (res == exp).all()
Ejemplo n.º 7
0
def test_ConfigurationModel():
    n = 0
    while n != 7:
        net = GeoNetwork.ConfigurationModel(
            grid=Grid.SmallTestGrid(),
            degrees=GeoNetwork.SmallTestNetwork().degree(),
            silence_level=2)
        n = net.n_links
    res = net.link_density
    exp = 0.46666667
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 8
0
def test_ErdosRenyi(capsys):
    print(
        GeoNetwork.ErdosRenyi(grid=Grid.SmallTestGrid(), n_nodes=6, n_links=5))
    out, err = capsys.readouterr()
    out_ref = "Generating Erdos-Renyi random graph with 6 nodes and 5 " + \
              "links...\nSetting area weights according to type surface " + \
              "...\nGeoNetwork:\n" + \
              "Network: undirected, 6 nodes, 5 links, " + \
              "link density 0.333.\nGeographical boundaries:\n" + \
              "         time     lat     lon\n" + \
              "   min    0.0    0.00    2.50\n" + \
              "   max    9.0   25.00   15.00\n"
    assert out == out_ref
Ejemplo n.º 9
0
def test_coord_sequence_from_rect_grid():
    res = Grid.coord_sequence_from_rect_grid(lat_grid=np.array([0., 5.]),
                                             lon_grid=np.array([1., 2.]))
    exp = (np.array([0., 0., 5., 5.]), np.array([1., 2., 1., 2.]))
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 10
0
from pyunicorn.core.grid import Grid
"""
This example code offers an overview of the spatial network code for GeoModel1 
and GeoModel2 can be called. Furthermore, with the python versions GeoModel1_py
and GeoModel2_py further analysis can be done, to visualize the working of the
network operations. 

"""

# Create Random Grids
rect_grid_num = 20  # For larger network sizes this might take a while to compute!

grid = Grid.RegularGrid(time_seq=np.arange(2),
                        lat_grid=np.random.randint(low=0,
                                                   high=40,
                                                   size=rect_grid_num),
                        lon_grid=np.random.randint(low=0,
                                                   high=40,
                                                   size=rect_grid_num))

erdos_renyi = sp.SpatialNetwork.ErdosRenyi(grid=grid,
                                           n_nodes=int(rect_grid_num**2),
                                           link_probability=0.1)
geo_model = sp.SpatialNetwork(grid=erdos_renyi.grid,
                              adjacency=erdos_renyi.adjacency)

# Apply geoModel code
new_link_list = geo_model.GeoModel1(n_steps=int(5e4),
                                    tolerance=1,
                                    grid_type='euclidean',
                                    verbose=False)
Ejemplo n.º 11
0
def test_cos_lon():
    res = Grid.SmallTestGrid().cos_lon()[:2]
    exp = np.array([0.999, 0.9962])
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 12
0
def test_sin_lon():
    res = Grid.SmallTestGrid().sin_lon()[:2]
    exp = np.array([0.0436, 0.0872])
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 13
0
def test_node_coordinates():
    res = Grid.SmallTestGrid().node_coordinates(3)
    exp = (15.0, 10.0)
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 14
0
def test_node_number():
    res = Grid.SmallTestGrid().node_number(lat_node=14., lon_node=9.)
    exp = 3
    assert res == exp
Ejemplo n.º 15
0
def test_lon_sequence():
    res = Grid.SmallTestGrid().lon_sequence()
    exp = np.array([2.5, 5., 7.5, 10., 12.5, 15.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 16
0
def test_convert_lon_coordinates():
    res = Grid.SmallTestGrid().convert_lon_coordinates(
        np.array([10., 350., 20., 340., 170., 190.]))
    exp = np.array([10., -10., 20., -20., 170., -170.])
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 17
0
def test_lat_sequence():
    res = Grid.SmallTestGrid().lat_sequence()
    exp = np.array([0., 5., 10., 15., 20., 25.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 18
0
def test_node_number():
    res = Grid.SmallTestGrid().node_number(x=(14., 9.))
    exp = 3
    assert res == exp
Ejemplo n.º 19
0
def test_region_indices():
    res = Grid.SmallTestGrid().region_indices(
        np.array([0., 0., 0., 11., 11., 11., 11., 0.])).astype(int)
    exp = np.array([0, 1, 1, 0, 0, 0])
    assert np.allclose(res, exp, atol=1e-04)
Ejemplo n.º 20
0
def test_boundaries():
    res = Grid.SmallTestGrid().print_boundaries()
    exp = "         time     lat     lon\n   min    0.0    0.00    2.50\n" + \
          "   max    9.0   25.00   15.00"
    assert res == exp
Ejemplo n.º 21
0
def test_grid_size():
    res = Grid.SmallTestGrid().print_grid_size()
    exp = '     space    time\n         6      10'
    assert res == exp