Example #1
0
    def test_near_points(self):
        """
            Check that the near-points function is working
        """
        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)
        # First check -- get points along y==50
        nt = util.near_transect(pc, [20., 50.], [80., 50.], tol=10.)
        assert (all(abs(pc.y[nt[0]] - 50.) < 10.))
        assert (all(nt[1] >= 0.))
        assert (all(nt[1] <= 60.))
        assert (np.allclose(pc.x[nt[0]] - 20., nt[1]))

        # Next check -- get points along x==50
        nt = util.near_transect(pc, [50., 20.], [50., 80.], tol=10.)
        assert (all(abs(pc.x[nt[0]] - 50.) < 10.))
        assert (all(nt[1] >= 0.))
        assert (all(nt[1] <= 60.))
        assert (np.allclose(pc.y[nt[0]] - 20., nt[1]))

        # Next check -- get points along x==y
        nt = util.near_transect(pc, [20., 20.], [80., 80.], tol=10.)
        assert (all(nt[1] >= 0.))
        # Length of line is 60*sqrt(2)
        assert (all(nt[1] <= 60. * 2**0.5))
        # Coords must be within 10*sqrt(2) of each other
        assert (all(abs(pc.x[nt[0]] - pc.y[nt[0]]) < 10. * 2**0.5))
        # The dot product of the points along the line is equal to nt[1]
        dt_Prd = ((pc.x[nt[0]] - 20.) / 2.**0.5 +
                  (pc.y[nt[0]] - 20.) / 2.**0.5)
        assert (np.allclose(dt_Prd, nt[1]))

        # Next check -- get points along x==2*y + 5
        nt = util.near_transect(pc, [25., 10.], [85., 40.], tol=10.)
        assert (all(nt[1] >= 0.))
        # Length of line is sqrt(60^2+30^3)
        assert (all(nt[1] <= (60.**2 + 30.**2)**0.5))
        # The dot product of the points along the line is equal to nt[1]
        # Unit vector along line is (1,0.5)/ll
        ll = (1.**2 + 0.5**2)**0.5
        dt_Prd = ((pc.x[nt[0]] - 25.) / ll + (pc.y[nt[0]] - 10.) * 0.5 / ll)
        assert (np.allclose(dt_Prd, nt[1]))

        os.remove('test_plot_utils.sww')
Example #2
0
 def test_near_points(self):
     """
         Check that the near-points function is working
     """ 
     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)
     # First check -- get points along y==50
     nt=util.near_transect(pc, [20., 50.], [80., 50.], tol=10.)
     assert(all(abs(pc.y[nt[0]]-50.)<10.))
     assert(all(nt[1]>=0.))
     assert(all(nt[1]<=60.))
     assert(np.allclose(pc.x[nt[0]]-20., nt[1]))
     
     # Next check -- get points along x==50
     nt=util.near_transect(pc, [50., 20.], [50., 80.], tol=10.)
     assert(all(abs(pc.x[nt[0]]-50.)<10.))
     assert(all(nt[1]>=0.))
     assert(all(nt[1]<=60.))
     assert(np.allclose(pc.y[nt[0]]-20., nt[1]))
     
     # Next check -- get points along x==y
     nt=util.near_transect(pc, [20., 20.], [80., 80.], tol=10.)
     assert(all(nt[1]>=0.))
     # Length of line is 60*sqrt(2)
     assert(all(nt[1]<=60.*2**0.5))
     # Coords must be within 10*sqrt(2) of each other
     assert(all(abs( pc.x[nt[0]]-pc.y[nt[0]]) < 10.*2**0.5))
     # The dot product of the points along the line is equal to nt[1]
     dt_Prd=( (pc.x[nt[0]]-20.)/2.**0.5 + (pc.y[nt[0]]-20.)/2.**0.5)
     assert(np.allclose(dt_Prd , nt[1]))
     
     # Next check -- get points along x==2*y + 5
     nt=util.near_transect(pc, [25., 10.], [85., 40.], tol=10.)
     assert(all(nt[1]>=0.))
     # Length of line is sqrt(60^2+30^3)
     assert(all(nt[1]<=(60.**2+30.**2)**0.5))
     # The dot product of the points along the line is equal to nt[1]
     # Unit vector along line is (1,0.5)/ll
     ll=(1.**2+0.5**2)**0.5
     dt_Prd=( (pc.x[nt[0]]-25.)/ll + (pc.y[nt[0]]-10.)*0.5/ll)
     assert(np.allclose(dt_Prd , nt[1]))
     
     os.remove('test_plot_utils.sww')
