Example #1
0
def test_storms():
    input_file_string = os.path.join(_THIS_DIR, 'drive_sp_params_storms.txt')
    inputs = ModelParameterDictionary(input_file_string)
    nrows = inputs.read_int('nrows')
    ncols = inputs.read_int('ncols')
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')
    time_to_run = inputs.read_float('run_time')
    uplift = inputs.read_float('uplift_rate')

    mg = RasterModelGrid(nrows, ncols, dx)

    mg.add_zeros('topographic__elevation', at='node')
    z = mg.zeros(at='node')
    mg['node']['topographic__elevation'] = z + np.random.rand(len(z)) / 1000.
    mg.add_zeros('water__volume_flux_in', at='node')

    precip = PrecipitationDistribution(input_file=input_file_string)
    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_file_string)

    for (interval_duration, rainfall_rate) in \
            precip.yield_storm_interstorm_duration_intensity():
        if rainfall_rate != 0.:
            mg.at_node['water__volume_flux_in'].fill(rainfall_rate)
            mg = fr.route_flow()
            sp.erode(mg, dt=interval_duration, Q_if_used='water__volume_flux')
        mg.at_node['topographic__elevation'][
            mg.core_nodes] += uplift * interval_duration
Example #2
0
def test_sp_voronoi():
    nnodes = 100

    np.random.seed(0)
    x = np.random.rand(nnodes)
    np.random.seed(1)
    y = np.random.rand(nnodes)
    mg = VoronoiDelaunayGrid(x, y)

    np.random.seed(2)
    z = mg.add_field('node', 'topographic__elevation',
                     np.random.rand(nnodes) / 10000., copy=False)

    fr = FlowRouter(mg)
    spe = StreamPowerEroder(mg, os.path.join(_THIS_DIR,
                                             'drive_sp_params_voronoi.txt'))

    for i in range(10):
        z[mg.core_nodes] += 0.01
        fr.route_flow()
        spe.erode(mg, 1.)

    z_tg = np.array([4.35994902e-05,   2.59262318e-06,   5.49662478e-05,
                     4.36094902e-05,   4.20367802e-05,   2.16664196e-03,
                     1.23484520e-02,   4.07654109e-02,   5.69974645e-02,
                     4.71086393e-02,   5.55056467e-02,   5.53655860e-02,
                     4.87984556e-02,   6.62132007e-02,   7.33132951e-02,
                     6.10003971e-02,   8.53975293e-05,   4.90709812e-02,
                     7.84728490e-02,   8.26091298e-02,   5.05246090e-05,
                     3.69289510e-02,   7.56743264e-02,   2.52850671e-02,
                     6.80517443e-02,   5.96745309e-05,   3.86335644e-02,
                     4.12526935e-02,   7.78476139e-02,   7.18165632e-02,
                     7.62359762e-02,   6.65702961e-02,   9.04684278e-02,
                     7.37203974e-02,   9.16862054e-02,   4.11168411e-02,
                     4.36498947e-02,   9.04430763e-02,   1.42123575e-02,
                     8.02734138e-02,   8.34895711e-02,   4.51564589e-02,
                     6.47124169e-02,   9.52317640e-02,   6.01917122e-05,
                     7.11667309e-02,   8.00463179e-02,   9.40668605e-02,
                     9.33247720e-02,   7.34011920e-02,   7.30924467e-02,
                     6.21387674e-02,   9.66278589e-02,   8.64266637e-02,
                     9.06100497e-02,   7.19991365e-02,   1.07162442e-02,
                     8.68685360e-02,   7.40515066e-02,   2.73264483e-02,
                     9.55406046e-02,   6.01817121e-05,   3.28663723e-02,
                     8.60706344e-02,   9.56285286e-02,   4.24741937e-02,
                     5.64139004e-03,   8.72373392e-02,   9.04304841e-02,
                     8.83708170e-02,   5.04000439e-05,   6.47845229e-02,
                     8.77304766e-02,   4.40894724e-02,   8.08029139e-02,
                     4.52732792e-02,   6.35806712e-02,   6.71004941e-02,
                     7.32682350e-02,   4.88067087e-02,   2.14920377e-02,
                     2.55509418e-06,   8.25346959e-02,   8.12610977e-02,
                     3.75778123e-02,   2.20818912e-02,   2.45940192e-02,
                     4.43365163e-02,   4.93255141e-02,   6.23517572e-02,
                     5.99594648e-02,   4.17977098e-06,   4.96450779e-02,
                     3.72952724e-02,   2.26332108e-03,   1.69925430e-02,
                     1.99835635e-02,   6.61481327e-05,   1.70477133e-05,
                     8.81652236e-05]  )

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Example #3
0
def test_sp_voronoi():
    nnodes = 100

    np.random.seed(0)
    x = np.random.rand(nnodes)
    np.random.seed(1)
    y = np.random.rand(nnodes)
    mg = VoronoiDelaunayGrid(x, y)

    np.random.seed(2)
    z = mg.add_field('node', 'topographic__elevation',
                     np.random.rand(nnodes) / 10000., copy=False)

    fr = FlowRouter(mg)
    spe = StreamPowerEroder(mg, os.path.join(_THIS_DIR,
                                             'drive_sp_params_voronoi.txt'))

    for i in range(10):
        z[mg.core_nodes] += 0.01
        fr.route_flow()
        spe.erode(mg, 1.)

    z_tg = np.array([4.35994902e-05,   2.59262318e-06,   5.49662478e-05,
                     6.56738615e-03,   4.20367802e-05,   1.21371424e-02,
                     2.16596169e-02,   4.73320898e-02,   6.00389761e-02,
                     5.22007356e-02,   5.37507115e-02,   5.95794752e-02,
                     5.29862904e-02,   6.76465914e-02,   7.31720024e-02,
                     6.18730861e-02,   8.53975293e-05,   5.32189275e-02,
                     7.34302556e-02,   8.07385044e-02,   5.05246090e-05,
                     4.08940657e-02,   7.39971005e-02,   3.31915602e-02,
                     6.72650419e-02,   5.96745309e-05,   4.72752445e-02,
                     3.60359567e-02,   7.59432065e-02,   7.24461985e-02,
                     7.80305760e-02,   4.93866869e-02,   8.69642467e-02,
                     7.21627626e-02,   8.96368291e-02,   4.65142080e-02,
                     6.07720217e-02,   8.83372939e-02,   2.35887558e-02,
                     7.97616193e-02,   8.35615355e-02,   4.61809032e-02,
                     6.34634214e-02,   9.25711770e-02,   4.11717225e-03,
                     7.24493623e-02,   7.97908053e-02,   9.10375623e-02,
                     9.13155023e-02,   7.10567915e-02,   7.35271752e-02,
                     6.13091341e-02,   9.45498463e-02,   8.48532386e-02,
                     8.82702021e-02,   7.14969941e-02,   2.22640943e-02,
                     8.53311932e-02,   7.49161159e-02,   3.48837223e-02,
                     9.30132692e-02,   6.01817121e-05,   3.87455443e-02,
                     8.44673586e-02,   9.35213577e-02,   6.76075824e-02,
                     1.58614508e-02,   8.51346837e-02,   8.83645680e-02,
                     8.69944117e-02,   5.04000439e-05,   5.02319084e-02,
                     8.63882765e-02,   5.00991880e-02,   7.65156630e-02,
                     5.07591983e-02,   6.54909962e-02,   6.91505342e-02,
                     7.33358371e-02,   5.30109890e-02,   2.99074601e-02,
                     2.55509418e-06,   8.21523907e-02,   8.09368483e-02,
                     4.35073025e-02,   3.04096109e-02,   3.26298627e-02,
                     4.92259177e-02,   5.48690358e-02,   6.44732130e-02,
                     6.28133567e-02,   4.17977098e-06,   5.37149677e-02,
                     4.32828136e-02,   1.30559903e-02,   2.62405261e-02,
                     2.86079272e-02,   6.61481327e-05,   1.70477133e-05,
                     8.81652236e-05])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Example #4
