コード例 #1
0
ファイル: run_SP.py プロジェクト: SiccarPoint/LL_sedfluxdep
def plot_and_calc_concavities_final_run(directory='.'):
    """
    Plots S-A for final topo saved in folder "directory".

    Returns (k_s, concavity) for lin regression on log log trend.

    Concavity is defined as positive.
    """
    mg2 = deepcopy(mg)
    z2 = mg2.add_zeros('node', 'topographic__elevation', noclobber=False)
    fr2 = FlowRouter(mg2)
    # search for topo saves, to establish the num files, codes etc:
    prefixed_z = [
        filename for filename in os.listdir(directory)
        if filename.startswith('topographic__elevation')
    ]
    # grab the unique ID, so we can differentiate plots (if desired)
    unique_ID = prefixed_z[0][-14:-4]
    # work on first save to establish num digits
    _format = 0
    while True:
        char = prefixed_z[-1][-16 - _format]
        try:
            num = int(char)
        except ValueError:  # was a str
            break
        else:
            _format += 1

    # load the final topo:
    z2[:] = np.loadtxt(directory + '/' + prefixed_z[-1])
    # create a new flow map:
    fr2.run_one_step()
    profile_IDs = channel_nodes(mg2,
                                mg2.at_node['topographic__steepest_slope'],
                                mg2.at_node['drainage_area'],
                                mg2.at_node['flow__receiver_node'])
    ch_dists = get_distances_upstream(
        mg2, len(mg2.at_node['topographic__steepest_slope']), profile_IDs,
        mg2.at_node['flow__link_to_receiver_node'])
    slopes = mg2.at_node['topographic__steepest_slope'][profile_IDs[0]]
    areas = mg2.at_node['drainage_area'][profile_IDs[0]]
    logslopes = np.log(slopes)
    logareas = np.log(areas)
    goodvals = np.logical_and(np.isfinite(logslopes), np.isfinite(logareas))
    concavity, log_k_s, _, _, _ = linregress(logareas[goodvals],
                                             logslopes[goodvals])
    k_s = np.exp(log_k_s)

    loglog(areas, slopes, 'x')
    loglog(areas, k_s * areas**concavity, '-')
    xlabel('Drainage area (m**2)')
    ylabel('Slope (m/m)')

    return k_s, -concavity
コード例 #2
0
ファイル: run_SP.py プロジェクト: SiccarPoint/LL_sedfluxdep
def draw_profile(grid, figure_name='profile'):
    """Plot the current channel long profile.
    """
    figure(figure_name)
    profile_IDs = channel_nodes(grid,
                                grid.at_node['topographic__steepest_slope'],
                                grid.at_node['drainage_area'],
                                grid.at_node['flow__receiver_node'])
    ch_dists = get_distances_upstream(
        grid, len(grid.at_node['topographic__steepest_slope']), profile_IDs,
        grid.at_node['flow__link_to_receiver_node'])
    plot(ch_dists[0], grid.at_node['topographic__elevation'][profile_IDs[0]])
    xlabel('Distance downstream (m)')
    ylabel('Elevation (m)')
コード例 #3
0
#perform the loops:
for i in xrange(nt):
    #note the input arguments here are not totally standardized between modules
    #mg = diffuse.diffuse(mg, i*dt)
    mg = lin_diffuse.diffuse(mg, dt)
    mg = fr.route_flow(grid=mg)
    mg = sp.erode(mg)

    ##plot long profiles along channels
    pylab.figure(6)
    profile_IDs = prf.channel_nodes(mg, mg.at_node['steepest_slope'],
                                    mg.at_node['drainage_area'],
                                    mg.at_node['upstream_ID_order'],
                                    mg.at_node['flow_receiver'])
    dists_upstr = prf.get_distances_upstream(
        mg, len(mg.at_node['steepest_slope']), profile_IDs,
        mg.at_node['links_to_flow_receiver'])
    prf.plot_profiles(dists_upstr, profile_IDs,
                      mg.at_node['topographic_elevation'])

    print 'Completed loop ', i

print 'Completed the simulation. Plotting...'

#Finalize and plot
# Clear previous plots
pylab.figure(1)
pylab.close()
pylab.figure(1)
im = imshow_node_grid(mg, 'water_discharges',
                      cmap='PuBu')  # display a colored image
