Changeset 1835


Ignore:
Timestamp:
Sep 15, 2005, 5:32:31 PM (18 years ago)
Author:
ole
Message:

Implemented tms file format (like sww without x, y)
Fixed broken test in sww2ers

Location:
inundation
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/data_manager.py

    r1833 r1835  
    20142014
    20152015
    2016 def timefile2swww(filename, quantity_names = None):
     2016def timefile2netcdf(filename, quantity_names = None):
    20172017    """Template for converting typical text files with time series to
    2018     NetCDF sww file.
     2018    NetCDF tms file.
    20192019
    20202020
     
    20972097
    20982098
    2099     #Create sww file
     2099    #Create NetCDF file
    21002100    from Scientific.IO.NetCDF import NetCDFFile
    21012101
    2102        
    2103 
    2104     fid = NetCDFFile(filename + '.sww', 'w')
     2102    fid = NetCDFFile(filename + '.tms', 'w')
    21052103
    21062104
     
    21212119
    21222120    fid.createDimension('number_of_timesteps', len(T))
    2123 
    2124     #if geo_reference is not None:
    2125     #    geo_reference.write_NetCDF(fid)
    2126                
    21272121
    21282122    fid.createVariable('time', Float, ('number_of_timesteps',))
     
    24192413
    24202414
     2415
     2416
     2417
     2418
     2419
     2420
     2421
     2422###############################################
    24212423#OBSOLETE STUFF
    24222424#Native checkpoint format.
     
    24702472    """Writes x,y,z,z,z coordinates of triangles constituting the bed
    24712473    elevation.
    2472     Not in use pt
     2474    FIXME: Not in use pt
    24732475    """
    24742476
    24752477    M, N = v0.shape
     2478
    24762479
    24772480    print X0
     
    29002903    if verbose: print 'Writing %s' %ersfile
    29012904    ermapper_grids.write_ermapper_grid(ersfile,grid_values, header)
     2905
     2906    fid.close()   
    29022907
    29032908##    ascid = open(ascfile, 'w')
  • inundation/pyvolution/domain.py

    r1830 r1835  
    345345        msg = ''
    346346        if self.min_timestep == self.max_timestep:
    347             msg += 'Time = %.4f, delta t = %.8f, steps=%d (%d)\n'\
     347            msg += 'Time = %.4f, delta t = %.8f, steps=%d (%d)'\
    348348                   %(self.time, self.min_timestep, self.number_of_steps,
    349349                     self.number_of_first_order_steps)
    350350        elif self.min_timestep > self.max_timestep:
    351             msg += 'Time = %.4f, steps=%d (%d)\n'\
     351            msg += 'Time = %.4f, steps=%d (%d)'\
    352352                   %(self.time, self.number_of_steps,
    353353                     self.number_of_first_order_steps)
    354354        else:
    355             msg += 'Time = %.4f, delta t in [%.8f, %.8f], steps=%d (%d)\n'\
     355            msg += 'Time = %.4f, delta t in [%.8f, %.8f], steps=%d (%d)'\
    356356                   %(self.time, self.min_timestep,
    357357                     self.max_timestep, self.number_of_steps,
  • inundation/pyvolution/ermapper_grids.py

    r1833 r1835  
    127127    # Write the registration coordinate information
    128128    fid.write('\t\tRegistrationCoord Begin\n')
    129     print X_Class
     129    ###print X_Class
    130130    fid.write('\t\t\t' + X_Class + '\t\t\t = ' + header[X_Class.lower()] + '\n')
    131131    fid.write('\t\t\t' + Y_Class + '\t\t\t = ' + header[Y_Class.lower()] + '\n')
  • inundation/pyvolution/test_data_manager.py

    r1833 r1835  
    17351735
    17361736
    1737      #FIXME This fails - smooth makes the comparism too hard for allclose
     1737    #FIXME This fails - smooth makes the comparism too hard for allclose
    17381738    def ztest_sww2domain3(self):
    17391739        ################################################
     
    21812181
    21822182        fid.close()
    2183         print fid
     2183       
    21842184        #Cleanup
    21852185        #FIXME the file clean-up doesn't work (eg Permission Denied Error)
    2186         #os.remove(sww.filename)
    2187 
    2188     def testz_sww2ers_real(self):
     2186        #Done - it was because sww2ers didn't close it's sww file
     2187        os.remove(sww.filename)
     2188
     2189
     2190    def xxxtestz_sww2ers_real(self):
    21892191        """Test that sww information can be converted correctly to asc/prj
    21902192        format readable by e.g. ArcView
     
    22092211#-------------------------------------------------------------
    22102212if __name__ == "__main__":
    2211     suite = unittest.makeSuite(Test_Data_Manager,'testz')
     2213    suite = unittest.makeSuite(Test_Data_Manager,'test')
    22122214    #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box')
    22132215    #suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem')
  • inundation/pyvolution/test_generic_boundary_conditions.py

    r1671 r1835  
    103103    def test_fileboundary_time_only(self):
    104104        """Test that boundary values can be read from file and interpolated
     105        This is using the .tms file format
    105106        """
    106107
     
    151152        #Convert ASCII file to NetCDF (Which is what we really like!)
    152153       
    153         from data_manager import timefile2swww               
    154         timefile2swww(filename, quantity_names = ['stage', 'ymomentum'])
    155        
    156 
    157 
    158         F = File_boundary(filename + '.sww', domain)
     154        from data_manager import timefile2netcdf               
     155        timefile2netcdf(filename, quantity_names = ['stage', 'ymomentum'])
     156       
     157
     158
     159        F = File_boundary(filename + '.tms', domain)
    159160
    160161       
    161162        os.remove(filename + '.txt')
    162         os.remove(filename + '.sww')       
     163        os.remove(filename + '.tms')       
    163164
    164165
     
    243244
    244245        #Convert ASCII file to NetCDF (Which is what we really like!)
    245         from data_manager import timefile2swww                
    246         timefile2swww(filename, quantity_names = ['stage', 'xmomentum'])
    247 
    248        
    249         try:
    250             F = File_boundary(filename + '.sww', domain)           
     246        from data_manager import timefile2netcdf               
     247        timefile2netcdf(filename, quantity_names = ['stage', 'xmomentum'])
     248
     249       
     250        try:
     251            F = File_boundary(filename + '.tms', domain)           
    251252        except:
    252253            pass
     
    255256       
    256257        os.remove(filename + '.txt')
    257         os.remove(filename + '.sww')       
     258        os.remove(filename + '.tms')       
    258259
    259260
  • inundation/pyvolution/test_shallow_water.py

    r1753 r1835  
    10111011
    10121012        #Convert ASCII file to NetCDF (Which is what we really like!)
    1013         from data_manager import timefile2swww       
    1014         timefile2swww(filename)
     1013        from data_manager import timefile2netcdf       
     1014        timefile2netcdf(filename)
    10151015
    10161016
    10171017       
    10181018        #Setup wind stress
    1019         F = file_function(filename + '.sww', quantities = ['Attribute0',
     1019        F = file_function(filename + '.tms', quantities = ['Attribute0',
    10201020                                                           'Attribute1'])
    10211021
  • inundation/pyvolution/test_util.py

    r1828 r1835  
    88from util import *
    99from config import epsilon
    10 from data_manager import timefile2swww
     10from data_manager import timefile2netcdf
    1111
    1212
     
    246246
    247247        #Convert ASCII file to NetCDF (Which is what we really like!)
    248         timefile2swww(filename)
    249 
    250 
    251         #Create file function
    252         F = file_function(filename + '.sww', quantities = ['Attribute0',
    253                                                            'Attribute1',
    254                                                            'Attribute2'])
     248        timefile2netcdf(filename)
     249
     250
     251        #Create file function from time series
     252        F = file_function(filename + '.tms',
     253                          quantities = ['Attribute0',
     254                                        'Attribute1',
     255                                        'Attribute2'])
    255256       
    256257        #Now try interpolation
     
    279280
    280281        os.remove(filename + '.txt')
    281         os.remove(filename + '.sww')       
     282        os.remove(filename + '.tms')       
    282283
    283284
     
    670671
    671672        #Convert ASCII file to NetCDF (Which is what we really like!)
    672         timefile2swww(filename)
     673        timefile2netcdf(filename)
    673674
    674675
     
    683684
    684685        #Check that domain.starttime is updated if non-existing
    685         F = file_function(filename + '.sww', domain)
     686        F = file_function(filename + '.tms', domain)
    686687       
    687688        assert allclose(domain.starttime, start)
     
    689690        #Check that domain.starttime is updated if too early
    690691        domain.starttime = start - 1
    691         F = file_function(filename + '.sww', domain)
     692        F = file_function(filename + '.tms', domain)
    692693        assert allclose(domain.starttime, start)
    693694
    694695        #Check that domain.starttime isn't updated if later
    695696        domain.starttime = start + 1
    696         F = file_function(filename + '.sww', domain)       
     697        F = file_function(filename + '.tms', domain)       
    697698        assert allclose(domain.starttime, start+1)
    698699
    699700        domain.starttime = start
    700         F = file_function(filename + '.sww', domain,
     701        F = file_function(filename + '.tms', domain,
    701702                          quantities = ['Attribute0', 'Attribute1', 'Attribute2'])
    702703       
     
    730731        assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
    731732
    732         os.remove(filename + '.sww')
     733        os.remove(filename + '.tms')
    733734        os.remove(filename + '.txt')       
    734735
     
    761762
    762763        #Convert ASCII file to NetCDF (Which is what we really like!)
    763         timefile2swww(filename)       
     764        timefile2netcdf(filename)       
    764765
    765766        a = [0.0, 0.0]
     
    775776        delta = 23
    776777        domain.starttime = start + delta
    777         #F = file_function(filename + '.sww', domain)
    778         F = file_function(filename + '.sww', domain,
     778        F = file_function(filename + '.tms', domain,
    779779                          quantities = ['Attribute0', 'Attribute1', 'Attribute2'])       
    780780        assert allclose(domain.starttime, start+delta)
     
    808808
    809809
    810         os.remove(filename + '.sww')
     810        os.remove(filename + '.tms')
    811811        os.remove(filename + '.txt')               
    812812
  • inundation/pyvolution/util.py

    r1819 r1835  
    137137                  quantities = None,
    138138                  interpolation_points = None, verbose = False):
    139     """If quantities is not specified, derive them from domain
    140     (if that is specified)
    141 
    142 
    143     see get_netcdf_file_function
    144     """
    145 
     139    """Read time history of spatial data from NetCDF file and return
     140    a callable object.
     141
     142    If the file has extension 'sww' then it is assumed to be spatio-temporal
     143    or temporal and the callable object will have the form f(t,x,y) or f(t)
     144    depending on whether the file contains spatial data
     145
     146    If the file has extension 'tms' then it is assumed to be temporal only
     147    and the callable object will have the form f(t)
     148
     149    Either form will return interpolated values based on the input file
     150    using the underlying interpolation_function.
     151
     152    If domain is specified, model time (domain.starttime)
     153    will be checked and possibly modified.
     154   
     155    All times are assumed to be in UTC
     156
     157    All spatial information is assumed to be in UTM coordinates.
     158
     159    See Interpolation function for further documentation
     160    """
     161   
    146162
    147163    #FIXME (OLE): Should check origin of domain against that of file
     
    230246    #are present in file
    231247    missing = []
    232     for quantity in ['time'] + quantity_names:  #FIXME: Add x, y back
     248    for quantity in ['time'] + quantity_names:
    233249        if not fid.variables.has_key(quantity):
    234250            missing.append(quantity)
     
    241257
    242258    #Decide whether this data has a spatial dimension
    243     #FIXME: Let us split this up into two functions: One that reads
    244     #sww and one that reads tms (time series only)
    245     #Definitely! (Ole 25 August 2005)
    246259    spatial = True
    247260    for quantity in ['x', 'y']:
     
    249262            spatial = False
    250263
    251 
     264    if filename[-3:] == 'tms' and spatial is True:
     265        msg = 'Files of type tms must not contain spatial information'
     266        raise msg
     267
     268    if filename[-3:] == 'sww' and spatial is False:
     269        msg = 'Files of type sww must contain spatial information'       
     270        raise msg       
    252271
    253272    #Get first timestep
  • inundation/validation/Completed/LWRU2/extract_timeseries.py

    r1742 r1835  
    1 """Read in sww file, interpolate at specified locations (ch 5,7,9) and compare
     1"""Read in tms file, interpolate at specified locations (ch 5,7,9) and compare
    22"""
    33
     
    1919
    2020#Input wave
    21 filename = 'Benchmark_2_input.sww'
     21filename = 'Benchmark_2_input.tms'
    2222print 'Reading', filename
    2323from Scientific.IO.NetCDF import NetCDFFile
  • inundation/validation/Completed/LWRU2/lwru2.py

    r1817 r1835  
    1515
    1616
    17 
    1817import sys
    1918from os import sep
     
    2120
    2221def prepare_timeboundary(filename):
    23     """Converting benchmark 2 time series to NetCDF sww file.
     22    """Converting benchmark 2 time series to NetCDF tms file.
     23    This is a 'throw-away' code taylor made for files like
     24    'Benchmark_2_input.txt' from the LWRU2 benchmark
    2425    """
    25 
    2626
    2727    print 'Preparing time boundary from %s' %filename
     
    3333    line = fid.readline()
    3434
     35    #Read remaining lines
    3536    lines = fid.readlines()
    3637    fid.close()
    3738
     39
    3840    N = len(lines)
    39 
    4041    T = zeros(N, Float)  #Time
    4142    Q = zeros(N, Float)  #Values
     
    4748        Q[i] = float(fields[1])
    4849
    49     #Create sww file
     50
     51    #Create tms file
    5052    from Scientific.IO.NetCDF import NetCDFFile
    5153
    52     outfile = filename[:-4] + '.sww'
     54    outfile = filename[:-4] + '.tms'
    5355    print 'Writing to', outfile
    5456    fid = NetCDFFile(outfile, 'w')
     
    9193
    9294
     95
    9396#######################
    94 # Domain
     97# Create Domain
    9598if use_variable_mesh is True:
    9699    print 'Creating domain from', project.mesh_filename
     
    99102                   (project.mesh_filename, Domain),
    100103                   dependencies = [project.mesh_filename])
    101 
    102 
    103104
    104105else:
     
    114115
    115116
    116 print "Number of triangles = ", len(domain)
     117import sys, os
     118base = os.path.basename(sys.argv[0])
     119domain.filename, _ = os.path.splitext(base)
     120domain.default_order = 2
     121domain.store = True    #Store for visualisation purposes
     122
     123domain.check_integrity()
     124print 'Number of triangles = ', len(domain)
    117125print 'The extent is ', domain.get_extent()
    118126
    119127
    120 #domain.check_integrity()
    121 domain.default_order = 2
    122128
    123 print "Number of triangles = ", len(domain)
    124 domain.store = True    #Store for visualisation purposes
    125 
    126 import sys, os
    127 base = os.path.basename(sys.argv[0])
    128 domain.filename, _ = os.path.splitext(base)
    129 
     129#######################
     130# Initial Conditions
    130131print 'Initial values'
    131132
     
    142143
    143144######################
    144 # Boundary conditions
     145# Boundary Conditions
    145146#
    146147print 'Boundaries'
     
    148149
    149150from pyvolution.util import file_function
    150 function = file_function(project.boundary_filename[:-4] + '.sww', domain,
     151function = file_function(project.boundary_filename[:-4] + '.tms',
     152                         domain,
    151153                         verbose = True)
    152154Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
     
    159161
    160162
    161 #Evolve
     163
     164#######################
     165# Evolve
    162166import time
    163167t0 = time.time()
Note: See TracChangeset for help on using the changeset viewer.