Ejemplo n.º 1
0
def test_sheetflow():
    flux = np.array(
        [0.00000000,  0.00000000,  0.00000000,  0.00000000,  0.00000000,
         0.00000000,  0.00000000,  0.00000000,  0.00000000,  0.00000000,
         0.00000000,  0.50000000,  1.35677118,  2.18064899,  2.98289061,
         3.77167837,  4.55070068,  5.32231777,  6.08818915,  6.34956448,
         0.00000000,  0.50000000,  1.64322882,  2.77444053,  3.90022802,
         5.01817926,  6.12943159,  7.23518857,  8.33656075,  8.93446352,
         0.00000000,  0.50000000,  1.50000000,  2.54491048,  3.60279934,
         4.66824237,  5.73835212,  6.81180077,  7.88776947,  8.46568929,
         0.00000000,  0.50000000,  1.50000000,  2.50000000,  3.51408202,
         4.54190001,  5.58151561,  6.63069288,  7.68748063,  8.25028271,
         0.00000000,  0.50000000,  1.50000000,  2.50000000,  3.51408202,
         4.54190001,  5.58151561,  6.63069288,  7.68748063,  8.25028271,
         0.00000000,  0.50000000,  1.50000000,  2.54491048,  3.60279934,
         4.66824237,  5.73835212,  6.81180077,  7.88776947,  8.46568929,
         0.00000000,  0.50000000,  1.64322882,  2.77444053,  3.90022802,
         5.01817926,  6.12943159,  7.23518857,  8.33656075,  8.93446352,
         0.00000000,  0.50000000,  1.35677118,  2.18064899,  2.98289061,
         3.77167837,  4.55070068,  5.32231777,  6.08818915,  6.34956448,
         0.00000000,  0.00000000,  0.00000000,  0.00000000,  0.00000000,
         0.00000000,  0.00000000,  0.00000000,  0.00000000,  0.00000000]
    )

    mg = RasterModelGrid((NROWS, NCOLS), (DX, DX))
    z = (3000. - mg.node_x) * 0.5
    mg.at_node['topographic__elevation'] = z

    mg.set_closed_boundaries_at_grid_edges(False, True, True, True)
    mg.at_node['water__volume_flux_in'] = np.ones_like(z, dtype=float)

    pfr = PotentialityFlowRouter(mg, INPUTS)
    pfr.route_flow(route_on_diagonals=True)

    assert_array_almost_equal(mg.at_node['water__volume_flux_magnitude'], flux)
Ejemplo n.º 2
0
def test_sheetflow():
    flux = np.array([
        0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000,
        0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.50000000,
        1.35677118, 2.18064899, 2.98289061, 3.77167837, 4.55070068, 5.32231777,
        6.08818915, 6.34956448, 0.00000000, 0.50000000, 1.64322882, 2.77444053,
        3.90022802, 5.01817926, 6.12943159, 7.23518857, 8.33656075, 8.93446352,
        0.00000000, 0.50000000, 1.50000000, 2.54491048, 3.60279934, 4.66824237,
        5.73835212, 6.81180077, 7.88776947, 8.46568929, 0.00000000, 0.50000000,
        1.50000000, 2.50000000, 3.51408202, 4.54190001, 5.58151561, 6.63069288,
        7.68748063, 8.25028271, 0.00000000, 0.50000000, 1.50000000, 2.50000000,
        3.51408202, 4.54190001, 5.58151561, 6.63069288, 7.68748063, 8.25028271,
        0.00000000, 0.50000000, 1.50000000, 2.54491048, 3.60279934, 4.66824237,
        5.73835212, 6.81180077, 7.88776947, 8.46568929, 0.00000000, 0.50000000,
        1.64322882, 2.77444053, 3.90022802, 5.01817926, 6.12943159, 7.23518857,
        8.33656075, 8.93446352, 0.00000000, 0.50000000, 1.35677118, 2.18064899,
        2.98289061, 3.77167837, 4.55070068, 5.32231777, 6.08818915, 6.34956448,
        0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000,
        0.00000000, 0.00000000, 0.00000000, 0.00000000
    ])

    mg = RasterModelGrid((NROWS, NCOLS), (DX, DX))
    z = (3000. - mg.node_x) * 0.5
    mg.at_node['topographic__elevation'] = z

    mg.set_closed_boundaries_at_grid_edges(False, True, True, True)
    mg.at_node['water__unit_flux_in'] = np.ones_like(z, dtype=float)

    pfr = PotentialityFlowRouter(mg, INPUTS)
    pfr.route_flow(route_on_diagonals=True)

    assert_array_almost_equal(mg.at_node['water__discharge'], flux)