コード例 #4
0
 mg_copy = deepcopy(mg)
 mg, _ = sde.erode(mg, dt)
 #print sde.iterations_in_dt
 #print 'capacity ', np.amax(capacity_out[mg.core_nodes])
 #print 'rel sed ', np.nanmax(sed_in[mg.core_nodes]/capacity_out[mg.core_nodes])
 if i % out_interval == 0:
     print('loop ', i)
     print(
         'max_slope',
         np.amax(mg.at_node['topographic__steepest_slope'][mg.core_nodes]))
     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'])
 if i % out_interval == 0:
     x_profiles.append(dists_upstr)
     z_profiles.append(mg.at_node['topographic__elevation'][profile_IDs])
     S_profiles.append(
         mg.at_node['topographic__steepest_slope'][profile_IDs])
     A_profiles.append(mg.at_node['drainage_area'][profile_IDs])
     if make_output_plots:
         pylab.figure('long_profile_anim')
         #prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['topographic_elevation'])
         plot(dists_upstr, mg.at_node['topographic_elevation'][profile_IDs])
         ylim([0, y_max])
         if i == 0:
コード例 #5
0
    #max_slope = np.max(np.fabs(neighbor_slopes),axis=1)
    #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes='steepest_slope')
    #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes=max_slope)
    mg_copy = deepcopy(mg)
    mg,_ = sde.erode(mg,dt)
    #print sde.iterations_in_dt
    #print 'capacity ', np.amax(capacity_out[mg.core_nodes])
    #print 'rel sed ', np.nanmax(sed_in[mg.core_nodes]/capacity_out[mg.core_nodes])
    if i%100 == 0:
        print 'loop ', i
        print 'max_slope', np.amax(mg.at_node['steepest_slope'][mg.core_nodes])
        pylab.figure("long_profiles")
        profile_IDs = prf.channel_nodes(mg, mg.at_node['steepest_slope'],
                        mg.at_node['drainage_area'], mg.at_node['upstream_ID_order'],
                        mg.at_node['flow_receiver'])
        dists_upstr = prf.get_distances_upstream(mg, len(mg.at_node['steepest_slope']),
                        profile_IDs, mg.at_node['links_to_flow_receiver'])
        prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['topographic_elevation'])
    #mg.update_boundary_nodes()
    #vid.add_frame(mg, 'topographic_elevation')
    
 
print 'Completed the simulation. Plotting...'

time_off = time()

#Finalize and plot

elev = mg['node']['topographic_elevation']
#imshow.imshow_node_grid(mg, elev)

print('Done.')
コード例 #6
0
 #mean_slope = np.mean(np.fabs(neighbor_slopes),axis=1)
 #max_slope = np.max(np.fabs(neighbor_slopes),axis=1)
 #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes='topographic__steepest_slope')
 #mg,_,capacity_out = tl.erode(mg,dt,slopes_at_nodes=max_slope)
 mg_copy = deepcopy(mg)
 mg,_ = sde.erode(mg,dt)
 #print sde.iterations_in_dt
 #print 'capacity ', np.amax(capacity_out[mg.core_nodes])
 #print 'rel sed ', np.nanmax(sed_in[mg.core_nodes]/capacity_out[mg.core_nodes])
 if i%out_interval == 0:
     print('loop ', i)
     print('max_slope', np.amax(mg.at_node['topographic__steepest_slope'][mg.core_nodes]))
     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'])
 if i%out_interval == 0:
     x_profiles.append(dists_upstr)
     z_profiles.append(mg.at_node['topographic__elevation'][profile_IDs])
     S_profiles.append(mg.at_node['topographic__steepest_slope'][profile_IDs])
     A_profiles.append(mg.at_node['drainage_area'][profile_IDs])
     if make_output_plots:
         pylab.figure('long_profile_anim')
         #prf.plot_profiles(dists_upstr, profile_IDs, mg.at_node['topographic_elevation'])
         plot(dists_upstr,mg.at_node['topographic_elevation'][profile_IDs])
         ylim([0,y_max])
         if i==0:
             savefig('profile_anim_000'+str(i)+'.png')
         elif i<100:
             savefig('profile_anim_00'+str(i)+'.png')
コード例 #7
0
ファイル: coupled_driver.py プロジェクト: brigidlynch/landlab
# perform the loops:
for i in xrange(nt):
    # note the input arguments here are not totally standardized between modules
    # mg = diffuse.diffuse(mg, i*dt)
    mg = lin_diffuse.diffuse(dt)
    mg = fr.route_flow()
    mg = sp.erode(mg)
    mg.at_node["topographic__elevation"][mg.core_nodes] += uplift_per_step

    ##plot long profiles along channels
    pylab.figure(6)
    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"])

    print("Completed loop ", i)

print("Completed the simulation. Plotting...")


