Exemplo 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., 9.317, 18.6339, 27.9509])
    assert np.allclose(res, exp, atol=1e-04)
Exemplo 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., 0.1616, 0.3231, 0.4847])
    assert np.allclose(res, exp, atol=1e-04)
Exemplo 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)
Exemplo n.º 4
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)
Exemplo n.º 5
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()
Exemplo n.º 6
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)
Exemplo n.º 7
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
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
def test_node_number():
    res = Grid.SmallTestGrid().node_number(lat_node=14., lon_node=9.)
    exp = 3
    assert res == exp
Exemplo n.º 11
0
def test_node_coordinates():
    res = Grid.SmallTestGrid().node_coordinates(3)
    exp = (15.0, 10.0)
    assert np.allclose(res, exp, atol=1e-04)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
0
def test_grid_size():
    res = Grid.SmallTestGrid().print_grid_size()
    exp = '     space    time\n         6      10'
    assert res == exp
Exemplo n.º 16
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
Exemplo 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)
Exemplo n.º 18
0
def test_node_number():
    res = Grid.SmallTestGrid().node_number(x=(14., 9.))
    exp = 3
    assert res == exp