source: anuga_work/production/australia_ph2/ceduna/build_boundary_64468.py @ 6342

Last change on this file since 6342 was 6342, checked in by myall, 15 years ago
File size: 5.8 KB
Line 
1"""
2Script for building boundary to run a tsunami inundation scenario for busselton,
3WA, Australia.  The boundary is sourced from the National Hazard Map.
4
5Input: order_filename from project.py
6       event_number needs to be reflected in the project file
7Output: creates a sts file and csv files stored in project.boundaries_dir_event.
8The run_busselton.py is reliant on the output of this script.
9"""
10import os
11from os import sep
12from os.path import join
13import project
14
15from anuga.utilities.numerical_tools import ensure_numeric
16from Scientific.IO.NetCDF import NetCDFFile
17from Numeric import asarray,transpose,sqrt,argmax,argmin,arange,Float,\
18    compress,zeros,fabs,allclose,ones
19from anuga.utilities.polygon import inside_polygon,read_polygon
20from time import localtime, strftime, gmtime
21from anuga.shallow_water.data_manager import urs2sts,create_sts_boundary
22
23try:
24    from pylab import plot,show,xlabel,ylabel,legend,title,savefig,hold
25except:
26    print 'Cannot import pylab plotting will not work. Csv files are still created'
27
28#--------------------------------------------------------------------------
29# Create sts boundary from mux2files
30#--------------------------------------------------------------------------
31# location of mux files
32# Note, this may change when all mux files are on the GA network
33dir=join(project.muxhome,'mux')
34
35# Refer to event_027255.list in home+state+sep+event08 for event details
36# taken from David's event list for 27255
37# Note, this is specific to the event and will be supplied by David.
38# In time, this will become more automated.
39urs_filenames = [
40    os.path.join(dir,'Sandwich-0006-z.grd'), 
41    os.path.join(dir,'Sandwich-0007-z.grd'),
42    os.path.join(dir,'Sandwich-0008-z.grd'),
43    os.path.join(dir,'Sandwich-0009-z.grd'), 
44    os.path.join(dir,'Sandwich-0010-z.grd'), 
45    os.path.join(dir,'Sandwich-0011-z.grd'), 
46    os.path.join(dir,'Sandwich-0012-z.grd'), 
47    os.path.join(dir,'Sandwich-0013-z.grd')] 
48 
49print 'number of sources', len(urs_filenames)
50
51if len(urs_filenames) == 8: #change per event
52
53    weight_factor = 24.2728 #change per event
54    weights=weight_factor*ones(len(urs_filenames),Float)
55
56    scenario_name = project.scenario_name
57    urs_order = join(project.urs_order)
58
59    print 'reading', urs_order
60
61    urs2sts(urs_filenames,
62            basename_out = join(project.event_sts),
63            ordering_filename = urs_order,
64            weights = weights,
65            mean_stage = project.tide,
66            verbose = True)
67else:
68    print 'number of sources do not match event.list'
69
70#------------------------------------------------------------------------------
71# Get gauges (timeseries of index points)
72#------------------------------------------------------------------------------
73def get_sts_gauge_data(filename,verbose=False):
74    from Numeric import asarray,transpose,sqrt,argmax,argmin,arange,Float,\
75        compress,zeros,fabs,take
76    fid = NetCDFFile(filename+'.sts', 'r')    #Open existing file for read
77    permutation = fid.variables['permutation'][:]
78    x = fid.variables['x'][:]+fid.xllcorner   #x-coordinates of vertices
79    y = fid.variables['y'][:]+fid.yllcorner   #y-coordinates of vertices
80    points=transpose(asarray([x.tolist(),y.tolist()]))
81    time=fid.variables['time'][:]+fid.starttime
82    elevation=fid.variables['elevation'][:]
83       
84    basename='sts_gauge'
85    quantity_names=['stage','xmomentum','ymomentum']
86    quantities = {}
87    for i, name in enumerate(quantity_names):
88        quantities[name] = fid.variables[name][:]
89
90    #------------------------------------------------------------------------------
91    # Get maxium wave height throughout timeseries at each index point
92    #------------------------------------------------------------------------------
93
94    maxname = 'max_sts_stage.csv'
95    fid_max = open(project.boundaries_dir_event+sep+maxname,'w')
96    s = 'index, x, y, max_stage \n'
97    fid_max.write(s)   
98    for j in range(len(x)):
99        index= permutation[j]
100        stage = quantities['stage'][:,j]
101        xmomentum = quantities['xmomentum'][:,j]
102        ymomentum = quantities['ymomentum'][:,j]
103
104        s = '%d, %.6f, %.6f, %.6f\n' %(index, x[j], y[j], max(stage))
105        fid_max.write(s)
106     
107    #------------------------------------------------------------------------------
108    # Get minium wave height throughout timeseries at each index point
109    #------------------------------------------------------------------------------
110
111    minname = 'min_sts_stage.csv'
112    fid_min = open(project.boundaries_dir_event+sep+minname,'w')
113    s = 'index, x, y, max_stage \n'
114    fid_min.write(s)   
115    for j in range(len(x)):
116        index= permutation[j]
117        stage = quantities['stage'][:,j]
118        xmomentum = quantities['xmomentum'][:,j]
119        ymomentum = quantities['ymomentum'][:,j]
120
121        s = '%d, %.6f, %.6f, %.6f\n' %(index, x[j], y[j], min(stage))
122        fid_min.write(s)
123       
124
125
126        fid_sts = open(project.boundaries_dir_event+sep+basename+'_'+ str(index)+'.csv', 'w')
127        s = 'time, stage, xmomentum, ymomentum \n'
128        fid_sts.write(s)
129
130    #------------------------------------------------------------------------------
131    # End of the get gauges
132    #------------------------------------------------------------------------------
133        for k in range(len(time)-1):
134            s = '%.6f, %.6f, %.6f, %.6f\n' %(time[k], stage[k], xmomentum[k], ymomentum[k])
135            fid_sts.write(s)
136
137        fid_sts.close()     
138
139    fid.close()
140
141
142    return quantities,elevation,time
143
144quantities,elevation,time=get_sts_gauge_data(os.path.join(project.boundaries_dir_event,project.scenario_name),verbose=False)
145
146print len(elevation), len(quantities['stage'][0,:])
147
Note: See TracBrowser for help on using the repository browser.