Ejemplo n.º 3
0
z = (3000.-mg.node_x)*0.5
#z = -mg.node_x-mg.node_y
#z = np.sqrt(mg.node_x**2 + mg.node_y**2)
#z = mg.node_x + mg.node_y
#val_to_replace_with = z.reshape((nrows,ncols))[3,3]
#z.reshape((nrows,ncols))[2:5,:] = val_to_replace_with
mg.at_node['topographic__elevation'] = z

#mg.set_fixed_value_boundaries_at_grid_edges(True, True, True, True)
mg.set_closed_boundaries_at_grid_edges(True, True, True, False)
figure(3)
imshow_node_grid(mg, mg.node_boundary_status)

mg.at_node['water__volume_flux_in'] = np.ones_like(z)

pfr = PotentialityFlowRouter(mg, 'pot_fr_params.txt')

pfr.route_flow(route_on_diagonals=True)

figure(1)
imshow_node_grid(mg, 'water__volume_flux_magnitude')
figure(2)
imshow_node_grid(mg, 'topographic__elevation')

out_sum = np.sum(mg.at_node['water__volume_flux_magnitude'].reshape((nrows,ncols))[-3,:])
print(out_sum)
print(np.sum(mg.at_node['water__volume_flux_in']), np.sum(mg.at_node['water__volume_flux_magnitude'][mg.boundary_nodes]))
print(out_sum - np.sum(mg.at_node['water__volume_flux_in']))

