source: anuga_work/production/hobart_2009/For_DVD/export_results_max.py @ 7304

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

Final changes to script

File size: 4.6 KB
Line 
1"""
2Generates ascii grids of nominated areas -
3Input: sww file from run_model.py
4       area 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 ~20m)
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
21directory = project.output_folder
22#Folders that contain the sww files of interest found in anuga/outputs
23time_dir1 = '20090619_165107_run_final_0_58260_None_kvanputt'
24time_dir2 = '20090619_165136_run_final_0.8_58260_None_kvanputt'
25
26time_dirs = [time_dir1, time_dir2] 
27
28# sww filename extensions ie. hobart_time_17640_0.sww, input into list 17640
29# make sure numbers are in sequential order
30times = [17640, 35280, 52920]
31           
32#Modify the cellsize value to set the size of the raster you require
33#Take into account mesh size when aplying this paramater
34cellsize = 20 #250
35
36#Now set the timestep at which you want the raster generated.
37#Either set the actual timestep required or use 'None' to indicate that
38#you want the maximum values in the raster over all timesteps
39timestep = None   #0
40
41# Set the special areas of interest.  If none, do: area=['All']
42# Areas identified below are specified by cooridinates in project.py 
43
44area = ['Hobart', 'NW', 'South'] 
45#area = ['All']     
46
47# one or more key strings from var_equations below
48var = ['depth', 'speed']
49
50######
51# Define allowed variable names and associated equations to generate values.
52# This would not normally change.
53######
54var_equations = {'stage':     'stage',
55                 'momentum':  '(xmomentum**2 + ymomentum**2)**0.5',
56                 'depth':     'stage-elevation',
57                 'speed':     '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)',
58                 'elevation': 'elevation' }
59
60
61######
62# Start script, running through variables, area, folder, sww file (determine by times)
63# Then creates a maximum asci if there is more than one sww file
64######
65
66for which_var in var:
67    if which_var not in var_equations:
68        print 'Unrecognized variable name: %s' % which_var
69        break
70
71    for which_area in area:
72        if which_area == 'All':
73            easting_min = None
74            easting_max = None
75            northing_min = None
76            northing_max = None
77        else:
78            try:
79                easting_min = eval('project.xmin%s' % which_area)
80                easting_max = eval('project.xmax%s' % which_area)
81                northing_min = eval('project.ymin%s' % which_area)
82                northing_max = eval('project.ymax%s' % which_area)
83            except AttributeError:
84                print 'Unrecognized area name: %s' % which_area
85                break
86
87        for time_dir in time_dirs:
88            names = [join(directory, time_dir, project.scenario_name)]
89            for time in times:
90                names.append(join(directory, time_dir, project.scenario_name)+ '_time_' + str(time) + '_0')
91           
92            asc_name = []   
93                           
94            for name in names:
95                outname = name + '_' + which_area + '_' + which_var
96                quantityname = var_equations[which_var]
97
98                print 'start sww2dem: time_dir=%s' % time_dir
99                print 'name=%s' % name
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           
114            if len(names) >1:
115                maxasc_outname = join(directory, time_dir, project.scenario_name)+'_'+which_area+'_'+which_var+'_max.asc'
116
117                print 'max asc outname ', maxasc_outname
118                print 'asc_name ', str(asc_name)
119               
120                MaxAsc(maxasc_outname, asc_name)
Note: See TracBrowser for help on using the repository browser.