# Finalize and plot
# Clear previous plots
pylab.figure(1)
pylab.close()
pylab.figure(1)
im = imshow_node_grid(mg, "water__volume_flux", cmap="PuBu")  # display a colored image
コード例 #8
0
ファイル: run_SP.py プロジェクト: SiccarPoint/LL_sedfluxdep
def draw_profile_evolution(start,
                           stop,
                           step,
                           format,
                           directory='.',
                           force_same_nodes=False,
                           plot_field_downstream=None,
                           different_runs_different_plots=True):
    """Plot a set of long profiles, loaded from saved data.

    "format" is the number of numbers in the file string.
    e.g., "00150" is 5. "012345" is 6.
    "plot_field_downstream" is the string of a field at which values should
    also be plotted, on a second figure.
    """
    mg2 = deepcopy(mg)
    z2 = mg2.add_zeros('node', 'topographic__elevation', noclobber=False)
    fr2 = FlowRouter(mg2)
    first = True
    for i in xrange(start, stop, step):
        num_zeros = format - len(str(i))
        numberstr = '0' * num_zeros + str(i) + '_'
        # search for this string as a topo:
        prefixed = [
            filename for filename in os.listdir(directory)
            if filename.startswith('topographic__elevation_' + numberstr)
        ]
        # grab the unique ID, so we can differentiate plots (if desired)
        unique_ID = prefixed[0][-14:-4]
        print('Plotting the profile with unique ID: ' + unique_ID)
        try:
            z2[:] = np.loadtxt(directory + '/' + prefixed[0])
        except IndexError:
            raise IndexError(
                "it's likely you've mis-set directory, or end is out of range")
        if plot_field_downstream is not None:
            prefixedvals = [
                filename for filename in os.listdir(directory)
                if filename.startswith(plot_field_downstream + '_' + numberstr)
            ]
            field_vals = np.loadtxt(directory + '/' + prefixedvals[0])
        fr2.run_one_step()
        if force_same_nodes:
            if first:
                if different_runs_different_plots:
                    draw_profile(mg2, figure_name=('profile_' + unique_ID))
                else:
                    draw_profile(mg2)
                first = False
                if plot_field_downstream is not None:
                    if different_runs_different_plots:
                        figure('field_values_downstream_' + unique_ID)
                    else:
                        figure('field_values_downstream')
                    plot(ch_dists[0], field_vals[profile_IDs[0]])
            else:
                if different_runs_different_plots:
                    figure('profile_' + unique_ID)
                else:
                    figure('profile')
                plot(ch_dists[0],
                     mg2.at_node['topographic__elevation'][profile_IDs[0]])
                if plot_field_downstream is not None:
                    if different_runs_different_plots:
                        figure('field_values_downstream_' + unique_ID)
                    else:
                        figure('field_values_downstream')
                    plot(ch_dists[0], field_vals[profile_IDs[0]])
        else:
            if different_runs_different_plots:
                draw_profile(mg2, figure_name=('profile_' + unique_ID))
            else:
                draw_profile(mg2)
            if plot_field_downstream is not None:
                profile_IDs = channel_nodes(
                    mg2, mg2.at_node['topographic__steepest_slope'],
                    mg2.at_node['drainage_area'],
                    mg2.at_node['flow__receiver_node'])
                ch_dists = get_distances_upstream(
                    mg2, len(mg2.at_node['topographic__steepest_slope']),
                    profile_IDs, mg2.at_node['flow__link_to_receiver_node'])
                if different_runs_different_plots:
                    figure('field_values_downstream_' + unique_ID)
                else:
                    figure('field_values_downstream')
                plot(ch_dists[0], field_vals[profile_IDs[0]])
    if plot_field_downstream is not None:
        if different_runs_different_plots:
            figure('field_values_downstream_' + unique_ID)
        else:
            figure('field_values_downstream')
        xlabel('Distance downstream (m)')
        ylabel('Field value')
## Plotting the topography
plt.figure(1)
imshow_grid(rmg1, 'topographic__elevation')

## More plotting...

## find the location of the largest channels
profile_IDs = prf.channel_nodes(rmg1,
                                rmg1.at_node['topographic__steepest_slope'],
                                rmg1.at_node['drainage_area'],
                                rmg1.at_node['flow__receiver_node'],
                                number_of_channels=2)

## find the distances upstream at each node along the profile
profile_upstream_dists = prf.get_distances_upstream(
    rmg1, len(rmg1.at_node['topographic__steepest_slope']), profile_IDs,
    rmg1.at_node['flow__link_to_receiver_node'])

## plot elevation vs. distance
plt.figure(2)
plt.plot(profile_upstream_dists[0], z1[profile_IDs[0]], 'b-', label='chan 1')
plt.plot(profile_upstream_dists[1], z1[profile_IDs[1]], 'r-', label='chan 2')
plt.title('elevation profiles')
plt.ylabel('elevation [m]')
plt.xlabel('distance upstream [m]')

## plot slope vs. drainage area
plt.figure(3)
plt.loglog(rmg1.at_node['drainage_area'][profile_IDs[0]],
           rmg1.at_node['topographic__steepest_slope'][profile_IDs[0]], 'b*')
plt.loglog(rmg1.at_node['drainage_area'][profile_IDs[1]],