1 | """Create mesh and time boundary for Hydrograph example |
---|
2 | """ |
---|
3 | |
---|
4 | |
---|
5 | from Numeric import array, zeros, Float, allclose |
---|
6 | |
---|
7 | from anuga.pmesh.mesh import * |
---|
8 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
9 | from anuga.coordinate_transforms.geo_reference import Geo_reference |
---|
10 | from anuga.geospatial_data import Geospatial_data |
---|
11 | |
---|
12 | import project |
---|
13 | |
---|
14 | |
---|
15 | def 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 | #------------------------------------------------------------- |
---|
70 | if __name__ == "__main__": |
---|
71 | |
---|
72 | |
---|
73 | # Prepare hydrograph |
---|
74 | prepare_hydrograph(filename='Q/QPMF_Rot_Sub13.tms') |
---|
75 | |
---|
76 | |
---|
77 | |
---|