Example #3
0
for i in range(len(nearest_points)):
    po = point_observations[i, -2]
    tu = point_observations[i, -1]
    anuga_data = p2.stage[tindex, nearest_points.tolist()[i]]
    newline = str(round(po,2)) + ', ' + str(round(anuga_data,2)) + ', ' + str(tu) + ', ' + \
          str(round(anuga_data - po,2)) + ', ' + str(round(anuga_data - tu,2)) + '\n'
    f.writelines(newline)

f.flush()
f.close()

if verbose: print('Plot transect')
## Plot transect 1 [need to guess appropriate end points as these are not so
## clear from the report]
xx = util.near_transect(p2, [103, 100.], [130., 80.], tol=0.5)
xx2 = xx[0]

pyplot.clf()
pyplot.figure(figsize=(16, 10.5))
pyplot.subplot(121)
pyplot.scatter(p2.x, p2.y, c=p2.elev, edgecolors='none')
# Add nice elevation data
colVals = numpy.maximum(numpy.minimum(p2.elev, 25.), 19.)
util.plot_triangles(p, values=colVals, edgecolors='none')

pyplot.gca().set_aspect('equal')
pyplot.scatter(p2.x[xx2], p2.y[xx2], color='green')
pyplot.xlim((40., 160.))
pyplot.ylim((0., 140.))
pyplot.title('Transect points in green')
for i in range(len(nearest_points)):
    po = point_observations[i,-2]
    tu = point_observations[i,-1]
    anuga_data = p2.stage[tindex, nearest_points.tolist()[i]]
    newline = str(round(po,2)) + ', ' + str(round(anuga_data,2)) + ', ' + str(tu) + ', ' + \
          str(round(anuga_data - po,2)) + ', ' + str(round(anuga_data - tu,2)) + '\n'
    f.writelines(newline)

f.flush()
f.close()


if verbose: print 'Plot transect'
## Plot transect 1 [need to guess appropriate end points as these are not so
## clear from the report]
xx=util.near_transect(p2,[103, 100.], [130.,80.],tol=0.5)
xx2=xx[0]

pyplot.clf()
pyplot.figure(figsize=(16,10.5))
pyplot.subplot(121)
pyplot.scatter(p2.x, p2.y, c=p2.elev,edgecolors='none')
# Add nice elevation data
colVals = numpy.maximum(numpy.minimum(p2.elev, 25.), 19.)
util.plot_triangles(p, values = colVals, edgecolors='none')

pyplot.gca().set_aspect('equal')
pyplot.scatter(p2.x[xx2],p2.y[xx2],color='green')
pyplot.xlim( (40., 160.))
pyplot.ylim( (0.,140.))
pyplot.title('Transect points in green')
from matplotlib import pyplot as pyplot
#import util # Routines to read in and work with ANUGA output
#from bal_and import plot_utils as util
from anuga.utilities import plot_utils as util

p2=util.get_output('runup_riverwall.sww', minimum_allowed_height=1.0e-03)
p=util.get_centroids(p2, velocity_extrapolation=True)

#p=util.get_output('runup_v2.sww', minimum_allowed_height=1.0e-03)

#------------------
# Select line
#------------------
#py_central=p.y[scipy.argmin(abs(p.y-50.))]
#v=(p.y==p.y[py_central])
v=util.near_transect(p, [0., 50.], [100., 50.], 10.)
v=v[0]
v=v[p.x[v].argsort()]

#--------------------
# Make plot animation
#--------------------
pyplot.close() #If the plot is open, there will be problems

if False:
    pyplot.ion()
    line, = pyplot.plot( (p.x[v].min(),p.x[v].max()) ,(p.xvel[:,v].min(),p.xvel[:,v].max() ) )
    for i in range(p.xmom.shape[0]):
        line.set_xdata(p.x[v])
        line.set_ydata(p.xvel[i,v])
        pyplot.draw()