def rasterDimensions(maxx, maxy, minx=0, miny=0, dy=100, dx=100): # construct the range x = pd.Series(range(int(minx), int(maxx) + 1, 1)) y = pd.Series(range(int(miny), int(maxy) + 1, 1)) # filter for values that meet the increment or is the last value cols = pd.Series(x.index).apply(lambda x1: x[x1] if x1 % dx == 0 or x1 == x[0] or x1 == x.index[-1] else None) rows = pd.Series(y.index).apply(lambda y1: y[y1] if y1 % dy == 0 or y1 == y[0] or y1 == y.index[-1] else None) # construct the indices row_list = np.array(rows.loc[pd.notnull(rows)]) col_list = np.array(cols.loc[pd.notnull(cols)]) # construct the raster raster = r.RasterModelGrid((len(row_list), len(col_list)), spacing=(dy, dx)) raster.add_zeros return (raster, row_list, col_list)
reload(stream_power) reload(raster) class data(object): ''' This is where all the whole-grid data lives, as arrays over the various elements of the grid. ''' #Data goes here!!! def __init__(self, grid): self.elev = grid.zeros() #some data iterations = 10 tstep = 1. #Make grid, set the elevs mg = raster.RasterModelGrid(50, 50, 1.) mg.set_inactive_boundaries(True, True, True, True) vectors = data(mg) #A surface dipping right, plus random noise: loading_vector = np.linspace(50,1,num=50) vectors.elev = np.repeat(loading_vector, 50) vectors.elev += np.random.random_sample(vectors.elev.shape)/10. vectors.init_elev = copy(vectors.elev) print vectors.elev.shape #print vectors.elev.reshape((5,10)) print vectors.elev.shape print type(vectors.elev) #print vectors.elev.reshape((5,10))
reload(flow_accumulation) reload(raster) class data(object): ''' This is where all the whole-grid data lives, as arrays over the various elements of the grid. ''' #Data goes here!!! def __init__(self, grid): self.elev = grid.zeros(centering='node') #some data #Make grid, set the elevs mg = raster.RasterModelGrid(5, 5, 1.) mg.set_inactive_boundaries(True, True, False, True) vectors = data(mg) vectors.elev = np.array([ 10., 10., 0., 10., 10., 10., 8., 8., 9., 10., 10., 4., 6., 7., 10., 10., 1., 3., 8., 10., 10., 0., 10., 10., 10. ]) print vectors.elev.reshape((5, 5)) print np.array(range(25)).reshape((5, 5)) #print mg.node_status.reshape((5,5)) #imshow_grid(mg,vectors.elev) #plot()