def main():
    nr = 5
    nc = 6
    nnodes = nr*nc
    dx=3
    #instantiate grid
    rg = RasterModelGrid(nr, nc, dx)
    #rg.set_inactive_boundaries(False, False, True, True)
    
    nodata_val=-1
    z  = nodata_val*np.ones( nnodes )    
    #set-up interior elevations with random numbers
    #for i in range(0, nnodes):
    #    if rg.is_interior(i):
    #        elevations[i]=random.random_sample()
    
    #set-up with prescribed elevations to test drainage area calcualtion
    helper = [7,8,9,10,13,14,15,16]
    for i in xrange(0, len(helper)):
        #print 'helper[i]', helper[i]
        z[helper[i]]=2+uniform(-0.5,0.5)
    helper = [19,20,21,22]
    for i in xrange(0, len(helper)):
        z[helper[i]]=3+uniform(-0.5,0.5)
        
    z[7]=1
    
    bc=WatershedBoundaryConditions()
    bc.set_bc_find_outlet(rg, z, nodata_val)
    
    #instantiate variable of type RouteFlowD8 Class
    flow_router = RouteFlowD8(len(z))
    #initial flow direction
    flowdirs, max_slopes = flow_router.calc_flowdirs(rg,z)
    #insantiate variable of type AccumFlow Class
    accumulator = AccumFlow(rg)
    #initial flow accumulation
    drain_area = accumulator.calc_flowacc(rg, z, flowdirs)
    
    print "elevations ", rg.node_vector_to_raster(z)
    print "flowdirs ", rg.node_vector_to_raster(flowdirs)
    print "drain_area ", rg.node_vector_to_raster(drain_area)
Beispiel #2
0
def main():
    nr = 5
    nc = 6
    nnodes = nr * nc
    dx = 3
    #instantiate grid
    rg = RasterModelGrid(nr, nc, dx)
    #rg.set_inactive_boundaries(False, False, True, True)

    nodata_val = -1
    z = nodata_val * np.ones(nnodes)
    #set-up interior elevations with random numbers
    #for i in range(0, nnodes):
    #    if rg.is_interior(i):
    #        elevations[i]=random.random_sample()

    #set-up with prescribed elevations to test drainage area calcualtion
    helper = [7, 8, 9, 10, 13, 14, 15, 16]
    for i in xrange(0, len(helper)):
        #print 'helper[i]', helper[i]
        z[helper[i]] = 2 + uniform(-0.5, 0.5)
    helper = [19, 20, 21, 22]
    for i in xrange(0, len(helper)):
        z[helper[i]] = 3 + uniform(-0.5, 0.5)

    z[7] = 1

    bc = WatershedBoundaryConditions()
    bc.set_bc_find_outlet(rg, z, nodata_val)

    #instantiate variable of type RouteFlowD8 Class
    flow_router = RouteFlowD8(len(z))
    #initial flow direction
    flowdirs, max_slopes = flow_router.calc_flowdirs(rg, z)
    #insantiate variable of type AccumFlow Class
    accumulator = AccumFlow(rg)
    #initial flow accumulation
    drain_area = accumulator.calc_flowacc(rg, z, flowdirs)

    print "elevations ", rg.node_vector_to_raster(z)
    print "flowdirs ", rg.node_vector_to_raster(flowdirs)
    print "drain_area ", rg.node_vector_to_raster(drain_area)
    def run_one_storm(self, grid, z, rainrate=None, storm_dur=None):

        if rainrate==None:
            rainrate = self.rainfall_myr
        if storm_dur==None:
            storm_dur = self.rain_duration_yr

        m=self.m
        n=self.n
        K=self.K
        frac = self.frac

        #interior_nodes are the nodes on which you will be calculating incision
        interior_nodes = grid.get_active_cell_node_ids()

        #instantiate variable of type RouteFlowD8 Class
        flow_router = RouteFlowD8(len(z))
        #initial flow direction
        flowdirs, max_slopes = flow_router.calc_flowdirs(grid,z)
        #print "elevations in runonestorm ",grid.node_vector_to_raster(z)
        #insantiate variable of type AccumFlow Class
        accumulator = AccumFlow(grid)
        #initial flow accumulation
        drain_area = accumulator.calc_flowacc(grid, z, flowdirs)

        time=0
        dt = storm_dur
        while time < storm_dur:
            #Calculate incision rate, should be in m/yr, should be negative
            #First make sure that there are no negative (uphill slopes)
            #Set those to zero, because incision rate should be zero there.
            max_slopes.clip(0)
            I=-K*np.power(rainrate*drain_area,m)*np.power(max_slopes,n)

            #print "incision rates ",grid.node_vector_to_raster(I)
            #print "flow dirs ",grid.node_vector_to_raster(flowdirs)
            #print "max slopes ",grid.node_vector_to_raster(max_slopes)
            #print "drainage area ", grid.node_vector_to_raster(drain_area)

            #Do a time-step check
            #If the downstream node is eroding at a slower rate than the
            #upstream node, there is a possibility of flow direction reversal,
            #or at least a flattening of the landscape.
            #Limit dt so that this flattening or reversal doesn't happen.
            #How close you allow these two points to get to eachother is
            #determined by the variable frac.
            for i in interior_nodes:
                dzdtdif = I[flowdirs[i]]-I[i]
                if dzdtdif > 0:
                    dtmin = frac*(z[i]-z[flowdirs[i]])/dzdtdif
                    #Nic do you need a test here to make sure that dtmin
                    #isn't too small?  Trying that out
                    if dtmin < dt:
                        if dtmin>0.001*dt:
                            dt = dtmin
                        else:
                            dt = 0.001*dt

            #should now have a stable timestep.
            #reduce elevations.
            z=I*dt+z

            #update elapsed time
            time=dt+time

            #check to see that you are within 0.01% of time
            #if so, done
            #otherwise, reset everything for next loop

            if time > 0.9999*storm_dur:
                #done!
                time = storm_dur
            else:
                #not done, reset everything
                #update time step to maximum possible
                dt = storm_dur - time
                #recalculate flow directions
                flowdirs, max_slopes = flow_router.calc_flowdirs(grid,z)
                #recalculate drainage area
                drain_area = accumulator.calc_flowacc(grid, z, flowdirs)

        return z