0
def test_sp_voronoi():
    nnodes = 100

    np.random.seed(0)
    x = np.random.rand(nnodes)
    np.random.seed(1)
    y = np.random.rand(nnodes)
    mg = VoronoiDelaunayGrid(x, y)

    np.random.seed(2)
    z = mg.add_field('node',
                     'topographic__elevation',
                     np.random.rand(nnodes) / 10000.,
                     copy=False)

    fr = FlowRouter(mg)
    spe = StreamPowerEroder(
        mg, os.path.join(_THIS_DIR, 'drive_sp_params_voronoi.txt'))

    for i in range(10):
        z[mg.core_nodes] += 0.01
        fr.route_flow()
        spe.erode(mg, 1.)

    z_tg = np.array([
        4.35994902e-05, 2.59262318e-06, 5.49662478e-05, 4.36094902e-05,
        4.20367802e-05, 2.16664196e-03, 1.23484520e-02, 4.07654109e-02,
        5.69974645e-02, 4.71086393e-02, 5.55056467e-02, 5.53655860e-02,
        4.87984556e-02, 6.62132007e-02, 7.33132951e-02, 6.10003971e-02,
        8.53975293e-05, 4.90709812e-02, 7.84728490e-02, 8.26091298e-02,
        5.05246090e-05, 3.69289510e-02, 7.56743264e-02, 2.52850671e-02,
        6.80517443e-02, 5.96745309e-05, 3.86335644e-02, 4.12526935e-02,
        7.78476139e-02, 7.18165632e-02, 7.62359762e-02, 6.65702961e-02,
        9.04684278e-02, 7.37203974e-02, 9.16862054e-02, 4.11168411e-02,
        4.36498947e-02, 9.04430763e-02, 1.42123575e-02, 8.02734138e-02,
        8.34895711e-02, 4.51564589e-02, 6.47124169e-02, 9.52317640e-02,
        6.01917122e-05, 7.11667309e-02, 8.00463179e-02, 9.40668605e-02,
        9.33247720e-02, 7.34011920e-02, 7.30924467e-02, 6.21387674e-02,
        9.66278589e-02, 8.64266637e-02, 9.06100497e-02, 7.19991365e-02,
        1.07162442e-02, 8.68685360e-02, 7.40515066e-02, 2.73264483e-02,
        9.55406046e-02, 6.01817121e-05, 3.28663723e-02, 8.60706344e-02,
        9.56285286e-02, 4.24741937e-02, 5.64139004e-03, 8.72373392e-02,
        9.04304841e-02, 8.83708170e-02, 5.04000439e-05, 6.47845229e-02,
        8.77304766e-02, 4.40894724e-02, 8.08029139e-02, 4.52732792e-02,
        6.35806712e-02, 6.71004941e-02, 7.32682350e-02, 4.88067087e-02,
        2.14920377e-02, 2.55509418e-06, 8.25346959e-02, 8.12610977e-02,
        3.75778123e-02, 2.20818912e-02, 2.45940192e-02, 4.43365163e-02,
        4.93255141e-02, 6.23517572e-02, 5.99594648e-02, 4.17977098e-06,
        4.96450779e-02, 3.72952724e-02, 2.26332108e-03, 1.69925430e-02,
        1.99835635e-02, 6.61481327e-05, 1.70477133e-05, 8.81652236e-05
    ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Example #5
0
def test_sp_old():
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str)
    nrows = inputs.read_int('nrows')
    ncols = inputs.read_int('ncols')
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')
    time_to_run = inputs.read_float('run_time')
    uplift = inputs.read_float('uplift_rate')
    init_elev = inputs.read_float('init_elev')

    mg = RasterModelGrid((nrows, ncols), spacing=(dx, dx))
    mg.set_closed_boundaries_at_grid_edges(False, False, True, True)

    mg.add_zeros('topographic__elevation', at='node')
    z = mg.zeros(at='node') + init_elev
    numpy.random.seed(0)
    mg['node']['topographic__elevation'] = z + \
        numpy.random.rand(len(z)) / 1000.

    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_str)
    elapsed_time = 0.
    while elapsed_time < time_to_run:
        if elapsed_time + dt > time_to_run:
            dt = time_to_run - elapsed_time
        fr.route_flow()
        sp.erode(mg, dt)
        mg.at_node['topographic__elevation'][mg.core_nodes] += uplift * dt
        elapsed_time += dt

    z_trg = numpy.array([5.48813504e-04,   7.15189366e-04,   6.02763376e-04,
                         5.44883183e-04,   4.23654799e-04,   6.45894113e-04,
                         1.02783376e-02,   9.66667235e-03,   6.15060782e-03,
                         3.83441519e-04,   7.91725038e-04,   1.00905776e-02,
                         8.98955843e-03,   5.32836181e-03,   7.10360582e-05,
                         8.71292997e-05,   9.96377080e-03,   9.63738797e-03,
                         7.31213677e-03,   8.70012148e-04,   9.78618342e-04,
                         1.02124693e-02,   8.78386002e-03,   4.88161060e-03,
                         1.18274426e-04,   6.39921021e-04,   1.00377580e-02,
                         9.54340293e-03,   6.05173814e-03,   4.14661940e-04,
                         2.64555612e-04,   1.02160196e-02,   8.61600088e-03,
                         4.77005225e-03,   1.87898004e-05,   6.17635497e-04,
                         9.30445558e-03,   9.48713993e-03,   7.25689742e-03,
                         6.81820299e-04,   3.59507901e-04,   5.79161813e-03,
                         6.83777542e-03,   6.18063842e-03,   6.66766715e-04,
                         6.70637870e-04,   2.10382561e-04,   1.28926298e-04,
                         3.15428351e-04,   3.63710771e-04])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_trg)
