Beispiel #1
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 = FlowAccumulator(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.run_one_step()
        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)
Beispiel #2
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 = FlowAccumulator(mg, flow_director='D8')
    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.run_one_step()
        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)
    fr = FlowRouter(rmg, method='D4', runoff_rate=float(rainfall_ms))
    fr1 = FlowRouter(rmg1, method='D4', runoff_rate=float(rainfall_ms))
    fr5 = FlowRouter(rmg5, method='D4', runoff_rate=float(rainfall_ms))
    fr10 = FlowRouter(rmg10, method='D4', runoff_rate=float(rainfall_ms))

    fr.run_one_step()
    fr1.run_one_step()
    fr5.run_one_step()
    fr10.run_one_step()

    last_z = copy.deepcopy(z)
    last_z1 = copy.deepcopy(z1)
    last_z5 = copy.deepcopy(z5)
    last_z10 = copy.deepcopy(z10)

    rmg, z, _ = dle.erode(rmg, dt=dt)
    rmg1, z1, e1 = dle1.erode(rmg1, dt=dt)
    rmg5, z5, e5 = dle5.erode(rmg5, dt=dt)
    rmg10, z10, e10 = dle10.erode(rmg10, dt=dt)

    total_incision_depth += last_z - z
    total_incision_depth1 += last_z1 - z1
    total_incision_depth5 += last_z5 - z5
    total_incision_depth10 += last_z10 - z10

    rmg['node']['topographic__elevation'][rmg.core_nodes] += (uplift_rate *
                                                              uplift_dt)
    rmg1['node']['topographic__elevation'][rmg1.core_nodes] += (uplift_rate *
                                                                uplift_dt)
    rmg5['node']['topographic__elevation'][rmg5.core_nodes] += (uplift_rate *
                                                                uplift_dt)
Beispiel #4
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.run_one_step()
    #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_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'])
        x_profiles.append(dists_upstr[:])
Beispiel #5
0
print("Running ...")

# instantiate the components:
fr = FlowAccumulator(mg, flow_director="D8")
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["surface_water__discharge"] * 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)
mg.status_at_node[mg.nodes_at_right_edge] = CLOSED_BOUNDARY

fr = FlowAccumulator(mg, flow_director="D8")
if DL_or_TL == "TL":
    tle = TransportLimitedEroder(mg, input_file)
else:
    spe = StreamPowerEroder(mg, input_file)

for i in range(nt):
    # print 'loop ', i
    mg.at_node["topographic__elevation"][mg.core_nodes] += uplift_per_step
    mg = fr.route_flow(grid=mg)
    if DL_or_TL == "TL":
        mg, _ = tle.erode(mg, dt)
    else:
        mg, _, _ = spe.erode(mg, dt=dt)
    if i % init_interval == 0:
        print("loop {0}".format(i))
        print(
            "max_slope",
            np.amax(mg.at_node["topographic__steepest_slope"][mg.core_nodes]),
        )
        pylab.figure("long_profiles_init")
        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,
Beispiel #7
0
    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.run_one_step()
            # 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
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.run_one_step()
    # 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_node"],
        )
        dists_upstr = prf.get_distances_upstream(
            mg,
            len(mg.at_node["topographic__steepest_slope"]),
sp = StreamPowerEroder(mg, './drive_sp_params.txt')
#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
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)

#Finalize and plot
print('Running ...')

# instantiate the components:
fr = FlowAccumulator(mg, flow_director='D8')
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['surface_water__discharge'] * 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()
Beispiel #11
0
# 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()
Beispiel #12
0
# 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()
Beispiel #13
0
import numpy as np
from matplotlib.pyplot import show
from six.moves import range

from landlab import VoronoiDelaunayGrid
from landlab.components import FlowAccumulator, StreamPowerEroder
from landlab.plot.imshow import imshow_grid

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 = FlowAccumulator(mg)
spe = StreamPowerEroder(mg, "drive_sp_params_voronoi.txt")

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

imshow_grid(mg, "topographic__elevation")

show()
Beispiel #14
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.run_one_step()
            #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 = FlowAccumulator(mg, flow_director='D8')
    sp = StreamPowerEroder(mg, input_file_string)

x_profiles = []
Beispiel #15
0
import numpy as np
from matplotlib.pyplot import show
from six.moves import range

from landlab import VoronoiDelaunayGrid
from landlab.components import FlowAccumulator, StreamPowerEroder
from landlab.plot.imshow import imshow_node_grid

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 = FlowAccumulator(mg)
spe = StreamPowerEroder(mg, "drive_sp_params_voronoi.txt")

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

imshow_node_grid(mg, "topographic__elevation")

show()
Beispiel #16
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.0, copy=False
    )

    fr = FlowAccumulator(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.run_one_step()
        spe.erode(mg, 1.0)

    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)
Beispiel #17
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)
Beispiel #18
0
    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.run_one_step()
            # 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 = FlowAccumulator(mg, flow_director="D8")
Beispiel #19
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.run_one_step()
    # 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_node"],
        )
        dists_upstr = prf.get_distances_upstream(
            mg,
            len(mg.at_node["topographic__steepest_slope"]),
mg.status_at_node[mg.nodes_at_right_edge] = CLOSED_BOUNDARY

fr = FlowAccumulator(mg, flow_director="D8")
if DL_or_TL == "TL":
    tle = TransportLimitedEroder(mg, input_file)
else:
    spe = StreamPowerEroder(mg, input_file)

for i in range(nt):
    # print 'loop ', i
    mg.at_node["topographic__elevation"][mg.core_nodes] += uplift_per_step
    mg = fr.route_flow(grid=mg)
    if DL_or_TL == "TL":
        mg, _ = tle.erode(mg, dt)
    else:
        mg, _, _ = spe.erode(mg, dt=dt)
    if i % init_interval == 0:
        print("loop {0}".format(i))
        print(
            "max_slope",
            np.amax(mg.at_node["topographic__steepest_slope"][mg.core_nodes]),
        )
        pylab.figure("long_profiles_init")
        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,
Beispiel #21
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), xy_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.0

    fr = FlowAccumulator(mg, flow_director="D8")
    sp = StreamPowerEroder(mg, input_str)
    elapsed_time = 0.0
    while elapsed_time < time_to_run:
        if elapsed_time + dt > time_to_run:
            dt = time_to_run - elapsed_time
        fr.run_one_step()
        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)