Beispiel #1
0
                                       left_is_closed=False, bottom_is_closed=False)
#Create a diagonal fault across the grid
blockuplift_nodes = np.where((mg.node_y < 55) & (mg.node_y > 45)
                             & (mg.node_x < 55) & (mg.node_x > 45))
z[blockuplift_nodes] += 10.0

# View the initial grid
figure()
imshow_grid(mg,
            'topographic__elevation',
            cmap='viridis',
            grid_units=['m', 'm'])
show()

linear_diffusivity = 0.01  #in m2 per year
ld = LinearDiffuser(grid=mg, linear_diffusivity=linear_diffusivity)

dt = 100.

#Evolve landscape
for i in range(25):
    ld.run_one_step(dt)

#Plot new landscape
figure()
imshow_grid(mg,
            'topographic__elevation',
            cmap='viridis',
            grid_units=['m', 'm'])
show()
z = mg.create_node_array_zeros() + leftmost_elev
z += initial_slope * np.amax(mg.node_y) - initial_slope * mg.node_y
#put these values plus roughness into that field
mg.at_node['topographic__elevation'] = z + np.random.rand(len(z)) / 100000.

#set up grid's boundary conditions (bottom, right, top, left is inactive)
mg.set_closed_boundaries_at_grid_edges(False, True, False, True)

# Display a message
print 'Running ...'

#instantiate the components:
fr = FlowRouter(mg)
sp = FastscapeEroder(mg, input_file)
diffuse = PerronNLDiffuse(mg, input_file)
lin_diffuse = LinearDiffuser(grid=mg, input_stream=input_file)

#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, dt)
    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'],
Beispiel #3
0
mg.add_zeros('topographic__elevation', at='node')
# in our case, slope is zero, so the leftmost_elev is the mean elev
z = mg.zeros(at='node') + leftmost_elev
# put these values plus roughness into that field
mg['node']['topographic__elevation'] = z + np.random.rand(len(z)) / 100000.

# set up its boundary conditions (bottom, left, top, right)
# The mechanisms for this are all automated within the grid object
mg.set_fixed_value_boundaries_at_grid_edges(True, True, True, True)

# Display a message
print('Running ...')

# instantiate the components:
diffuse = PerronNLDiffuse(mg, input_file)
lin_diffuse = LinearDiffuser(grid=mg, input_stream=input_file)
# lin_diffuse.initialize(input_file)

# Perform the loops.
# First, we do the nonlinear diffusion:

# We're going to perform a block uplift of the interior of the grid, but
# leave the boundary nodes at their original elevations.
# access this function of the grid, and store the output with a local name
uplifted_nodes = mg.get_core_nodes()
#(Note: Node numbering runs across from the bottom left of the grid.)

# nt is the number of timesteps we calculated above, i.e., loop nt times.
# We never actually use i within the loop, but we could do.
for i in range(nt):
    #("range" is a clever memory-saving way of producing consecutive integers to govern a loop)
len(z)

#Create a diagonal fault across the grid
fault_y = 50.0 + 0.25 * mg.node_x
upthrown_nodes = numpy.where(mg.node_y > fault_y)
z[upthrown_nodes] += 10.0 + 0.01 * mg.node_x[upthrown_nodes]

#Illustrate the grid
imshow_node_grid(mg,
                 'topographic__elevation',
                 cmap='jet',
                 grid_units=['m', 'm'])
show()

#Instantiate the diffusion component:
linear_diffuse = LinearDiffuser(grid=mg,
                                input_stream='./diffusion_input_file.txt')

#Set boundary conditions
mg.set_closed_boundaries_at_grid_edges(False, True, False, True)

#set a model timestep
#(the component will subdivide this as needed to keep things stable)
dt = 2000.

#Evolve landscape
for i in range(25):
    linear_diffuse.diffuse(dt)

