Ignore:
Timestamp:
Oct 4, 2016, 4:13:00 PM (9 years ago)
Author:
steve
Message:

Commit svn after a lot of git updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/anuga/file_conversion/tests/test_2pts.py

    r9733 r9737  
    155155
    156156
    157     def test_sww2pts_centroids(self):
     157    def test_sww2pts_centroids_1_5(self):
    158158        """Test that sww information can be converted correctly to pts data at specified coordinates
    159159        - in this case, the centroids.
     
    170170        # Create shallow water domain
    171171        domain = Domain(*rectangular(2, 2))
     172        domain.set_flow_algorithm('1_5')
    172173
    173174        B = Transmissive_boundary(domain)
    174175        domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
    175176
    176         domain.set_name('datatest')
     177        domain.set_name('datatest_1_5')
    177178
    178179        ptsfile = domain.get_name() + '_elevation.pts'
     
    228229                data_points = points,
    229230                NODATA_value = NODATA_value)
    230         #ref_point_values = [-0.5, -0.5, -1, -1, -1, -1, -1.5, -1.5]   #At centroids
    231 
    232         ref_point_values = [-0.72222223, -0.72222223, -1.00000002, -1.00000002,
    233                             -1.00000002, -1.00000002, -1.27777779, -1.27777779]
     231       
     232        ref_point_values = [-0.5, -0.5, -1, -1, -1, -1, -1.5, -1.5]   #At centroids
     233
     234
    234235        point_values = Geospatial_data(ptsfile).get_attributes()
    235236        #print 'P', point_values
     
    244245
    245246
     247
     248    def test_sww2pts_centroids_de0(self):
     249        """Test that sww information can be converted correctly to pts data at specified coordinates
     250        - in this case, the centroids.
     251        """
     252
     253        import time, os
     254        from anuga.file.netcdf import NetCDFFile
     255        # Used for points that lie outside mesh
     256        NODATA_value = 1758323
     257
     258        # Setup
     259        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
     260
     261        # Create shallow water domain
     262        domain = Domain(*rectangular(2, 2))
     263
     264        B = Transmissive_boundary(domain)
     265        domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
     266
     267        domain.set_name('datatest_de0')
     268
     269        ptsfile = domain.get_name() + '_elevation.pts'
     270        swwfile = domain.get_name() + '.sww'
     271
     272        domain.set_datadir('.')
     273        domain.format = 'sww'
     274        domain.set_quantity('elevation', lambda x,y: -x-y)
     275
     276        domain.geo_reference = Geo_reference(56,308500,6189000)
     277
     278        sww = SWW_file(domain)
     279        sww.store_connectivity()
     280        sww.store_timestep()
     281
     282        #self.domain.tight_slope_limiters = 1
     283        domain.evolve_to_end(finaltime = 0.01)
     284        sww.store_timestep()
     285
     286        # Check contents in NetCDF
     287        fid = NetCDFFile(sww.filename, netcdf_mode_r)
     288
     289        # Get the variables
     290        x = fid.variables['x'][:]
     291        y = fid.variables['y'][:]
     292        elevation = fid.variables['elevation'][:]
     293        time = fid.variables['time'][:]
     294        stage = fid.variables['stage'][:]
     295
     296        volumes = fid.variables['volumes'][:]
     297
     298
     299        # Invoke interpolation for vertex points       
     300        points = num.concatenate( (x[:,num.newaxis],y[:,num.newaxis]), axis=1 )
     301        points = num.ascontiguousarray(points)
     302        sww2pts(domain.get_name() + '.sww',
     303                quantity = 'elevation',
     304                data_points = points,
     305                NODATA_value = NODATA_value)
     306        ref_point_values = elevation
     307        point_values = Geospatial_data(ptsfile).get_attributes()
     308        #print 'P', point_values
     309        #print 'Ref', ref_point_values       
     310        assert num.allclose(point_values, ref_point_values)       
     311
     312
     313
     314        # Invoke interpolation for centroids
     315        points = domain.get_centroid_coordinates()
     316        #print points
     317        sww2pts(domain.get_name() + '.sww',
     318                quantity = 'elevation',
     319                data_points = points,
     320                NODATA_value = NODATA_value)
     321        #ref_point_values = [-0.5, -0.5, -1, -1, -1, -1, -1.5, -1.5]   #At centroids
     322
     323        ref_point_values = [-0.77777777, -0.77777777, -0.99999998, -0.99999998,
     324                             -0.99999998, -0.99999998, -1.22222221, -1.22222221]
     325        point_values = Geospatial_data(ptsfile).get_attributes()
     326        #print 'P', point_values
     327        #print 'Ref', ref_point_values       
     328        assert num.allclose(point_values, ref_point_values)       
     329
     330        fid.close()
     331
     332        #Cleanup
     333        os.remove(sww.filename)
     334        os.remove(ptsfile)
     335
    246336#-------------------------------------------------------------
    247337
    248338if __name__ == "__main__":
    249     suite = unittest.makeSuite(Test_2Pts, 'test_sww')
     339    suite = unittest.makeSuite(Test_2Pts, 'test_')
    250340    runner = unittest.TextTestRunner() #verbosity=2)
    251341    runner.run(suite)   
Note: See TracChangeset for help on using the changeset viewer.