示例#1
0
def test_geometric_distance_distribution():
    res = GeoGrid.SmallTestGrid().geometric_distance_distribution(3)[0]
    exp = np.array([0.3333, 0.4667, 0.2])
    assert np.allclose(res, exp, atol=1e-04)

    res = GeoGrid.SmallTestGrid().geometric_distance_distribution(3)[1]
    exp = np.array([0., 0.1616, 0.3231, 0.4847])
    assert np.allclose(res, exp, atol=1e-04)
示例#2
0
def test_RegularGrid():
    res = GeoGrid.RegularGrid(time_seq=np.arange(2),
                              lat_grid=np.array([0., 5.]),
                              lon_grid=np.array([1., 2.]),
                              silence_level=2).lat_sequence()
    exp = np.array([0., 0., 5., 5.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)

    res = GeoGrid.RegularGrid(time_seq=np.arange(2),
                              lat_grid=np.array([0., 5.]),
                              lon_grid=np.array([1., 2.]),
                              silence_level=2).lon_sequence()
    exp = np.array([1., 2., 1., 2.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)
示例#3
0
def test_angular_distance():
    res = GeoGrid.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)
示例#4
0
def test_ConfigurationModel():
    n = 0
    while n != 7:
        net = GeoNetwork.Model("Configuration",
                               grid=GeoGrid.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)
示例#5
0
def test_ErdosRenyi(capsys):
    print(
        GeoNetwork.Model("ErdosRenyi",
                         grid=GeoGrid.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:\nSpatialNetwork:\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
示例#6
0
def test_sin_lon():
    res = GeoGrid.SmallTestGrid().sin_lon()[:2]
    exp = np.array([0.0436, 0.0872])
    assert np.allclose(res, exp, atol=1e-04)
示例#7
0
def test_cos_lon():
    res = GeoGrid.SmallTestGrid().cos_lon()[:2]
    exp = np.array([0.999, 0.9962])
    assert np.allclose(res, exp, atol=1e-04)
示例#8
0
def test_node_number2d():
    res = GeoGrid.SmallTestGrid().node_number(lat_node=14., lon_node=9.)
    exp = 3
    assert res == exp
示例#9
0
def test_convert_lon_coordinates():
    res = GeoGrid.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)
示例#10
0
def test_lon_sequence():
    res = GeoGrid.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)
示例#11
0
def test_lat_sequence():
    res = GeoGrid.SmallTestGrid().lat_sequence()
    exp = np.array([0., 5., 10., 15., 20., 25.], dtype=np.float32)
    assert np.allclose(res, exp, atol=1e-04)
示例#12
0
def test_coord_sequence_from_rect_grid():
    res = GeoGrid.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)
示例#13
0
def test_region_indices():
    res = GeoGrid.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)
示例#14
0
def test_boundaries():
    res = GeoGrid.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