source: trunk/anuga_work/development/Rudy_vandrie_2007/blackbutt/create_hydrograph.py @ 7924

Last change on this file since 7924 was 4441, checked in by ole, 18 years ago

Work with Rudy and Ted 9 May 20007

File size: 1.9 KB
Line 
1"""Create mesh and time boundary for Hydrograph example
2"""
3
4
5from Numeric import array, zeros, Float, allclose
6
7from anuga.pmesh.mesh import *
8from anuga.pmesh.mesh_interface import create_mesh_from_regions
9from anuga.coordinate_transforms.geo_reference import Geo_reference
10from anuga.geospatial_data import Geospatial_data
11
12import project
13
14
15def prepare_hydrograph(filename):
16    """Convert .asc hydrograph file to NetCDF tms file.
17    This is a 'throw-away' code taylor made for this type of file
18
19    Two columns
20    Time in hours    flow [m^3/s]
21    """
22
23    from Scientific.IO.NetCDF import NetCDFFile
24    from Numeric import array
25
26    assert filename[-4:] == '.tms'
27   
28    outfilename = filename
29    infilename = filename[:-4] + '.asc'
30
31    print 'Creating', outfilename
32
33    # Read the ascii (.txt) version of this file
34    fid = open(infilename)
35
36    # Read all lines and search for selected hydrograph
37    lines = fid.readlines()
38    fid.close()
39
40    time = []
41    flow = []
42    for line in lines:
43        fields = line.split()
44        time.append( float(fields[0])*3600   ) # Convert h to s
45        flow.append( float(fields[1]) )       
46
47
48    # Convert to NetCDF
49    N = len(time)
50    T = array(time, Float)  # Time (seconds)
51    Q = array(flow, Float)  # Values (m^3/s)
52
53
54    # Create tms NetCDF file
55    fid = NetCDFFile(outfilename, 'w')
56    fid.institution = 'Geoscience Australia'
57    fid.description = 'Hydrograph example'
58    fid.starttime = 0.0
59    fid.createDimension('number_of_timesteps', len(T))
60    fid.createVariable('time', Float, ('number_of_timesteps',))
61    fid.variables['time'][:] = T
62
63    fid.createVariable('hydrograph', Float, ('number_of_timesteps',))
64    fid.variables['hydrograph'][:] = Q
65
66    fid.close()
67
68
69#-------------------------------------------------------------
70if __name__ == "__main__":
71
72
73    # Prepare hydrograph
74    prepare_hydrograph(filename='Q/QPMF_Rot_Sub13.tms')
75
76
77
Note: See TracBrowser for help on using the repository browser.