source: anuga_core/source/contributed_code/flood/create_Rain.py @ 7286

Last change on this file since 7286 was 7286, checked in by ole, 15 years ago

Added create_rain and create_flow from Petar Milevski. These scripts are used to create tms files for flood modelling

File size: 3.0 KB
Line 
1"""Create mesh and time boundary for Rainfall 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
12#import project
13
14
15def 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#-------------------------------------------------------------
70if __name__ == "__main__":
71    prepare_rainfall(filename='RAU25.tms')
72if __name__ == "__main__":
73    prepare_rainfall(filename='RAU26.tms')
74if __name__ == "__main__":
75    prepare_rainfall(filename='RAV24.tms')
76if __name__ == "__main__":
77    prepare_rainfall(filename='RAV25.tms')
78if __name__ == "__main__":
79    prepare_rainfall(filename='RAV26.tms')
80if __name__ == "__main__":
81    prepare_rainfall(filename='RAW24.tms') 
82if __name__ == "__main__":
83    prepare_rainfall(filename='RAW25.tms') 
84if __name__ == "__main__":
85    prepare_rainfall(filename='RAW26.tms') 
86if __name__ == "__main__":
87    prepare_rainfall(filename='RAX24.tms')
88if __name__ == "__main__":
89    prepare_rainfall(filename='RAX25.tms')
90if __name__ == "__main__":
91    prepare_rainfall(filename='RAX26.tms')
92if __name__ == "__main__":
93    prepare_rainfall(filename='RAY24.tms')
94if __name__ == "__main__":
95    prepare_rainfall(filename='RAY25.tms')
96if __name__ == "__main__":
97    prepare_rainfall(filename='RAY26.tms')
98if __name__ == "__main__":
99    prepare_rainfall(filename='RAZ24.tms')
100if __name__ == "__main__":
101    prepare_rainfall(filename='RAZ25.tms')
102if __name__ == "__main__":
103    prepare_rainfall(filename='RAZ26.tms') 
Note: See TracBrowser for help on using the repository browser.