Ignore:
Timestamp:
Sep 5, 2015, 4:03:54 PM (10 years ago)
Author:
steve
Message:

Adding in multiple git commit

Location:
trunk/anuga_core/anuga/file_conversion
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/anuga/file_conversion/dem2array.py

    r9497 r9734  
    7777    Z = Z.reshape(nrows,ncols)
    7878    Z = num.where(Z == NODATA_value , num.nan, Z)
    79 
     79    #changed the orientation of Z array to make it consistent with grd2array result
     80    Z = num.fliplr(Z.T)
    8081
    8182    #print ncols, nrows, xllcorner,yllcorner, cellsize, NODATA_value, zone
  • trunk/anuga_core/anuga/file_conversion/dem2pts.py

    r8832 r9734  
    4242
    4343    if use_cache is True:
    44         from caching import cache
     44        from anuga.caching import cache
    4545        result = cache(_dem2pts, name_in, kwargs,
    4646                       dependencies = [name_in],
     
    153153    outfile.nrows = nrows
    154154
    155     dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols))
     155    #dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols))
    156156    totalnopoints = nrows*ncols
    157157
  • trunk/anuga_core/anuga/file_conversion/sww2dem.py

    r9550 r9734  
    180180            log.critical('    Time: %f' % times)
    181181        else:
    182             log.critical('    Start time: %f' % fid.starttime[0])
     182            log.critical('    Start time: %f' % fid.starttime)
    183183        log.critical('  Extent:')
    184184        log.critical('    x [m] in [%f, %f], len(x) == %d'
  • trunk/anuga_core/anuga/file_conversion/tests/test_dem2array.py

    r9510 r9734  
    6666       
    6767        Z_ex = num.array(ref_elevation,num.float).reshape(12,11)
    68 
    69         #Write prj file with metadata
     68        Z_ex = num.fliplr(Z_ex.T)
     69       
     70        #Write prj file with metadata
    7071        metafilename = root+'.prj'
    7172        fid = open(metafilename, 'w')
     
    9192        x,y, Z = dem2array(root+'.dem')
    9293       
    93 #         print Z
    94 #         print Z_ex
    9594#         print x
    9695#         print xvec
    9796#         print y
    9897#         print yvec       
    99        
    10098        assert num.allclose(Z,Z_ex)
    10199        assert num.allclose(x,xvec)
  • trunk/anuga_core/anuga/file_conversion/tests/test_dem2pts.py

    r9551 r9734  
    126126                ref_points.append ([xnew,ynew]) #Relative point values
    127127
    128         assert num.allclose(points, ref_points)
    129 
    130         assert num.allclose(elevation, ref_elevation)
     128        assert num.allclose(points[:], ref_points)
     129
     130        assert num.allclose(elevation[:], ref_elevation)
    131131
    132132        #Cleanup
     
    390390        #print new_ref_points, len(new_ref_points)
    391391
    392         assert num.allclose(elevation, ref_elevation)
    393         assert num.allclose(points, new_ref_points)
     392        assert num.allclose(elevation[:], ref_elevation)
     393        assert num.allclose(points[:], new_ref_points)
    394394
    395395
  • trunk/anuga_core/anuga/file_conversion/tests/test_file_conversion.py

    r9562 r9734  
    1919from anuga.file.mux import WAVEHEIGHT_MUX_LABEL, EAST_VELOCITY_LABEL, \
    2020                            NORTH_VELOCITY_LABEL
    21 
    2221import sys
    2322import unittest
     
    2625import os
    2726
     27def axes2points(x, y):
     28    """Generate all combinations of grid point coordinates from x and y axes
     29
     30    Args:
     31        * x: x coordinates (array)
     32        * y: y coordinates (array)
     33
     34    Returns:
     35        * P: Nx2 array consisting of coordinates for all
     36             grid points defined by x and y axes. The x coordinate
     37             will vary the fastest to match the way 2D numpy
     38             arrays are laid out by default ('C' order). That way,
     39             the x and y coordinates will match a corresponding
     40             2D array A when flattened (A.flat[:] or A.reshape(-1))
     41
     42    Note:
     43        Example
     44
     45        x = [1, 2, 3]
     46        y = [10, 20]
     47
     48        P = [[1, 10],
     49             [2, 10],
     50             [3, 10],
     51             [1, 20],
     52             [2, 20],
     53             [3, 20]]
     54    """
     55    import numpy
     56   
     57    # Reverse y coordinates to have them start at bottom of array
     58    y = numpy.flipud(y)
     59
     60    # Repeat x coordinates for each y (fastest varying)
     61    X = numpy.kron(numpy.ones(len(y)), x)
     62
     63    # Repeat y coordinates for each x (slowest varying)
     64    Y = numpy.kron(y, numpy.ones(len(x)))
     65
     66    # Check
     67    N = len(X)
     68    assert len(Y) == N
     69
     70    # Create Nx2 array of x and y coordinates
     71    X = numpy.reshape(X, (N, 1))
     72    Y = numpy.reshape(Y, (N, 1))
     73    P = numpy.concatenate((X, Y), axis=1)
     74
     75    # Return
     76    return P
     77
     78def linear_function(point):
     79    point = num.array(point)
     80    return point[:,0]+3*point[:,1]
    2881
    2982class Test_File_Conversion(unittest.TestCase):
     
    945998        os.remove(root+'.txt')
    946999
     1000   
     1001    def test_grd2array_dem2array(self):
     1002        '''test the conversion result of grd to array and dem to array. The pts files should be the same'''
     1003        #ANUGA models
     1004        from anuga.file_conversion.grd2array import grd2array
     1005        from anuga.file_conversion.dem2array import dem2array
     1006        from anuga.file_conversion.asc2dem import asc2dem
     1007
     1008        #Create .asc file. Uses the example from test_grd2array.py
     1009        """ Format of asc file
     1010        ncols         11
     1011        nrows         12
     1012        xllcorner     240000
     1013        yllcorner     7620000
     1014        cellsize      6000
     1015        NODATA_value  -9999
     1016        """
     1017       
     1018        x0 = 0.0
     1019        y0 = 0.0
     1020       
     1021        ncols = 11  # Nx
     1022        nrows = 12  # Ny
     1023        xllcorner = x0
     1024        yllcorner = y0
     1025        cellsize  = 1.0
     1026        NODATA_value =  -9999
     1027       
     1028        #Create .asc file
     1029        root = 'test_asc'
     1030        txt_file = root+'.asc'
     1031        datafile = open(txt_file,"w")
     1032        datafile.write('ncols '+str(ncols)+"\n")
     1033        datafile.write('nrows '+str(nrows)+"\n")
     1034        datafile.write('xllcorner '+str(xllcorner)+"\n")
     1035        datafile.write('yllcorner '+str(yllcorner)+"\n")
     1036        datafile.write('cellsize '+str(cellsize)+"\n")
     1037        datafile.write('NODATA_value '+str(NODATA_value)+"\n")
     1038       
     1039        x_ex = num.linspace(xllcorner, xllcorner+(ncols-1)*cellsize, ncols)
     1040        y_ex = num.linspace(yllcorner, yllcorner+(nrows-1)*cellsize, nrows)
     1041        Z_ex = [[  0.,  3.,  6.,  9., 12., 15., 18., 21., 24., 27., 30., 33.],
     1042                 [  1.,  4.,  7., 10., 13., 16., 19., 22., 25., 28., 31., 34.],
     1043                 [  2.,  5.,  8., 11., 14., 17., 20., 23., 26., 29., 32., 35.],
     1044                 [  3.,  6.,  9., 12., 15., 18., 21., 24., 27., 30., 33., 36.],
     1045                 [  4.,  7., 10., 13., 16., 19., 22., 25., 28., 31., 34., 37.],
     1046                 [  5.,  8., 11., 14., 17., 20., 23., 26., 29., 32., 35., 38.],
     1047                 [  6.,  9., 12., 15., 18., 21., 24., 27., 30., 33., 36., 39.],
     1048                 [  7., 10., 13., 16., 19., 22., 25., 28., 31., 34., 37., 40.],
     1049                 [  8., 11., 14., 17., 20., 23., 26., 29., 32., 35., 38., 41.],
     1050                 [  9., 12., 15., 18., 21., 24., 27., 30., 33., 36., 39., 42.],
     1051                 [ 10., 13., 16., 19., 22., 25., 28., 31., 34., 37., 40., 43.]]
     1052
     1053        points = axes2points(x_ex, y_ex)
     1054       
     1055        datavalues = linear_function(points)
     1056        datavalues = datavalues.reshape(nrows,ncols)
     1057
     1058        for row in datavalues:
     1059            #print row
     1060            datafile.write(" ".join(str(elem) for elem in row) + "\n")         
     1061        datafile.close()
     1062
     1063
     1064        #create dem file from asc file
     1065        txt_file_prj = root+'.prj'
     1066        fid = open(txt_file_prj, 'w')
     1067        fid.write("""Projection UTM
     1068        Zone 56
     1069        Datum WGS84
     1070        Zunits NO
     1071        Units METERS
     1072        Spheroid WGS84
     1073        Xshift 0.0000000000
     1074        Yshift 10000000.0000000000
     1075        Parameters
     1076        """)
     1077        fid.close()
     1078       
     1079        txt_file_dem = root+'.dem'
     1080        asc2dem(name_in=txt_file, name_out=root,
     1081                use_cache=False, verbose=False)
     1082
     1083        #convert grd to array
     1084        x_grd, y_grd, Z_grd = grd2array(txt_file)
     1085        #convert dem to array
     1086        x_dem, y_dem, Z_dem = dem2array(txt_file_dem)
     1087       
     1088        #check grd2array and dem2array results are equal
     1089        assert num.allclose(x_grd, x_dem)
     1090        assert num.allclose(y_grd, y_dem)
     1091        assert num.allclose(Z_grd, Z_dem)
     1092
     1093        #check grd2array (dem2array) results are correct
     1094        assert num.allclose(x_grd, x_ex)
     1095        assert num.allclose(y_grd, y_ex)
     1096        assert num.allclose(Z_grd, Z_ex)
     1097
     1098        try:
     1099            os.remove(root + '.dem')
     1100            os.remove(root + '.asc')
     1101            os.remove(root + '.prj')
     1102        except:
     1103            # Expect error on windows
     1104            pass
    9471105#-------------------------------------------------------------
    9481106
  • trunk/anuga_core/anuga/file_conversion/tests/test_sww2dem.py

    r9733 r9734  
    1 import unittest, os
     1import unittest, os, sys
    22import numpy as num
    33
     
    2525from pprint import pprint
    2626
     27from cStringIO import StringIO
     28import sys
     29
     30class Capturing(list):
     31    def __enter__(self):
     32        self._stdout = sys.stdout
     33        sys.stdout = self._stringio = StringIO()
     34        return self
     35    def __exit__(self, *args):
     36        self.extend(self._stringio.getvalue().splitlines())
     37        sys.stdout = self._stdout
     38
    2739class Test_Sww2Dem(unittest.TestCase):
    2840    def setUp(self):
     
    3850
    3951        # Set some field values
    40         domain.set_quantity('elevation', lambda x,y: -x)
     52        domain.set_quantity('elevation', lambda x, y:-x)
    4153        domain.set_quantity('friction', 0.03)
    4254
     
    4557        # Boundary conditions
    4658        B = Transmissive_boundary(domain)
    47         domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
     59        domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B})
    4860
    4961
    5062        ######################
    51         #Initial condition - with jumps
     63        # Initial condition - with jumps
    5264        bed = domain.quantities['elevation'].vertex_values
    5365        stage = num.zeros(bed.shape, num.float)
     
    5668        for i in range(stage.shape[0]):
    5769            if i % 2 == 0:
    58                 stage[i,:] = bed[i,:] + h
     70                stage[i, :] = bed[i, :] + h
    5971            else:
    60                 stage[i,:] = bed[i,:]
     72                stage[i, :] = bed[i, :]
    6173
    6274        domain.set_quantity('stage', stage)
     
    6779
    6880        C = domain.get_vertex_coordinates()
    69         self.X = C[:,0:6:2].copy()
    70         self.Y = C[:,1:6:2].copy()
     81        self.X = C[:, 0:6:2].copy()
     82        self.Y = C[:, 1:6:2].copy()
    7183
    7284        self.F = bed
     85#       self.verbose = False
    7386        self.verbose = False
    74 
    7587
    7688    def tearDown(self):
     
    100112        self.domain.format = 'sww'
    101113        self.domain.smooth = True
    102         self.domain.set_quantity('elevation', lambda x,y: -x-y)
     114        self.domain.set_quantity('elevation', lambda x, y:-x - y)
    103115        self.domain.set_quantity('stage', 1.0)
    104116
     
    110122
    111123
    112         self.domain.evolve_to_end(finaltime = 0.01)
     124        self.domain.evolve_to_end(finaltime=0.01)
    113125        sww.store_timestep()
    114126
    115127        cellsize = 0.25
    116         #Check contents
    117         #Get NetCDF
     128        # Check contents
     129        # Get NetCDF
    118130
    119131        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    134146        fid.close()
    135147
    136         #Export to ascii/prj files
    137         sww2dem(self.domain.get_name()+'.sww',
    138                 self.domain.get_name()+'_elevation.asc',
    139                 quantity = 'elevation',
    140                 cellsize = cellsize,
    141                 number_of_decimal_places = 9,
    142                 verbose = self.verbose)
    143 
    144         #Check prj (meta data)
     148        # Export to ascii/prj files
     149        sww2dem(self.domain.get_name() + '.sww',
     150                self.domain.get_name() + '_elevation.asc',
     151                quantity='elevation',
     152                cellsize=cellsize,
     153                number_of_decimal_places=9,
     154                verbose=self.verbose)
     155
     156        # Check prj (meta data)
    145157        prjid = open(prjfile)
    146158        lines = prjid.readlines()
     
    183195
    184196
    185         #Check asc file
     197        # Check asc file
    186198        ascid = open(ascfile)
    187199        lines = ascid.readlines()
     
    212224        assert L[1].strip().lower() == '-9999'
    213225
    214         #Check grid values
     226        # Check grid values
    215227        for j in range(5):
    216             L = lines[6+j].strip().split()
    217             y = (4-j) * cellsize
     228            L = lines[6 + j].strip().split()
     229            y = (4 - j) * cellsize
    218230            for i in range(5):
    219                 assert num.allclose(float(L[i]), -i*cellsize - y)
     231                assert num.allclose(float(L[i]), -i * cellsize - y)
    220232               
    221         #Cleanup
     233        # Cleanup
    222234        os.remove(prjfile)
    223235        os.remove(ascfile)
     
    226238        prjfile = self.domain.get_name() + '_depth.prj'
    227239
    228         #Export to ascii/prj files
    229         sww2dem(self.domain.get_name()+'.sww',
     240        # Export to ascii/prj files
     241        sww2dem(self.domain.get_name() + '.sww',
    230242                ascfile,
    231                 quantity = 'depth',
    232                 cellsize = cellsize,
    233                 number_of_decimal_places = 9,
    234                 verbose = self.verbose)
    235        
    236         #Check asc file
     243                quantity='depth',
     244                cellsize=cellsize,
     245                number_of_decimal_places=9,
     246                verbose=self.verbose)
     247       
     248        # Check asc file
    237249        ascid = open(ascfile)
    238250        lines = ascid.readlines()
     
    263275        assert L[1].strip().lower() == '-9999'
    264276
    265         #Check grid values
     277        # Check grid values
    266278        for j in range(5):
    267             L = lines[6+j].strip().split()
    268             y = (4-j) * cellsize
     279            L = lines[6 + j].strip().split()
     280            y = (4 - j) * cellsize
    269281            for i in range(5):
    270                 assert num.allclose(float(L[i]), 1 - (-i*cellsize - y))
    271 
    272 
    273         #Cleanup
     282                assert num.allclose(float(L[i]), 1 - (-i * cellsize - y))
     283
     284
     285        # Cleanup
    274286        os.remove(prjfile)
    275287        os.remove(ascfile)
     
    303315        import time, os
    304316
    305         #Create basic mesh (100m x 100m)
     317        # Create basic mesh (100m x 100m)
    306318        points, vertices, boundary = rectangular(2, 2, 100, 100)
    307319
    308         #Create shallow water domain
     320        # Create shallow water domain
    309321        domain = Domain(points, vertices, boundary)
    310322        domain.default_order = 2
     
    323335
    324336        # FIXME: de0 algorithm doesn't recreate a linear function!
    325         domain.set_quantity('elevation', lambda x,y: -x-y)
     337        domain.set_quantity('elevation', lambda x, y:-x - y)
    326338        domain.set_quantity('stage', 0)
    327339
    328340        B = Transmissive_boundary(domain)
    329         domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
     341        domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B})
    330342
    331343        #
     
    335347       
    336348        domain.tight_slope_limiters = 1
    337         domain.evolve_to_end(finaltime = 0.01)
    338         sww.store_timestep()
    339 
    340         cellsize = 10.0  #10m grid
    341 
    342        
    343         #Export to ascii/prj files
     349        domain.evolve_to_end(finaltime=0.01)
     350        sww.store_timestep()
     351
     352        cellsize = 10.0  # 10m grid
     353
     354       
     355        # Export to ascii/prj files
    344356        sww2dem(domain.get_name() + '.sww',
    345357                domain.get_name() + '_elevation.asc',
    346                 quantity = 'elevation',
    347                 cellsize = cellsize,
    348                 number_of_decimal_places = 3,
    349                 verbose = self.verbose,
     358                quantity='elevation',
     359                cellsize=cellsize,
     360                number_of_decimal_places=3,
     361                verbose=self.verbose,
    350362                block_size=2)
    351363
    352364
    353         #Check prj (meta data)
     365        # Check prj (meta data)
    354366        prjid = open(prjfile)
    355367        lines = prjid.readlines()
     
    392404
    393405
    394         #Check asc file
     406        # Check asc file
    395407        ascid = open(ascfile)
    396408        lines = ascid.readlines()
     
    421433        assert L[1].strip().lower() == '-9999'
    422434
    423         #Check grid values (FIXME: Use same strategy for other sww2dem tests)
     435        # Check grid values (FIXME: Use same strategy for other sww2dem tests)
    424436
    425437        V = [-1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.333e+02, -1.367e+02, -1.400e+02, -1.433e+02, -1.467e+02, -1.500e+02,
    426              -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.300e+02, -1.333e+02, -1.367e+02, -1.400e+02, -1.467e+02,
    427              -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.233e+02, -1.267e+02, -1.300e+02, -1.367e+02, -1.433e+02,
    428              -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.167e+02, -1.200e+02, -1.267e+02, -1.333e+02, -1.400e+02,
    429              -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.100e+02, -1.167e+02, -1.233e+02, -1.300e+02, -1.367e+02,
    430              -6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.333e+02,
    431              -6.333e+01, -7.000e+01, -7.667e+01, -8.333e+01, -9.000e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02,
    432              -6.000e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.333e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02,
    433              -5.667e+01, -6.333e+01, -7.000e+01, -7.333e+01, -7.667e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02,
    434              -5.333e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.000e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02,
    435              -5.000e+01, -5.333e+01, -5.667e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02 ]   
     438             - 9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.300e+02, -1.333e+02, -1.367e+02, -1.400e+02, -1.467e+02,
     439             - 8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.233e+02, -1.267e+02, -1.300e+02, -1.367e+02, -1.433e+02,
     440             - 8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.167e+02, -1.200e+02, -1.267e+02, -1.333e+02, -1.400e+02,
     441             - 7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.100e+02, -1.167e+02, -1.233e+02, -1.300e+02, -1.367e+02,
     442             - 6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.333e+02,
     443             - 6.333e+01, -7.000e+01, -7.667e+01, -8.333e+01, -9.000e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02,
     444             - 6.000e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.333e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02,
     445             - 5.667e+01, -6.333e+01, -7.000e+01, -7.333e+01, -7.667e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02,
     446             - 5.333e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.000e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02,
     447             - 5.000e+01, -5.333e+01, -5.667e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02 ]   
    436448       
    437449        for i, line in enumerate(lines[6:]):
    438             for j, value in enumerate( line.split() ):
    439                 assert num.allclose(float(value), V[i*11+j],
     450            for j, value in enumerate(line.split()):
     451                assert num.allclose(float(value), V[i * 11 + j],
    440452                                    atol=1.0e-12, rtol=1.0e-12)
    441453
    442454                # Note: Equality can be obtained in this case,
    443455                # but it is better to use allclose.
    444                 #assert float(value) == -(10-i+j)*cellsize
    445 
    446 
    447         #fid.close()
    448 
    449         #Cleanup
    450         #os.remove(prjfile)
    451         #os.remove(ascfile)
    452         #os.remove(swwfile)
     456                # assert float(value) == -(10-i+j)*cellsize
     457
     458
     459        # fid.close()
     460
     461        # Cleanup
     462        os.remove(prjfile)
     463        os.remove(ascfile)
     464        os.remove(swwfile)
    453465       
    454466
     
    479491        import time, os
    480492
    481         #Create basic mesh (100m x 100m)
     493        # Create basic mesh (100m x 100m)
    482494        points, vertices, boundary = rectangular(2, 2, 100, 100)
    483495
    484         #Create shallow water domain
     496        # Create shallow water domain
    485497        domain = Domain(points, vertices, boundary)
    486498        domain.set_flow_algorithm('1_5')
     
    499511
    500512        #
    501         domain.set_quantity('elevation', lambda x,y: -x-y)
     513        domain.set_quantity('elevation', lambda x, y:-x - y)
    502514        domain.set_quantity('stage', 0)
    503515
    504516        B = Transmissive_boundary(domain)
    505         domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
     517        domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B})
    506518
    507519
     
    512524       
    513525        domain.tight_slope_limiters = 1
    514         domain.evolve_to_end(finaltime = 0.01)
    515         sww.store_timestep()
    516 
    517         cellsize = 10  #10m grid
    518 
    519 
    520 
    521         #Export to ascii/prj files
     526        domain.evolve_to_end(finaltime=0.01)
     527        sww.store_timestep()
     528
     529        cellsize = 10  # 10m grid
     530
     531
     532
     533        # Export to ascii/prj files
    522534        sww2dem(domain.get_name() + '.sww',
    523535                domain.get_name() + '_elevation.asc',
    524                 quantity = 'elevation',
    525                 cellsize = cellsize,
    526                 number_of_decimal_places = 9,
    527                 verbose = self.verbose,
     536                quantity='elevation',
     537                cellsize=cellsize,
     538                number_of_decimal_places=9,
     539                verbose=self.verbose,
    528540                block_size=2)
    529541
    530542
    531         #Check prj (meta data)
     543        # Check prj (meta data)
    532544        prjid = open(prjfile)
    533545        lines = prjid.readlines()
     
    570582
    571583
    572         #Check asc file
     584        # Check asc file
    573585        ascid = open(ascfile)
    574586        lines = ascid.readlines()
     
    599611        assert L[1].strip().lower() == '-9999'
    600612
    601         #Check grid values (FIXME: Use same strategy for other sww2dem tests)
     613        # Check grid values (FIXME: Use same strategy for other sww2dem tests)
    602614        for i, line in enumerate(lines[6:]):
    603             for j, value in enumerate( line.split() ):
    604                 assert num.allclose(float(value), -(10-i+j)*cellsize,
     615            for j, value in enumerate(line.split()):
     616                assert num.allclose(float(value), -(10 - i + j) * cellsize,
    605617                                    atol=1.0e-12, rtol=1.0e-12)
    606618
    607619                # Note: Equality can be obtained in this case,
    608620                # but it is better to use allclose.
    609                 #assert float(value) == -(10-i+j)*cellsize
    610 
    611 
    612         #Cleanup
    613         #os.remove(prjfile)
    614         #os.remove(ascfile)
    615         #os.remove(swwfile)
     621                # assert float(value) == -(10-i+j)*cellsize
     622
     623
     624        # Cleanup
     625        os.remove(prjfile)
     626        os.remove(ascfile)
     627        os.remove(swwfile)
    616628
    617629
     
    631643        import time, os
    632644
    633         #Setup
     645        # Setup
    634646
    635647        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
    636648
    637         #Create basic mesh (100m x 100m)
     649        # Create basic mesh (100m x 100m)
    638650        points, vertices, boundary = rectangular_cross(20, 1, 20.0, 1.0)
    639651
    640         #Create shallow water domain
     652        # Create shallow water domain
    641653        domain = Domain(points, vertices, boundary)
    642654        domain.default_order = 1
     
    658670
    659671        B = Transmissive_boundary(domain)
    660         domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
     672        domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B})
    661673
    662674
     
    667679       
    668680        domain.tight_slope_limiters = 1
    669         domain.evolve_to_end(finaltime = 0.01)
    670         sww.store_timestep()
    671 
    672         cellsize = 1.0  #0.1 grid
    673 
    674 
    675         #Check contents
    676         #Get NetCDF
     681        domain.evolve_to_end(finaltime=0.01)
     682        sww.store_timestep()
     683
     684        cellsize = 1.0  # 0.1 grid
     685
     686
     687        # Check contents
     688        # Get NetCDF
    677689
    678690        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    686698
    687699
    688         #Export to ascii/prj files
    689         sww2dem(domain.get_name()+'.sww',
     700        # Export to ascii/prj files
     701        sww2dem(domain.get_name() + '.sww',
    690702                domain.get_name() + '_elevation.asc',
    691                 quantity = 'elevation',
    692                 cellsize = cellsize,
    693                 number_of_decimal_places = 9,
    694                 verbose = self.verbose,
     703                quantity='elevation',
     704                cellsize=cellsize,
     705                number_of_decimal_places=9,
     706                verbose=self.verbose,
    695707                block_size=2)
    696708
    697709
    698         #Check prj (meta data)
     710        # Check prj (meta data)
    699711        prjid = open(prjfile)
    700712        lines = prjid.readlines()
     
    738750
    739751
    740         #Check asc file
     752        # Check asc file
    741753        ascid = open(ascfile)
    742754        lines = ascid.readlines()
     
    769781        assert L[1].strip().lower() == '-9999'
    770782
    771         #Check grid values (FIXME: Use same strategy for other sww2dem tests)
     783        # Check grid values (FIXME: Use same strategy for other sww2dem tests)
    772784        for i, line in enumerate(lines[6:]):
    773             for j, value in enumerate( line.split() ):
    774                 #print value
     785            for j, value in enumerate(line.split()):
     786                # print value
    775787                assert num.allclose(float(value), 0.0,
    776788                                    atol=1.0e-12, rtol=1.0e-12)
     
    778790                # Note: Equality can be obtained in this case,
    779791                # but it is better to use allclose.
    780                 #assert float(value) == -(10-i+j)*cellsize
     792                # assert float(value) == -(10-i+j)*cellsize
    781793
    782794
     
    784796
    785797
    786         #Cleanup
     798        # Cleanup
    787799        os.remove(prjfile)
    788800        os.remove(ascfile)
     
    824836        import time, os
    825837
    826         #Setup
     838        # Setup
    827839
    828840        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
    829841
    830         #Create basic mesh (100m x 100m)
     842        # Create basic mesh (100m x 100m)
    831843        points, vertices, boundary = rectangular(2, 2, 100, 100)
    832844
    833         #Create shallow water domain
     845        # Create shallow water domain
    834846        domain = Domain(points, vertices, boundary)
    835847        domain.set_flow_algorithm('1_5')
     
    847859
    848860        #
    849         domain.set_quantity('elevation', lambda x,y: -x-y)
     861        domain.set_quantity('elevation', lambda x, y:-x - y)
    850862        domain.set_quantity('stage', 0)
    851863
    852864        B = Transmissive_boundary(domain)
    853         domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
     865        domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B})
    854866
    855867
     
    859871        sww.store_timestep()
    860872
    861         #domain.tight_slope_limiters = 1
    862         domain.evolve_to_end(finaltime = 0.01)
    863         sww.store_timestep()
    864 
    865         cellsize = 10  #10m grid
    866 
    867 
    868         #Check contents
    869         #Get NetCDF
     873        # domain.tight_slope_limiters = 1
     874        domain.evolve_to_end(finaltime=0.01)
     875        sww.store_timestep()
     876
     877        cellsize = 10  # 10m grid
     878
     879
     880        # Check contents
     881        # Get NetCDF
    870882
    871883        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    882894        sww2dem(domain.get_name() + '.sww',
    883895                domain.get_name() + '_elevation.asc',
    884                 quantity = 'elevation',
    885                 cellsize = cellsize,
    886                 number_of_decimal_places = 9,
    887                 easting_min = 308530,
    888                 easting_max = 308570,
    889                 northing_min = 6189050,
    890                 northing_max = 6189100,
    891                 verbose = self.verbose)
     896                quantity='elevation',
     897                cellsize=cellsize,
     898                number_of_decimal_places=9,
     899                easting_min=308530,
     900                easting_max=308570,
     901                northing_min=6189050,
     902                northing_max=6189100,
     903                verbose=self.verbose)
    892904
    893905        fid.close()
     
    935947
    936948
    937         #Check asc file
     949        # Check asc file
    938950        ascid = open(ascfile)
    939951        lines = ascid.readlines()
     
    964976        assert L[1].strip().lower() == '-9999'
    965977
    966         #Check grid values
     978        # Check grid values
    967979        for i, line in enumerate(lines[6:]):
    968             for j, value in enumerate( line.split() ):
    969                 #assert float(value) == -(10-i+j)*cellsize
    970                 assert float(value) == -(10-i+j+3)*cellsize
    971 
    972 
    973 
    974         #Cleanup
     980            for j, value in enumerate(line.split()):
     981                # assert float(value) == -(10-i+j)*cellsize
     982                assert float(value) == -(10 - i + j + 3) * cellsize
     983
     984
     985
     986        # Cleanup
    975987        os.remove(prjfile)
    976988        os.remove(ascfile)
     
    9881000        import time, os
    9891001
    990         #Setup
     1002        # Setup
    9911003        self.domain.set_name('datatest')
    9921004
     
    9981010        self.domain.format = 'sww'
    9991011        self.domain.smooth = True
    1000         self.domain.set_quantity('elevation', lambda x,y: -x-y)
    1001 
    1002         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1012        self.domain.set_quantity('elevation', lambda x, y:-x - y)
     1013
     1014        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    10031015
    10041016
     
    10071019        sww.store_timestep()
    10081020
    1009         #self.domain.tight_slope_limiters = 1
    1010         self.domain.evolve_to_end(finaltime = 0.01)
     1021        # self.domain.tight_slope_limiters = 1
     1022        self.domain.evolve_to_end(finaltime=0.01)
    10111023        sww.store_timestep()
    10121024
    10131025        cellsize = 0.25
    1014         #Check contents
    1015         #Get NetCDF
     1026        # Check contents
     1027        # Get NetCDF
    10161028
    10171029        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    10251037
    10261038
    1027         #Export to ascii/prj files
     1039        # Export to ascii/prj files
    10281040        sww2dem(self.domain.get_name() + '.sww',
    10291041                self.domain.get_name() + '_stage.asc',
    1030                 quantity = 'stage',
    1031                 cellsize = cellsize,
    1032                 number_of_decimal_places = 9,
    1033                 reduction = min)
    1034 
    1035 
    1036         #Check asc file
     1042                quantity='stage',
     1043                cellsize=cellsize,
     1044                number_of_decimal_places=9,
     1045                reduction=min)
     1046
     1047
     1048        # Check asc file
    10371049        ascid = open(ascfile)
    10381050        lines = ascid.readlines()
     
    10641076
    10651077
    1066         #Check grid values (where applicable)
     1078        # Check grid values (where applicable)
    10671079        for j in range(5):
    1068             if j%2 == 0:
    1069                 L = lines[6+j].strip().split()
    1070                 jj = 4-j
     1080            if j % 2 == 0:
     1081                L = lines[6 + j].strip().split()
     1082                jj = 4 - j
    10711083                for i in range(5):
    1072                     if i%2 == 0:
    1073                         index = jj/2 + i/2*3
    1074                         val0 = stage[0,index]
    1075                         val1 = stage[1,index]
    1076 
    1077                         #print i, j, index, ':', L[i], val0, val1
     1084                    if i % 2 == 0:
     1085                        index = jj / 2 + i / 2 * 3
     1086                        val0 = stage[0, index]
     1087                        val1 = stage[1, index]
     1088
     1089                        # print i, j, index, ':', L[i], val0, val1
    10781090                        assert num.allclose(float(L[i]), min(val0, val1))
    10791091
     
    10811093        fid.close()
    10821094
    1083         #Cleanup
     1095        # Cleanup
    10841096        os.remove(prjfile)
    10851097        os.remove(ascfile)
     
    10951107        import time, os
    10961108
    1097         #Setup
     1109        # Setup
    10981110        self.domain.set_name('datatest')
    10991111
     
    11051117        self.domain.format = 'sww'
    11061118        self.domain.smooth = True
    1107         self.domain.set_quantity('elevation', lambda x,y: -x-y)
    1108 
    1109         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1119        self.domain.set_quantity('elevation', lambda x, y:-x - y)
     1120
     1121        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    11101122
    11111123        sww = SWW_file(self.domain)
     
    11131125        sww.store_timestep()
    11141126
    1115         #self.domain.tight_slope_limiters = 1
    1116         self.domain.evolve_to_end(finaltime = 0.01)
     1127        # self.domain.tight_slope_limiters = 1
     1128        self.domain.evolve_to_end(finaltime=0.01)
    11171129        sww.store_timestep()
    11181130
    11191131        cellsize = 0.25
    1120         #Check contents
    1121         #Get NetCDF
     1132        # Check contents
     1133        # Get NetCDF
    11221134
    11231135        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    11301142        stage = fid.variables['stage'][:]
    11311143
    1132         #Export to ascii/prj files
     1144        # Export to ascii/prj files
    11331145        sww2dem(self.domain.get_name() + '.sww',
    11341146                self.domain.get_name() + '_stage.asc',
    1135                 quantity = 'stage',
    1136                 cellsize = cellsize,
    1137                 number_of_decimal_places = 9,
    1138                 reduction = 1,
     1147                quantity='stage',
     1148                cellsize=cellsize,
     1149                number_of_decimal_places=9,
     1150                reduction=1,
    11391151                verbose=self.verbose)
    11401152
    11411153
    1142         #Check asc file
     1154        # Check asc file
    11431155        ascid = open(ascfile)
    11441156        lines = ascid.readlines()
     
    11691181        assert L[1].strip().lower() == '-9999'
    11701182
    1171         #Check grid values (where applicable)
     1183        # Check grid values (where applicable)
    11721184        for j in range(5):
    1173             if j%2 == 0:
    1174                 L = lines[6+j].strip().split()
    1175                 jj = 4-j
     1185            if j % 2 == 0:
     1186                L = lines[6 + j].strip().split()
     1187                jj = 4 - j
    11761188                for i in range(5):
    1177                     if i%2 == 0:
    1178                         index = jj/2 + i/2*3
     1189                    if i % 2 == 0:
     1190                        index = jj / 2 + i / 2 * 3
    11791191                       
    1180                         val = stage[1,index]
     1192                        val = stage[1, index]
    11811193                   
    11821194                        assert num.allclose(float(L[i]), val)
     
    11841196        fid.close()
    11851197
    1186         #Cleanup
     1198        # Cleanup
    11871199        os.remove(prjfile)
    11881200        os.remove(ascfile)
     
    11991211        import time, os
    12001212
    1201         #Setup
     1213        # Setup
    12021214        self.domain.set_name('datatest')
    12031215
     
    12091221        self.domain.format = 'sww'
    12101222        self.domain.smooth = True
    1211         self.domain.set_quantity('elevation', lambda x,y: -x-y)
     1223        self.domain.set_quantity('elevation', lambda x, y:-x - y)
    12121224        self.domain.set_quantity('stage', 0.0)
    12131225
    1214         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1226        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    12151227
    12161228
     
    12191231        sww.store_timestep()
    12201232
    1221         #self.domain.tight_slope_limiters = 1
    1222         self.domain.evolve_to_end(finaltime = 0.01)
     1233        # self.domain.tight_slope_limiters = 1
     1234        self.domain.evolve_to_end(finaltime=0.01)
    12231235        sww.store_timestep()
    12241236
    12251237        cellsize = 0.25
    1226         #Check contents
    1227         #Get NetCDF
     1238        # Check contents
     1239        # Get NetCDF
    12281240
    12291241        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    12371249
    12381250
    1239         #Export to ascii/prj files
    1240         sww2dem(self.domain.get_name()+'.sww',
    1241                 name_out = 'datatest_depth.asc',
    1242                 quantity = 'stage - elevation',
    1243                 cellsize = cellsize,
    1244                 number_of_decimal_places = 9,
    1245                 reduction = min,
    1246                 verbose = self.verbose)
    1247 
    1248 
    1249         #Check asc file
     1251        # Export to ascii/prj files
     1252        sww2dem(self.domain.get_name() + '.sww',
     1253                name_out='datatest_depth.asc',
     1254                quantity='stage - elevation',
     1255                cellsize=cellsize,
     1256                number_of_decimal_places=9,
     1257                reduction=min,
     1258                verbose=self.verbose)
     1259
     1260
     1261        # Check asc file
    12501262        ascid = open(ascfile)
    12511263        lines = ascid.readlines()
     
    12771289
    12781290
    1279         #Check grid values (where applicable)
     1291        # Check grid values (where applicable)
    12801292        for j in range(5):
    1281             if j%2 == 0:
    1282                 L = lines[6+j].strip().split()
    1283                 jj = 4-j
     1293            if j % 2 == 0:
     1294                L = lines[6 + j].strip().split()
     1295                jj = 4 - j
    12841296                for i in range(5):
    1285                     if i%2 == 0:
    1286                         index = jj/2 + i/2*3
    1287                         val0 = stage[0,index] - z[index]
    1288                         val1 = stage[1,index] - z[index]
    1289 
    1290                         #print i, j, index, ':', L[i], val0, val1
     1297                    if i % 2 == 0:
     1298                        index = jj / 2 + i / 2 * 3
     1299                        val0 = stage[0, index] - z[index]
     1300                        val1 = stage[1, index] - z[index]
     1301
     1302                        # print i, j, index, ':', L[i], val0, val1
    12911303                        assert num.allclose(float(L[i]), min(val0, val1))
    12921304
     
    12941306        fid.close()
    12951307
    1296         #Cleanup
     1308        # Cleanup
    12971309        os.remove(prjfile)
    12981310        os.remove(ascfile)
     
    13121324        import time, os
    13131325
    1314         #Setup mesh not coinciding with rectangle.
    1315         #This will cause missing values to occur in gridded data
     1326        # Setup mesh not coinciding with rectangle.
     1327        # This will cause missing values to occur in gridded data
    13161328
    13171329
     
    13201332                  [0.0, 0.0], [0.5, 0.0], [1.0, 0.0]]
    13211333
    1322         vertices = [ [4,1,3], [5,2,4], [1,4,2], [2,0,1]]
    1323 
    1324         #Create shallow water domain
     1334        vertices = [ [4, 1, 3], [5, 2, 4], [1, 4, 2], [2, 0, 1]]
     1335
     1336        # Create shallow water domain
    13251337        domain = Domain(points, vertices)
    13261338        domain.set_flow_algorithm('1_5')
    1327         domain.default_order=2
    1328 
    1329 
    1330         #Set some field values
    1331         domain.set_quantity('elevation', lambda x,y: -x-y)
     1339        domain.default_order = 2
     1340
     1341
     1342        # Set some field values
     1343        domain.set_quantity('elevation', lambda x, y:-x - y)
    13321344        domain.set_quantity('friction', 0.03)
    13331345
     
    13361348        # Boundary conditions
    13371349        B = Transmissive_boundary(domain)
    1338         domain.set_boundary( {'exterior': B} )
     1350        domain.set_boundary({'exterior': B})
    13391351
    13401352
    13411353        ######################
    1342         #Initial condition - with jumps
     1354        # Initial condition - with jumps
    13431355
    13441356        bed = domain.quantities['elevation'].vertex_values
     
    13481360        for i in range(stage.shape[0]):
    13491361            if i % 2 == 0:
    1350                 stage[i,:] = bed[i,:] + h
     1362                stage[i, :] = bed[i, :] + h
    13511363            else:
    1352                 stage[i,:] = bed[i,:]
     1364                stage[i, :] = bed[i, :]
    13531365
    13541366        domain.set_quantity('stage', stage)
     
    13651377        domain.smooth = True
    13661378
    1367         domain.geo_reference = Geo_reference(56,308500,6189000)
     1379        domain.geo_reference = Geo_reference(56, 308500, 6189000)
    13681380
    13691381        sww = SWW_file(domain)
     
    13721384
    13731385        cellsize = 0.25
    1374         #Check contents
    1375         #Get NetCDF
     1386        # Check contents
     1387        # Get NetCDF
    13761388
    13771389        fid = NetCDFFile(swwfile, netcdf_mode_r)
     
    13861398            geo_reference = Geo_reference(NetCDFObject=fid)
    13871399        except AttributeError, e:
    1388             geo_reference = Geo_reference(DEFAULT_ZONE,0,0)
    1389 
    1390         #Export to ascii/prj files
    1391         sww2dem(domain.get_name()+'.sww',
    1392                 domain.get_name()+'_elevation.asc',
    1393                 quantity = 'elevation',
    1394                 cellsize = cellsize,
    1395                 number_of_decimal_places = 9,
    1396                 verbose = self.verbose)
    1397 
    1398 
    1399         #Check asc file
     1400            geo_reference = Geo_reference(DEFAULT_ZONE, 0, 0)
     1401
     1402        # Export to ascii/prj files
     1403        sww2dem(domain.get_name() + '.sww',
     1404                domain.get_name() + '_elevation.asc',
     1405                quantity='elevation',
     1406                cellsize=cellsize,
     1407                number_of_decimal_places=9,
     1408                verbose=self.verbose)
     1409
     1410
     1411        # Check asc file
    14001412        ascid = open(ascfile)
    14011413        lines = ascid.readlines()
     
    14261438        assert L[1].strip().lower() == '-9999'
    14271439
    1428         #Check grid values
     1440        # Check grid values
    14291441        for j in range(5):
    1430             L = lines[6+j].strip().split()
     1442            L = lines[6 + j].strip().split()
    14311443            assert len(L) == 5
    1432             y = (4-j) * cellsize
     1444            y = (4 - j) * cellsize
    14331445
    14341446            for i in range(5):
    1435                 #print i
    1436                 if i+j >= 4:
    1437                     assert num.allclose(float(L[i]), -i*cellsize - y)
     1447                # print i
     1448                if i + j >= 4:
     1449                    assert num.allclose(float(L[i]), -i * cellsize - y)
    14381450                else:
    1439                     #Missing values
     1451                    # Missing values
    14401452                    assert num.allclose(float(L[i]), -9999)
    14411453
     
    14441456        fid.close()
    14451457
    1446         #Cleanup
     1458        # Cleanup
    14471459        os.remove(prjfile)
    14481460        os.remove(ascfile)
     
    14611473        NODATA_value = 1758323
    14621474
    1463         #Setup
     1475        # Setup
    14641476        self.domain.set_name('datatest')
    14651477        self.domain.set_flow_algorithm('1_5')
     
    14711483        self.domain.format = 'sww'
    14721484        self.domain.smooth = True
    1473         self.domain.set_quantity('elevation', lambda x,y: -x-y)
    1474 
    1475         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1485        self.domain.set_quantity('elevation', lambda x, y:-x - y)
     1486
     1487        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    14761488
    14771489        sww = SWW_file(self.domain)
     
    14791491        sww.store_timestep()
    14801492
    1481         #self.domain.tight_slope_limiters = 1
    1482         self.domain.evolve_to_end(finaltime = 0.01)
     1493        # self.domain.tight_slope_limiters = 1
     1494        self.domain.evolve_to_end(finaltime=0.01)
    14831495        sww.store_timestep()
    14841496
    14851497        cellsize = 0.25
    1486         #Check contents
    1487         #Get NetCDF
     1498        # Check contents
     1499        # Get NetCDF
    14881500
    14891501        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    14971509
    14981510
    1499         #Export to ers files
     1511        # Export to ers files
    15001512        outname = self.domain.get_name() + '_elevation.ers'
    15011513        sww2dem(self.domain.get_name() + '.sww',
    15021514                outname,
    1503                 quantity = 'elevation',
    1504                 cellsize = cellsize,
    1505                 number_of_decimal_places = 9,
    1506                 NODATA_value = NODATA_value,
    1507                 verbose = self.verbose)
    1508 
    1509         #Check header data
     1515                quantity='elevation',
     1516                cellsize=cellsize,
     1517                number_of_decimal_places=9,
     1518                NODATA_value=NODATA_value,
     1519                verbose=self.verbose)
     1520
     1521        # Check header data
    15101522        from anuga.abstract_2d_finite_volumes.ermapper_grids import read_ermapper_header, read_ermapper_data
    15111523
     
    15181530        assert header['xdimension'] == '0.25'
    15191531        assert header['ydimension'] == '0.25'
    1520         assert float(header['eastings']) == 308500.0   #xllcorner
    1521         assert float(header['northings']) == 6189000.0 #yllcorner
     1532        assert float(header['eastings']) == 308500.0  # xllcorner
     1533        assert float(header['northings']) == 6189000.0  # yllcorner
    15221534        assert int(header['nroflines']) == 5
    15231535        assert int(header['nrofcellsperline']) == 5
    15241536        assert int(header['nullcellvalue']) == NODATA_value
    1525         #FIXME - there is more in the header
    1526 
    1527 
    1528         #Check grid data
     1537        # FIXME - there is more in the header
     1538
     1539
     1540        # Check grid data
    15291541        grid = read_ermapper_data(self.domain.get_name() + '_elevation')
    15301542
    15311543
    15321544
    1533         ref_grid = [-1,    -1.25, -1.5, -1.75, -2.0,
    1534                     -0.75, -1.0,  -1.25, -1.5, -1.75,
    1535                     -0.5,  -0.75, -1.0, -1.25, -1.5,
    1536                     -0.25, -0.5,  -0.75, -1.0, -1.25,
    1537                     -0.0,  -0.25, -0.5, -0.75, -1.0]
    1538 
    1539 
    1540        
    1541         #pprint(grid)
     1545        ref_grid = [-1, -1.25, -1.5, -1.75, -2.0,
     1546                    - 0.75, -1.0, -1.25, -1.5, -1.75,
     1547                    - 0.5, -0.75, -1.0, -1.25, -1.5,
     1548                    - 0.25, -0.5, -0.75, -1.0, -1.25,
     1549                    - 0.0, -0.25, -0.5, -0.75, -1.0]
     1550
     1551
     1552       
     1553        # pprint(grid)
    15421554        assert num.allclose(grid, ref_grid)
    15431555
    15441556        fid.close()
    15451557
    1546         #Cleanup
    1547         #FIXME the file clean-up doesn't work (eg Permission Denied Error)
    1548         #Done (Ole) - it was because sww2ers didn't close it's sww file
     1558        # Cleanup
     1559        # FIXME the file clean-up doesn't work (eg Permission Denied Error)
     1560        # Done (Ole) - it was because sww2ers didn't close it's sww file
    15491561        os.remove(sww.filename)
    15501562        os.remove(self.domain.get_name() + '_elevation')
     
    15621574        NODATA_value = 1758323
    15631575
    1564         #Setup
     1576        # Setup
    15651577        self.domain.set_name('datatest')
    15661578
     
    15711583        self.domain.format = 'sww'
    15721584        self.domain.smooth = True
    1573         self.domain.set_quantity('elevation', lambda x,y: -x-y)
    1574 
    1575         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1585        self.domain.set_quantity('elevation', lambda x, y:-x - y)
     1586
     1587        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    15761588
    15771589        sww = SWW_file(self.domain)
     
    15791591        sww.store_timestep()
    15801592
    1581         #self.domain.tight_slope_limiters = 1
    1582         self.domain.evolve_to_end(finaltime = 0.01)
     1593        # self.domain.tight_slope_limiters = 1
     1594        self.domain.evolve_to_end(finaltime=0.01)
    15831595        sww.store_timestep()
    15841596
    15851597        cellsize = 0.25
    1586         #Check contents
    1587         #Get NetCDF
     1598        # Check contents
     1599        # Get NetCDF
    15881600
    15891601        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    15971609
    15981610
    1599         #Export to ers files
     1611        # Export to ers files
    16001612        outname = self.domain.get_name() + '_elevation.ers'
    16011613        sww2dem(self.domain.get_name() + '.sww',
    16021614                outname,
    1603                 quantity = 'elevation',
    1604                 cellsize = cellsize,
    1605                 number_of_decimal_places = 9,
    1606                 NODATA_value = NODATA_value,
    1607                 verbose = self.verbose)
    1608 
    1609         #Check header data
     1615                quantity='elevation',
     1616                cellsize=cellsize,
     1617                number_of_decimal_places=9,
     1618                NODATA_value=NODATA_value,
     1619                verbose=self.verbose)
     1620
     1621        # Check header data
    16101622        from anuga.abstract_2d_finite_volumes.ermapper_grids import read_ermapper_header, read_ermapper_data
    16111623
     
    16181630        assert header['xdimension'] == '0.25'
    16191631        assert header['ydimension'] == '0.25'
    1620         assert float(header['eastings']) == 308500.0   #xllcorner
    1621         assert float(header['northings']) == 6189000.0 #yllcorner
     1632        assert float(header['eastings']) == 308500.0  # xllcorner
     1633        assert float(header['northings']) == 6189000.0  # yllcorner
    16221634        assert int(header['nroflines']) == 5
    16231635        assert int(header['nrofcellsperline']) == 5
    16241636        assert int(header['nullcellvalue']) == NODATA_value
    1625         #FIXME - there is more in the header
    1626 
    1627 
    1628         #Check grid data
     1637        # FIXME - there is more in the header
     1638
     1639
     1640        # Check grid data
    16291641        grid = read_ermapper_data(self.domain.get_name() + '_elevation')
    16301642
    16311643
    16321644        ref_grid = [-1.        , -1.08333325, -1.16666663, -1.33333325, -1.5       ,
    1633                     -0.91666663, -1.        , -1.08333325, -1.25      , -1.33333325,
    1634                     -0.83333331, -0.91666663, -1.        , -1.08333325, -1.16666663,
    1635                     -0.66666663, -0.75      , -0.91666663, -1.        , -1.08333325,
    1636                     -0.5       , -0.66666663, -0.83333331, -0.91666663, -1.        ],
    1637 
    1638        
    1639         #pprint(grid)
     1645                    - 0.91666663, -1.        , -1.08333325, -1.25      , -1.33333325,
     1646                    - 0.83333331, -0.91666663, -1.        , -1.08333325, -1.16666663,
     1647                    - 0.66666663, -0.75      , -0.91666663, -1.        , -1.08333325,
     1648                    - 0.5       , -0.66666663, -0.83333331, -0.91666663, -1.        ],
     1649
     1650       
     1651        # pprint(grid)
    16401652       
    16411653        assert num.allclose(grid, ref_grid)
     
    16431655        fid.close()
    16441656
    1645         #Cleanup
    1646         #FIXME the file clean-up doesn't work (eg Permission Denied Error)
    1647         #Done (Ole) - it was because sww2ers didn't close it's sww file
     1657        # Cleanup
     1658        # FIXME the file clean-up doesn't work (eg Permission Denied Error)
     1659        # Done (Ole) - it was because sww2ers didn't close it's sww file
    16481660        os.remove(sww.filename)
    16491661        os.remove(self.domain.get_name() + '_elevation')
     
    16581670
    16591671        base_name = 'tegp'
    1660         #Setup
    1661         self.domain.set_name(base_name+'_P0_8')
     1672        # Setup
     1673        self.domain.set_name(base_name + '_P0_8')
    16621674        swwfile = self.domain.get_name() + '.sww'
    16631675
     
    16661678        self.domain.format = 'sww'
    16671679        self.domain.smooth = True
    1668         self.domain.set_quantity('elevation', lambda x,y: -x-y)
     1680        self.domain.set_quantity('elevation', lambda x, y:-x - y)
    16691681        self.domain.set_quantity('stage', 1.0)
    16701682
    1671         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1683        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    16721684
    16731685        sww = SWW_file(self.domain)
    16741686        sww.store_connectivity()
    16751687        sww.store_timestep()
    1676         self.domain.evolve_to_end(finaltime = 0.0001)
    1677         #Setup
    1678         self.domain.set_name(base_name+'_P1_8')
     1688        self.domain.evolve_to_end(finaltime=0.0001)
     1689        # Setup
     1690        self.domain.set_name(base_name + '_P1_8')
    16791691        swwfile2 = self.domain.get_name() + '.sww'
    16801692        sww = SWW_file(self.domain)
    16811693        sww.store_connectivity()
    16821694        sww.store_timestep()
    1683         self.domain.evolve_to_end(finaltime = 0.0002)
     1695        self.domain.evolve_to_end(finaltime=0.0002)
    16841696        sww.store_timestep()
    16851697
    16861698        cellsize = 0.25
    1687         #Check contents
    1688         #Get NetCDF
     1699        # Check contents
     1700        # Get NetCDF
    16891701
    16901702        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    16991711        fid.close()
    17001712
    1701         #Export to ascii/prj files
     1713        # Export to ascii/prj files
    17021714        extra_name_out = 'yeah'
    17031715        sww2dem_batch(base_name,
    1704                     quantities = ['elevation', 'depth'],
    1705                     extra_name_out = extra_name_out,
    1706                     cellsize = cellsize,
    1707                     verbose = self.verbose,
    1708                     format = 'asc')
     1716                    quantities=['elevation', 'depth'],
     1717                    extra_name_out=extra_name_out,
     1718                    cellsize=cellsize,
     1719                    verbose=self.verbose,
     1720                    format='asc')
    17091721
    17101722        prjfile = base_name + '_P0_8_elevation_yeah.prj'
    17111723        ascfile = base_name + '_P0_8_elevation_yeah.asc'       
    1712         #Check asc file
     1724        # Check asc file
    17131725        ascid = open(ascfile)
    17141726        lines = ascid.readlines()
    17151727        ascid.close()
    1716         #Check grid values
     1728        # Check grid values
    17171729        for j in range(5):
    1718             L = lines[6+j].strip().split()
    1719             y = (4-j) * cellsize
     1730            L = lines[6 + j].strip().split()
     1731            y = (4 - j) * cellsize
    17201732            for i in range(5):
    1721                 #print " -i*cellsize - y",  -i*cellsize - y
    1722                 #print "float(L[i])", float(L[i])
    1723                 assert num.allclose(float(L[i]), -i*cellsize - y)               
    1724         #Cleanup
     1733                # print " -i*cellsize - y",  -i*cellsize - y
     1734                # print "float(L[i])", float(L[i])
     1735                assert num.allclose(float(L[i]), -i * cellsize - y)               
     1736        # Cleanup
    17251737        os.remove(prjfile)
    17261738        os.remove(ascfile)
     
    17281740        prjfile = base_name + '_P1_8_elevation_yeah.prj'
    17291741        ascfile = base_name + '_P1_8_elevation_yeah.asc'       
    1730         #Check asc file
     1742        # Check asc file
    17311743        ascid = open(ascfile)
    17321744        lines = ascid.readlines()
    17331745        ascid.close()
    1734         #Check grid values
     1746        # Check grid values
    17351747        for j in range(5):
    1736             L = lines[6+j].strip().split()
    1737             y = (4-j) * cellsize
     1748            L = lines[6 + j].strip().split()
     1749            y = (4 - j) * cellsize
    17381750            for i in range(5):
    1739                 #print " -i*cellsize - y",  -i*cellsize - y
    1740                 #print "float(L[i])", float(L[i])
    1741                 assert num.allclose(float(L[i]), -i*cellsize - y)               
    1742         #Cleanup
     1751                # print " -i*cellsize - y",  -i*cellsize - y
     1752                # print "float(L[i])", float(L[i])
     1753                assert num.allclose(float(L[i]), -i * cellsize - y)               
     1754        # Cleanup
    17431755        os.remove(prjfile)
    17441756        os.remove(ascfile)
    17451757        os.remove(swwfile)
    17461758
    1747         #Check asc file
     1759        # Check asc file
    17481760        ascfile = base_name + '_P0_8_depth_yeah.asc'
    17491761        prjfile = base_name + '_P0_8_depth_yeah.prj'
     
    17511763        lines = ascid.readlines()
    17521764        ascid.close()
    1753         #Check grid values
     1765        # Check grid values
    17541766        for j in range(5):
    1755             L = lines[6+j].strip().split()
    1756             y = (4-j) * cellsize
     1767            L = lines[6 + j].strip().split()
     1768            y = (4 - j) * cellsize
    17571769            for i in range(5):
    1758                 assert num.allclose(float(L[i]), 1 - (-i*cellsize - y))
    1759         #Cleanup
     1770                assert num.allclose(float(L[i]), 1 - (-i * cellsize - y))
     1771        # Cleanup
    17601772        os.remove(prjfile)
    17611773        os.remove(ascfile)
    17621774
    1763         #Check asc file
     1775        # Check asc file
    17641776        ascfile = base_name + '_P1_8_depth_yeah.asc'
    17651777        prjfile = base_name + '_P1_8_depth_yeah.prj'
     
    17671779        lines = ascid.readlines()
    17681780        ascid.close()
    1769         #Check grid values
     1781        # Check grid values
    17701782        for j in range(5):
    1771             L = lines[6+j].strip().split()
    1772             y = (4-j) * cellsize
     1783            L = lines[6 + j].strip().split()
     1784            y = (4 - j) * cellsize
    17731785            for i in range(5):
    1774                 assert num.allclose(float(L[i]), 1 - (-i*cellsize - y))
    1775         #Cleanup
     1786                assert num.allclose(float(L[i]), 1 - (-i * cellsize - y))
     1787        # Cleanup
    17761788        os.remove(prjfile)
    17771789        os.remove(ascfile)
     
    17931805            pass
    17941806
    1795         #Setup
     1807        # Setup
    17961808        self.domain.set_name('teg')
    17971809
     
    18031815        self.domain.set_flow_algorithm('1_5')
    18041816        self.domain.smooth = True
    1805         self.domain.set_quantity('elevation', lambda x,y: -x-y)
     1817        self.domain.set_quantity('elevation', lambda x, y:-x - y)
    18061818        self.domain.set_quantity('stage', 1.0)
    18071819
    1808         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1820        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    18091821
    18101822        sww = SWW_file(self.domain)
    18111823        sww.store_connectivity()
    18121824        sww.store_timestep()
    1813         self.domain.evolve_to_end(finaltime = 0.01)
     1825        self.domain.evolve_to_end(finaltime=0.01)
    18141826        sww.store_timestep()
    18151827
    18161828        cellsize = 0.25
    1817         #Check contents
    1818         #Get NetCDF
     1829        # Check contents
     1830        # Get NetCDF
    18191831
    18201832        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    18291841        fid.close()
    18301842
    1831         #Export to ascii/prj files
     1843        # Export to ascii/prj files
    18321844        sww2dem_batch(self.domain.get_name(),
    1833                 quantities = 'elevation',
    1834                 cellsize = cellsize,
    1835                 verbose = self.verbose,
    1836                 format = 'asc')
    1837 
    1838         #Check asc file
     1845                quantities='elevation',
     1846                cellsize=cellsize,
     1847                verbose=self.verbose,
     1848                format='asc')
     1849
     1850        # Check asc file
    18391851        ascid = open(ascfile)
    18401852        lines = ascid.readlines()
     
    18491861        assert num.allclose(float(L[1].strip().lower()), 6189000)
    18501862
    1851         #Check grid values
    1852         #print '==='
     1863        # Check grid values
     1864        # print '==='
    18531865        for j in range(5):
    1854             L = lines[6+j].strip().split()
    1855             y = (4-j) * cellsize
     1866            L = lines[6 + j].strip().split()
     1867            y = (4 - j) * cellsize
    18561868            for i in range(5):
    1857                 #print float(L[i])
    1858                 assert num.allclose(float(L[i]), -i*cellsize - y)
     1869                # print float(L[i])
     1870                assert num.allclose(float(L[i]), -i * cellsize - y)
    18591871               
    1860         #Cleanup
     1872        # Cleanup
    18611873        os.remove(prjfile)
    18621874        os.remove(ascfile)
     
    18771889            pass
    18781890
    1879         #Setup
     1891        # Setup
    18801892        self.domain.set_name('tegII')
    18811893
     
    18851897        self.domain.set_flow_algorithm('1_5')
    18861898        self.domain.smooth = True
    1887         self.domain.set_quantity('elevation', lambda x,y: -x-y)
     1899        self.domain.set_quantity('elevation', lambda x, y:-x - y)
    18881900        self.domain.set_quantity('stage', 1.0)
    18891901
    1890         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     1902        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    18911903
    18921904        sww = SWW_file(self.domain)
    18931905        sww.store_connectivity()
    18941906        sww.store_timestep()
    1895         self.domain.evolve_to_end(finaltime = 0.01)
     1907        self.domain.evolve_to_end(finaltime=0.01)
    18961908        sww.store_timestep()
    18971909
    18981910        cellsize = 0.25
    1899         #Check contents
    1900         #Get NetCDF
     1911        # Check contents
     1912        # Get NetCDF
    19011913
    19021914        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    19111923        ymomentum = fid.variables['ymomentum'][:]       
    19121924
    1913         #print 'stage', stage
    1914         #print 'xmom', xmomentum
    1915         #print 'ymom', ymomentum       
     1925        # print 'stage', stage
     1926        # print 'xmom', xmomentum
     1927        # print 'ymom', ymomentum       
    19161928
    19171929        fid.close()
    19181930
    1919         #Export to ascii/prj files
     1931        # Export to ascii/prj files
    19201932        if True:
    19211933            sww2dem_batch(self.domain.get_name(),
    1922                         quantities = ['elevation', 'depth'],
    1923                         cellsize = cellsize,
    1924                         verbose = self.verbose,
    1925                         format = 'asc')
     1934                        quantities=['elevation', 'depth'],
     1935                        cellsize=cellsize,
     1936                        verbose=self.verbose,
     1937                        format='asc')
    19261938
    19271939        else:
    19281940            sww2dem_batch(self.domain.get_name(),
    1929                 quantities = ['depth'],
    1930                 cellsize = cellsize,
    1931                 verbose = self.verbose,
    1932                 format = 'asc')
     1941                quantities=['depth'],
     1942                cellsize=cellsize,
     1943                verbose=self.verbose,
     1944                format='asc')
    19331945
    19341946
    19351947            export_grid(self.domain.get_name(),
    1936                 quantities = ['elevation'],
    1937                 cellsize = cellsize,
    1938                 verbose = self.verbose,
    1939                 format = 'asc')
     1948                quantities=['elevation'],
     1949                cellsize=cellsize,
     1950                verbose=self.verbose,
     1951                format='asc')
    19401952
    19411953        prjfile = self.domain.get_name() + '_elevation.prj'
    19421954        ascfile = self.domain.get_name() + '_elevation.asc'
    19431955       
    1944         #Check asc file
     1956        # Check asc file
    19451957        ascid = open(ascfile)
    19461958        lines = ascid.readlines()
     
    19551967        assert num.allclose(float(L[1].strip().lower()), 6189000)
    19561968
    1957         #print "ascfile", ascfile
    1958         #Check grid values
     1969        # print "ascfile", ascfile
     1970        # Check grid values
    19591971        for j in range(5):
    1960             L = lines[6+j].strip().split()
    1961             y = (4-j) * cellsize
     1972            L = lines[6 + j].strip().split()
     1973            y = (4 - j) * cellsize
    19621974            for i in range(5):
    1963                 #print " -i*cellsize - y",  -i*cellsize - y
    1964                 #print "float(L[i])", float(L[i])
    1965                 assert num.allclose(float(L[i]), -i*cellsize - y)
    1966 
    1967         #Cleanup
     1975                # print " -i*cellsize - y",  -i*cellsize - y
     1976                # print "float(L[i])", float(L[i])
     1977                assert num.allclose(float(L[i]), -i * cellsize - y)
     1978
     1979        # Cleanup
    19681980        os.remove(prjfile)
    19691981        os.remove(ascfile)
    19701982       
    1971         #Check asc file
     1983        # Check asc file
    19721984        ascfile = self.domain.get_name() + '_depth.asc'
    19731985        prjfile = self.domain.get_name() + '_depth.prj'
     
    19841996        assert num.allclose(float(L[1].strip().lower()), 6189000)
    19851997
    1986         #Check grid values
     1998        # Check grid values
    19871999        for j in range(5):
    1988             L = lines[6+j].strip().split()
    1989             y = (4-j) * cellsize
     2000            L = lines[6 + j].strip().split()
     2001            y = (4 - j) * cellsize
    19902002            for i in range(5):
    1991                 #print " -i*cellsize - y",  -i*cellsize - y
    1992                 #print "float(L[i])", float(L[i])               
    1993                 assert num.allclose(float(L[i]), 1 - (-i*cellsize - y))
    1994 
    1995         #Cleanup
     2003                # print " -i*cellsize - y",  -i*cellsize - y
     2004                # print "float(L[i])", float(L[i])               
     2005                assert num.allclose(float(L[i]), 1 - (-i * cellsize - y))
     2006
     2007        # Cleanup
    19962008        os.remove(prjfile)
    19972009        os.remove(ascfile)
     
    20132025            pass
    20142026
    2015         #Setup
     2027        # Setup
    20162028       
    20172029        self.domain.set_name('tegIII')
     
    20232035        self.domain.format = 'sww'
    20242036        self.domain.smooth = True
    2025         self.domain.set_quantity('elevation', lambda x,y: -x-y)
     2037        self.domain.set_quantity('elevation', lambda x, y:-x - y)
    20262038        self.domain.set_quantity('stage', 1.0)
    20272039
    2028         self.domain.geo_reference = Geo_reference(56,308500,6189000)
     2040        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
    20292041       
    20302042        sww = SWW_file(self.domain)
    20312043        sww.store_connectivity()
    2032         sww.store_timestep() #'stage')
    2033         self.domain.evolve_to_end(finaltime = 0.01)
    2034         sww.store_timestep() #'stage')
     2044        sww.store_timestep()  # 'stage')
     2045        self.domain.evolve_to_end(finaltime=0.01)
     2046        sww.store_timestep()  # 'stage')
    20352047
    20362048        cellsize = 0.25
    2037         #Check contents
    2038         #Get NetCDF
     2049        # Check contents
     2050        # Get NetCDF
    20392051
    20402052        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     
    20492061        fid.close()
    20502062
    2051         #Export to ascii/prj files
     2063        # Export to ascii/prj files
    20522064        extra_name_out = 'yeah'
    20532065        if True:
    20542066            sww2dem_batch(self.domain.get_name(),
    2055                         quantities = ['elevation', 'depth'],
    2056                         extra_name_out = extra_name_out,
    2057                         cellsize = cellsize,
    2058                         verbose = self.verbose,
    2059                         format = 'asc')
     2067                        quantities=['elevation', 'depth'],
     2068                        extra_name_out=extra_name_out,
     2069                        cellsize=cellsize,
     2070                        verbose=self.verbose,
     2071                        format='asc')
    20602072
    20612073        else:
    20622074            sww2dem_batch(self.domain.get_name(),
    2063                 quantities = ['depth'],
    2064                 cellsize = cellsize,
    2065                 verbose = self.verbose,
    2066                 format = 'asc')
     2075                quantities=['depth'],
     2076                cellsize=cellsize,
     2077                verbose=self.verbose,
     2078                format='asc')
    20672079
    20682080
    20692081            sww2dem_batch(self.domain.get_name(),
    2070                 quantities = ['elevation'],
    2071                 cellsize = cellsize,
    2072                 verbose = self.verbose,
    2073                 format = 'asc')
     2082                quantities=['elevation'],
     2083                cellsize=cellsize,
     2084                verbose=self.verbose,
     2085                format='asc')
    20742086
    20752087        prjfile = self.domain.get_name() + '_elevation_yeah.prj'
    20762088        ascfile = self.domain.get_name() + '_elevation_yeah.asc'
    20772089       
    2078         #Check asc file
     2090        # Check asc file
    20792091        ascid = open(ascfile)
    20802092        lines = ascid.readlines()
     
    20892101        assert num.allclose(float(L[1].strip().lower()), 6189000)
    20902102
    2091         #print "ascfile", ascfile
    2092         #Check grid values
     2103        # print "ascfile", ascfile
     2104        # Check grid values
    20932105        for j in range(5):
    2094             L = lines[6+j].strip().split()
    2095             y = (4-j) * cellsize
     2106            L = lines[6 + j].strip().split()
     2107            y = (4 - j) * cellsize
    20962108            for i in range(5):
    2097                 #print " -i*cellsize - y",  -i*cellsize - y
    2098                 #print "float(L[i])", float(L[i])
    2099                 assert num.allclose(float(L[i]), -i*cellsize - y)
     2109                # print " -i*cellsize - y",  -i*cellsize - y
     2110                # print "float(L[i])", float(L[i])
     2111                assert num.allclose(float(L[i]), -i * cellsize - y)
    21002112               
    2101         #Cleanup
     2113        # Cleanup
    21022114        os.remove(prjfile)
    21032115        os.remove(ascfile)
    21042116       
    2105         #Check asc file
     2117        # Check asc file
    21062118        ascfile = self.domain.get_name() + '_depth_yeah.asc'
    21072119        prjfile = self.domain.get_name() + '_depth_yeah.prj'
     
    21182130        assert num.allclose(float(L[1].strip().lower()), 6189000)
    21192131
    2120         #Check grid values
     2132        # Check grid values
    21212133        for j in range(5):
    2122             L = lines[6+j].strip().split()
    2123             y = (4-j) * cellsize
     2134            L = lines[6 + j].strip().split()
     2135            y = (4 - j) * cellsize
    21242136            for i in range(5):
    2125                 assert num.allclose(float(L[i]), 1 - (-i*cellsize - y))
    2126 
    2127         #Cleanup
     2137                assert num.allclose(float(L[i]), 1 - (-i * cellsize - y))
     2138
     2139        # Cleanup
    21282140        os.remove(prjfile)
    21292141        os.remove(ascfile)
     
    21362148        try:
    21372149            sww2dem_batch('a_small_round-egg',
    2138                         quantities = ['elevation', 'depth'],
    2139                         cellsize = 99,
    2140                         verbose = self.verbose,
    2141                         format = 'asc')
     2150                        quantities=['elevation', 'depth'],
     2151                        cellsize=99,
     2152                        verbose=self.verbose,
     2153                        format='asc')
    21422154        except IOError:
    21432155            pass
    21442156        else:
    2145             self.assertTrue(0 ==1,  'Bad input did not throw exception error!')
     2157            self.assertTrue(0 == 1, 'Bad input did not throw exception error!')
     2158       
     2159    def test_sww2dem_verbose_True(self):
     2160        '''test sww2dem when verbose is True
     2161        uses the example from function test_sww2dem_asc_elevation_depth'''
     2162        import anuga.utilities.log as log
     2163        cwd = os.getcwd()
     2164        LOG_FILENAME = cwd + '/log_critical_message.log'
     2165        filehandler = log.logging.FileHandler(LOG_FILENAME)
     2166        filehandler.setLevel(log.logging.CRITICAL)
     2167        log.logging.getLogger('').addHandler(filehandler)
     2168        # Setup
     2169        self.domain.set_name('datatest')
     2170
     2171        prjfile = self.domain.get_name() + '_elevation.prj'
     2172        ascfile = self.domain.get_name() + '_elevation.asc'
     2173        swwfile = self.domain.get_name() + '.sww'
     2174
     2175        self.domain.set_datadir('.')
     2176        self.domain.set_flow_algorithm('1_5')
     2177        self.domain.format = 'sww'
     2178        self.domain.smooth = True
     2179        self.domain.set_quantity('elevation', lambda x, y:-x - y)
     2180        self.domain.set_quantity('stage', 1.0)
     2181
     2182        self.domain.geo_reference = Geo_reference(56, 308500, 6189000)
     2183
     2184        sww = SWW_file(self.domain)
     2185        sww.store_connectivity()
     2186        sww.store_timestep()
     2187
     2188        self.domain.evolve_to_end(finaltime=0.01)
     2189        sww.store_timestep()
     2190
     2191        cellsize = 0.25
     2192
     2193        with Capturing() as myout:
     2194            sww2dem(swwfile, ascfile,
     2195                   quantity='elevation',
     2196                   cellsize=cellsize,
     2197                   number_of_decimal_places=9,
     2198                   verbose=True)
     2199             
     2200        log_critical_msg = open(LOG_FILENAME)
     2201        output = log_critical_msg.read()
     2202        log_critical_msg.close()
     2203        output = output.split('\n')
     2204        #print output, 'log message output'
     2205   
     2206        output_verbose_True = '''Reading from datatest.sww
     2207Output directory is datatest_elevation.asc
     2208------------------------------------------------
     2209Statistics of SWW file:
     2210  Name: datatest.sww
     2211  Reference:
     2212    Lower left corner: [308500.000000, 6189000.000000]
     2213    Start time: 0.000000
     2214  Extent:
     2215    x [m] in [0.000000, 1.000000], len(x) == 9
     2216    y [m] in [0.000000, 1.000000], len(y) == 9
     2217    t [s] in [0.000000, 0.010000], len(t) == 2
     2218  Quantities [SI units]:
     2219    stage in [1.000000, 1.000000]
     2220    xmomentum in [-0.000000, 0.000000]
     2221    ymomentum in [-0.000000, 0.000000]
     2222    elevation in [-2.000000, 0.000000]
     2223Slicing sww file, num points: 9, block size: 10000
     2224Processed values for elevation are in [-2.000000, 0.000000]
     2225Creating grid
     2226Interpolated values are in [-2.000000, 0.000000]
     2227Writing datatest_elevation.prj
     2228Writing datatest_elevation.asc
     2229Doing row 0 of 5
     2230Doing row 1 of 5
     2231Doing row 2 of 5
     2232Doing row 3 of 5
     2233Doing row 4 of 5'''
     2234
     2235        output_verbose_True = output_verbose_True.split('\n')
     2236       
     2237        # check the output line by line
     2238        for output_verbose_True_line, line in zip(output_verbose_True, output):
     2239            assert line.lstrip() == output_verbose_True_line.lstrip()
     2240            # cleanup
     2241            try:
     2242                os.remove(prjfile)
     2243            except:
     2244                pass
     2245            try:
     2246                os.remove(ascfile)
     2247            except:
     2248                pass
     2249            try:
     2250                os.remove(swwfile)
     2251            except:
     2252                pass
     2253    #     os.remove(LOG_FILENAME)
     2254        log.logging.disable(log.logging.CRITICAL)
     2255   
     2256        os.remove(LOG_FILENAME)
     2257       
    21462258       
    21472259
     
    21492261
    21502262if __name__ == "__main__":
    2151     #suite = unittest.makeSuite(Test_Shallow_Water, 'test_rainfall_forcing_with_evolve')
     2263    # suite = unittest.makeSuite(Test_Shallow_Water, 'test_rainfall_forcing_with_evolve')
     2264
     2265
    21522266    suite = unittest.makeSuite(Test_Sww2Dem, 'test_')
    21532267    runner = unittest.TextTestRunner(verbosity=1)
Note: See TracChangeset for help on using the changeset viewer.