1 | """Create mesh and time boundary for Rainfall 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_rainfall(filename): |
---|
16 | """Convert .asc rainfall 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 Seconds Rainfall [mm/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 | rain = [] |
---|
42 | for line in lines: |
---|
43 | fields = line.split() |
---|
44 | time.append( float(fields[0])) # No Conversion needed this time may need to amend for other formats ie: Hrs, Minutes etc.. |
---|
45 | rain.append( float(fields[1])) |
---|
46 | |
---|
47 | |
---|
48 | # Convert to NetCDF |
---|
49 | N = len(time) |
---|
50 | T = array(time, Float) # Time (seconds) |
---|
51 | R = array(rain, Float) # Values (mm) |
---|
52 | |
---|
53 | |
---|
54 | # Create tms NetCDF file |
---|
55 | fid = NetCDFFile(outfilename, 'w') |
---|
56 | fid.institution = 'Test for Lake Entrance Rd Site' |
---|
57 | fid.description = 'Rainfall Convert 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('rainfall', Float, ('number_of_timesteps',)) |
---|
64 | fid.variables['rainfall'][:] = R |
---|
65 | |
---|
66 | fid.close() |
---|
67 | |
---|
68 | |
---|
69 | #------------------------------------------------------------- |
---|
70 | if __name__ == "__main__": |
---|
71 | prepare_rainfall(filename='RAU25.tms') |
---|
72 | if __name__ == "__main__": |
---|
73 | prepare_rainfall(filename='RAU26.tms') |
---|
74 | if __name__ == "__main__": |
---|
75 | prepare_rainfall(filename='RAV24.tms') |
---|
76 | if __name__ == "__main__": |
---|
77 | prepare_rainfall(filename='RAV25.tms') |
---|
78 | if __name__ == "__main__": |
---|
79 | prepare_rainfall(filename='RAV26.tms') |
---|
80 | if __name__ == "__main__": |
---|
81 | prepare_rainfall(filename='RAW24.tms') |
---|
82 | if __name__ == "__main__": |
---|
83 | prepare_rainfall(filename='RAW25.tms') |
---|
84 | if __name__ == "__main__": |
---|
85 | prepare_rainfall(filename='RAW26.tms') |
---|
86 | if __name__ == "__main__": |
---|
87 | prepare_rainfall(filename='RAX24.tms') |
---|
88 | if __name__ == "__main__": |
---|
89 | prepare_rainfall(filename='RAX25.tms') |
---|
90 | if __name__ == "__main__": |
---|
91 | prepare_rainfall(filename='RAX26.tms') |
---|
92 | if __name__ == "__main__": |
---|
93 | prepare_rainfall(filename='RAY24.tms') |
---|
94 | if __name__ == "__main__": |
---|
95 | prepare_rainfall(filename='RAY25.tms') |
---|
96 | if __name__ == "__main__": |
---|
97 | prepare_rainfall(filename='RAY26.tms') |
---|
98 | if __name__ == "__main__": |
---|
99 | prepare_rainfall(filename='RAZ24.tms') |
---|
100 | if __name__ == "__main__": |
---|
101 | prepare_rainfall(filename='RAZ25.tms') |
---|
102 | if __name__ == "__main__": |
---|
103 | prepare_rainfall(filename='RAZ26.tms') |
---|