"""Create mesh and time boundary for Rainfall example """ from Numeric import array, zeros, Float, allclose from anuga.pmesh.mesh import * from anuga.pmesh.mesh_interface import create_mesh_from_regions from anuga.coordinate_transforms.geo_reference import Geo_reference from anuga.geospatial_data import Geospatial_data #import project def prepare_hydrograph(filename): """Convert .asc rainfall file to NetCDF tms file. This is a 'throw-away' code taylor made for this type of file Two columns Time in Seconds Flow [m3/s] """ from Scientific.IO.NetCDF import NetCDFFile from Numeric import array assert filename[-4:] == '.tms' outfilename = filename infilename = filename[:-4] + '.asc' print 'Creating', outfilename # Read the ascii (.txt) version of this file fid = open(infilename) # Read all lines and search for selected hydrograph lines = fid.readlines() fid.close() time = [] hydrograph = [] for line in lines: fields = line.split() time.append( float(fields[0])*60) # this has been changed to convert flows where the time is in minutes, remove the *60 if your time is in seconds already hydrograph.append( float(fields[1])) print time # Convert to NetCDF N = len(time) T = array(time, Float) # Time (seconds) R = array(hydrograph, Float) # Values (mm) # Create tms NetCDF file fid = NetCDFFile(outfilename, 'w') fid.institution = 'Test for Lake Entrance Rd Site' fid.description = 'Hydrograph Convert example' fid.starttime = 0.0 fid.createDimension('number_of_timesteps', len(T)) fid.createVariable('time', Float, ('number_of_timesteps',)) fid.variables['time'][:] = T fid.createVariable('hydrograph', Float, ('number_of_timesteps',)) fid.variables['hydrograph'][:] = R fid.close() #------------------------------------------------------------- if __name__ == "__main__": prepare_hydrograph(filename='hydrograph100.tms')