Example #6
0
def test_sp_old():
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str)
    nrows = inputs.read_int('nrows')
    ncols = inputs.read_int('ncols')
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')
    time_to_run = inputs.read_float('run_time')
    uplift = inputs.read_float('uplift_rate')
    init_elev = inputs.read_float('init_elev')

    mg = RasterModelGrid((nrows, ncols), spacing=(dx, dx))
    mg.set_closed_boundaries_at_grid_edges(False, False, True, True)

    mg.add_zeros('topographic__elevation', at='node')
    z = mg.zeros(at='node') + init_elev
    numpy.random.seed(0)
    mg['node']['topographic__elevation'] = z + \
        numpy.random.rand(len(z)) / 1000.

    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_str)
    elapsed_time = 0.
    while elapsed_time < time_to_run:
        if elapsed_time + dt > time_to_run:
            dt = time_to_run - elapsed_time
        fr.route_flow()
        sp.erode(mg, dt)
        mg.at_node['topographic__elevation'][mg.core_nodes] += uplift * dt
        elapsed_time += dt

    z_trg = numpy.array([  5.48813504e-04,   7.15189366e-04,   6.02763376e-04,
                           5.44883183e-04,   4.23654799e-04,   6.45894113e-04,
                           1.01830760e-02,   9.58036770e-03,   6.55865452e-03,
                           3.83441519e-04,   7.91725038e-04,   1.00142749e-02,
                           8.80798884e-03,   5.78387585e-03,   7.10360582e-05,
                           8.71292997e-05,   9.81911417e-03,   9.52243406e-03,
                           7.55093226e-03,   8.70012148e-04,   9.78618342e-04,
                           1.00629755e-02,   8.49253798e-03,   5.33216680e-03,
                           1.18274426e-04,   6.39921021e-04,   9.88956320e-03,
                           9.47119567e-03,   6.43790696e-03,   4.14661940e-04,
                           2.64555612e-04,   1.00450743e-02,   8.37262908e-03,
                           5.21540904e-03,   1.87898004e-05,   6.17635497e-04,
                           9.21286940e-03,   9.34022513e-03,   7.51114450e-03,
                           6.81820299e-04,   3.59507901e-04,   6.19166921e-03,
                           7.10456176e-03,   6.62585507e-03,   6.66766715e-04,
                           6.70637870e-04,   2.10382561e-04,   1.28926298e-04,
                           3.15428351e-04,   3.63710771e-04])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_trg)
