def main(): # First we will create an instance of PrecipitationDistribution PD = PrecipitationDistribution() # Because the values for storm duration, interstorm duration, storm # depth and intensity are set stochastically in the initialization # phase, we should see that they seem reasonable. print("Mean storm duration is: ", PD.mean_storm, " hours, while the value from the Poisson distribution is: ", PD.storm_duration) print("Mean interstorm Duration is: ", PD.mean_interstorm, 'hours, while the value from the Poisson distribution is: ', PD.interstorm_duration) print("Mean storm depth is: ", PD.mean_storm_depth, 'mm, while the value from the Poisson distribution is: ', PD.storm_depth) print("Mean intensity is: ", PD.mean_intensity, 'mm/hr, while the value from the Poisson distribution is: ', PD.intensity) print('\n') # If we update the values, we can verify they are changing. PD.update() print("Storm Duration is: ", PD.storm_duration, 'hours.') print("Interstorm Duration is: ", PD.interstorm_duration, 'hours.') print("Storm Depth is: ", PD.storm_depth, 'mm.') print("Intensity is: ", PD.intensity, 'mm.') # If we generate a time series we can plot a precipitation distribution PD.get_storm_time_series() # And get the storm array from the component.. storm_arr = PD.storm_time_series # And now to call the plotting method. create_precip_plot(storm_arr)
def main(): """ do some stuff """ # User-defined parameter values nr = 5 nc = 6 nnodes = nr*nc dx=1 #instantiate grid rg = landlab.RasterModelGrid(nr, nc, dx) #rg.set_inactive_boundaries(False, False, True, True) nodata_val=0 elevations = 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] elevations[helper]=2 helper = [19,20,21,22] elevations[helper]=3 elevations[7]=1 # Get a 2D array version of the elevations elev_raster = rg.node_vector_to_raster(elevations,True) of=OverlandFlow('input_data.txt',rg,0) rainfall = PrecipitationDistribution() rainfall.initialize('input_data.txt') rainfall.update #for now this is in hours, so put into seconds storm_duration = rainfall.storm_duration*3600 #in mm/hour, so convert to m/second storm_intensity = rainfall.intensity/1000/3600 print "storm duration, seconds ", storm_duration print "storm duration, hours ", rainfall.storm_duration print "storm intensity ", storm_intensity tau = of.run_one_step(rg,elevations,storm_duration,storm_intensity)
def main(): """ do some stuff """ # User-defined parameter values nr = 5 nc = 6 nnodes = nr * nc dx = 1 #instantiate grid rg = landlab.RasterModelGrid(nr, nc, dx) #rg.set_inactive_boundaries(False, False, True, True) nodata_val = 0 elevations = 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] elevations[helper] = 2 helper = [19, 20, 21, 22] elevations[helper] = 3 elevations[7] = 1 # Get a 2D array version of the elevations elev_raster = rg.node_vector_to_raster(elevations, True) of = OverlandFlow('input_data.txt', rg, 0) rainfall = PrecipitationDistribution() rainfall.initialize('input_data.txt') rainfall.update #for now this is in hours, so put into seconds storm_duration = rainfall.storm_duration * 3600 #in mm/hour, so convert to m/second storm_intensity = rainfall.intensity / 1000 / 3600 print "storm duration, seconds ", storm_duration print "storm duration, hours ", rainfall.storm_duration print "storm intensity ", storm_intensity tau = of.run_one_step(rg, elevations, storm_duration, storm_intensity)
def main(): # First we will create an instance of PrecipitationDistribution PD = PrecipitationDistribution() # Because the values for storm duration, interstorm duration, storm # depth and intensity are set stochastically in the initialization # phase, we should see that they seem reasonable. print "Mean storm duration is: ", PD.mean_storm, " hours, while the value from the Poisson distribution is: ", PD.storm_duration print "Mean interstorm Duration is: ", PD.mean_interstorm, 'hours, while the value from the Poisson distribution is: ', PD.interstorm_duration print "Mean storm depth is: ", PD.mean_storm_depth, 'mm, while the value from the Poisson distribution is: ', PD.storm_depth print "Mean intensity is: ", PD.mean_intensity, 'mm/hr, while the value from the Poisson distribution is: ', PD.intensity print '\n' # If we update the values, we can verify they are changing. PD.update() print "Storm Duration is: ", PD.storm_duration, 'hours.' print "Interstorm Duration is: ", PD.interstorm_duration, 'hours.' print "Storm Depth is: ", PD.storm_depth, 'mm.' print "Intensity is: ", PD.intensity, 'mm.' # If we generate a time series we can plot a precipitation distribution PD.get_storm_time_series() # And get the storm array from the component.. storm_arr = PD.storm_time_series # And now to call the plotting method. create_precip_plot(storm_arr)
def main(): print 'We are going to use TrialRun as our class instance.' TrialRun = PrecipitationDistribution() print 'TrialRun = PrecipitationDistribution()' print '\n' print "TrialRun's values before initiation..." print "Storm Duration is: ", TrialRun.storm_duration, 'hours.' print "Interstorm Duration is: ", TrialRun.interstorm_duration, 'hours.' print "Storm Depth is: ", TrialRun.storm_depth, 'mm.' print "Intensity is: ", TrialRun.intensity, 'mm/hr.' print '\n' print 'We should initialize TrialRun... TrialRun.initialize()' TrialRun.initialize() print '\n' print 'What are the mean values read in from the input file?' print "Mean Storm Duration is: ", TrialRun.mean_storm, 'hours.' print "Interstorm Duration is: ", TrialRun.mean_interstorm, 'hours.' print "Storm Depth is: ", TrialRun.mean_storm_depth, 'mm.' print "Intensity is: ", TrialRun.mean_intensity, 'mm/hr.' print '\n' print "Let's see what what the class members are after the first initialization..." print "Storm Duration is: ", TrialRun.storm_duration, 'hours.' print "Interstorm Duration is: ", TrialRun.interstorm_duration, 'hours.' print "Storm Depth is: ", TrialRun.storm_depth, 'mm.' print "Intensity is: ", TrialRun.intensity, 'mm/hr.' print '\n' print 'Now we will update these values using TrialRun.update()' TrialRun.update() print "Storm Duration is: ", TrialRun.storm_duration, 'hours.' print "Interstorm Duration is: ", TrialRun.interstorm_duration, 'hours.' print "Storm Depth is: ", TrialRun.storm_depth, 'mm.' print "Intensity is: ", TrialRun.intensity, 'mm.' print '\n' print 'Now we are going to generate a time series:' TrialRun.get_storm_time_series() print TrialRun.storm_time_series
## Plant types are defined as following: # GRASS = 0; SHRUB = 1; TREE = 2; BARE = 3; # SHRUBSEEDLING = 4; TREESEEDLING = 5 ## Assign plant type for representative ecohydrologic simulations grid['cell']['VegetationType'] = np.arange(0,6) ## Create input dictionary from text file InputFile = 'Inputs_Vegetation_CA.txt' data = txt_data_dict( InputFile ) # Create dictionary that holds the inputs # Create rainfall, radiation, potential evapotranspiration, # soil moisture and Vegetation objects # Assign parameters to the components PD_D = PrecipitationDistribution(mean_storm = data['mean_storm_dry'], \ mean_interstorm = data['mean_interstorm_dry'], mean_storm_depth = data['mean_storm_depth_dry']) PD_W = PrecipitationDistribution(mean_storm = data['mean_storm_wet'], \ mean_interstorm = data['mean_interstorm_wet'], mean_storm_depth = data['mean_storm_depth_wet']) Rad = Radiation( grid ) PET_Tree = PotentialEvapotranspiration( grid1, method = data['PET_method'], \ MeanTmaxF = data['MeanTmaxF_tree'], DeltaD = data['DeltaD'] ) PET_Shrub = PotentialEvapotranspiration( grid1, method = data['PET_method'], \ MeanTmaxF = data['MeanTmaxF_shrub'], DeltaD = data['DeltaD'] ) PET_Grass = PotentialEvapotranspiration( grid1, method = data['PET_method'], \ MeanTmaxF = data['MeanTmaxF_grass'], DeltaD = data['DeltaD'] )
""" import os from matplotlib import pyplot as plt from landlab.components.uniform_precip.generate_uniform_precip import PrecipitationDistribution from landlab.components.fire_generator.generate_fire import FireGenerator import numpy as np from math import ceil # Input text file name and location filename = os.path.join(os.path.dirname(__file__), 'fireraininput.txt') # Initializing the PrecipitationDistribution class using the default file # and getting the time series needed for comparison against the fire time series. Rain = PrecipitationDistribution(filename) Rain.get_storm_time_series() storm = Rain.storm_time_series # Initializing the FireGenerator class using the default file and getting the # time series needed for comparison against the precipitation time series. # As an additional step, we should find the scale parameter and set it. # The default value is set to 0. Fire = FireGenerator(filename) Fire.get_scale_parameter() Fire.generate_fire_time_series() fires = Fire.fire_events ## Methods used to find these potentially erosion-inducing events.
def main(): """ initialize DEM Get storm info Generate hydrograph """ start_time = time.time() dem_name = 'HalfFork.asc' input_file = 'input_data.txt' IT_FILE = os.path.join(os.path.dirname(__file__), input_file) # Create and initialize a raster model grid by reading a DEM DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name) print('Reading data from "' + str(DATA_FILE) + '"') (rg, z) = read_esri_ascii(DATA_FILE) nodata_val = -9999 # Modify the grid DEM to set all nodata nodes to inactive boundaries rg.set_nodata_nodes_to_inactive( z, nodata_val) # set nodata nodes to inactive bounds print('DEM has ' + str(rg.number_of_node_rows) + ' rows, ' + str(rg.number_of_node_columns) + ' columns, and cell size ' + str(rg.dx)) # Select point to sample at. #study_row = 110 #study_column = 150 # #study_node = rg.grid_coords_to_node_id(study_row, study_column) ## Set outlet point to set boundary conditions. the_outlet_row = 240 the_outlet_column = 215 the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row, the_outlet_column) rg.set_fixed_value_boundaries(the_outlet_node) # Get a 2D array version of the elevations for plotting purposes elev_raster = rg.node_vector_to_raster(z, True) # Everything below plots the topography and sampling points # levels = [] # x_up = 1990 # while x_up !=2200: # levels.append(x_up) # x_up+=1 # plt.figure('Topography') # plt.contourf(elev_raster, levels, colors='k')#('r','g','b')) # plt.set_cmap('bone') # plt.colorbar() # # plt.plot([150],[109],'cs', label= 'Study Node') # plt.plot([215],[9], 'wo', label= 'Outlet') # plt.legend(loc=3) pd = PrecipitationDistribution() pd.initialize() duration_hrs = pd.storm_duration intensity_mmhr = pd.intensity duration_secs = duration_hrs * 60.0 * 60.0 intensity_ms = ((intensity_mmhr / 1000.0) / 3600.0) total_duration_secs = 1.25 * duration_secs #print 'total_duration_secs: ', total_duration_secs of = OverlandFlow() #IT_FILE,rg,0) of.initialize(rg) ## (-,-,-,-,how long we route overland flow, intensity in m/s, duration of storm) ## ## Trial 1, 10 year storm ## #of.flow_at_one_node(rg,z,study_node,900,(7.167*(10**-6)), 2916) #of.flow_at_one_node(rg, z, study_node,9000, (1.384*(10**-5)), 2916) #of.flow_at_one_node(rg, z, study_node,900, (7.06*(10**-6)), 900) #of.plot_at_one_node() of.flow_across_grid(rg, z, 5800, (9.2177 * (10**-6)), 5868) #of.flow_at_one_node(rg,z,study_node,150,(9.2177*(10**-6)),5868) of.plot_water_depths(rg) of.plot_discharge(rg) of.plot_shear_stress_grid(rg) of.plot_slopes(rg) #rg.display_grid() endtime = time.time() print endtime - start_time, "seconds" plt.show() plt.show() plt.show()
(grid1, elevation) = read_esri_ascii(_DEFAULT_INPUT_FILE_1) grid1['node']['Elevation'] = elevation grid = rmg(5, 4, 5) grid['node']['Elevation'] = 1700. * np.ones(grid.number_of_nodes) grid1['cell']['VegetationType'] = np.random.randint(0, 4, grid1.number_of_cells) # Age of the plants is randomnly generated by the constructor of vegca # component. Seedlings of shrubs and trees are determined by their age # within the constructor as well. Hence the random vegetation type # field is called for types GRASS, SHRUB, TREE and BARE only. -SN 10Mar15 grid['cell']['VegetationType'] = np.arange(0, 6) # Create radiation, soil moisture and Vegetation objects PD_D = PrecipitationDistribution(mean_storm = data['mean_storm_dry'], \ mean_interstorm = data['mean_interstorm_dry'], mean_storm_depth = data['mean_storm_depth_dry']) PD_W = PrecipitationDistribution(mean_storm = data['mean_storm_wet'], \ mean_interstorm = data['mean_interstorm_wet'], mean_storm_depth = data['mean_storm_depth_wet']) Rad = Radiation(grid) PET_Tree = PotentialEvapotranspiration( grid1, method = data['PET_method'], \ MeanTmaxF = data['MeanTmaxF_tree'], DeltaD = data['DeltaD'] ) PET_Shrub = PotentialEvapotranspiration( grid1, method = data['PET_method'], \ MeanTmaxF = data['MeanTmaxF_shrub'], DeltaD = data['DeltaD'] ) PET_Grass = PotentialEvapotranspiration( grid1, method = data['PET_method'], \ MeanTmaxF = data['MeanTmaxF_grass'], DeltaD = data['DeltaD'] )
def main(): """ initialize DEM Get storm info Generate hydrograph """ start_time = time.time() dem_name = 'HalfFork.asc' input_file = 'input_data.txt' IT_FILE = os.path.join(os.path.dirname(__file__), input_file) # Create and initialize a raster model grid by reading a DEM DATA_FILE = os.path.join(os.path.dirname(__file__), dem_name) print('Reading data from "'+str(DATA_FILE)+'"') (rg, z) = read_esri_ascii(DATA_FILE) nodata_val=-9999 # Modify the grid DEM to set all nodata nodes to inactive boundaries rg.set_nodata_nodes_to_inactive(z, nodata_val) # set nodata nodes to inactive bounds print('DEM has ' + str(rg.number_of_node_rows) + ' rows, ' + str(rg.number_of_node_columns) + ' columns, and cell size ' + str(rg.dx)) # Select point to sample at. #study_row = 110 #study_column = 150 # #study_node = rg.grid_coords_to_node_id(study_row, study_column) ## Set outlet point to set boundary conditions. the_outlet_row = 240 the_outlet_column = 215 the_outlet_node = rg.grid_coords_to_node_id(the_outlet_row, the_outlet_column) rg.set_fixed_value_boundaries(the_outlet_node) # Get a 2D array version of the elevations for plotting purposes elev_raster = rg.node_vector_to_raster(z,True) # Everything below plots the topography and sampling points # levels = [] # x_up = 1990 # while x_up !=2200: # levels.append(x_up) # x_up+=1 # plt.figure('Topography') # plt.contourf(elev_raster, levels, colors='k')#('r','g','b')) # plt.set_cmap('bone') # plt.colorbar() # # plt.plot([150],[109],'cs', label= 'Study Node') # plt.plot([215],[9], 'wo', label= 'Outlet') # plt.legend(loc=3) pd = PrecipitationDistribution() pd.initialize() duration_hrs = pd.storm_duration intensity_mmhr = pd.intensity duration_secs = duration_hrs*60.0*60.0 intensity_ms = ((intensity_mmhr/1000.0)/3600.0) total_duration_secs = 1.25 * duration_secs #print 'total_duration_secs: ', total_duration_secs of=OverlandFlow()#IT_FILE,rg,0) of.initialize(rg) ## (-,-,-,-,how long we route overland flow, intensity in m/s, duration of storm) ## ## Trial 1, 10 year storm ## #of.flow_at_one_node(rg,z,study_node,900,(7.167*(10**-6)), 2916) #of.flow_at_one_node(rg, z, study_node,9000, (1.384*(10**-5)), 2916) #of.flow_at_one_node(rg, z, study_node,900, (7.06*(10**-6)), 900) #of.plot_at_one_node() of.flow_across_grid(rg, z, 5800, (9.2177*(10**-6)), 5868) #of.flow_at_one_node(rg,z,study_node,150,(9.2177*(10**-6)),5868) of.plot_water_depths(rg) of.plot_discharge(rg) of.plot_shear_stress_grid(rg) of.plot_slopes(rg) #rg.display_grid() endtime = time.time() print endtime - start_time, "seconds" plt.show() plt.show() plt.show()
""" import os from matplotlib import pyplot as plt from landlab.components.uniform_precip.generate_uniform_precip import PrecipitationDistribution from landlab.components.fire_generator.generate_fire import FireGenerator import numpy as np from math import ceil # Input text file name and location filename = os.path.join(os.path.dirname(__file__), 'fireraininput.txt') # Initializing the PrecipitationDistribution class using the default file # and getting the time series needed for comparison against the fire time series. Rain = PrecipitationDistribution(filename) Rain.get_storm_time_series() storm= Rain.storm_time_series # Initializing the FireGenerator class using the default file and getting the # time series needed for comparison against the precipitation time series. # As an additional step, we should find the scale parameter and set it. # The default value is set to 0. Fire = FireGenerator(filename) Fire.get_scale_parameter() Fire.generate_fire_time_series() fires = Fire.fire_events ## Methods used to find these potentially erosion-inducing events.
mg['node'][ 'topographic__elevation'] = z + numpy.random.rand(len(z))/1000. mg.add_zeros('node', 'water__volume_flux_in') #make some K values in a field to test #mg.at_node['K_values'] = 0.1+numpy.random.rand(nrows*ncols)/10. mg.at_node['K_values'] = numpy.empty(nrows*ncols, dtype=float) #mg.at_node['K_values'].fill(0.1+numpy.random.rand()/10.) mg.at_node['K_values'].fill(0.001) print( 'Running ...' ) #instantiate the components: fr = FlowRouter(mg) sp = StreamPowerEroder(mg, input_file_string) #fsp = Fsc(mg, input_file_string) precip = PrecipitationDistribution(input_file=input_file_string) #load the Fastscape module too, to allow direct comparison fsp = Fsc(mg, input_file_string) 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.:
## Written by Jordan Marie Adams ## Last updated: October 29, 2013 import os from matplotlib import pyplot as plt from landlab.components.uniform_precip.generate_uniform_precip import PrecipitationDistribution from landlab.components.fire_generator.generate_fire import FireGenerator import numpy as np from math import ceil ## INPUT TXT FILE WITH NECESSARY PARAMETERS ## filename = os.path.join(os.path.dirname(__file__), 'fireraininput.txt') ## INITIALIZING THE CLASSES IN LANDLAB ## Rain = PrecipitationDistribution() Rain.initialize(filename) Rain.get_storm_time_series() ## UNITS IN DAYS storm= Rain.storm_time_series Fire = FireGenerator() Fire.initialize(filename) Fire.get_scale_parameter() Fire.generate_fire_time_series() fires = Fire.fire_events ## FUNCTIONS TO GET POTENTIAL EROSION EVENTS ## set_threshold() ## ## ## GETS THRESHOLD BASED ON
## Written by Jordan Marie Adams ## Last updated: October 29, 2013 import os from matplotlib import pyplot as plt from landlab.components.uniform_precip.generate_uniform_precip import PrecipitationDistribution from landlab.components.fire_generator.generate_fire import FireGenerator import numpy as np from math import ceil ## INPUT TXT FILE WITH NECESSARY PARAMETERS ## filename = os.path.join(os.path.dirname(__file__), 'fireraininput.txt') ## INITIALIZING THE CLASSES IN LANDLAB ## Rain = PrecipitationDistribution() Rain.initialize(filename) Rain.get_storm_time_series() ## UNITS IN DAYS storm = Rain.storm_time_series Fire = FireGenerator() Fire.initialize(filename) Fire.get_scale_parameter() Fire.generate_fire_time_series() fires = Fire.fire_events ## FUNCTIONS TO GET POTENTIAL EROSION EVENTS ## set_threshold() ## ## ## GETS THRESHOLD BASED ON