def blackBox(self, rain, erodibility, m, n): """ Main entry point for running badlands model with different forcing conditions. The following forcing conditions can be used: - different uniform rain (uniform meaning same precipitation value on the entire region) - different uniform erodibility (uniform meaning same erodibility value on the entire region) Parameters ---------- variable: rain Requested uniform precipitation value. variable: erodibility Requested uniform erodibility value. variable: m, n Values of m and n indicate how the incision rate scales with bed shear stress for constant value of sediment flux and sediment transport capacity. Returns ------ variable: elev_vec Elevation as a 2D numpy array (regularly spaced dataset with resolution equivalent to simulation one) variable: erdp_vec Cumulative erosion/deposition accumulation as a 2D numpy array (regularly spaced as well) variable: erdp_pts_vec Cumulative erosion/deposition at particular co-ordinates on the grid stored in erdp_coords """ tstart = time.clock() # Re-initialise badlands model model = badlandsModel() # Load the XmL input file model.load_xml(str(self.run_nb), self.input, muted=self.muted) # Adjust erodibility based on given parameter model.input.SPLero = erodibility model.flow.erodibility.fill(erodibility) # Adjust precipitation values based on given parameter model.force.rainVal[:] = rain #Adjust m and n values model.input.SPLm = m model.input.SPLn = n elev_vec = collections.OrderedDict() erdp_vec = collections.OrderedDict() erdp_pts_vec = collections.OrderedDict() for x in range(len(self.sim_interval)): self.simtime = self.sim_interval[x] model.run_to_time(self.simtime, muted=self.muted) elev, erdp = self.interpolateArray(model.FVmesh.node_coords[:, :2], model.elevation, model.cumdiff) erdp_pts = np.zeros((self.erdp_coords.shape[0])) for count, val in enumerate(self.erdp_coords): erdp_pts[count] = erdp[val[0], val[1]] elev_vec[self.simtime] = elev erdp_vec[self.simtime] = erdp erdp_pts_vec[self.simtime] = erdp_pts # print 'Badlands black box model took (s):',time.clock()-tstart return elev_vec, erdp_vec, erdp_pts_vec
def blackBox(self, rain, erodibility, m , n, marinediff, aerialdiff): """ Main entry point for running badlands model with different forcing conditions. The following forcing conditions can be used: - different uniform rain (uniform meaning same precipitation value on the entire region) - different uniform erodibility (uniform meaning same erodibility value on the entire region) Parameters ---------- variable : inputname XML file defining the parameters used to run Badlands simulation. variable: rain Requested uniform precipitation value. variable: erodibility Requested uniform erodibility value. variable: etime Duration of the experiment. Return ------ The function returns 2D numpy arrays containing the following information: variable: elev Elevation as a 2D numpy array (regularly spaced dataset with resolution equivalent to simulation one) variable: erdp Cumulative erosion/deposition accumulation as a 2D numpy array (regularly spaced as well) """ tstart = time.clock() # Re-initialise badlands model model = badlandsModel() # Load the XmL input file model.load_xml(str(self.run_nb), self.input, muted = self.muted) # Adjust erodibility based on given parameter #model.input.SPLero = erodibility #model.flow.erodibility.fill(erodibility) # Adjust precipitation values based on given parameter model.force.rainVal[:] = rain #Adjust m and n values #model.input.SPLm = m #model.input.SPLn = n #model.input.CDm = marinediff #model.input.CDa = aerialdiff k=round(erodibility*2)/2 #Adjust the parameters by our value k, and save them out newFile = "Examples/mountain/temp2/uplift"+str(k)+".csv" model.input.tectFile[0]=newFile elev_vec = collections.OrderedDict() erdp_vec = collections.OrderedDict() erdp_pts_vec = collections.OrderedDict() for x in range(len(self.sim_interval)): self.simtime = self.sim_interval[x] model.run_to_time(self.simtime, muted = self.muted) elev, erdp = self.interpolateArray(model.FVmesh.node_coords[:, :2], model.elevation, model.cumdiff) erdp_pts = np.zeros((self.erdp_coords.shape[0])) for count, val in enumerate(self.erdp_coords): erdp_pts[count] = erdp[val[0], val[1]] elev_vec[self.simtime] = elev erdp_vec[self.simtime] = erdp erdp_pts_vec[self.simtime] = erdp_pts # print 'Badlands black box model took (s):',time.clock()-tstart return elev_vec, erdp_vec, erdp_pts_vec
def topoGenerator(directory, inputname, rain, erodibility, m, n, simtime, erdp_coords, final_noise): """ Parameters ---------- variable : directory variable: inputname variable: height variable: zmin variable: zmax variable: height variable: zData variable: title """ sim_interval = np.arange(0, simtime + 1, simtime / 4) model = badlandsModel() model.load_xml(str(simtime), inputname, verbose=False, muted=True) model.input.SPLero = erodibility model.flow.erodibility.fill(erodibility) model.force.rainVal[:] = rain model.input.SPLm = m model.input.SPLn = n # bPts = model.recGrid.boundsPt # print ('bPTs', bPts) # ePts = model.recGrid.edgesPt # print ('ePTs', ePts) # print(model.disp) # # model.force.disp[::bPts] = 0 # return elev_vec = collections.OrderedDict() erdp_vec = collections.OrderedDict() erdp_pts_vec = collections.OrderedDict() for x in range(len(sim_interval)): simtime = sim_interval[x] model.run_to_time(simtime, muted=True) elev, erdp = interpolateArray(model.FVmesh.node_coords[:, :2], model.elevation, model.cumdiff) erdp_pts = np.zeros((erdp_coords.shape[0])) for count, val in enumerate(erdp_coords): erdp_pts[count] = erdp[val[0], val[1]] # Adding Noise tausq_elev = elev.max() * (0.01) + 0.5 tausq_erdp = erdp.max() * (0.01) + 0.5 tausq_erdp_pts = erdp_pts.max() * (0.01) + 0.5 elev_noise = np.random.normal(0, np.sqrt(abs(tausq_elev)), elev.size) elev_noise = np.reshape(elev_noise, (elev.shape[0], elev.shape[1])) erdp_noise = np.random.normal(0, np.sqrt(abs(tausq_erdp)), erdp.size) erdp_noise = np.reshape(erdp_noise, (erdp.shape[0], erdp.shape[1])) erdp_pts_noise = np.random.normal(0, np.sqrt(abs(tausq_erdp_pts)), erdp_pts.size) erdp_pts_noise = np.reshape(erdp_pts_noise, (erdp_pts.shape)) elev_ = np.matrix(elev) erdp_ = np.matrix(erdp) erdp_pts_ = np.matrix(erdp_pts) if final_noise and simtime == sim_interval[-1]: elev_mat = np.add(elev_, elev_noise) erdp_mat = np.add(erdp_, erdp_noise) erdp_pts_mat = np.add(erdp_pts_, erdp_pts_noise) else: elev_mat = elev_ erdp_mat = erdp_ erdp_pts_mat = erdp_pts_ elev_vec[simtime] = elev_mat erdp_vec[simtime] = erdp_mat erdp_pts_vec[simtime] = erdp_pts_mat for k, v in elev_vec.items(): if k == sim_interval[0]: # np.savetxt('%s/data/initial_elev.txt' %directory, elev_vec[k],fmt='%.5f') viewGrid(directory, 'initial_elev', 'N/A', rain, erodibility, zData=elev_vec[k], title='Export Slope Grid') elif k == sim_interval[-1]: np.savetxt('%s/data/final_elev.txt' % directory, elev_vec[k], fmt='%.5f') viewGrid(directory, 'final_elev', 'N/A', rain, erodibility, zData=elev_vec[k], title='Export Slope Grid') for k, v in erdp_vec.items(): # if k == sim_interval[0]: # np.savetxt('%s/data/initial_erdp.txt' %directory, erdp_vec[k],fmt='%.5f') # viewMap(directory,'initial_erdp', 'N/A', rain, erodibility, zData=erdp_vec[k], title='Export Slope Grid') if k == sim_interval[-1]: np.savetxt('%s/data/final_erdp.txt' % directory, erdp_vec[k], fmt='%.5f') viewMap(directory, 'final_erdp', 'N/A', rain, erodibility, zData=erdp_vec[k], title='Export Slope Grid') erdp_pts_arr = np.zeros((sim_interval.size, erdp_pts_mat.size)) count = 0 for k, v in erdp_pts_vec.items(): erdp_pts_arr[count] = v count += 1 # if k == sim_interval[0]: # np.savetxt('%s/data/initial_erdp_pts.txt' %directory, erdp_pts_vec[k],fmt='%.5f') # viewBar(directory,'initial_erdp_pts', 'N/A', rain, erodibility, xData = erdp_coords, yData=erdp_pts_mat, title='Export Slope Grid') if k == sim_interval[-1]: np.savetxt('%s/data/final_erdp_pts.txt' % directory, erdp_pts_arr, fmt='%.5f') viewBar(directory, 'final_erdp_pts', 'N/A', rain, erodibility, xData=erdp_coords, yData=erdp_pts_arr[-1], title='Export Slope Grid') return
from pyBadlands.model import Model as badlandsModel # from ipyparallel import Client # Connect to the MPI cluster and configure our view # client = Client(profile='mpi') # initialise model model = badlandsModel() model.load_xml('data/demo-input.xml') model.run_to_time(100) # run model for 100 years