Example #7
0
def test_sp_old():
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str)
    nrows = inputs.read_int('nrows')
    ncols = inputs.read_int('ncols')
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')
    time_to_run = inputs.read_float('run_time')
    uplift = inputs.read_float('uplift_rate')
    init_elev = inputs.read_float('init_elev')

    mg = RasterModelGrid((nrows, ncols), spacing=(dx, dx))
    mg.set_closed_boundaries_at_grid_edges(False, False, True, True)

    mg.add_zeros('topographic__elevation', at='node')
    z = mg.zeros(at='node') + init_elev
    numpy.random.seed(0)
    mg['node']['topographic__elevation'] = z + \
        numpy.random.rand(len(z)) / 1000.

    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_str)
    elapsed_time = 0.
    while elapsed_time < time_to_run:
        if elapsed_time + dt > time_to_run:
            dt = time_to_run - elapsed_time
        fr.route_flow()
        sp.erode(mg, dt)
        mg.at_node['topographic__elevation'][mg.core_nodes] += uplift * dt
        elapsed_time += dt

    z_trg = numpy.array([
        5.48813504e-04, 7.15189366e-04, 6.02763376e-04, 5.44883183e-04,
        4.23654799e-04, 6.45894113e-04, 1.01830760e-02, 9.58036770e-03,
        6.55865452e-03, 3.83441519e-04, 7.91725038e-04, 1.00142749e-02,
        8.80798884e-03, 5.78387585e-03, 7.10360582e-05, 8.71292997e-05,
        9.81911417e-03, 9.52243406e-03, 7.55093226e-03, 8.70012148e-04,
        9.78618342e-04, 1.00629755e-02, 8.49253798e-03, 5.33216680e-03,
        1.18274426e-04, 6.39921021e-04, 9.88956320e-03, 9.47119567e-03,
        6.43790696e-03, 4.14661940e-04, 2.64555612e-04, 1.00450743e-02,
        8.37262908e-03, 5.21540904e-03, 1.87898004e-05, 6.17635497e-04,
        9.21286940e-03, 9.34022513e-03, 7.51114450e-03, 6.81820299e-04,
        3.59507901e-04, 6.19166921e-03, 7.10456176e-03, 6.62585507e-03,
        6.66766715e-04, 6.70637870e-04, 2.10382561e-04, 1.28926298e-04,
        3.15428351e-04, 3.63710771e-04
    ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_trg)
Example #8
0
def test_sp_old():
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str)
    nrows = inputs.read_int('nrows')
    ncols = inputs.read_int('ncols')
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')
    time_to_run = inputs.read_float('run_time')
    uplift = inputs.read_float('uplift_rate')
    init_elev = inputs.read_float('init_elev')

    mg = RasterModelGrid((nrows, ncols), spacing=(dx, dx))
    mg.set_closed_boundaries_at_grid_edges(False, False, True, True)

    mg.add_zeros('topographic__elevation', at='node')
    z = mg.zeros(at='node') + init_elev
    numpy.random.seed(0)
    mg['node']['topographic__elevation'] = z + \
        numpy.random.rand(len(z)) / 1000.

    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_str)
    elapsed_time = 0.
    while elapsed_time < time_to_run:
        if elapsed_time + dt > time_to_run:
            dt = time_to_run - elapsed_time
        fr.route_flow()
        sp.erode(mg, dt)
        mg.at_node['topographic__elevation'][mg.core_nodes] += uplift * dt
        elapsed_time += dt

    z_trg = numpy.array([
        5.48813504e-04, 7.15189366e-04, 6.02763376e-04, 5.44883183e-04,
        4.23654799e-04, 6.45894113e-04, 1.02783376e-02, 9.66667235e-03,
        6.15060782e-03, 3.83441519e-04, 7.91725038e-04, 1.00905776e-02,
        8.98955843e-03, 5.32836181e-03, 7.10360582e-05, 8.71292997e-05,
        9.96377080e-03, 9.63738797e-03, 7.31213677e-03, 8.70012148e-04,
        9.78618342e-04, 1.02124693e-02, 8.78386002e-03, 4.88161060e-03,
        1.18274426e-04, 6.39921021e-04, 1.00377580e-02, 9.54340293e-03,
        6.05173814e-03, 4.14661940e-04, 2.64555612e-04, 1.02160196e-02,
        8.61600088e-03, 4.77005225e-03, 1.87898004e-05, 6.17635497e-04,
        9.30445558e-03, 9.48713993e-03, 7.25689742e-03, 6.81820299e-04,
        3.59507901e-04, 5.79161813e-03, 6.83777542e-03, 6.18063842e-03,
        6.66766715e-04, 6.70637870e-04, 2.10382561e-04, 1.28926298e-04,
        3.15428351e-04, 3.63710771e-04
    ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_trg)
def test_sp_discharges_old():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_discharge.txt')
    inputs = ModelParameterDictionary(input_str)
    nrows = 5
    ncols = 5
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')

    mg = RasterModelGrid(nrows, ncols, dx)
    mg.add_zeros('topographic__elevation', at='node')
    z = np.array([
        5., 5., 0., 5., 5., 5., 2., 1., 2., 5., 5., 3., 2., 3., 5., 5., 4., 4.,
        4., 5., 5., 5., 5., 5., 5.
    ])
    mg['node']['topographic__elevation'] = z

    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_str)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow()
        my_Q = mg.at_node['water__volume_flux'] * 1.
        sp.erode(mg,
                 dt,
                 node_drainage_areas='drainage_area',
                 slopes_at_nodes='topographic__steepest_slope',
                 Q_if_used=my_Q)

    z_tg = np.array([
        5.00000000e+00, 5.00000000e+00, 0.00000000e+00, 5.00000000e+00,
        5.00000000e+00, 5.00000000e+00, 1.29289322e+00, 1.00000000e-06,
        1.29289322e+00, 5.00000000e+00, 5.00000000e+00, 2.29289322e+00,
        1.00000000e+00, 2.29289322e+00, 5.00000000e+00, 5.00000000e+00,
        3.29289322e+00, 3.00000000e+00, 3.29289322e+00, 5.00000000e+00,
        5.00000000e+00, 5.00000000e+00, 5.00000000e+00, 5.00000000e+00,
        5.00000000e+00
    ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
def test_sp_discharges():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_discharge.txt')
    inputs = ModelParameterDictionary(input_str)
    nrows = 5
    ncols = 5
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')

    mg = RasterModelGrid(nrows, ncols, dx)
    mg.add_zeros('topographic__elevation', at='node')
    z = np.array([5., 5., 0., 5., 5.,
                  5., 2., 1., 2., 5.,
                  5., 3., 2., 3., 5.,
                  5., 4., 4., 4., 5.,
                  5., 5., 5., 5., 5.])
    mg['node']['topographic__elevation'] = z

    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_str)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow(method='D8')
        my_Q = mg.at_node['water__volume_flux'] * 1.
        sp.erode(mg, dt, node_drainage_areas='drainage_area',
                 slopes_at_nodes='topographic__steepest_slope',
                 Q_if_used=my_Q)

    z_tg = np.array([5.00000000e+00,   5.00000000e+00,   0.00000000e+00,
                     5.00000000e+00,   5.00000000e+00,   5.00000000e+00,
                     1.29289322e+00,   1.00000000e-06,   1.29289322e+00,
                     5.00000000e+00,   5.00000000e+00,   2.29289322e+00,
                     1.00000000e+00,   2.29289322e+00,   5.00000000e+00,
                     5.00000000e+00,   3.29289322e+00,   3.00000000e+00,
                     3.29289322e+00,   5.00000000e+00,   5.00000000e+00,
                     5.00000000e+00,   5.00000000e+00,   5.00000000e+00,
                     5.00000000e+00])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Example #11
0
#make some surface load stresses in a field to test
mg.at_node['surface_load__stress'] = np.zeros(nrows*ncols, dtype=float)

#instantiate:
gf = gFlex(mg, './coupled_SP_gflex_params.txt')
fsp = FastscapeEroder(mg, './coupled_SP_gflex_params.txt')
sp = StreamPowerEroder(mg, './coupled_SP_gflex_params.txt')
fr = FlowRouter(mg)

#perform the loop:
elapsed_time = 0. #total time in simulation
while elapsed_time < time_to_run:
    print(elapsed_time)
    if elapsed_time+dt>time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.route_flow()
    #mg = fsp.erode(mg)
    mg,_,_ = sp.erode(mg, dt, node_drainage_areas='drainage_area', slopes_at_nodes='topographic__steepest_slope')
    mg.at_node['surface_load__stress'] = (mg.at_node['topographic__elevation']+1000)*rock_stress_param
    gf.flex_lithosphere()
    mg.at_node['topographic__elevation'][mg.number_of_nodes//4:3.*mg.number_of_nodes//4] += uplift_perstep
    elapsed_time += dt

pylab.figure(1)
im = imshow_node_grid(mg, 'topographic__elevation')  # display a colored image

pylab.figure(2)
im = imshow_node_grid(mg, 'lithosphere_surface__elevation_increment')
)
mg["node"]["topographic__elevation"] = z

print("Running ...")

# instantiate the components:
fr = FlowRouter(mg)
sp = StreamPowerEroder(mg, "./drive_sp_params_discharge.txt")
# load the Fastscape module too, to allow direct comparison
fsp = Fsc(mg, "./drive_sp_params_discharge.txt")

# perform the loop (once!)
for i in range(1):
    fr.route_flow(method="D8")
    my_Q = mg.at_node["water__discharge"] * 1.0
    sp.erode(mg, dt, node_drainage_areas="drainage_area", slopes_at_nodes="topographic__steepest_slope", Q_if_used=my_Q)
    # no uplift

# print the stream power that was calculated:
print("stream power values:")
print(mg.at_node["stream_power_erosion"])

# Finalize and plot
elev = mg["node"]["topographic__elevation"]
elev_r = mg.node_vector_to_raster(elev)

# Clear previous plots
pylab.figure(1)
pylab.close()

# Plot topography
fsp = FastscapeEroder(mg, "./drive_sp_params.txt")

# perform the loop:
elapsed_time = 0.  # total time in simulation
while elapsed_time < time_to_run:
    print(elapsed_time)
    if elapsed_time + dt > time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.run_one_step()
    # print 'Area: ', numpy.max(mg.at_node['drainage_area'])
    # mg = fsp.erode(mg)
    mg, _, _ = sp.erode(
        mg,
        dt,
        node_drainage_areas="drainage_area",
        slopes_at_nodes="topographic__steepest_slope",
        K_if_used="K_values",
    )
    # add uplift
    mg.at_node["topographic__elevation"][mg.core_nodes] += uplift * dt
    elapsed_time += dt

time_off = time.time()
print("Elapsed time: ", time_off - time_on)

# Finalize and plot
elev = mg["node"]["topographic__elevation"]
elev_r = mg.node_vector_to_raster(elev)

# Clear previous plots
Example #14
0
S_profiles = []
A_profiles = []

#perturb:
time_to_run = 5000000.
dt = 10000.
out_tstep = 50000.
elapsed_time = 0.  #total time in simulation
while elapsed_time < time_to_run:
    if elapsed_time + dt > time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.route_flow()
    #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
    #mg = fsp.erode(mg)
    mg, _, _ = sp.erode(mg, dt, K_if_used='K_values')

    #plot long profiles along channels
    if numpy.allclose(elapsed_time % out_tstep, 0.) or numpy.allclose(
            elapsed_time % out_tstep, 1.):
        pylab.figure("long_profiles")
        profile_IDs = prf.channel_nodes(
            mg, mg.at_node['topographic__steepest_slope'],
            mg.at_node['drainage_area'], mg.at_node['flow_receiver'])
        dists_upstr = prf.get_distances_upstream(
            mg, len(mg.at_node['topographic__steepest_slope']), profile_IDs,
            mg.at_node['links_to_flow_receiver'])

        prf.plot_profiles(dists_upstr, profile_IDs,
                          mg.at_node['topographic_elevation'])
        x_profiles.append(dists_upstr[:])
#load the Fastscape module too, to allow direct comparison
fsp = FastscapeEroder(mg, './drive_sp_params.txt')

#perform the loop:
elapsed_time = 0. #total time in simulation
while elapsed_time < time_to_run:
#for i in range(10):
    print(elapsed_time)
    if elapsed_time+dt>time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.route_flow(method='D8')
    lf.map_depressions()
    #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
    #mg = fsp.erode(mg)
    mg,_,_ = sp.erode(mg, dt, node_drainage_areas='drainage_area', slopes_at_nodes='topographic__steepest_slope', K_if_used='K_values')
    #add uplift
    mg.at_node['topographic__elevation'][mg.core_nodes] += uplift*dt
    elapsed_time += dt

time_off = time.time()
print('Elapsed time: ', time_off-time_on)

#Finalize and plot
elev = mg['node']['topographic__elevation']
elev_r = mg.node_vector_to_raster(elev)

# Clear previous plots
pylab.figure(1)
pylab.close()
Example #16
0
S_profiles = []
A_profiles = []

#perturb:
time_to_run = 5000000.
dt=10000.
out_tstep = 50000.
elapsed_time = 0. #total time in simulation
while elapsed_time < time_to_run:
    if elapsed_time+dt>time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.route_flow()
    #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
    #mg = fsp.erode(mg)
    mg,_,_ = sp.erode(mg, dt, K_if_used='K_values')

    #plot long profiles along channels
    if numpy.allclose(elapsed_time%out_tstep,0.) or numpy.allclose(elapsed_time%out_tstep,1.):
        pylab.figure("long_profiles")
        profile_IDs = prf.channel_nodes(mg, mg.at_node['topographic__steepest_slope'],
                        mg.at_node['drainage_area'], mg.at_node['flow_receiver'])
        dists_upstr = prf.get_distances_upstream(mg, len(mg.at_node['topographic__steepest_slope']),
                        profile_IDs, mg.at_node['links_to_flow_receiver'])

        prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['topographic_elevation'])
        x_profiles.append(dists_upstr[:])
        z_profiles.append(mg.at_node['topographic_elevation'][profile_IDs])
        S_profiles.append(mg.at_node['steepest_slope'][profile_IDs])
        A_profiles.append(mg.at_node['drainage_area'][profile_IDs])
        prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['topographic__elevation'])
