Ejemplo n.º 1
0
def test_sp_discharges_new():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_discharge_new.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    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, **inputs)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow()
        sp.run_one_step(dt)

    z_tg = np.array([
        5., 5., 0., 5., 5., 5., 1.47759225, 0.43050087, 1.47759225, 5., 5.,
        2.32883687, 1.21525044, 2.32883687, 5., 5., 3.27261262, 3.07175015,
        3.27261262, 5., 5., 5., 5., 5., 5.
    ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Ejemplo n.º 2
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__unit_flux_in', at='node')

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

    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()
            sp.run_one_step(dt)
        mg.at_node['topographic__elevation'][
            mg.core_nodes] += uplift * interval_duration
Ejemplo n.º 3
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__unit_flux_in', at='node')

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

    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()
            sp.run_one_step(dt)
        mg.at_node['topographic__elevation'][
            mg.core_nodes] += uplift * interval_duration
Ejemplo n.º 4
0
def test_sp_discharges_new():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_discharge_new.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, **inputs)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow()
        sp.run_one_step(dt)

    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_new():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_discharge_new.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    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, **inputs)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow()
        sp.run_one_step(dt)

    z_tg = np.array([5.        ,  5.        ,  0.        ,  5.        ,
                     5.        ,  5.        ,  1.47759225,  0.43050087,
                     1.47759225,  5.        ,  5.        ,  2.32883687,
                     1.21525044,  2.32883687,  5.        ,  5.        ,
                     3.27261262,  3.07175015,  3.27261262,  5.        ,
                     5.        ,  5.        ,  5.        ,  5.        ,
                     5.        ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Ejemplo n.º 6
0
def test_sp_new():
    """
    Tests new style component instantiation and run.
    """
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    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, **inputs)
    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.run_one_step(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)
Ejemplo n.º 7
0
def test_sp_new():
    """
    Tests new style component instantiation and run.
    """
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    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, **inputs)
    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.run_one_step(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)
Ejemplo n.º 8
0
def test_sp_new():
    """
    Tests new style component instantiation and run.
    """
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    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, **inputs)
    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.run_one_step(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)
Ejemplo n.º 9
0
def test_sp_new():
    """
    Tests new style component instantiation and run.
    """
    input_str = os.path.join(_THIS_DIR, 'drive_sp_params.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    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, **inputs)
    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.run_one_step(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)
Ejemplo n.º 10
0
def test_sp_widths():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_widths.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    nrows = 5
    ncols = 5
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')

    mg = RasterModelGrid(nrows, ncols, dx)
    widths = np.ones(mg.number_of_nodes, dtype=float)
    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, use_W=widths, **inputs)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow()
        sqrt_A = mg.at_node['drainage_area']**0.5
        widths[mg.core_nodes] = sqrt_A[mg.core_nodes]/sqrt_A[
            mg.core_nodes].mean()
        # so widths has mean=1.
        # note the issue with drainage_area not defined at perimeter => nans
        # if not careful...
        sp.run_one_step(dt)

    z_tg = np.array([ 5.        ,  5.        ,  0.        ,  5.        ,
                      5.        ,  5.        ,  1.37222369,  0.36876358,
                      1.37222369,  5.        ,  5.        ,  2.17408606,
                      1.07986038,  2.17408606,  5.        ,  5.        ,
                      3.08340277,  2.85288049,  3.08340277,  5.        ,
                      5.        ,  5.        ,  5.        ,  5.        ,
                      5.        ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Ejemplo n.º 11
0
def test_sp_widths():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_widths.txt')
    inputs = ModelParameterDictionary(input_str, auto_type=True)
    nrows = 5
    ncols = 5
    dx = inputs.read_float('dx')
    dt = inputs.read_float('dt')

    mg = RasterModelGrid(nrows, ncols, dx)
    widths = np.ones(mg.number_of_nodes, dtype=float)
    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, use_W=widths, **inputs)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow()
        sqrt_A = mg.at_node['drainage_area']**0.5
        widths[mg.core_nodes] = sqrt_A[mg.core_nodes] / sqrt_A[
            mg.core_nodes].mean()
        # so widths has mean=1.
        # note the issue with drainage_area not defined at perimeter => nans
        # if not careful...
        sp.run_one_step(dt)

    z_tg = np.array([
        5., 5., 0., 5., 5., 5., 1.37222369, 0.36876358, 1.37222369, 5., 5.,
        2.17408606, 1.07986038, 2.17408606, 5., 5., 3.08340277, 2.85288049,
        3.08340277, 5., 5., 5., 5., 5., 5.
    ])

    assert_array_almost_equal(mg.at_node['topographic__elevation'], z_tg)
Ejemplo n.º 12
0
def test_sp_discharges_new():
    input_str = os.path.join(_THIS_DIR, 'test_sp_params_discharge_new.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, **inputs)

    # perform the loop (once!)
    for i in range(1):
        fr.route_flow()
        sp.run_one_step(dt)

    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)