source: production/pt_hedland_2006/get_building_inundation.py @ 3031

Last change on this file since 3031 was 2896, checked in by sexton, 19 years ago

scripts for determining building inundation - Onslow and Pt Hedland

File size: 3.9 KB
Line 
1""" Script for calculating maximum inundation at building locations
2
3    Inputs:
4
5    swwfile             - name of sww file
6                        - assume that all conserved quantities have been stored
7                   
8    buildings_filename  - name of file containing building data, sourced
9                          from NBED
10
11    time_min            - beginning of user defined time range
12                          - default will be first available time found in swwfile
13                       
14    time_max            - end of user defined time range
15                          - default will be last available time found in swwfile
16                       
17    Output:
18   
19    - building_filename (.csv) augmented to include maximum depth, momentum and
20      velocity and stored in same location as swwfile
21      Name = augmented_buildings.csv
22     
23    """
24
25from pyvolution.util import file_function
26import project
27from os import sep
28from math import sqrt
29
30# Inputs
31#timestampdir = '' # HAT
32timestampdir = '' # LAT
33file_loc = project.outputdir + timestampdir + sep
34swwfile = file_loc + project.basename + '.sww'
35buildings_filename = project.buildings_filename
36time_min = None
37time_max = None
38
39def get_buildings_from_file(filename):
40    from coordinate_transforms.redfearn import redfearn
41    fid = open(filename)
42    lines = fid.readlines()
43    fid.close()
44    buildings = []
45    line1 = lines[0]
46    line11 = line1.split(',')
47    for i in range(len(line11)):
48        if line11[i].strip('\n').strip(' ') == 'LATITUDE': lat_index = i
49        if line11[i].strip('\n').strip(' ') == 'LONGITUDE': lon_index = i
50        if line11[i].strip('\n').strip(' ') == 'BUILDING_N': name_index = i
51    for line in lines[1:]:
52        fields = line.split(',')
53        lat = float(fields[lat_index])
54        lon = float(fields[lon_index])
55        z, easting, northing = redfearn(lat,lon)
56        buildings.append([easting, northing])
57        loc = fields[name_index]
58   
59    return buildings, lines
60
61print '\n Buildings obtained from: %s \n' %buildings_filename
62buildings, lines = get_buildings_from_file(buildings_filename)
63
64sww_quantity = ['stage', 'elevation', 'xmomentum', 'ymomentum']
65
66f = file_function(swwfile,
67                  quantities = sww_quantity,
68                  interpolation_points = buildings,
69                  verbose = True,
70                  use_cache = True)
71
72T = f.get_time()
73
74if time_min is None:
75    time_min = min(T)
76else:
77    if time_min < min(T):
78        msg = 'Minimum time entered not correct - please try again'
79        raise Exception, msg
80
81if time_max is None:
82    time_max = max(T)
83else:
84    if time_max > max(T):
85        msg = 'Maximum time entered not correct - please try again'
86        raise Exception, msg
87
88lines[0] = lines[0].strip() +\
89           ',MAX INUNDATION DEPTH (m)' +\
90           ',MAX MOMENTUM (m^2/s)' +\
91           ',MAX SPEED (m/s) \n'
92
93for k, g in enumerate(buildings):
94    print 'Building %d of %d' %(k, len(buildings))
95    max_depth = 0
96    max_momentum = 0
97    max_velocity = 0     
98    for i, t in enumerate(T): 
99            w = f(t, point_id = k)[0]
100            z = f(t, point_id = k)[1]
101            uh = f(t, point_id = k)[2]
102            vh = f(t, point_id = k)[3]
103            depth = w-z
104            m = sqrt(uh*uh + vh*vh)   
105            vel = m / (depth + 1.e-30) 
106            if depth > max_depth: max_depth = w-z
107            if m > max_momentum: max_momentum = m
108            if vel > max_velocity: max_velocity = vel
109
110    lines[k+1] = lines[k+1].strip() +\
111                 ',%f' %max_depth +\
112                 ',%f' %max_momentum +\
113                 ',%f\n' %max_velocity
114
115augbuildingsfile = file_loc + 'augmented_buildings.csv'
116
117fid = open(augbuildingsfile, 'w')
118for line in lines:
119    fid.write(line)
120fid.close()
121
122print '\n Augmented building file written to %s \n' %augbuildingsfile
Note: See TracBrowser for help on using the repository browser.