Example #17
0
    #raise NameError
    mg = copy.deepcopy(mg_mature)
except NameError:
    print('building a new grid...')
    out_interval = 50000.
    last_trunc = time_to_run  #we use this to trigger taking an output plot
    #run to a steady state:
    #We're going to cheat by running Fastscape SP for the first part of the solution
    for (interval_duration,
         rainfall_rate) in precip.yield_storm_interstorm_duration_intensity():
        if rainfall_rate != 0.:
            mg.at_node['water__unit_flux_in'].fill(rainfall_rate)
            mg = fr.route_flow()
            #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
            mg, _, _ = sp.erode(mg,
                                interval_duration,
                                Q_if_used='water__volume_flux',
                                K_if_used='K_values')
        #add uplift
        mg.at_node['topographic__elevation'][
            mg.core_nodes] += uplift * interval_duration
        this_trunc = precip.elapsed_time // out_interval
        if this_trunc != last_trunc:  #a new loop round
            print('made it to loop ', out_interval * this_trunc)
            last_trunc = this_trunc

    mg_mature = copy.deepcopy(mg)

else:
    #reinstantiate the components with the new grid
    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_file_string)
fsp = FastscapeEroder(mg, "./coupled_SP_gflex_params.txt")
sp = StreamPowerEroder(mg, "./coupled_SP_gflex_params.txt")
fr = FlowAccumulator(mg, flow_director="D8")