show()
Ejemplo n.º 4
0
def test_in_network():
    # a valley network produced by stream power:
    z = np.array([3.12900830e-04,   3.66462671e-04,   9.44438515e-04,
                  1.45006772e-04,   1.91406099e-04,   4.42053204e-04,
                  2.99818052e-04,   5.45267467e-04,   4.12129514e-04,
                  7.43816953e-04,   1.59251681e-04,   7.39577249e+01,
                  6.68718419e+01,   2.95535987e+01,   7.69715256e+01,
                  4.61083179e+01,   5.70611522e+01,   6.99664564e+01,
                  8.29355817e+01,   5.85563532e-04,   2.60300016e-04,
                  8.99636726e+01,   1.11946320e+02,   5.16553709e+01,
                  1.38432251e+02,   1.02903579e+02,   1.27601424e+02,
                  8.59469601e+01,   4.77495429e+01,   8.00781223e-04,
                  4.13095981e-04,   7.41309307e+01,   1.31747968e+02,
                  1.11724617e+02,   1.71687943e+02,   1.93482716e+02,
                  1.61044205e+02,   1.34775824e+02,   7.63077925e+01,
                  8.85837646e-04,   6.94907676e-04,   5.53654246e+01,
                  9.95405009e+01,   1.81345288e+02,   1.88975196e+02,
                  1.78104180e+02,   1.75231160e+02,   1.14932425e+02,
                  5.12018382e+01,   1.26501797e-04,   8.34527300e-04,
                  8.80562940e+01,   1.24009142e+02,   1.55635807e+02,
                  1.56683637e+02,   1.62398410e+02,   1.04070282e+02,
                  6.99665030e+01,   6.41256897e+01,   5.50951003e-04,
                  2.02545919e-04,   3.05799760e+01,   5.02285119e+01,
                  8.31442034e+01,   1.75898080e+02,   1.80095770e+02,
                  1.23416767e+02,   6.97604901e+01,   3.04864568e+01,
                  4.42047775e-04,   5.75778629e-04,   8.13990441e+01,
                  1.17362500e+02,   1.35317452e+02,   1.78842796e+02,
                  9.65391990e+01,   1.16520146e+02,   1.59289373e+02,
                  8.29784784e+01,   4.21911459e-04,   7.83145812e-04,
                  8.44510235e+01,   6.85512072e+01,   3.99258990e+01,
                  9.07740020e+01,   4.47116751e+01,   1.05333999e+02,
                  1.04965376e+02,   6.42615041e+01,   8.48184002e-04,
                  9.92952214e-04,   5.44805365e-04,   6.83657298e-04,
                  4.27967811e-04,   4.40101095e-04,   5.47248461e-04,
                  5.77178429e-06,   4.39642103e-04,   4.80194778e-04,
                  9.24014550e-04])

    flux = np.array([0.71259316,   1.83684053,   7.98879336,   9.29556058,
                     10.55574138,   7.24717075,   7.35872565,   4.50198345,
                     1.97243029,   0.54929957,   1.71629201,   2.51051881,
                     2.92200909,  17.86860506,   4.15011452,   8.63568651,
                     7.26035354,   4.03993054,   2.05376022,   3.22879774,
                     3.64720173,   2.49610302,   1.96767906,  11.22263014,
                     2.93014856,   5.64199803,   3.24078038,   4.45203171,
                     6.62959451,   4.89790426,   6.37085028,   5.61698632,
                     2.07622910,   5.07309101,   2.93574511,   1.58440439,
                     2.98059775,   2.89536436,   4.32847468,   7.65823581,
                     6.75481149,   8.75145535,   6.37428052,   1.86527306,
                     1.71832016,   2.21381817,   2.14143388,   3.76828344,
                     9.74905731,   7.61218631,  13.23331816,   3.94223434,
                     3.12961197,   3.66940158,   4.73780806,   3.63252392,
                     8.36581084,  10.53572540,   8.04446793,  12.51965897,
                     12.20119563,  26.49337737,  20.10974987,  11.85575877,
                     1.84082688,   1.58440439,   4.20691725,  10.24822185,
                     19.04410064,  10.58826422,  10.25346723,   2.18153267,
                     2.00375244,   2.51941157,   1.65546848,   5.73599744,
                     3.04184663,   1.58440439,   2.47361063,   8.29762758,
                     1.42053367,   1.95945056,   3.39713331,   5.74421869,
                     4.29959761,  11.13098904,   2.56199932,   2.59397940,
                     3.16455917,   1.84587679,   0.57901390,   1.94727188,
                     4.37381176,   5.18582361,   7.70532091,   6.86738229,
                     6.04728286,   2.94714474,   2.00238426,   0.88296519])

    potnt = np.array([0.00000000,    0.00000000,    0.00000000,    0.00000000,
                      0.00000000,    0.00000000,    0.00000000,    0.00000000,
                      0.00000000,    0.00000000,    0.00000000,    3.11607782,
                      4.55006628,   42.19484548,    4.51089463,   17.74767207,
                      11.86792011,    5.93094409,    2.26828834,    0.00000000,
                      0.00000000,    3.44492073,    2.99141368,   86.14598295,
                      3.22150654,   13.04937646,    4.51470410,   10.17131370,
                      14.01678016,    0.00000000,    0.00000000,    8.30460195,
                      2.72370114,   19.70198723,    4.81322624,    2.37203114,
                      4.76156757,    3.84190283,    5.53509620,    0.00000000,
                      0.00000000,   16.37964991,   18.32384346,    2.62626616,
                      3.21546389,    5.36483142,    3.18817287,    5.90189406,
                      18.67655153,    0.00000000,    0.00000000,    4.00510836,
                      3.72650973,    5.71530087,   24.27830939,   10.79812183,
                      29.22832978,   32.48924644,    9.86359775,    0.00000000,
                      0.00000000,   59.87184966,  154.76673703,   74.08035402,
                      3.21059221,    2.38746224,    7.36767179,   45.28386960,
                      44.05471543,    0.00000000,    0.00000000,    3.05098779,
                      2.45849055,    3.12955437,    1.87486166,   25.11244631,
                      6.21239887,    1.64106832,    3.28554137,    0.00000000,
                      0.00000000,    2.36944471,    5.71708702,   13.67642516,
                      4.71435055,   22.42310636,    3.41364647,    3.49569092,
                      4.14217802,    0.00000000,    0.00000000,    0.00000000,
                      0.00000000,    0.00000000,    0.00000000,    0.00000000,
                      0.00000000,    0.00000000,    0.00000000,    0.00000000])

    mg = RasterModelGrid((NROWS, NCOLS), (DX, DX))

    mg.add_field('node', 'topographic__elevation', z)

    mg.at_node['water__volume_flux_in'] = DX * DX * np.ones_like(z) * 100. / (
        60. * 60. * 24. * 365.25)  # remember, flux is /s, so this is a small number!

    pfr = PotentialityFlowRouter(mg, INPUTS)
    pfr.route_flow(return_components=True)

    assert_array_almost_equal(mg.at_node['water__volume_flux_magnitude'], flux)
    assert_array_almost_equal(mg.at_node['potentiality_field'][mg.core_nodes],
                              potnt[mg.core_nodes])
