def instantiate_rain_generator(self): """Instantiate RainGenerator.""" # Handle option for duration. self.opt_stochastic_duration = (self.params['opt_stochastic_duration']) if self.opt_stochastic_duration: self.rain_generator = \ PrecipitationDistribution(mean_storm_duration=self.params['mean_storm_duration'], mean_interstorm_duration=self.params['mean_interstorm_duration'], mean_storm_depth=self.params['mean_storm_depth'], total_t=self.params['run_duration'], delta_t=self.params['dt'], random_seed=int(self.params['random_seed'])) self.run_for = self.run_for_stochastic # override base method else: from scipy.special import gamma mean_storm__intensity = (self._length_factor) * self.params[ 'mean_storm__intensity'] # has units length per time intermittency_factor = self.params['intermittency_factor'] self.rain_generator = \ PrecipitationDistribution(mean_storm_duration=1.0, mean_interstorm_duration=1.0, mean_storm_depth=1.0, random_seed=int(self.params['random_seed'])) self.intermittency_factor = intermittency_factor self.mean_storm__intensity = mean_storm__intensity self.shape_factor = self.params['precip_shape_factor'] self.scale_factor = (self.mean_storm__intensity / gamma(1.0 + (1.0 / self.shape_factor))) self.n_sub_steps = int(self.params['number_of_sub_time_steps'])
def instantiate_rain_generator(self): """Instantiate component used to generate storm sequence.""" # Handle option for duration. if self.opt_stochastic_duration: self.rain_generator = PrecipitationDistribution( mean_storm_duration=self.mean_storm_duration, mean_interstorm_duration=self.mean_interstorm_duration, mean_storm_depth=self.mean_storm_depth, total_t=self.clock.stop, delta_t=self.clock.step, random_seed=self.seed, ) self.run_for = self.run_for_stochastic # override base method else: from scipy.special import gamma self.rain_generator = PrecipitationDistribution( mean_storm_duration=1.0, mean_interstorm_duration=1.0, mean_storm_depth=1.0, random_seed=self.seed, ) self.scale_factor = self.rainfall__mean_rate / gamma( 1.0 + (1.0 / self.shape_factor)) if (isinstance(self.number_of_sub_time_steps, (int, np.integer)) is False): raise ValueError( ("number_of_sub_time_steps must be of type integer.")) self.n_sub_steps = self.number_of_sub_time_steps
def initialize(data, grid, grid1): """Initialize random plant type field. Plant types are defined as the following: * GRASS = 0 * SHRUB = 1 * TREE = 2 * BARE = 3 * SHRUBSEEDLING = 4 * TREESEEDLING = 5 """ grid1.at_cell['vegetation__plant_functional_type'] = compose_veg_grid( grid1, percent_bare=data['percent_bare_initial'], percent_grass=data['percent_grass_initial'], percent_shrub=data['percent_shrub_initial'], percent_tree=data['percent_tree_initial']) # Assign plant type for representative ecohydrologic simulations grid.at_cell['vegetation__plant_functional_type'] = np.arange(6) grid1.at_node['topographic__elevation'] = np.full(grid1.number_of_nodes, 1700.) grid.at_node['topographic__elevation'] = np.full(grid.number_of_nodes, 1700.) precip_dry = PrecipitationDistribution( mean_storm_duration=data['mean_storm_dry'], mean_interstorm_duration=data['mean_interstorm_dry'], mean_storm_depth=data['mean_storm_depth_dry']) precip_wet = PrecipitationDistribution( mean_storm_duration=data['mean_storm_wet'], mean_interstorm_duration=data['mean_interstorm_wet'], mean_storm_depth=data['mean_storm_depth_wet']) radiation = Radiation(grid) pet_tree = PotentialEvapotranspiration(grid, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_tree'], delta_d=data['DeltaD']) pet_shrub = PotentialEvapotranspiration(grid, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_shrub'], delta_d=data['DeltaD']) pet_grass = PotentialEvapotranspiration(grid, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_grass'], delta_d=data['DeltaD']) soil_moisture = SoilMoisture(grid, **data) # Soil Moisture object vegetation = Vegetation(grid, **data) # Vegetation object vegca = VegCA(grid1, **data) # Cellular automaton object # Initializing inputs for Soil Moisture object grid.at_cell['vegetation__live_leaf_area_index'] = ( 1.6 * np.ones(grid.number_of_cells)) grid.at_cell['soil_moisture__initial_saturation_fraction'] = ( 0.59 * np.ones(grid.number_of_cells)) return (precip_dry, precip_wet, radiation, pet_tree, pet_shrub, pet_grass, soil_moisture, vegetation, vegca)
def Initialize_(data, grid, grid1): # Plant types are defined as following: # GRASS = 0; SHRUB = 1; TREE = 2; BARE = 3; # SHRUBSEEDLING = 4; TREESEEDLING = 5 # Initialize random plant type field grid1['cell']['vegetation__plant_functional_type'] = compose_veg_grid( grid1, percent_bare=data['percent_bare_initial'], percent_grass=data['percent_grass_initial'], percent_shrub=data['percent_shrub_initial'], percent_tree=data['percent_tree_initial']) # Assign plant type for representative ecohydrologic simulations grid['cell']['vegetation__plant_functional_type'] = np.arange(0, 6) grid1['node']['topographic__elevation'] = (1700. * np.ones(grid1.number_of_nodes)) grid['node']['topographic__elevation'] = (1700. * np.ones(grid.number_of_nodes)) PD_D = PrecipitationDistribution( mean_storm_duration=data['mean_storm_dry'], mean_interstorm_duration=data['mean_interstorm_dry'], mean_storm_depth=data['mean_storm_depth_dry']) PD_W = PrecipitationDistribution( mean_storm_duration=data['mean_storm_wet'], mean_interstorm_duration=data['mean_interstorm_wet'], mean_storm_depth=data['mean_storm_depth_wet']) Rad = Radiation(grid) PET_Tree = PotentialEvapotranspiration(grid, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_tree'], delta_d=data['DeltaD']) PET_Shrub = PotentialEvapotranspiration(grid, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_shrub'], delta_d=data['DeltaD']) PET_Grass = PotentialEvapotranspiration(grid, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_grass'], delta_d=data['DeltaD']) SM = SoilMoisture(grid, **data) # Soil Moisture object VEG = Vegetation(grid, **data) # Vegetation object vegca = VegCA(grid1, **data) # Cellular automaton object # # Initializing inputs for Soil Moisture object grid['cell']['vegetation__live_leaf_area_index'] = ( 1.6 * np.ones(grid.number_of_cells)) grid['cell']['soil_moisture__initial_saturation_fraction'] = ( 0.59 * np.ones(grid.number_of_cells)) # Initializing Soil Moisture return PD_D, PD_W, Rad, PET_Tree, PET_Shrub, PET_Grass, SM, \ VEG, vegca
def __init__(self, input_file=None, params=None): """Initialize the StochasticDischargeHortonianModel.""" # Call ErosionModel's init super(StochasticDischargeHortonianModel, self).__init__(input_file=input_file, params=params) # Instantiate components self.flow_router = FlowRouter(self.grid, **self.params) self.lake_filler = DepressionFinderAndRouter(self.grid, **self.params) self.rain_generator = \ PrecipitationDistribution(delta_t=self.params['dt'], total_time=self.params['run_duration'], **self.params) # Add a field for discharge if 'surface_water__discharge' not in self.grid.at_node: self.grid.add_zeros('node', 'surface_water__discharge') self.discharge = self.grid.at_node['surface_water__discharge'] # Get the infiltration-capacity parameter self.infilt = self.params['infiltration_capacity'] # Run flow routing and lake filler (only once, because we are not # not changing topography) self.flow_router.run_one_step() self.lake_filler.map_depressions()
def test_stoch_sp_raster_record_state(): """ Initialize HydrologyEventStreamPower on a raster grid. Use several storm-interstorm pairs and make sure state recorded as expected. """ mg = RasterModelGrid((3, 3), xy_spacing=10.0) mg.set_status_at_node_on_edges( right=mg.BC_NODE_IS_CLOSED, top=mg.BC_NODE_IS_CLOSED, left=mg.BC_NODE_IS_CLOSED, bottom=mg.BC_NODE_IS_FIXED_VALUE, ) mg.add_ones("node", "topographic__elevation") mg.add_zeros("node", "aquifer_base__elevation") wt = mg.add_ones("node", "water_table__elevation") gdp = GroundwaterDupuitPercolator(mg, recharge_rate=1e-6) pd = PrecipitationDistribution( mg, mean_storm_duration=10, mean_interstorm_duration=100, mean_storm_depth=1e-3, total_t=200, ) pd.seed_generator(seedval=1) hm = HydrologyEventStreamPower(mg, precip_generator=pd, groundwater_model=gdp) wt0 = wt.copy() hm.run_step_record_state() times = np.array([ 0.0, hm.storm_dts[0], hm.storm_dts[0] + hm.interstorm_dts[0], hm.storm_dts[0] + hm.interstorm_dts[0] + hm.storm_dts[1], hm.storm_dts[0] + hm.interstorm_dts[0] + hm.storm_dts[1] + hm.interstorm_dts[1], ]) intensities = np.zeros(5) intensities[0] = hm.intensities[0] intensities[2] = hm.intensities[1] assert_equal(hm.time, times) assert_equal(hm.intensity, intensities) assert_equal(hm.qs_all.shape, (5, 9)) assert_equal(hm.Q_all.shape, (5, 9)) assert_equal(hm.wt_all.shape, (5, 9)) assert_equal(hm.qs_all[0, :], np.zeros(9)) assert_equal(hm.Q_all[0, :], np.zeros(9)) assert_equal(hm.wt_all[0, :], wt0)
def test_stoch_sp_threshold_above_threshold(): """ Test the stochastic event model with stream power threshold in which the one core node is set up to exceed erosion threshold for the value of Q that it attains. This can be checked by comparing the accumulated q to the threshold value needed for erosion Q0. """ mg = RasterModelGrid((3, 3), xy_spacing=10.0) mg.set_status_at_node_on_edges( right=mg.BC_NODE_IS_CLOSED, top=mg.BC_NODE_IS_CLOSED, left=mg.BC_NODE_IS_CLOSED, bottom=mg.BC_NODE_IS_FIXED_VALUE, ) elev = mg.add_ones("node", "topographic__elevation") mg.add_zeros("node", "aquifer_base__elevation") wt = mg.add_ones("node", "water_table__elevation") elev[4] += 0.01 wt[:] = elev gdp = GroundwaterDupuitPercolator(mg, recharge_rate=1e-6) pd = PrecipitationDistribution( mg, mean_storm_duration=10, mean_interstorm_duration=100, mean_storm_depth=1e-3, total_t=100, ) pd.seed_generator(seedval=1) hm = HydrologyEventThresholdStreamPower( mg, precip_generator=pd, groundwater_model=gdp, sp_coefficient=1e-5, sp_threshold=1e-12, ) hm.run_step() storm_dt = 1.4429106411 # storm duration storm_q = 0.0244046740 # accumulated q before threshold effect subtracted interstorm_q = 0.0 # interstorm q is zero in this case assert_almost_equal( hm.q_eff[4], 0.5 * (max(interstorm_q - hm.Q0[4], 0) + max(storm_q - hm.Q0[4], 0)) * storm_dt / hm.T_h, )
def test_storms(): dt = 500.0 uplift = 0.0001 mean_duration = 100.0 mean_interstorm = 400.0 mean_depth = 5.0 storm_run_time = 3000000.0 delta_t = 500.0 mg = RasterModelGrid((10, 10), xy_spacing=1000.0) mg.add_zeros("topographic__elevation", at="node") z = mg.zeros(at="node") mg["node"]["topographic__elevation"] = z + np.random.rand(len(z)) / 1000.0 mg.add_zeros("water__unit_flux_in", at="node") precip = PrecipitationDistribution( mean_storm_duration=mean_duration, mean_interstorm_duration=mean_interstorm, mean_storm_depth=mean_depth, total_t=storm_run_time, delta_t=delta_t, ) fr = FlowAccumulator(mg, flow_director="D8") sp = StreamPowerEroder( mg, K_sp=0.0001, m_sp=0.5, n_sp=1.0, threshold_sp=1.0, discharge_field="surface_water__discharge", ) for ( interval_duration, rainfall_rate, ) in precip.yield_storm_interstorm_duration_intensity(): if rainfall_rate != 0.0: mg.at_node["water__unit_flux_in"].fill(rainfall_rate) fr.run_one_step() sp.run_one_step(dt) mg.at_node["topographic__elevation"][mg.core_nodes] += ( uplift * interval_duration)
def test_storms(): input_file_string = os.path.join(_THIS_DIR, "drive_sp_params_storms.txt") inputs = ModelParameterDictionary(input_file_string, auto_type=True) nrows = inputs.read_int("nrows") ncols = inputs.read_int("ncols") dx = inputs.read_float("dx") dt = inputs.read_float("dt") uplift = inputs.read_float("uplift_rate") mean_duration = inputs.read_float("mean_storm") mean_interstorm = inputs.read_float("mean_interstorm") mean_depth = inputs.read_float("mean_depth") storm_run_time = inputs.read_float("storm_run_time") delta_t = inputs.read_float("delta_t") mg = RasterModelGrid((nrows, ncols), xy_spacing=dx) mg.add_zeros("topographic__elevation", at="node") z = mg.zeros(at="node") mg["node"]["topographic__elevation"] = z + np.random.rand(len(z)) / 1000.0 mg.add_zeros("water__unit_flux_in", at="node") precip = PrecipitationDistribution( mean_storm_duration=mean_duration, mean_interstorm_duration=mean_interstorm, mean_storm_depth=mean_depth, total_t=storm_run_time, delta_t=delta_t, ) fr = FlowAccumulator(mg, flow_director="D8") sp = StreamPowerEroder(mg, **inputs) for ( interval_duration, rainfall_rate, ) in precip.yield_storm_interstorm_duration_intensity(): if rainfall_rate != 0.0: mg.at_node["water__unit_flux_in"].fill(rainfall_rate) fr.run_one_step() sp.run_one_step(dt) mg.at_node["topographic__elevation"][mg.core_nodes] += ( uplift * interval_duration)
def test_storms(): input_file_string = os.path.join(_THIS_DIR, 'drive_sp_params_storms.txt') inputs = ModelParameterDictionary(input_file_string, 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') mean_duration = inputs.read_float('mean_storm') mean_interstorm = inputs.read_float('mean_interstorm') mean_depth = inputs.read_float('mean_depth') storm_run_time = inputs.read_float('storm_run_time') delta_t = inputs.read_float('delta_t') 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( mean_storm_duration=mean_duration, mean_interstorm_duration=mean_interstorm, mean_storm_depth=mean_depth, total_t=storm_run_time, delta_t=delta_t) fr = FlowAccumulator(mg, flow_director='D8') 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) fr.run_one_step() sp.run_one_step(dt) mg.at_node['topographic__elevation'][ mg.core_nodes] += uplift * interval_duration
def test_stoch_sp_threshold_hex(): """ Initialize HydrologyEventStreamPower on a hex grid. Use single storm-interstorm pair and make sure it returns the quantity calculated. This is not an analytical solution, just the value that is returned when using gdp and adaptive timestep solver. Confirms that hex grid returns the same value as raster grid, adjusted for cell area. Confirms that when streampower threshold is zero (Default), returns the same values as HydrologyEventStreamPower. """ mg = HexModelGrid((3, 3), node_layout="rect", spacing=10.0) mg.status_at_node[mg.status_at_node == 1] = 4 mg.status_at_node[0] = 1 mg.add_ones("node", "topographic__elevation") mg.add_zeros("node", "aquifer_base__elevation") mg.add_ones("node", "water_table__elevation") gdp = GroundwaterDupuitPercolator(mg, recharge_rate=1e-6) pd = PrecipitationDistribution( mg, mean_storm_duration=10, mean_interstorm_duration=100, mean_storm_depth=1e-3, total_t=100, ) pd.seed_generator(seedval=1) hm = HydrologyEventThresholdStreamPower(mg, precip_generator=pd, groundwater_model=gdp, routing_method="Steepest") hm.run_step() assert_almost_equal(hm.q_eff[4], 0.00017614 * np.sqrt(3) / 2) assert_almost_equal( hm.q_an[4], 0.00017614 * np.sqrt(3) / 2 / np.sqrt(np.sqrt(3) / 2 * 100))
def test_stoch_sp_threshold_raster_null(): """ Initialize HydrologyEventThresholdStreamPower on a raster grid. Use single storm-interstorm pair and make sure it returns the quantity calculated. This is not an analytical solution, just the value that is returned when using gdp and adaptive timestep solver. Confirms that when streampower threshold is zero (Default), returns the same values as HydrologyEventStreamPower. """ mg = RasterModelGrid((3, 3), xy_spacing=10.0) mg.set_status_at_node_on_edges( right=mg.BC_NODE_IS_CLOSED, top=mg.BC_NODE_IS_CLOSED, left=mg.BC_NODE_IS_CLOSED, bottom=mg.BC_NODE_IS_FIXED_VALUE, ) mg.add_ones("node", "topographic__elevation") mg.add_zeros("node", "aquifer_base__elevation") mg.add_ones("node", "water_table__elevation") gdp = GroundwaterDupuitPercolator(mg, recharge_rate=1e-6) pd = PrecipitationDistribution( mg, mean_storm_duration=10, mean_interstorm_duration=100, mean_storm_depth=1e-3, total_t=100, ) pd.seed_generator(seedval=1) hm = HydrologyEventThresholdStreamPower(mg, precip_generator=pd, groundwater_model=gdp) hm.run_step() assert_almost_equal(hm.q_eff[4], 0.00017614) assert_almost_equal(hm.q_an[4], 0.00017614 / 10.0)
else: raise TypeError("grid should be Raster or Hex") gdp = GroundwaterDupuitPercolator( mg, porosity=n, hydraulic_conductivity=Ks, regularization_f=0.01, recharge_rate=0.0, courant_coefficient=0.05, vn_coefficient=0.05, callback_fun=write_SQ, ) pdr = PrecipitationDistribution(mg, mean_storm_duration=tr, mean_interstorm_duration=tb, mean_storm_depth=ds, total_t=T_h) pdr.seed_generator(seedval=2) hm = HydrologyEventStreamPower( mg, routing_method=method, precip_generator=pdr, groundwater_model=gdp, ) #run model hm.run_step_record_state() f.close()
rmg5.set_closed_boundaries_at_grid_edges(True, True, True, True) rmg5.status_at_node[1] = 1 rmg10.set_closed_boundaries_at_grid_edges(True, True, True, True) rmg10.status_at_node[1] = 1 link_to_sample = 200 sample_das = [201, 24048, 14834, 14268, 12097, 8035, 5022] # sample drainage areas ## GENERATE AND SET PRECIPITATION TIME SERIES total_t = 1000.* 365.25 * 24 # 1,000 years of rainfall generated. thresh = 0.5 # Intensity threshold (lower limit, mm/hr) PD = PrecipitationDistribution(mean_storm_duration = 10.75, mean_interstorm_duration=433.58, mean_storm_depth = 9.62, total_t=total_t) storm_arr = np.array(PD.get_storm_time_series()) intensity_threshold, = np.where(storm_arr[:, 2] > thresh) interstorm_durs = (storm_arr[intensity_threshold][:,0][np.arange(1, len(storm_arr[intensity_threshold]) - 1)] - storm_arr[intensity_threshold][:, 1][np.arange(0, len(storm_arr[intensity_threshold]) - 2)]) durations = (storm_arr[intensity_threshold][:,1] - storm_arr[intensity_threshold][:,0]) durations_s = [x * 3600. for x in durations]
base = grid.add_zeros('node', 'aquifer_base__elevation') base[:] = elev - b wt = grid.add_zeros('node', 'water_table__elevation') wt[:] = elev # initialize landlab and DupuitLEM components gdp = GroundwaterDupuitPercolator(grid, porosity=n, hydraulic_conductivity=ks, recharge_rate=0.0, vn_coefficient=0.5, courant_coefficient=0.5, ) pdr = PrecipitationDistribution(grid, mean_storm_duration=tr, mean_interstorm_duration=tb, mean_storm_depth=ds, total_t=Nt*(tr+tb)) pdr.seed_generator(seedval=1235) svm = SchenkVadoseModel( potential_evapotranspiration_rate=pet, available_relative_saturation=Srange, profile_depth=b, porosity=n, num_bins=Nz, ) hm = HydrologyEventVadoseStreamPower( grid, precip_generator=pdr, groundwater_model=gdp, vadose_model=svm,
def initialize_components(data, grid_veg=None, grid=None, pet_method='Cosine'): # Plant types are defined as following: # GRASS = 0; SHRUB = 1; TREE = 2; BARE = 3; # SHRUBSEEDLING = 4; TREESEEDLING = 5 # Initialize random plant type field grid.at_cell['vegetation__plant_functional_type'] = compose_veg_grid( grid, percent_bare=data['percent_bare_initial'], percent_grass=data['percent_grass_initial'], percent_shrub=data['percent_shrub_initial'], percent_tree=data['percent_tree_initial']) # Assign plant type for representative ecohydrologic simulations grid_veg.at_cell['vegetation__plant_functional_type'] = np.arange(0, 6) grid.at_node['topographic__elevation'] = np.full(grid.number_of_nodes, 1700.) grid_veg.at_node['topographic__elevation'] = np.full( grid_veg.number_of_nodes, 1700.) precip_dry = PrecipitationDistribution( mean_storm_duration=data['mean_storm_dry'], mean_interstorm_duration=data['mean_interstorm_dry'], mean_storm_depth=data['mean_storm_depth_dry'], random_seed=None) precip_wet = PrecipitationDistribution( mean_storm_duration=data['mean_storm_wet'], mean_interstorm_duration=data['mean_interstorm_wet'], mean_storm_depth=data['mean_storm_depth_wet'], random_seed=None) radiation = Radiation(grid_veg) if pet_method == 'Cosine': pet_tree = PotentialEvapotranspiration( grid_veg, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_tree'], delta_d=data['DeltaD']) pet_shrub = PotentialEvapotranspiration( grid_veg, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_shrub'], delta_d=data['DeltaD']) pet_grass = PotentialEvapotranspiration( grid_veg, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_grass'], delta_d=data['DeltaD']) elif pet_method == 'PriestleyTaylor': pet_met = PotentialEvapotranspiration(grid_veg, method='PriestleyTaylor') soil_moisture = SoilMoisture(grid_veg, **data) # Soil Moisture object vegetation = Vegetation(grid_veg, **data) # Vegetation object vegca = VegCA(grid, **data) # Cellular automaton object # # Initializing inputs for Soil Moisture object grid_veg.at_cell['vegetation__live_leaf_area_index'] = ( 1.6 * np.ones(grid_veg.number_of_cells)) grid_veg.at_cell['soil_moisture__initial_saturation_fraction'] = ( 0.59 * np.ones(grid_veg.number_of_cells)) # Initializing Soil Moisture if pet_method == 'Cosine': return (precip_dry, precip_wet, radiation, pet_tree, pet_shrub, pet_grass, soil_moisture, vegetation, vegca) elif pet_method == 'PriestleyTaylor': return (precip_dry, precip_wet, radiation, pet_met, soil_moisture, vegetation, vegca)
def initialize(data, grid, grid1, grid2, elevation): """Initialize random plant type field. Plant types are defined as the following: * GRASS = 0 * SHRUB = 1 * TREE = 2 * BARE = 3 * SHRUBSEEDLING = 4 * TREESEEDLING = 5 """ grid['cell']['vegetation__plant_functional_type'] = compose_veg_grid( grid, percent_bare=data['percent_bare_initial'], percent_grass=data['percent_grass_initial'], percent_shrub=data['percent_shrub_initial'], percent_tree=data['percent_tree_initial']) # Assign plant type for representative ecohydrologic simulations grid1.at_cell['vegetation__plant_functional_type'] = np.arange(6) grid1.at_node['topographic__elevation'] = np.full(grid1.number_of_nodes, 1700.) grid.at_node['topographic__elevation'] = elevation grid2.at_node['topographic__elevation'] = elevation if data['runon_switch']: (ordered_cells, grid2) = get_ordered_cells_for_soil_moisture( grid2, outlet_id=4877) # hugo10mws: 1331 # 36704 grid.at_node['flow__receiver_node'] = ( grid2.at_node['flow__receiver_node']) else: ordered_cells = None precip_dry = PrecipitationDistribution( mean_storm_duration=data['mean_storm_dry'], mean_interstorm_duration=data['mean_interstorm_dry'], mean_storm_depth=data['mean_storm_depth_dry'], random_seed=None) precip_wet = PrecipitationDistribution( mean_storm_duration=data['mean_storm_wet'], mean_interstorm_duration=data['mean_interstorm_wet'], mean_storm_depth=data['mean_storm_depth_wet'], random_seed=None) radiation = Radiation(grid) rad_pet = Radiation(grid1) pet_tree = PotentialEvapotranspiration(grid1, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_tree'], delta_d=data['DeltaD']) pet_shrub = PotentialEvapotranspiration(grid1, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_shrub'], delta_d=data['DeltaD']) pet_grass = PotentialEvapotranspiration(grid1, method=data['PET_method'], MeanTmaxF=data['MeanTmaxF_grass'], delta_d=data['DeltaD']) soil_moisture = SoilMoisture(grid, ordered_cells=ordered_cells, **data) # Soil Moisture object vegetation = Vegetation(grid, **data) # Vegetation object vegca = VegCA(grid, **data) # Cellular automaton object # # Initializing inputs for Soil Moisture object grid['cell']['vegetation__live_leaf_area_index'] = ( 1.6 * np.ones(grid.number_of_cells)) grid['cell']['soil_moisture__initial_saturation_fraction'] = ( 0.59 * np.ones(grid.number_of_cells)) # Initializing Soil Moisture return (precip_dry, precip_wet, radiation, rad_pet, pet_tree, pet_shrub, pet_grass, soil_moisture, vegetation, vegca, ordered_cells)
mg["node"]["topographic__elevation"] = z + numpy.random.rand(len(z)) / 1000. mg.add_zeros("node", "water__unit_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 = FlowAccumulator(mg, flow_director="D8") sp = StreamPowerEroder(mg, input_file_string) # fsp = FastscapeEroder(mg, input_file_string) precip = PrecipitationDistribution(input_file=input_file_string) # load the Fastscape module too, to allow direct comparison fsp = FastscapeEroder(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,
rmg5.set_closed_boundaries_at_grid_edges(True, True, True, True) rmg5.status_at_node[1] = 1 rmg10.set_closed_boundaries_at_grid_edges(True, True, True, True) rmg10.status_at_node[1] = 1 link_to_sample = 200 sample_das = [201, 24048, 14834, 14268, 12097, 8035, 5022] # sample drainage areas ## GENERATE AND SET PRECIPITATION TIME SERIES total_t = 1000. * 365.25 * 24 # 1,000 years of rainfall generated. thresh = 0.5 # Intensity threshold (lower limit, mm/hr) PD = PrecipitationDistribution(mean_storm_duration=11.75, mean_interstorm_duration=146.25, mean_storm_depth=4.775, total_t=total_t) storm_arr = np.array(PD.get_storm_time_series()) intensity_threshold, = np.where(storm_arr[:, 2] > thresh) interstorm_durs = (storm_arr[intensity_threshold][:, 0][np.arange( 1, len(storm_arr[intensity_threshold]) - 1)] - storm_arr[intensity_threshold][:, 1][np.arange( 0, len(storm_arr[intensity_threshold]) - 2)]) durations = (storm_arr[intensity_threshold][:, 1] - storm_arr[intensity_threshold][:, 0]) durations_s = [x * 3600. for x in durations]
grid = RasterModelGrid((125, 125), xy_spacing=v0) grid.set_status_at_node_on_edges(right=grid.BC_NODE_IS_CLOSED, top=grid.BC_NODE_IS_CLOSED, \ left=grid.BC_NODE_IS_FIXED_VALUE, bottom=grid.BC_NODE_IS_CLOSED) elev = grid.add_zeros('node', 'topographic__elevation') elev[:] = b + 0.1 * hg * np.random.rand(len(elev)) base = grid.add_zeros('node', 'aquifer_base__elevation') wt = grid.add_zeros('node', 'water_table__elevation') wt[:] = elev.copy() #initialize landlab components gdp = GroundwaterDupuitPercolator(grid, porosity=n, hydraulic_conductivity=ksat, \ regularization_f=0.01, recharge_rate=0.0, \ courant_coefficient=0.9, vn_coefficient = 0.9) pd = PrecipitationDistribution(grid, mean_storm_duration=tr, mean_interstorm_duration=tb, mean_storm_depth=ds, total_t=Th) pd.seed_generator(seedval=1235) ld = LinearDiffuser(grid, linear_diffusivity=D) #initialize other models hm = HydrologyEventStreamPower( grid, precip_generator=pd, groundwater_model=gdp, ) #use surface_water_area_norm__discharge (Q/sqrt(A)) for Theodoratos definitions sp = FastscapeEroder(grid, K_sp=Ksp,
import numpy as np from landlab.utils.depth_dependent_roughness import depth_dependent_mannings_n from matplotlib import pyplot as plt from landlab.plot import imshow_grid from scipy.stats import norm import time import matplotlib.pyplot as plt plt.rcParams["font.family"] = "Helvetica" plt.rcParams['font.size'] = 10 ## Generate 1000 year precipitation time series total_t = 1000.*365.25*24 lowRvar_PrecipDist = PrecipitationDistribution(mean_storm_duration = 11.75, mean_interstorm_duration = 146.25, mean_storm_depth = 4.775, total_t=total_t) highRvar_PrecipDist = PrecipitationDistribution(mean_storm_duration = 10.75, mean_interstorm_duration = 433.58, mean_storm_depth = 9.62, total_t=total_t) thresh = 0.5 # Get actual time series for the high Rvar case highRvar_storm_arr = np.array(highRvar_PrecipDist.get_storm_time_series()) highRvar_intensity_threshold, = np.where(highRvar_storm_arr[:, 2] > thresh) highRvar_durations = highRvar_storm_arr[highRvar_intensity_threshold][:,1]-highRvar_storm_arr[highRvar_intensity_threshold][:,0] highRvar_durations_s = [x *3600. for x in highRvar_durations]