1 | import os |
---|
2 | from os import sep |
---|
3 | import project |
---|
4 | try: |
---|
5 | from pylab import plot,show,xlabel,ylabel,legend,title,savefig,hold |
---|
6 | except: |
---|
7 | print 'Cannot import pylab plotting will not work. Csv files are still created' |
---|
8 | from anuga.utilities.polygon import inside_polygon |
---|
9 | from anuga.utilities.numerical_tools import ensure_numeric |
---|
10 | from Scientific.IO.NetCDF import NetCDFFile |
---|
11 | |
---|
12 | def get_sts_gauge_data(filename,verbose=False): |
---|
13 | from Numeric import asarray,transpose,sqrt,argmax,argmin,arange,Float,\ |
---|
14 | compress,zeros,fabs,take |
---|
15 | fid = NetCDFFile(filename+'.sts', 'r') #Open existing file for read |
---|
16 | x = fid.variables['x'][:]+fid.xllcorner #x-coordinates of vertices |
---|
17 | y = fid.variables['y'][:]+fid.yllcorner #y-coordinates of vertices |
---|
18 | points=transpose(asarray([x.tolist(),y.tolist()])) |
---|
19 | time=fid.variables['time'][:]+fid.starttime |
---|
20 | elevation=fid.variables['elevation'][:] |
---|
21 | print 'hello', fid.variables.keys() |
---|
22 | |
---|
23 | |
---|
24 | basename='sts_gauge' |
---|
25 | quantity_names=['stage','xmomentum','ymomentum'] |
---|
26 | quantities = {} |
---|
27 | for i, name in enumerate(quantity_names): |
---|
28 | quantities[name] = fid.variables[name][:] |
---|
29 | |
---|
30 | maxname = 'max_sts_stage.csv' |
---|
31 | fid_max = open(project.boundaries_dir+sep+maxname,'w') |
---|
32 | s = 'x, y, max_stage \n' |
---|
33 | fid_max.write(s) |
---|
34 | for j in range(len(x)): |
---|
35 | locx=int(x[j]) |
---|
36 | locy=int(y[j]) |
---|
37 | stage = quantities['stage'][:,j] |
---|
38 | xmomentum = quantities['xmomentum'][:,j] |
---|
39 | ymomentum = quantities['ymomentum'][:,j] |
---|
40 | |
---|
41 | s = '%.6f, %.6f, %.6f\n' %(x[j], y[j], max(stage)) |
---|
42 | fid_max.write(s) |
---|
43 | |
---|
44 | fid_sts = open(project.boundaries_dir+sep+basename+'_'+str(locx)+'_'+str(locy)+'.csv', 'w') |
---|
45 | s = 'time, stage, xmomentum, ymomentum \n' |
---|
46 | fid_sts.write(s) |
---|
47 | |
---|
48 | for k in range(len(time)-1): |
---|
49 | s = '%.6f, %.6f, %.6f, %.6f\n' %(time[k], stage[k], xmomentum[k], ymomentum[k]) |
---|
50 | fid_sts.write(s) |
---|
51 | |
---|
52 | fid_sts.close() |
---|
53 | |
---|
54 | fid.close() |
---|
55 | |
---|
56 | return quantities,elevation,time |
---|
57 | |
---|
58 | quantities,elevation,time=get_sts_gauge_data(os.path.join(project.boundaries_dir,project.scenario_name),verbose=False) |
---|
59 | |
---|
60 | print len(elevation), len(quantities['stage'][0,:]) |
---|