Ejemplo n.º 5
0
def test_in_network():
    # a valley network produced by stream power:
    z = np.array([
        3.12900830e-04, 3.66462671e-04, 9.44438515e-04, 1.45006772e-04,
        1.91406099e-04, 4.42053204e-04, 2.99818052e-04, 5.45267467e-04,
        4.12129514e-04, 7.43816953e-04, 1.59251681e-04, 7.39577249e+01,
        6.68718419e+01, 2.95535987e+01, 7.69715256e+01, 4.61083179e+01,
        5.70611522e+01, 6.99664564e+01, 8.29355817e+01, 5.85563532e-04,
        2.60300016e-04, 8.99636726e+01, 1.11946320e+02, 5.16553709e+01,
        1.38432251e+02, 1.02903579e+02, 1.27601424e+02, 8.59469601e+01,
        4.77495429e+01, 8.00781223e-04, 4.13095981e-04, 7.41309307e+01,
        1.31747968e+02, 1.11724617e+02, 1.71687943e+02, 1.93482716e+02,
        1.61044205e+02, 1.34775824e+02, 7.63077925e+01, 8.85837646e-04,
        6.94907676e-04, 5.53654246e+01, 9.95405009e+01, 1.81345288e+02,
        1.88975196e+02, 1.78104180e+02, 1.75231160e+02, 1.14932425e+02,
        5.12018382e+01, 1.26501797e-04, 8.34527300e-04, 8.80562940e+01,
        1.24009142e+02, 1.55635807e+02, 1.56683637e+02, 1.62398410e+02,
        1.04070282e+02, 6.99665030e+01, 6.41256897e+01, 5.50951003e-04,
        2.02545919e-04, 3.05799760e+01, 5.02285119e+01, 8.31442034e+01,
        1.75898080e+02, 1.80095770e+02, 1.23416767e+02, 6.97604901e+01,
        3.04864568e+01, 4.42047775e-04, 5.75778629e-04, 8.13990441e+01,
        1.17362500e+02, 1.35317452e+02, 1.78842796e+02, 9.65391990e+01,
        1.16520146e+02, 1.59289373e+02, 8.29784784e+01, 4.21911459e-04,
        7.83145812e-04, 8.44510235e+01, 6.85512072e+01, 3.99258990e+01,
        9.07740020e+01, 4.47116751e+01, 1.05333999e+02, 1.04965376e+02,
        6.42615041e+01, 8.48184002e-04, 9.92952214e-04, 5.44805365e-04,
        6.83657298e-04, 4.27967811e-04, 4.40101095e-04, 5.47248461e-04,
        5.77178429e-06, 4.39642103e-04, 4.80194778e-04, 9.24014550e-04
    ])

    flux = np.array([
        0.71259316, 1.83684053, 7.98879336, 9.29556058, 10.55574138,
        7.24717075, 7.35872565, 4.50198345, 1.97243029, 0.54929957, 1.71629201,
        2.51051881, 2.92200909, 17.86860506, 4.15011452, 8.63568651,
        7.26035354, 4.03993054, 2.05376022, 3.22879774, 3.64720173, 2.49610302,
        1.96767906, 11.22263014, 2.93014856, 5.64199803, 3.24078038,
        4.45203171, 6.62959451, 4.89790426, 6.37085028, 5.61698632, 2.07622910,
        5.07309101, 2.93574511, 1.58440439, 2.98059775, 2.89536436, 4.32847468,
        7.65823581, 6.75481149, 8.75145535, 6.37428052, 1.86527306, 1.71832016,
        2.21381817, 2.14143388, 3.76828344, 9.74905731, 7.61218631,
        13.23331816, 3.94223434, 3.12961197, 3.66940158, 4.73780806,
        3.63252392, 8.36581084, 10.53572540, 8.04446793, 12.51965897,
        12.20119563, 26.49337737, 20.10974987, 11.85575877, 1.84082688,
        1.58440439, 4.20691725, 10.24822185, 19.04410064, 10.58826422,
        10.25346723, 2.18153267, 2.00375244, 2.51941157, 1.65546848,
        5.73599744, 3.04184663, 1.58440439, 2.47361063, 8.29762758, 1.42053367,
        1.95945056, 3.39713331, 5.74421869, 4.29959761, 11.13098904,
        2.56199932, 2.59397940, 3.16455917, 1.84587679, 0.57901390, 1.94727188,
        4.37381176, 5.18582361, 7.70532091, 6.86738229, 6.04728286, 2.94714474,
        2.00238426, 0.88296519
    ])

    potnt = np.array([
        0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000,
        0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 3.11607782,
        4.55006628, 42.19484548, 4.51089463, 17.74767207, 11.86792011,
        5.93094409, 2.26828834, 0.00000000, 0.00000000, 3.44492073, 2.99141368,
        86.14598295, 3.22150654, 13.04937646, 4.51470410, 10.17131370,
        14.01678016, 0.00000000, 0.00000000, 8.30460195, 2.72370114,
        19.70198723, 4.81322624, 2.37203114, 4.76156757, 3.84190283,
        5.53509620, 0.00000000, 0.00000000, 16.37964991, 18.32384346,
        2.62626616, 3.21546389, 5.36483142, 3.18817287, 5.90189406,
        18.67655153, 0.00000000, 0.00000000, 4.00510836, 3.72650973,
        5.71530087, 24.27830939, 10.79812183, 29.22832978, 32.48924644,
        9.86359775, 0.00000000, 0.00000000, 59.87184966, 154.76673703,
        74.08035402, 3.21059221, 2.38746224, 7.36767179, 45.28386960,
        44.05471543, 0.00000000, 0.00000000, 3.05098779, 2.45849055,
        3.12955437, 1.87486166, 25.11244631, 6.21239887, 1.64106832,
        3.28554137, 0.00000000, 0.00000000, 2.36944471, 5.71708702,
        13.67642516, 4.71435055, 22.42310636, 3.41364647, 3.49569092,
        4.14217802, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000,
        0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000
    ])

    mg = RasterModelGrid((NROWS, NCOLS), (DX, DX))

    mg.add_field('node', 'topographic__elevation', z)

    mg.at_node['water__unit_flux_in'] = DX * DX * np.ones_like(z) * 100. / (
        60. * 60. * 24. * 365.25
    )  # remember, flux is /s, so this is a small number!

    pfr = PotentialityFlowRouter(mg, INPUTS)
    pfr.route_flow(return_components=True)

    assert_array_almost_equal(mg.at_node['water__discharge'], flux)
    assert_array_almost_equal(mg.at_node['flow__potential'][mg.core_nodes],
                              potnt[mg.core_nodes])
