source: anuga_work/production/gold_coast_2009/export_results_max.py @ 7365

Last change on this file since 7365 was 7365, checked in by kristy, 15 years ago

updated script with times

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