def test_triangle_areas(self): """ Check that triangle areas is working as it should """ self.create_domain(InitialOceanStage=1., InitialLandStage=0., flowAlg='DE0', verbose=verbose) p = util.get_output('test_plot_utils.sww') pc = util.get_centroids(p, velocity_extrapolation=True) # Check that subsetting works ta = util.triangle_areas(p) ta_1 = util.triangle_areas(p, range(10)) assert (all(ta[range(10)] == ta_1)) # Independently compute an example and check it x0 = p.x[p.vols[0][0]] y0 = p.y[p.vols[0][0]] x1 = p.x[p.vols[0][1]] y1 = p.y[p.vols[0][1]] x2 = p.x[p.vols[0][2]] y2 = p.y[p.vols[0][2]] # Use 0.5 a * b len_a = ((x1 - x0)**2 + (y1 - y0)**2)**0.5 vec_01 = np.array([x1 - x0, y1 - y0]) vec_01 = vec_01 / ((vec_01**2).sum())**0.5 vec_01_perp = np.array([vec_01[1], -vec_01[0]]) len_b = (x2 - x0) * vec_01_perp[0] + (y2 - y0) * vec_01_perp[1] assert (np.allclose(abs(0.5 * len_a * len_b), ta[0])) os.remove('test_plot_utils.sww')
def test_triangle_areas(self): """ Check that triangle areas is working as it should """ self.create_domain(InitialOceanStage=1., InitialLandStage=0., flowAlg='DE0', verbose=verbose) p=util.get_output('test_plot_utils.sww') pc=util.get_centroids(p,velocity_extrapolation=True) # Check that subsetting works ta=util.triangle_areas(p) ta_1=util.triangle_areas(p,range(10)) assert(all(ta[range(10)]==ta_1)) # Independently compute an example and check it x0=p.x[p.vols[0][0]] y0=p.y[p.vols[0][0]] x1=p.x[p.vols[0][1]] y1=p.y[p.vols[0][1]] x2=p.x[p.vols[0][2]] y2=p.y[p.vols[0][2]] # Use 0.5 a * b len_a = ((x1-x0)**2 + (y1-y0)**2)**0.5 vec_01 = np.array([ x1-x0, y1-y0]) vec_01 = vec_01/((vec_01**2).sum())**0.5 vec_01_perp=np.array([vec_01[1], -vec_01[0]]) len_b = (x2-x0)*vec_01_perp[0] + (y2-y0)*vec_01_perp[1] assert(np.allclose(abs(0.5*len_a*len_b),ta[0])) os.remove('test_plot_utils.sww')
def test_water_volume(self): """ Check that water volume is right We assume triangle areas are computed ok, but note they are tested above """ self.create_domain(InitialOceanStage=1., InitialLandStage=0., flowAlg='DE0', verbose=verbose) p=util.get_output('test_plot_utils.sww') pc=util.get_centroids(p,velocity_extrapolation=True) # Check that subsetting works ta=util.triangle_areas(p) # Independently computed water volume wVol_2=(ta*pc.height[2,:]).sum() wv=util.water_volume(p,pc) assert(np.allclose(wVol_2, wv[2])) os.remove('test_plot_utils.sww')
def test_water_volume(self): """ Check that water volume is right We assume triangle areas are computed ok, but note they are tested above """ self.create_domain(InitialOceanStage=1., InitialLandStage=0., flowAlg='DE0', verbose=verbose) p = util.get_output('test_plot_utils.sww') pc = util.get_centroids(p, velocity_extrapolation=True) # Check that subsetting works ta = util.triangle_areas(p) # Independently computed water volume wVol_2 = (ta * pc.height[2, :]).sum() wv = util.water_volume(p, pc) assert (np.allclose(wVol_2, wv[2])) os.remove('test_plot_utils.sww')
def quickPlots(swwFile=None, ocean_land_threshold=None, fig_dir=None, figScale=None): """ Routine to make a set of 'quick and dirty' plots of initial conditions + maxima. Useful for preliminary check on ANUGA outputs """ if(swwFile is None): parser.print_help() print ' ' raise Exception, 'Must give an sww file' # Make directory for figures try: os.mkdir(fig_dir) except: 'Cannot make directory' pass # Read in sww file p=util.get_output(swwFile) p2=util.get_centroids(p,velocity_extrapolation=True) xRange=p2.x.max()-p2.x.min() yRange=p2.y.max()-p2.y.min() figSize=(figScale, figScale*yRange/xRange) # Use spatial coordinates x=p2.x+p.xllcorner y=p2.y+p.yllcorner # Plot friction try: pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=p2.friction,edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Friction') pyplot.colorbar() pyplot.savefig(fig_dir+'/Friction.png') pyplot.close() except: print 'Cannot plot friction' # Plot elevation try: pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=p2.elev,edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Elevation') pyplot.colorbar() pyplot.savefig(fig_dir+'/Elevation.png') pyplot.close() except: print 'Cannot plot elevation' # Plot Initial Stage (where elevation<ocean_land_threshold) pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=p2.stage[0,:]*(p2.elev<ocean_land_threshold),edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Initial Stage (zero where elevation > '+ str(ocean_land_threshold) +' )') pyplot.colorbar() pyplot.savefig(fig_dir+'/Initial_stage.png') pyplot.close() # Plot Initial Depth pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=p2.height[0,:],edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Initial Depth') pyplot.colorbar() pyplot.savefig(fig_dir+'/Initial_depth.png') pyplot.close() # Initial Speed pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=p2.vel[0,:],edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Initial speed ') pyplot.colorbar() pyplot.savefig(fig_dir+'/Initial_speed.png') pyplot.close() # Triangle areas triA=util.triangle_areas(p) tri_len_scale=(triA*2)**0.5 pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=tri_len_scale,edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Mesh triangle side length scale (2*area)^0.5') pyplot.colorbar() pyplot.savefig(fig_dir+'/Triangle_side_length.png') pyplot.close() # Max stage in wet areas maxStage=p2.stage.max(axis=0) pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=maxStage*(maxStage>p2.elev), edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Max stage (zeroed in dry areas)') pyplot.colorbar() pyplot.savefig(fig_dir+'/Max_stage.png') pyplot.close() # Max depth maxDepth=p2.height.max(axis=0) pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=maxDepth, edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Max depth') pyplot.colorbar() pyplot.savefig(fig_dir+'/Max_depth.png') pyplot.close() # Max speed in wet areas maxSpeed=p2.vel.max(axis=0) pyplot.figure(figsize=figSize) pyplot.scatter(x,y,c=maxSpeed, edgecolors='none') pyplot.gca().set_aspect('equal') pyplot.title('Max speed') pyplot.colorbar() pyplot.savefig(fig_dir+'/Max_speed.png') pyplot.close()