Ejemplo n.º 6
0
mg = RasterModelGrid(nrows, ncols, dx)

# attempt to implement diffusion with flow routing...

#modify the fields in the grid
z = mg.create_node_array_zeros() + init_elev
mg.at_node['topographic__elevation'] = z + np.random.rand(len(z))/1000.
mg.create_node_array_zeros('water__volume_flux_in')

#Set boundary conditions
mg.set_closed_boundaries_at_grid_edges(True, True, True, False)
mg.set_fixed_value_boundaries_at_grid_edges(False, False, False, True)
inlet_node = np.array((mg.number_of_node_columns + 1))
mg.at_node['water__volume_flux_in'].fill(0.)
mg.at_node['water__volume_flux_in'][inlet_node] = 1.
pfr = PotentialityFlowRouter(mg, 'pot_fr_params.txt')

interior_nodes = mg.core_nodes

# do the loop
for i in xrange(2000):
    if i%50==0:
        print('loop '+str(i))
    mg.at_node['topographic__elevation'][inlet_node] = 1.
    pfr.route_flow(route_on_diagonals=True)
    #imshow(mg, 'water__volume_flux_magnitude')
    #show()
    kd = mg.at_node['water__volume_flux_magnitude']   # 0.01 m2 per year
    # dt = np.nanmin(0.2*mg.dx*mg.dx/kd)   # CFL condition
    dt = 0.5
    g = mg.calculate_gradients_at_active_links(mg.at_node['topographic__elevation'])