# perform the loop:
elapsed_time = 0.  # total time in simulation
while elapsed_time < time_to_run:
    print(elapsed_time)
    if elapsed_time + dt > time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.run_one_step()
    # mg = fsp.erode(mg)
    mg, _, _ = sp.erode(
        mg,
        dt,
        node_drainage_areas="drainage_area",
        slopes_at_nodes="topographic__steepest_slope",
    )
    mg.at_node["surface_load__stress"] = (
        mg.at_node["topographic__elevation"] + 1000) * rock_stress_param
    gf.flex_lithosphere()
    mg.at_node["topographic__elevation"][mg.number_of_nodes // 4:3. *
                                         mg.number_of_nodes //
                                         4] += uplift_perstep
    elapsed_time += dt

pylab.figure(1)
im = imshow_node_grid(mg, "topographic__elevation")  # display a colored image

pylab.figure(2)
im = imshow_node_grid(mg, "lithosphere_surface__elevation_increment")
Example #19
0
try:
    #raise NameError
    mg = copy.deepcopy(mg_mature)
except NameError:
    print('building a new grid...')
    out_interval = 50000.
    last_trunc = time_to_run #we use this to trigger taking an output plot
    #run to a steady state:
    #We're going to cheat by running Fastscape SP for the first part of the solution
    for (interval_duration, rainfall_rate) in precip.yield_storm_interstorm_duration_intensity():
        if rainfall_rate != 0.:
            mg.at_node['water__unit_flux_in'].fill(rainfall_rate)
            mg = fr.route_flow()
            #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
            mg,_,_ = sp.erode(mg, interval_duration, Q_if_used='surface_water__discharge', K_if_used='K_values')
        #add uplift
        mg.at_node['topographic__elevation'][mg.core_nodes] += uplift*interval_duration
        this_trunc = precip.elapsed_time//out_interval
        if this_trunc != last_trunc: #a new loop round
            print('made it to loop ', out_interval*this_trunc)
            last_trunc=this_trunc

    mg_mature = copy.deepcopy(mg)

