source: trunk/anuga_core/source/anuga/file_conversion/urs2txt.py @ 7758

Last change on this file since 7758 was 7758, checked in by hudson, 14 years ago

Added extra file conversion classes to file_conversion.

File size: 2.4 KB
Line 
1
2
3##
4# @brief Convert a set of URS files to a text file.
5# @param basename_in Stem path to the 3 URS files.
6# @param location_index ??
7def urs2txt(basename_in, location_index=None):
8    """
9    Not finished or tested
10    """
11
12    files_in = [basename_in + WAVEHEIGHT_MUX_LABEL,
13                basename_in + EAST_VELOCITY_LABEL,
14                basename_in + NORTH_VELOCITY_LABEL]
15    quantities = ['HA','UA','VA']
16
17    d = ","
18
19    # instantiate urs_points of the three mux files.
20    mux = {}
21    for quantity, file in map(None, quantities, files_in):
22        mux[quantity] = Urs_points(file)
23
24    # Could check that the depth is the same. (hashing)
25
26    # handle to a mux file to do depth stuff
27    a_mux = mux[quantities[0]]
28
29    # Convert to utm
30    latitudes = a_mux.lonlatdep[:,1]
31    longitudes = a_mux.lonlatdep[:,0]
32    points_utm, zone = \
33        convert_from_latlon_to_utm(latitudes=latitudes, longitudes=longitudes)
34    depths = a_mux.lonlatdep[:,2]
35
36    # open the output text file, start writing.
37    fid = open(basename_in + '.txt', 'w')
38
39    fid.write("zone: " + str(zone) + "\n")
40
41    if location_index is not None:
42        #Title
43        li = location_index
44        fid.write('location_index' + d + 'lat' + d + 'long' + d +
45                  'Easting' + d + 'Northing' + '\n')
46        fid.write(str(li) + d + str(latitudes[li]) + d +
47                  str(longitudes[li]) + d + str(points_utm[li][0]) + d +
48                  str(points_utm[li][01]) + '\n')
49
50    # the non-time dependent stuff
51    #Title
52    fid.write('location_index' + d + 'lat' + d + 'long' + d +
53              'Easting' + d + 'Northing' + d + 'depth m' + '\n')
54    i = 0
55    for depth, point_utm, lat, long in map(None, depths, points_utm,
56                                           latitudes, longitudes):
57
58        fid.write(str(i) + d + str(lat) + d + str(long) + d +
59                  str(point_utm[0]) + d + str(point_utm[01]) + d +
60                  str(depth) + '\n')
61        i += 1
62
63    #Time dependent
64    if location_index is not None:
65        time_step = a_mux.time_step
66        i = 0
67        #Title
68        fid.write('time' + d + 'HA depth m' + d + 'UA momentum East x m/sec' +
69                  d + 'VA momentum North y m/sec' + '\n')
70        for HA, UA, VA in map(None, mux['HA'], mux['UA'], mux['VA']):
71            fid.write(str(i*time_step) + d + str(HA[location_index]) + d +
72                      str(UA[location_index]) + d +
73                      str(VA[location_index]) + '\n')
74            i += 1
75
Note: See TracBrowser for help on using the repository browser.