source: anuga_work/production/bunbury_storm_surge_2009/export_results_max.py @ 7658

Last change on this file since 7658 was 7613, checked in by fountain, 14 years ago

Bunbury storm surge modelling

File size: 4.8 KB
Line 
1"""
2Generates ascii grids of nominated areas -
3Input: sww file from run_perth.py
4       boundaries for grids from project.py
5Outputs: ascii grids of specified variables
6Stored in the 'outputs_dir' folder for respective .sww file
7
8Note:
9If producing a grid for the enitre extent cellsize should be greater than 30m
10If producing grids for inundation area resolution should be greater than mesh (ie ~22m)
11"""
12
13import project, os
14import sys
15from os.path import join
16from anuga.lib.maxasc.maxasc import MaxAsc
17from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
18from anuga.shallow_water.data_manager import sww2dem
19from os import sep
20
21
22directory = project.output_folder
23time_dir1 = '20100103_102505_run_storm_surge_final_0_alby_coarse_lfountai'
24
25time_dirs = [time_dir1] 
26
27# sww filename extensions ie. hobart_time_17640_0.sww, input into list 17640
28# make sure numbers are in sequential order
29times = []
30           
31#Modify the cellsize value to set the size of the raster you require
32#Take into account mesh size when aplying this paramater
33cellsize = 20 #250
34
35#Now set the timestep at which you want the raster generated.
36#Either set the actual timestep required or use 'None' to indicate that
37#you want the maximum values in the raster over all timesteps
38timestep = 0
39
40# Set the special areas of interest.  If none, do: area=['All']
41# Areas identified below are specified by cooridinates in project.py 
42
43#area = ['South', 'NW', 'Hobart']
44area = ['All']     
45
46# one or more key strings from var_equations below
47var = ['elevation']
48
49######
50# Define allowed variable names and associated equations to generate values.
51# This would not normally change.
52######
53var_equations = {'stage':     'stage',
54                 'momentum':  '(xmomentum**2 + ymomentum**2)**0.5',
55                 'depth':     'stage-elevation',
56                 'speed':     '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)',
57                 'elevation': 'elevation' }
58
59
60######
61# Start script, running through variables, area, folder, sww file (determine by times)
62# Then creates a maximum asci if there is more than one sww file
63######
64
65for which_var in var:
66    if which_var not in var_equations:
67        print 'Unrecognized variable name: %s' % which_var
68        break
69
70    for which_area in area:
71        if which_area == 'All':
72            easting_min = None
73            easting_max = None
74            northing_min = None
75            northing_max = None
76        else:
77            try:
78                easting_min = eval('project.xmin%s' % which_area)
79                easting_max = eval('project.xmax%s' % which_area)
80                northing_min = eval('project.ymin%s' % which_area)
81                northing_max = eval('project.ymax%s' % which_area)
82            except AttributeError:
83                print 'Unrecognized area name: %s' % which_area
84                break
85
86        for time_dir in time_dirs:
87            names = [join(directory, time_dir, project.scenario_name)]
88            for time in times:
89                names.append(join(directory, time_dir, project.scenario_name)+ '_time_' + str(time) + '_0')
90           
91            asc_name = []   
92            print 'start sww2dem: time_dir = %s' % time_dir               
93            for name in names:
94
95                outname = name + '_' + which_area + '_' + which_var
96                quantityname = var_equations[which_var]
97
98                print 'start sww2dem: name = %s' % os.path.basename(name)
99               
100                sww2dem(name, basename_out = outname,
101                            quantity = quantityname,
102                            timestep = timestep,
103                            cellsize = cellsize,     
104                            easting_min = easting_min,
105                            easting_max = easting_max,
106                            northing_min = northing_min,
107                            northing_max = northing_max,       
108                            reduction = max, 
109                            verbose = True,
110                            format = 'asc')
111
112                asc_name.append(outname + '.asc')
113            #print 'list = %s' % asc_name
114            #print 'max asc outname ', maxasc_outname
115            #print 'name=%s' % name
116            print 'which area=%s' % which_area
117            print 'which var=%s' % which_var
118            #print 'asc_name ', str(asc_name)
119            if len(names) >1:
120                maxasc_outname = join(directory, time_dir, project.scenario_name)+'_'+which_area+'_'+which_var+'_max.asc'
121
122                print 'max asc outname ', maxasc_outname
123                print 'asc_name ', str(asc_name)
124               
125                MaxAsc(maxasc_outname, asc_name)
126            else:
127                print 'Only one sww file, no Max file required' 
128
Note: See TracBrowser for help on using the repository browser.