else:
    #reinstantiate the components with the new grid
    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_file_string)

x_profiles = []
Example #20
0
S_profiles = []
A_profiles = []

# perturb:
time_to_run = 5000000.0
dt = 10000.0
out_tstep = 50000.0
elapsed_time = 0.0  # total time in simulation
while elapsed_time < time_to_run:
    if elapsed_time + dt > time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.route_flow()
    # print 'Area: ', numpy.max(mg.at_node['drainage_area'])
    # mg = fsp.erode(mg)
    mg, _, _ = sp.erode(mg, dt, K_if_used="K_values")

    # plot long profiles along channels
    if numpy.allclose(elapsed_time % out_tstep, 0.0) or numpy.allclose(elapsed_time % out_tstep, 1.0):
        pylab.figure("long_profiles")
        profile_IDs = prf.channel_nodes(
            mg,
            mg.at_node["topographic__steepest_slope"],
            mg.at_node["drainage_area"],
            mg.at_node["flow__receiver_node"],
        )
        dists_upstr = prf.get_distances_upstream(
            mg, len(mg.at_node["topographic__steepest_slope"]), profile_IDs, mg.at_node["flow__link_to_receiver_node"]
        )

        prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node["topographic_elevation"])
Example #21
0
fsp = FastscapeEroder(mg, './drive_sp_params.txt')

#perform the loop:
elapsed_time = 0.  #total time in simulation
counter = 0.
while elapsed_time < time_to_run:
    print(elapsed_time)
    if elapsed_time + dt > time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.route_flow(method='D8')
    #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
    #mg = fsp.erode(mg)
    mg, _, _ = sp.erode(mg,
                        dt,
                        node_drainage_areas='drainage_area',
                        slopes_at_nodes='topographic__steepest_slope',
                        K_if_used='K_values')
    #add uplift
    mg.at_node['topographic__elevation'][mg.core_nodes] += uplift * dt
    elapsed_time += dt
    if counter % 20 == 0:
        pylab.figure('profiles')
        profiles = prf.analyze_channel_network_and_plot(mg)
    counter += 1

time_off = time.time()
print('Elapsed time: ', time_off - time_on)

time_off = time.time()
print('Elapsed time: ', time_off - time_on)
Example #22
0
fsp = FastscapeEroder(mg, "./coupled_SP_gflex_params.txt")
sp = StreamPowerEroder(mg, "./coupled_SP_gflex_params.txt")
fr = FlowAccumulator(mg, flow_director="D8")

# perform the loop:
elapsed_time = 0.  # total time in simulation
while elapsed_time < time_to_run:
    print(elapsed_time)
    if elapsed_time + dt > time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.run_one_step()
    # mg = fsp.erode(mg)
    mg, _, _ = sp.erode(
        mg,
        dt,
        node_drainage_areas="drainage_area",
        slopes_at_nodes="topographic__steepest_slope",
    )
    mg.at_node["surface_load__stress"] = (
        mg.at_node["topographic__elevation"] + 1000
    ) * rock_stress_param
    gf.flex_lithosphere()
    mg.at_node["topographic__elevation"][
        mg.number_of_nodes // 4 : 3. * mg.number_of_nodes // 4
    ] += uplift_perstep
    elapsed_time += dt

pylab.figure(1)
im = imshow_grid(mg, "topographic__elevation")  # display a colored image

pylab.figure(2)
Example #23
0
fsp = FastscapeEroder(mg, "./drive_sp_params.txt")

# perform the loop:
elapsed_time = 0.  # total time in simulation
while elapsed_time < time_to_run:
    print(elapsed_time)
    if elapsed_time + dt > time_to_run:
        print("Short step!")
        dt = time_to_run - elapsed_time
    mg = fr.run_one_step()
    # print 'Area: ', numpy.max(mg.at_node['drainage_area'])
    # mg = fsp.erode(mg)
    mg, _, _ = sp.erode(
        mg,
        dt,
        node_drainage_areas="drainage_area",
        slopes_at_nodes="topographic__steepest_slope",
        K_if_used="K_values",
    )
    # add uplift
    mg.at_node["topographic__elevation"][mg.core_nodes] += uplift * dt
    elapsed_time += dt