Beispiel #4
0
def main():
    nr = 5
    nc = 6
    nnodes = nr * nc
    dx = 1
    #instantiate grid
    rg = RasterModelGrid(nr, nc, dx)
    #rg.set_inactive_boundaries(False, False, True, True)

    nodata_val = -1
    z = nodata_val * np.ones(nnodes)
    #set-up interior elevations with random numbers
    #for i in range(0, nnodes):
    #    if rg.is_interior(i):
    #        elevations[i]=random.random_sample()

    #set-up elevations
    helper = [7, 8, 9, 10, 13, 14, 15, 16]
    for i in xrange(0, len(helper)):
        #print 'helper[i]', helper[i]
        z[helper[i]] = 2 + uniform(-0.5, 0.5)
    helper = [19, 20, 21, 22]
    for i in xrange(0, len(helper)):
        z[helper[i]] = 3 + uniform(-0.5, 0.5)

    z[7] = 1

    #set up boundary conditions
    bc = WatershedBoundaryConditions()
    outlet_loc = bc.set_bc_find_outlet(rg, z, nodata_val)
    zoutlet = z[outlet_loc]

    #some helper and parameter values
    total_run_time = 500000  #yr
    uplift_rate = 0.001  #m/yr
    rain_rate = 1  #m/yr
    storm_duration = 50  #years

    elapsed_time = 0  #years

    #set up fluvial incision component
    incisor = PowerLawIncision('input_file.txt', rg)

    #print "elevations before ", rg.node_vector_to_raster(z)
    #interior_nodes are the nodes on which you will be operating
    interior_nodes = rg.get_active_cell_node_ids()

    while elapsed_time < total_run_time:
        #uplift the landscape
        z[interior_nodes] = z[interior_nodes] + uplift_rate * storm_duration
        z[outlet_loc] = zoutlet
        #erode the landscape
        z = incisor.run_one_storm(rg, z, rain_rate, storm_duration)
        #update the time
        elapsed_time = elapsed_time + storm_duration

    #below purely for plotting reasons
    #instantiate variable of type RouteFlowD8 Class
    flow_router = RouteFlowD8(len(z))
    #initial flow direction
    flowdirs, max_slopes = flow_router.calc_flowdirs(rg, z)
    #insantiate variable of type AccumFlow Class
    accumulator = AccumFlow(rg)
    #initial flow accumulation
    drain_area = accumulator.calc_flowacc(rg, z, flowdirs)

    #m,b = polyfit(log10(drain_area[interior_nodes]), log10(max_slopes[interior_nodes]), 1)
    z[interior_nodes] = z[interior_nodes] + uplift_rate * storm_duration
    z[outlet_loc] = zoutlet

    plt.loglog(
        np.array(drain_area),
        np.array(max_slopes),
        'ro',
    )
    plt.show()
    imshow_grid(rg, z, values_at='node')
