Changeset 7820


Ignore:
Timestamp:
Jun 11, 2010, 11:42:42 AM (10 years ago)
Author:
hudson
Message:

Added unit test for sww_merge.

Location:
trunk/anuga_core/source/anuga/utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/utilities/sww_merge.py

    r7819 r7820  
     1"""
     2    Merge a list of .sww files together into a single file.
     3"""
     4
    15import numpy as num
    26from anuga.utilities.numerical_tools import ensure_numeric
     
    1115    """
    1216        Merge a list of sww files into a single file.
     17       
     18        May be useful for parallel runs. Note that some advanced information
     19        and custom quantities may not be exported.
    1320    """
    1421   
     
    8188
    8289    for q in dynamic_quantities:
    83         q_values = ensure_numeric(out_d_quantities[quantity])
    84         x = q_values.astype(netcdf_float)
    85         fido.variables[q] = x
    86 
     90        q_values = out_d_quantities[q]
     91        for i, time_slice in enumerate(q_values):
     92            fido.variables[q][i] = num.array(time_slice, netcdf_float)
     93       
    8794        # This updates the _range values
    8895        q_range = fido.variables[q + Write_sww.RANGE][:]
     
    98105   
    99106
    100 from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular, \
    101                                                             rectangular_cross
    102 from anuga.shallow_water.shallow_water_domain import Domain
    103 from anuga.file.sww import SWW_file
    104 from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \
    105     Dirichlet_boundary
    106 
    107 Bd = Dirichlet_boundary([0.5, 0., 0.])
    108 
    109 # Create shallow water domain
    110 domain = Domain(*rectangular_cross(2, 2))
    111 domain.set_name('test1')
    112 domain.set_quantity('elevation', 2)
    113 domain.set_quantity('stage', 5)
    114 domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
    115 for t in domain.evolve(yieldstep=0.5, finaltime=1):
    116     pass
    117    
    118 domain = Domain(*rectangular(3, 3))
    119 domain.set_name('test2')
    120 domain.set_quantity('elevation', 3)
    121 domain.set_quantity('stage', 50)
    122 domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
    123 for t in domain.evolve(yieldstep=0.5, finaltime=1):
    124     pass
    125        
    126 sww_merge(['test1.sww', 'test2.sww'], 'test_out.sww', verbose = True)
  • trunk/anuga_core/source/anuga/utilities/test_file_utils.py

    r7780 r7820  
    66from anuga.utilities.file_utils import copy_code_files, get_all_swwfiles
    77from anuga.utilities.file_utils import del_dir
     8from sww_merge import sww_merge
    89
    910
     
    109110        assert len(iterate)==4           
    110111
     112    def test_merge_swwfiles(self):
     113        from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular, \
     114                                                                    rectangular_cross
     115        from anuga.shallow_water.shallow_water_domain import Domain
     116        from anuga.file.sww import SWW_file
     117        from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \
     118            Dirichlet_boundary
     119
     120        Bd = Dirichlet_boundary([0.5, 0., 0.])
     121
     122        # Create shallow water domain
     123        domain = Domain(*rectangular_cross(2, 2))
     124        domain.set_name('test1')
     125        domain.set_quantity('elevation', 2)
     126        domain.set_quantity('stage', 5)
     127        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
     128        for t in domain.evolve(yieldstep=0.5, finaltime=1):
     129            pass
     130           
     131        domain = Domain(*rectangular(3, 3))
     132        domain.set_name('test2')
     133        domain.set_quantity('elevation', 3)
     134        domain.set_quantity('stage', 50)
     135        domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
     136        for t in domain.evolve(yieldstep=0.5, finaltime=1):
     137            pass
     138               
     139        outfile = 'test_out.sww'
     140        sww_merge(['test1.sww', 'test2.sww'], outfile)
     141        self.failUnless(os.access(outfile, os.F_OK)) 
     142       
     143        # remove temp files
     144        os.remove('test1.sww')
     145        os.remove('test2.sww')
     146      #  os.remove(outfile)     
     147       
     148       
     149
    111150#-------------------------------------------------------------
    112151
    113152if __name__ == "__main__":
    114     #suite = unittest.makeSuite(Test_Data_Manager, 'test_sww2domain2')
    115     suite = unittest.makeSuite(Test_FileUtils, 'test_sww')
     153    suite = unittest.makeSuite(Test_FileUtils, 'test')
    116154    runner = unittest.TextTestRunner() #verbosity=2)
    117155    runner.run(suite)   
Note: See TracChangeset for help on using the changeset viewer.