time_off = time.time()
print("Elapsed time: ", time_off - time_on)

# Finalize and plot
elev = mg["node"]["topographic__elevation"]
elev_r = mg.node_vector_to_raster(elev)

# Clear previous plots
Example #24
0
from six.moves import range

from landlab import VoronoiDelaunayGrid
from landlab.components.flow_routing import FlowRouter
from landlab.components.stream_power import StreamPowerEroder
from landlab.plot.imshow import imshow_node_grid
import numpy as np
from matplotlib.pyplot import figure, show

nnodes = 10000

x, y = np.random.rand(nnodes), np.random.rand(nnodes)
mg = VoronoiDelaunayGrid(x,y)

z = mg.add_field('node', 'topographic__elevation', np.random.rand(nnodes)/10000., copy=False)

fr = FlowRouter(mg)
spe = StreamPowerEroder(mg, 'drive_sp_params_voronoi.txt')

for i in range(100):
    z[mg.core_nodes] += 0.01
    fr.route_flow()
    spe.erode(mg, 1.)

imshow_node_grid(mg, 'topographic__elevation')

show()
Example #25
0
    #raise NameError
    mg = copy.deepcopy(mg_mature)
except NameError:
    print('building a new grid...')
    out_interval = 50000.
    last_trunc = time_to_run  #we use this to trigger taking an output plot
    #run to a steady state:
    #We're going to cheat by running Fastscape SP for the first part of the solution
    for (interval_duration,
         rainfall_rate) in precip.yield_storm_interstorm_duration_intensity():
        if rainfall_rate != 0.:
            mg.at_node['water__unit_flux_in'].fill(rainfall_rate)
            mg = fr.route_flow()
            #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
            mg, _, _ = sp.erode(mg,
                                interval_duration,
                                Q_if_used='water__discharge',
                                K_if_used='K_values')
        #add uplift
        mg.at_node['topographic__elevation'][
            mg.core_nodes] += uplift * interval_duration
        this_trunc = precip.elapsed_time // out_interval
        if this_trunc != last_trunc:  #a new loop round
            print('made it to loop ', out_interval * this_trunc)
            last_trunc = this_trunc

    mg_mature = copy.deepcopy(mg)

else:
    #reinstantiate the components with the new grid
    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_file_string)
mg['node']['topographic__elevation'] = z

print('Running ...')

# instantiate the components:
fr = FlowRouter(mg)
sp = StreamPowerEroder(mg, './drive_sp_params_discharge.txt')
# load the Fastscape module too, to allow direct comparison
fsp = Fsc(mg, './drive_sp_params_discharge.txt')

# perform the loop (once!)
for i in range(1):
    fr.route_flow(method='D8')
    my_Q = mg.at_node['water__volume_flux']*1.
    sp.erode(mg, dt, node_drainage_areas='drainage_area',
             slopes_at_nodes='topographic__steepest_slope',
             Q_if_used=my_Q)
    # no uplift

# print the stream power that was calculated:
print('stream power values:')
print(mg.at_node['stream_power_erosion'])

# Finalize and plot
elev = mg['node']['topographic__elevation']
elev_r = mg.node_vector_to_raster(elev)

# Clear previous plots
pylab.figure(1)
pylab.close()
print('Running ...')

# instantiate the components:
fr = FlowRouter(mg)
sp = StreamPowerEroder(mg, './drive_sp_params_discharge.txt')
# load the Fastscape module too, to allow direct comparison
fsp = Fsc(mg, './drive_sp_params_discharge.txt')

# perform the loop (once!)
for i in range(1):
    fr.route_flow(method='D8')
    my_Q = mg.at_node['water__volume_flux'] * 1.
    sp.erode(mg,
             dt,
             node_drainage_areas='drainage_area',
             slopes_at_nodes='topographic__steepest_slope',
             Q_if_used=my_Q)
    # no uplift

# print the stream power that was calculated:
print('stream power values:')
print(mg.at_node['stream_power_erosion'])

# Finalize and plot
elev = mg['node']['topographic__elevation']
elev_r = mg.node_vector_to_raster(elev)

# Clear previous plots
pylab.figure(1)
pylab.close()
Example #28
0
try:
    #raise NameError
    mg = copy.deepcopy(mg_mature)
except NameError:
    print('building a new grid...')
    out_interval = 50000.
    last_trunc = time_to_run #we use this to trigger taking an output plot
    #run to a steady state:
    #We're going to cheat by running Fastscape SP for the first part of the solution
    for (interval_duration, rainfall_rate) in precip.yield_storm_interstorm_duration_intensity():
        if rainfall_rate != 0.:
            mg.at_node['water__unit_flux_in'].fill(rainfall_rate)
            mg = fr.route_flow()
            #print 'Area: ', numpy.max(mg.at_node['drainage_area'])
            mg,_,_ = sp.erode(mg, interval_duration, Q_if_used='water__volume_flux', K_if_used='K_values')
        #add uplift
        mg.at_node['topographic__elevation'][mg.core_nodes] += uplift*interval_duration
        this_trunc = precip.elapsed_time//out_interval
        if this_trunc != last_trunc: #a new loop round
            print('made it to loop ', out_interval*this_trunc)
            last_trunc=this_trunc

    mg_mature = copy.deepcopy(mg)

else:
    #reinstantiate the components with the new grid
    fr = FlowRouter(mg)
    sp = StreamPowerEroder(mg, input_file_string)

x_profiles = []