def main():
    nr = 5
    nc = 6
    nnodes = nr*nc
    dx=1
    #instantiate grid
    rg = RasterModelGrid(nr, nc, dx)
    #rg.set_inactive_boundaries(False, False, True, True)

    nodata_val=-1
    z  = nodata_val*np.ones( nnodes )
    #set-up interior elevations with random numbers
    #for i in range(0, nnodes):
    #    if rg.is_interior(i):
    #        elevations[i]=random.random_sample()

    #set-up elevations
    helper = [7,8,9,10,13,14,15,16]
    for i in xrange(0, len(helper)):
        #print 'helper[i]', helper[i]
        z[helper[i]]=2+uniform(-0.5,0.5)
    helper = [19,20,21,22]
    for i in xrange(0, len(helper)):
        z[helper[i]]=3+uniform(-0.5,0.5)

    z[7]=1

    #set up boundary conditions
    bc=WatershedBoundaryConditions()
    outlet_loc = bc.set_bc_find_outlet(rg, z, nodata_val)
    zoutlet=z[outlet_loc]

    #some helper and parameter values
    total_run_time = 500000 #yr
    uplift_rate = 0.001 #m/yr
    rain_rate = 1 #m/yr
    storm_duration = 50 #years

    elapsed_time = 0 #years

    #set up fluvial incision component
    incisor = PowerLawIncision('input_file.txt',rg)

    #print "elevations before ", rg.node_vector_to_raster(z)
    #interior_nodes are the nodes on which you will be operating
    interior_nodes = rg.get_active_cell_node_ids()

    while elapsed_time < total_run_time:
        #uplift the landscape
        z[interior_nodes] = z[interior_nodes]+uplift_rate * storm_duration
        z[outlet_loc]=zoutlet
        #erode the landscape
        z = incisor.run_one_storm(rg,z,rain_rate,storm_duration)
        #update the time
        elapsed_time = elapsed_time+storm_duration

    #below purely for plotting reasons
    #instantiate variable of type RouteFlowD8 Class
    flow_router = RouteFlowD8(len(z))
    #initial flow direction
    flowdirs, max_slopes = flow_router.calc_flowdirs(rg,z)
    #insantiate variable of type AccumFlow Class
    accumulator = AccumFlow(rg)
    #initial flow accumulation
    drain_area = accumulator.calc_flowacc(rg, z, flowdirs)

    #m,b = polyfit(log10(drain_area[interior_nodes]), log10(max_slopes[interior_nodes]), 1)
    z[interior_nodes] = z[interior_nodes]+uplift_rate * storm_duration
    z[outlet_loc]=zoutlet

    plt.loglog(np.array(drain_area),np.array(max_slopes),'ro',)
    plt.show()
    imshow_grid(rg,z, values_at='node')
