source: development/momentum_sink/scripts/process_gauges.py @ 3322

Last change on this file since 3322 was 2927, checked in by nicholas, 19 years ago

final update of all relavent data

File size: 2.5 KB
Line 
1"""Read in sww file, interpolate at specified locations and plot time series
2Additionally, store augmented building database with max inundation depths
3"""
4
5import project
6from pyvolution.util import file_function
7from pyvolution.coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn
8from pylab import *
9
10
11plot = False
12   
13swwfile = project.outputname + '.sww'
14
15def get_gauges_from_file(filename):
16    fid = open(filename)
17    lines = fid.readlines()
18    fid.close()
19
20    gauges = []
21    gaugelocation = []
22    for line in lines[1:]:
23        fields = line.split(',')
24        location = fields[0]
25        easting = float(fields[1])
26        northing = float(fields[2])
27     
28        gauges.append([easting, northing])
29        gaugelocation.append(location)
30
31    #Return gauges and raw data for subsequent storage   
32    return gauges, lines, gaugelocation
33
34gauges, lines, locations = get_gauges_from_file(project.gauge_filename)
35
36
37#Read model output
38quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum']
39f = file_function(swwfile,
40                  quantities = quantities,
41                  interpolation_points = gauges,
42                  verbose = True,
43                  use_cache = True)
44
45
46lines[0] = lines[0].strip() +\
47               ',MAX INUNDATION DEPTH (m)' +\
48               ',MAX MOMENTUM (m^2/s)\n'           
49               
50from math import sqrt
51N = len(gauges)
52for k, g in enumerate(gauges):
53    if k%((N+10)/10)==0:
54        print 'Doing row %d of %d' %(k, N)
55
56    model_time = []
57    stages = []
58    elevations = []
59    momenta = []
60
61    max_depth = 0
62    max_momentum = 0   
63    for i, t in enumerate(f.T):
64        w = f(t, point_id = k)[0]
65        z = f(t, point_id = k)[1]
66        uh = f(t, point_id = k)[2]
67        vh = f(t, point_id = k)[3]       
68
69        m = sqrt(uh*uh + vh*vh)   #Absolute momentum
70       
71        model_time.append(t)       
72        stages.append(w)
73        elevations.append(z)  #Should be constant over time
74        momenta.append(m) 
75
76        if w-z > max_depth:
77            max_depth = w-z
78        if m > max_momentum:           
79            max_momentum = m   
80
81    #Augment building data
82    lines[k+1] = lines[k+1].strip() +\
83                     ',%f' %max_depth +\
84                     ',%f\n' %max_momentum
85   
86    print lines[k]
87   
88#Store new building file with mak depths added
89
90#FN = 'inundation_augmented_' + project.gauge_filename
91FN = project.gauge_outname
92fid = open(FN, 'w')
93for line in lines:
94    fid.write(line)
95fid.close()   
96
Note: See TracBrowser for help on using the repository browser.