def maketopo(): """ Output topography file for the entire domain """ outfile = "beach.topotype2" topotools.topo2writer(outfile, topo, xlower, xupper, ylower, yupper, nxpoints, nypoints)
def write_data_objects(self): super(PlaneWaveBaseTest,self).write_data_objects() # Write out bathy file mx = self.run_data.clawdata.mx my = self.run_data.clawdata.my xlower = self.run_data.clawdata.xlower xupper = self.run_data.clawdata.xupper ylower = self.run_data.clawdata.ylower yupper = self.run_data.clawdata.yupper dx = (xupper - xlower) / mx dy = (yupper - ylower) / my d = min(dx,dy) mx = int((xupper - xlower) / d) + 8 my = int((yupper - ylower) / d) + 8 xlower = xlower - d*4.0 ylower = ylower - d*4.0 xupper = xupper + d*4.0 yupper = yupper + d*4.0 def step(x,y): x_c,y_c = transform_p2c(x,y,self.ml_data.bathy_location,0.0, self.ml_data.bathy_angle) return ((x_c <= 0.0) * self.ml_data.bathy_left + (x_c > 0.0) * self.ml_data.bathy_right) tt.topo2writer('./topo.data',step, xlower,xupper,ylower,yupper,mx,my,nodata_value=-99999)
def maketopo(): """ output topography for entire domain """ #pad outfile = 'FlumeRunoutPad_10cm.tt2' xlower = 65.0 xupper = 180.00 ylower = -10.0 yupper = 12.0 nxpoints = int((xupper - xlower) / 0.05) + 1 nypoints = int((yupper - ylower) / 0.05) + 1 gt.topo2writer(outfile, bed_curve, xlower, xupper, ylower, yupper, nxpoints, nypoints) #hill outfile = 'FlumeHillside_1m.tt2' xlower = -10.0 xupper = 72.0 ylower = -10.0 yupper = 12.0 nxpoints = int((xupper - xlower) / 1.0) + 1 nypoints = int((yupper - ylower) / 1.0) + 1 gt.topo2writer(outfile, hill, xlower, xupper, ylower, yupper, nxpoints, nypoints) #bed outfile = 'FlumeHopper_-10.0m_4.4m_1cm.tt2' xlower = -11.0 xupper = 71.6 ylower = 0.0 yupper = 2.0 nxpoints = int((xupper - xlower) / 0.01) + 1 nypoints = int((yupper - ylower) / 0.01) + 1 gt.topo2writer(outfile, bed_curve, xlower, xupper, ylower, yupper, nxpoints, nypoints) #wall0 outfile = 'FlumeWall_-10.0m_4.4m_y0_1cm.tt2' xlower = -10.0 xupper = 71.5 ylower = -0.5 yupper = 0.0 nxpoints = int((xupper - xlower) / 0.02) + 1 nypoints = int((yupper - ylower) / 0.02) + 1 gt.topo2writer(outfile, wall, xlower, xupper, ylower, yupper, nxpoints, nypoints) #wall2 outfile = 'FlumeWall_-10.0m_4.4m_y2_1cm.tt2' xlower = -10.0 xupper = 71.5 ylower = 2.0 yupper = 2.5 nxpoints = int((xupper - xlower) / 0.02) + 1 nypoints = int((yupper - ylower) / 0.02) + 1 gt.topo2writer(outfile, wall, xlower, xupper, ylower, yupper, nxpoints, nypoints)
def write_topo_file(topo_file,topo_type=1,factor=4,bathy_type=None,plot=False, force=False,verbose=False): """Creates topography file needed by the simulation""" if os.path.exists(topo_file): if not force: ans = raw_input("The file %s already exists, replace: [Y/n] " % topo_file) if ans[0].capitalize() == 'N': print "File %s already exists, use force if you want to replace the existing file." % topo_file return print "Creating topography file ",topo_file # Look at parameters of domain data = Data('./amr2ez.data') dx = abs(data.xupper-data.xlower) / (data.mx) dy = abs(data.yupper-data.ylower) / (data.my) d = min(dx,dy) mx = int((data.xupper-data.xlower) / d) + 8 my = int((data.yupper-data.ylower) / d) + 8 xlower = data.xlower-d*4.0 ylower = data.ylower-d*4.0 xupper = data.xupper+d*4.0 yupper = data.yupper+d*4.0 bathy_profiles = generate_profiles() # Pick out bathymetry profile if bathy_type is None: bathy_profile = 'flat' if bathy_type in bathy_profiles.keys(): bathy_profile = bathy_profiles[bathy_type] else: err_msg = "Bathy profile %s not found, available options are" % bathy_type for name in bathy_profiles.keys(): err_msg = '\n '.join((err_msg,name)) raise Exception(err_msg) if verbose: print "%s profile: %s" % (bathy_type,bathy_profile) # Create and write topography bathy_func = util.create_topo_func(bathy_profile,verbose=verbose) N = len(bathy_profile) if topo_type == 1: tt.topo1writer(topo_file,bathy_func,xlower,xupper,ylower,yupper, factor*mx,factor*my) elif topo_type == 2: print (xlower - xupper) / (factor*mx) print (ylower - yupper) / (factor*my) tt.topo2writer(topo_file,bathy_func,xlower,xupper,ylower,yupper, factor*mx,factor*my) else: raise Exception("Unknown topo type %s requested" % topo_type) # Plotting if plot: plot_profiles({bathy_type:bathy_profile},factor=factor)
def maketopo(): """ output topography for entire domain """ #pad outfile = 'FlumeRunoutPad_10cm.tt2' xlower = 65.0 xupper = 180.00 ylower = -10.0 yupper = 12.0 nxpoints = int((xupper-xlower)/0.05) + 1 nypoints = int((yupper-ylower)/0.05) + 1 gt.topo2writer(outfile,bed_curve,xlower,xupper,ylower,yupper,nxpoints,nypoints) #hill outfile = 'FlumeHillside_1m.tt2' xlower = -10.0 xupper = 72.0 ylower = -10.0 yupper = 12.0 nxpoints = int((xupper-xlower)/1.0) + 1 nypoints = int((yupper-ylower)/1.0) + 1 gt.topo2writer(outfile,hill,xlower,xupper,ylower,yupper,nxpoints,nypoints) #bed outfile = 'FlumeHopper_-10.0m_4.4m_1cm.tt2' xlower = -11.0 xupper = 71.6 ylower = 0.0 yupper = 2.0 nxpoints = int((xupper-xlower)/0.01) + 1 nypoints = int((yupper-ylower)/0.01) + 1 gt.topo2writer(outfile,bed_curve,xlower,xupper,ylower,yupper,nxpoints,nypoints) #wall0 outfile = 'FlumeWall_-10.0m_4.4m_y0_1cm.tt2' xlower = -10.0 xupper = 71.5 ylower = -0.5 yupper = 0.0 nxpoints = int((xupper-xlower)/0.02) + 1 nypoints = int((yupper-ylower)/0.02) + 1 gt.topo2writer(outfile,wall,xlower,xupper,ylower,yupper,nxpoints,nypoints) #wall2 outfile= 'FlumeWall_-10.0m_4.4m_y2_1cm.tt2' xlower = -10.0 xupper = 71.5 ylower = 2.0 yupper = 2.5 nxpoints = int((xupper-xlower)/0.02) + 1 nypoints = int((yupper-ylower)/0.02) + 1 gt.topo2writer(outfile,wall,xlower,xupper,ylower,yupper,nxpoints,nypoints)
def maketopo(): """ Output topography file for the entire domain """ nxpoints = 201 nypoints = 201 xlower = -100.e0 xupper = 100.e0 yupper = 100.e0 ylower = -100.e0 outfile= "bowl.topotype2" topotools.topo2writer(outfile,topo,xlower,xupper,ylower,yupper,nxpoints,nypoints)
def maketopo(): """ Output topography file for the entire domain """ nxpoints = 201 nypoints = 201 xlower = -100.e0 xupper = 100.e0 yupper = 100.e0 ylower = -100.e0 outfile = "bowl.topotype2" topotools.topo2writer(outfile, topo, xlower, xupper, ylower, yupper, nxpoints, nypoints)
def makeqinit(): """ output initialization files """ #test initial file outfile= 'FlumeQinit.tt2' xlower = -10.0 xupper = 0.0 ylower = 0.0 yupper = 2.0 nxpoints = int((xupper-xlower)/0.01) + 1 nypoints = int((yupper-ylower)/0.01) + 1 gt.topo2writer(outfile,flume_eta,xlower,xupper,ylower,yupper,nxpoints,nypoints)
def makeqinit(): """ output initialization files """ #test initial file outfile = 'FlumeQinit.tt2' xlower = -10.0 xupper = 0.0 ylower = 0.0 yupper = 2.0 nxpoints = int((xupper - xlower) / 0.01) + 1 nypoints = int((yupper - ylower) / 0.01) + 1 gt.topo2writer(outfile, flume_eta, xlower, xupper, ylower, yupper, nxpoints, nypoints)
def maketopo(): """ Output topography file for the entire domain """ outfile= "landslide.topotype2" topotools.topo2writer(outfile,topo,xlower,xupper,ylower,yupper,nxpoints,nypoints)
def plot_profiles(profiles,topo_type=1,factor=4,verbose=True): import tempfile import shutil import matplotlib.pyplot as plt # Assume an amr2ez.data file is present data = Data('./amr2ez.data') dx = abs(data.xupper-data.xlower) / (data.mx) dy = abs(data.yupper-data.ylower) / (data.my) d = min(dx,dy) mx = int((data.xupper-data.xlower) / d) + 8 my = int((data.yupper-data.ylower) / d) + 8 xlower = data.xlower-d*4.0 ylower = data.ylower-d*4.0 xupper = data.xupper+d*4.0 yupper = data.yupper+d*4.0 bathy_path = tempfile.mkdtemp() grid_size = int(np.ceil(np.sqrt(len(profiles.keys())))) index = 1 plt.figure(1) for (name,profile) in profiles.iteritems(): topo_file = os.path.join(bathy_path,name) # Write out temporary file bathy_func = util.create_topo_func(profile,verbose=verbose) N = len(profile) factor = 4 if topo_type == 1: tt.topo1writer(topo_file,bathy_func,xlower,xupper,ylower,yupper, factor*mx,factor*my) elif topo_type == 2: tt.topo2writer(topo_file,bathy_func,xlower,xupper,ylower,yupper, factor*mx,factor*my) else: raise Exception("Invalid topo_type %s." % topo_type) # Read it back in (X,Y,Z) = tt.topofile2griddata(topo_file,topotype=topo_type) slice_index = int(X.shape[0] / 2.0) x = X[slice_index,:] b = Z[slice_index,:] limits = [np.min(x),np.max(x),np.min(b)*1.05,np.max(b)*1.05] wet_index = np.nonzero(b < 0.0) plt.subplot(grid_size,grid_size,index) plt.hold(True) plt.plot(x,b,'k',linewidth=2) plt.plot(x[wet_index],np.zeros(x[wet_index].shape),'b') plt.axis(limits) plt.title(name) plt.xlabel('km') plt.ylabel('m') locs,labels = plt.xticks() labels = locs/1e3 plt.xticks(locs,labels) plt.hold(False) index = index + 1 plt.show() shutil.rmtree(bathy_path)