def main():
    nr = 50
    nc = 60
    nnodes = nr*nc
    dx=10
    #instantiate grid
    rg = RasterModelGrid(nr, nc, dx)
    rg.set_inactive_boundaries(False, True, True, True)
    
    z  = np.zeros( nnodes )    
    #set-up interior elevations with random numbers
    for i in range(0, nnodes):
        if rg.is_interior(i):
            z[i]=2+uniform(-0.5,0.5)
    
    #some helper and parameter values
    total_run_time = 10000 #yr
    one_twentieth_time = total_run_time/20
    uplift_rate = 0.001 #m/yr
    rain_rate = 1 #m/yr
    storm_duration = 50 #years
    
    elapsed_time = 0 #years
    
    #set up fluvial incision component
    incisor = PowerLawIncision('input_file.txt',rg)
    
    #print "elevations before ", rg.node_vector_to_raster(z)
    #interior_nodes are the nodes on which you will be operating
    interior_nodes = rg.get_active_cell_node_ids()
    
    while elapsed_time < total_run_time:  
        #erode the landscape
        z = incisor.run_one_storm(rg,z,rain_rate,storm_duration)
        #uplift the landscape
        z[interior_nodes] = z[interior_nodes]+uplift_rate * storm_duration
        #update the time
        elapsed_time = elapsed_time+storm_duration
        #print "elapsed_time", elapsed_time
        if elapsed_time%one_twentieth_time == 0:
            print("elapsed time",elapsed_time)
            elev_raster = rg.node_vector_to_raster(z,True)
            # Plot topography
            pylab.figure(22)
            im = pylab.imshow(elev_raster, cmap=pylab.cm.RdBu, extent=[0, nc*rg.dx, 0, nr*rg.dx])
            cb = pylab.colorbar(im)
            cb.set_label('Elevation (m)', fontsize=12)
            pylab.title('Topography')
            pylab.show()
    
    #below purely for plotting reasons
    #instantiate variable of type RouteFlowD8 Class
    flow_router = RouteFlowD8(len(z))
    #initial flow direction
    flowdirs, max_slopes = flow_router.calc_flowdirs(rg,z)
    #insantiate variable of type AccumFlow Class
    accumulator = AccumFlow(rg)
    #initial flow accumulation
    drain_area = accumulator.calc_flowacc(rg, z, flowdirs)
    
    plt.loglog(np.array(drain_area),np.array(max_slopes),'ro',)
    plt.xlabel('drainage area, m')
    plt.ylabel('surface slope')
    plt.show()
    
    elev_raster = rg.node_vector_to_raster(z,True)
    # Plot topography
    pylab.figure(22)
    im = pylab.imshow(elev_raster, cmap=pylab.cm.RdBu, extent=[0, nc*rg.dx, 0, nr*rg.dx])
    cb = pylab.colorbar(im)
    cb.set_label('Elevation (m)', fontsize=12)
    pylab.title('Topography')
    
    pylab.show()    