#Plot new landscape
figure()
imshow_node_grid(mg,
Beispiel #5
0
topo=Dataset('topography_wrf_hydro.nc')
topography=topo.variables['TOPOGRAPHY'][:]
topographic__elevation=np.asarray(topography, dtype=float).ravel()
mg.add_field('node', 'topographic__elevation', topographic__elevation) #create the field


#set boundary conditions -- these should match those used in the topography creation driver
for edge in (mg.nodes_at_left_edge, mg.nodes_at_right_edge):
    mg.status_at_node[edge] = CLOSED_BOUNDARY
for edge in (mg.nodes_at_top_edge, mg.nodes_at_bottom_edge):
    mg.status_at_node[edge] = FIXED_VALUE_BOUNDARY

#instantiate the components
fr = FlowRouter(mg)
sp = StreamPowerEroder(mg, input_file)
lin_diffuse = LinearDiffuser(mg, input_file)

print( 'Running ...' )
time_on = time.time()

#text for discharge file names
streamflow = "streamflow"
nc = ".nc"

elapsed_time = 0. #total time in simulation

#create list of all discharge files to be used, repeat as many times as necessary for run time.
#Example: here we have a total of 20 discharge files -- we need one file for every time step and we have 100 timesteps. 
# We will repeat the discharge file namelist 5 times Run Time = 100 yrs dt = 1yr 
rep_num = int(5) #depends on how many discharge files/time steps you have
discharge_filename=[streamflow + repr(j) + nc for k in range(rep_num) for j in range(1,21)]
Beispiel #6
0
z = mg.create_node_array_zeros() + leftmost_elev
z += initial_slope * np.amax(mg.node_y) - initial_slope * mg.node_y
# put these values plus roughness into that field
mg.at_node['topographic__elevation'] = z + np.random.rand(len(z)) / 100000.

# set up grid's boundary conditions (bottom, right, top, left is inactive)
mg.set_closed_boundaries_at_grid_edges(False, True, False, True)

# Display a message
print('Running ...')

# instantiate the components:
fr = FlowRouter(mg)
sp = SPEroder(mg, input_file)
diffuse = PerronNLDiffuse(mg, input_file)
lin_diffuse = LinearDiffuser(grid=mg, input_stream=input_file)

# 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']),
Beispiel #7
0
def run_model(input_file=None,
              savepath=None,
              initial_topo_file=None,
              initial_seed_file=None):
    from landlab.components.flow_routing.route_flow_dn_JL import FlowRouter
    from landlab.components.stream_power.fastscape_stream_power_JL import FastscapeEroder
    #from landlab.components.stream_power.stream_power import StreamPowerEroder
    from landlab.components.sink_fill.pit_fill_pf import PitFiller
    from landlab.components.diffusion.diffusion import LinearDiffuser
    from landlab import ModelParameterDictionary
    #from landlab.plot import channel_profile as prf
    from landlab.plot.imshow import imshow_node_grid
    from landlab.io.esri_ascii import write_esri_ascii
    from landlab.io.esri_ascii import read_esri_ascii
    from landlab import RasterModelGrid

    #from analysis_method import analyze_drainage_percentage
    #from analysis_method import analyze_drainage_percentage_each_grid
    #from analysis_method import analyze_mean_erosion
    #from analysis_method import elev_diff_btwn_moraine_upland
    #from analysis_method import label_catchment
    #from analysis_method import cross_section
    #from analysis_method import analyze_node_below_threshold
    #from analysis_method import identify_drained_area
    #from analysis_method import save_result
    from analysis_method import shiftColorMap

    import copy
    import numpy as np
    import matplotlib
    import matplotlib.pyplot as plt
    import os
    import time
    import sys
    import shutil

    sys.setrecursionlimit(5000)

    #===============================================================================
    #get the needed properties to build the grid:
    if input_file is None:
        input_file = './coupled_params_sp.txt'
    inputs = ModelParameterDictionary(input_file)
    nrows = inputs.read_int('nrows')
    ncols = inputs.read_int('ncols')
    dx = inputs.read_float('dx')
    initial_slope = inputs.read_float('initial_slope')
    rightmost_elevation = initial_slope * ncols * dx
    #rightmost_elevation = inputs.read_float('rightmost_elevation')
    uplift_rate = inputs.read_float('uplift_rate')
    incision_rate = inputs.read_float('incision_rate')
    runtime = inputs.read_float('total_time')
    dt = inputs.read_float('dt')
    nt = int(runtime // dt)
    k_sp = inputs.read_float('K_sp')
    m_sp = inputs.read_float('m_sp')
    uplift_per_step = uplift_rate * dt
    incision_per_step = incision_rate * dt
    moraine_height = inputs.read_float('moraine_height')
    moraine_width = inputs.read_float('moraine_width')
    #valley_width = inputs.read_float('valley_width')
    valley_depth = inputs.read_float('valley_depth')
    num_outs = inputs.read_int('number_of_outputs')
    output_interval = int(nt // num_outs)
    diff = inputs.read_float('linear_diffusivity')
    #threshold_stream_power = inputs.read_float('threshold_stream_power')
    threshold_AS = inputs.read_float('threshold_AS')
    #threshold_erosion = dt*threshold_stream_power
    gw_coeff = inputs.read_float('gw_coeff')
    all_dry = inputs.read_bool('all_dry')
    fill_sink_with_water = inputs.read_bool('fill_sink_with_water')
    #===============================================================================

    #===============================================================================
    if initial_topo_file is None:
        #instantiate the grid object
        mg = RasterModelGrid(nrows, ncols, dx)

        ##create the elevation field in the grid:
        #create the field
        #specifically, this field has a triangular ramp
        #moraine at the north edge of the domain.
        mg.add_zeros('node', 'topographic__elevation', units='m')
        z = mg.at_node['topographic__elevation']
        moraine_start_y = np.max(mg.node_y) - moraine_width
        moraine_ys = np.where(mg.node_y > moraine_start_y)
        z[moraine_ys] += (mg.node_y[moraine_ys] - np.min(
            mg.node_y[moraine_ys])) * (moraine_height / moraine_width)

        #set valley
        #valley_start_x = np.min(mg.node_x)+valley_width
        #valley_ys = np.where((mg.node_x<valley_start_x)&(mg.node_y<moraine_start_y-valley_width))
        #z[valley_ys] -= (np.max(mg.node_x[valley_ys])-mg.node_x[valley_ys])*(valley_depth/valley_width)

        #set ramp (towards valley)
        upland = np.where(mg.node_y < moraine_start_y)
        z[upland] -= (np.max(mg.node_x[upland]) -
                      mg.node_x[upland]) * (rightmost_elevation / (ncols * dx))
        z += rightmost_elevation

        #set ramp (away from moraine)
        #upland = np.where(mg.node_y<moraine_start_y)
        #z[upland] -= (moraine_start_y-mg.node_y[upland])*initial_slope

        #put these values plus roughness into that field
        if initial_seed_file is None:
            z += np.random.rand(len(z)) / 1
        else:
            (seedgrid,
             seed) = read_esri_ascii(initial_seed_file,
                                     name='topographic__elevation_seed')
            z += seed
        mg.at_node['topographic__elevation'] = z

        #set river valley
        river_valley, = np.where(
            np.logical_and(
                mg.node_x == 0,
                np.logical_or(mg.status_at_node == 1, mg.status_at_node == 2)))
        mg.at_node['topographic__elevation'][river_valley] = -valley_depth
    else:
        (mg, z) = read_esri_ascii(initial_topo_file,
                                  name='topographic__elevation')

    #set river valley
    river_valley, = np.where(
        np.logical_and(
            mg.node_x == 0,
            np.logical_or(mg.status_at_node == 1, mg.status_at_node == 2)))
    mg.at_node['topographic__elevation'][river_valley] = -valley_depth

    #set up grid's boundary conditions (right, top, left, bottom) is inactive
    mg.set_closed_boundaries_at_grid_edges(True, True, False, True)

    #set up boundary along moraine
    #moraine_start_y = np.max(mg.node_y)-moraine_width
    #bdy_moraine_ids = np.where((mg.node_y > moraine_start_y) & (mg.node_x == 0))
    #mg.status_at_node[bdy_moraine_ids]=4
    #mg._update_links_nodes_cells_to_new_BCs()
    #===============================================================================

    #===============================================================================
    #instantiate the components:
    fr = FlowRouter(mg)
    pf = PitFiller(mg)
    sp = FastscapeEroder(mg, input_file, threshold_sp=threshold_AS * k_sp)
    #sp = StreamPowerEroder(mg, input_file, threshold_sp=threshold_erosion, use_Q=True)
    #diffuse = PerronNLDiffuse(mg, input_file)
    #lin_diffuse = LinearDiffuser(mg, input_file, method='on_diagonals')
    lin_diffuse = LinearDiffuser(mg, input_file)
    #===============================================================================

    #===============================================================================
    #instantiate plot setting
    plt.close('all')
    output_time = output_interval
    plot_num = 0
    mycmap = shiftColorMap(matplotlib.cm.gist_earth, 'mycmap')

    #folder name
    if savepath is None:
        if all_dry:
            name_tag = 'All_dry'
        elif fill_sink_with_water:
            name_tag = 'Not_all_dry_no_sink'
        else:
            name_tag = 'Not_all_dry_sink'
        savepath = 'results/sensitivity_test_threshold_same_seed/'+name_tag+'_dt=' + str(dt) + '_total_time=' + str(runtime) + '_k_sp=' + str(k_sp) + \
                '_uplift_rate=' + str(uplift_rate) + '_incision_rate=' + str(incision_rate) + '_initial_slope=' + str(initial_slope) + \
                '_threshold=' + str(threshold_stream_power)
    if not os.path.isdir(savepath):
        os.makedirs(savepath)

    #copy params_file
    if not os.path.isfile(savepath + '/coupled_params_sp.txt'):
        shutil.copy(input_file, savepath + '/coupled_params_sp.txt')

    # Display a message
    print 'Running ...'
    print savepath

    #save initial topography
    write_esri_ascii(savepath + '/Topography_t=0.0.txt', mg,
                     'topographic__elevation')

    #time
    start_time = time.time()
    #===============================================================================

    #===============================================================================
    #perform the loops:
    for i in xrange(nt):
        #note the input arguments here are not totally standardized between modules
        ''' 
        # simulate changing climate
        if (((i+1)*dt // 5000.) % 2) == 0.:
            all_dry = False
        else:
            all_dry = True
        '''

        #sp = FastscapeEroder(mg, input_file, threshold_sp = threshold_stream_power)

        #update elevation
        mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_per_step
        mg.at_node['topographic__elevation'][river_valley] -= incision_per_step

        #mg = lin_diffuse.diffuse(dt)

        #route and erode
        original_topo = mg.at_node['topographic__elevation'].copy()
        slope = mg.at_node['topographic__steepest_slope'].copy()
        filled_nodes = None
        if all_dry or fill_sink_with_water:
            mg = pf.pit_fill()
            filled_nodes, = np.where(
                (mg.at_node['topographic__elevation'] - original_topo) > 0)
        mg = fr.route_flow(routing_flat=all_dry)
        old_topo = mg.at_node['topographic__elevation'].copy()
        #mg, temp_z, temp_sp = sp.erode(mg, dt, Q_if_used='water__volume_flux')
        mg = sp.erode(mg, dt, flooded_nodes=filled_nodes)

        new_topo = mg.at_node['topographic__elevation'].copy()
        mg.at_node[
            'topographic__elevation'] = original_topo + new_topo - old_topo

        #diffuse
        #for j in range(10):
        #    mg = lin_diffuse.diffuse(dt/10)
        mg = lin_diffuse.diffuse(dt)

        if i + 1 == output_time:
            print 'Saving data...'

            plot_num += 1
            plt.figure(plot_num)
            im = imshow_node_grid(mg, 'topographic__elevation', plot_name='t = '+str(int((i+1)*dt))+' years', \
                grid_units = ['m','m'], cmap=mycmap, allow_colorbar=True, \
                vmin=0-valley_depth-incision_rate*runtime, vmax=5.+moraine_height+uplift_rate*runtime)
            plt.savefig(savepath + '/Topography_t=' + str(
                (i + 1) * dt) + '.jpg',
                        dpi=300)

            write_esri_ascii(
                savepath + '/Topography_t=' + str((i + 1) * dt) + '.txt', mg,
                'topographic__elevation')

            output_time += output_interval

        plt.close('all')

        print("--- %.2f minutes ---" %
              ((time.time() - start_time) / 60)), 'Completed loop', i + 1

    plt.close('all')

    print 'Finished simulating.'
    #===============================================================================

    #===============================================================================
    #analyze_drainage_percentage(savepath, True)
    #analyze_mean_erosion(savepath, True)
    #elev_diff_btwn_moraine_upland(savepath, True)
    #label_catchment(savepath)
    #cross_section(savepath)
    #===============================================================================

    print 'Done!'
    print '\n'
z = mg.add_zeros('node', 'topographic__elevation')

#Check the size of the array
len(z)

#Create a diagonal fault across the grid
fault_y = 50.0 + 0.25*mg.node_x
upthrown_nodes = numpy.where(mg.node_y>fault_y)
z[upthrown_nodes] += 10.0 + 0.01*mg.node_x[upthrown_nodes]

#Illustrate the grid
imshow_node_grid(mg, 'topographic__elevation', cmap='jet', grid_units=['m','m'])
show()

#Instantiate the diffusion component:
linear_diffuse = LinearDiffuser(grid=mg, input_stream='./diffusion_input_file.txt')

#Set boundary conditions
mg.set_closed_boundaries_at_grid_edges(False, True, False, True)

#set a model timestep
#(the component will subdivide this as needed to keep things stable)
dt = 2000.

#Evolve landscape
for i in range(25):
    linear_diffuse.diffuse(dt)

#Plot new landscape
figure()
imshow_node_grid(mg, 'topographic__elevation', cmap='jet', grid_units=['m','m'])
Beispiel #9
0
dt = inputs.read_float('dt')
time_to_run = inputs.read_float('run_time')
init_elev = inputs.read_float('init_elev')
uplift_rate = inputs.read_float('uplift_rate')

mg = RasterModelGrid(nrows, ncols, dx)

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

mg.set_fixed_value_boundaries_at_grid_edges(True, True, True, True)

#instantiate:
dfn = LinearDiffuser(mg, './diffusion_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
    dfn.diffuse(dt)
    mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_rate*dt
    elapsed_time += dt

pylab.figure(1)
im = imshow_node_grid(mg, 'topographic__elevation')  # display a colored image
Beispiel #10
0
dt = inputs.read_float('dt')
time_to_run = inputs.read_float('run_time')
init_elev = inputs.read_float('init_elev')
uplift_rate = inputs.read_float('uplift_rate')

mg = RasterModelGrid(nrows, ncols, dx)

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

mg.set_fixed_value_boundaries_at_grid_edges(True, True, True, True)

#instantiate:
dfn = LinearDiffuser(mg, './diffusion_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
    dfn.diffuse(dt)
    mg.at_node['topographic__elevation'][mg.core_nodes] += uplift_rate * dt
    elapsed_time += dt

pylab.figure(1)
im = imshow_node_grid(mg, 'topographic__elevation')  # display a colored image
mg = RasterModelGrid((nrows, ncols), dx)
z = mg.add_zeros('node', 'topographic__elevation')
# add some roughness as the initial topography, this lets "natural" channel planforms arise
initial_roughness = np.random.rand(z.size) / 100000.
z += initial_roughness

#set the boundary conditions - here we have closed boundaries at the top/bottom and fixed boundaries at the left/right
for edge in (mg.nodes_at_left_edge, mg.nodes_at_right_edge):
    mg.status_at_node[edge] = FIXED_VALUE_BOUNDARY
for edge in (mg.nodes_at_top_edge, mg.nodes_at_bottom_edge):
    mg.status_at_node[edge] = CLOSED_BOUNDARY

#instantiate the components
fr = FlowRouter(mg, input_file)
sp = StreamPowerEroder(mg, input_file)
lin_diffuse = LinearDiffuser(mg, input_file)

#run the model
elapsed_time = 0.  #total time in simulation
for i in range(nt):
    lin_diffuse.run_one_step(dt)
    fr.run_one_step(
    )  # route_flow isn't time sensitive, so it doesn't take dt as input
    sp.run_one_step(dt)
    mg.at_node['topographic__elevation'][
        mg.core_nodes] += uplift_per_step  # add the uplift

    # if you want to see the evolution of the topogrpahy through time (say to check for steady state) you can output a topography at each time step
    #write_netcdf(('topography_output'+ str(elapsed_time) +'.nc'), mg, names='topographic__elevation')

    elapsed_time += dt