Beispiel #7
0
def main():
    nr = 50
    nc = 60
    nnodes = nr * nc
    dx = 10
    #instantiate grid
    rg = RasterModelGrid(nr, nc, dx)
    rg.set_inactive_boundaries(False, True, True, True)

    z = np.zeros(nnodes)
    #set-up interior elevations with random numbers
    for i in range(0, nnodes):
        if rg.is_interior(i):
            z[i] = 2 + uniform(-0.5, 0.5)

    #some helper and parameter values
    total_run_time = 10000  #yr
    one_twentieth_time = total_run_time / 20
    uplift_rate = 0.001  #m/yr
    rain_rate = 1  #m/yr
    storm_duration = 50  #years

    elapsed_time = 0  #years

    #set up fluvial incision component
    incisor = PowerLawIncision('input_file.txt', rg)

    #print "elevations before ", rg.node_vector_to_raster(z)
    #interior_nodes are the nodes on which you will be operating
    interior_nodes = rg.get_active_cell_node_ids()

    while elapsed_time < total_run_time:
        #erode the landscape
        z = incisor.run_one_storm(rg, z, rain_rate, storm_duration)
        #uplift the landscape
        z[interior_nodes] = z[interior_nodes] + uplift_rate * storm_duration
        #update the time
        elapsed_time = elapsed_time + storm_duration
        #print "elapsed_time", elapsed_time
        if elapsed_time % one_twentieth_time == 0:
            print "elapsed time", elapsed_time
            elev_raster = rg.node_vector_to_raster(z, True)
            # Plot topography
            pylab.figure(22)
            im = pylab.imshow(elev_raster,
                              cmap=pylab.cm.RdBu,
                              extent=[0, nc * rg.dx, 0, nr * rg.dx])
            cb = pylab.colorbar(im)
            cb.set_label('Elevation (m)', fontsize=12)
            pylab.title('Topography')
            pylab.show()

    #below purely for plotting reasons
    #instantiate variable of type RouteFlowD8 Class
    flow_router = RouteFlowD8(len(z))
    #initial flow direction
    flowdirs, max_slopes = flow_router.calc_flowdirs(rg, z)
    #insantiate variable of type AccumFlow Class
    accumulator = AccumFlow(rg)
    #initial flow accumulation
    drain_area = accumulator.calc_flowacc(rg, z, flowdirs)

    plt.loglog(
        np.array(drain_area),
        np.array(max_slopes),
        'ro',
    )
    plt.xlabel('drainage area, m')
    plt.ylabel('surface slope')
    plt.show()

    elev_raster = rg.node_vector_to_raster(z, True)
    # Plot topography
    pylab.figure(22)
    im = pylab.imshow(elev_raster,
                      cmap=pylab.cm.RdBu,
                      extent=[0, nc * rg.dx, 0, nr * rg.dx])
    cb = pylab.colorbar(im)
    cb.set_label('Elevation (m)', fontsize=12)
    pylab.title('Topography')

    pylab.show()
 def run_one_storm(self, grid, z, rainrate=None, storm_dur=None):
     
     if rainrate==None:
         rainrate = self.rainfall_myr
     if storm_dur==None:
         storm_dur = self.rain_duration_yr
         
     m=self.m
     n=self.n
     K=self.K
     frac = self.frac
     
     #interior_nodes are the nodes on which you will be calculating incision 
     interior_nodes = grid.get_active_cell_node_ids()
     
     #instantiate variable of type RouteFlowD8 Class
     flow_router = RouteFlowD8(len(z))
     #initial flow direction
     flowdirs, max_slopes = flow_router.calc_flowdirs(grid,z)
     #print "elevations in runonestorm ",grid.node_vector_to_raster(z)
     #insantiate variable of type AccumFlow Class
     accumulator = AccumFlow(grid)
     #initial flow accumulation
     drain_area = accumulator.calc_flowacc(grid, z, flowdirs)
     
     time=0
     dt = storm_dur
     while time < storm_dur:
         #Calculate incision rate, should be in m/yr, should be negative
         #First make sure that there are no negative (uphill slopes)
         #Set those to zero, because incision rate should be zero there.
         max_slopes.clip(0)
         I=-K*np.power(rainrate*drain_area,m)*np.power(max_slopes,n)
         
         #print "incision rates ",grid.node_vector_to_raster(I)
         #print "flow dirs ",grid.node_vector_to_raster(flowdirs)
         #print "max slopes ",grid.node_vector_to_raster(max_slopes)
         #print "drainage area ", grid.node_vector_to_raster(drain_area)
         
         #Do a time-step check
         #If the downstream node is eroding at a slower rate than the 
         #upstream node, there is a possibility of flow direction reversal,
         #or at least a flattening of the landscape. 
         #Limit dt so that this flattening or reversal doesn't happen.
         #How close you allow these two points to get to eachother is
         #determined by the variable frac.
         for i in interior_nodes:
             dzdtdif = I[flowdirs[i]]-I[i]
             if dzdtdif > 0:
                 dtmin = frac*(z[i]-z[flowdirs[i]])/dzdtdif
                 #Nic do you need a test here to make sure that dtmin 
                 #isn't too small?  Trying that out
                 if dtmin < dt:
                     if dtmin>0.001*dt:
                         dt = dtmin
                     else:
                         dt = 0.001*dt
         
         #should now have a stable timestep.
         #reduce elevations.
         z=I*dt+z
         
         #update elapsed time
         time=dt+time
         
         #check to see that you are within 0.01% of time
         #if so, done
         #otherwise, reset everything for next loop
         
         if time > 0.9999*storm_dur:
             #done!
             time = storm_dur
         else:
             #not done, reset everything
             #update time step to maximum possible
             dt = storm_dur - time
             #recalculate flow directions
             flowdirs, max_slopes = flow_router.calc_flowdirs(grid,z)
             #recalculate drainage area
             drain_area = accumulator.calc_flowacc(grid, z, flowdirs)
     
     return z