source: anuga_work/production/new_south_wales/batemans_bay/export_results_max.py @ 7577

Last change on this file since 7577 was 7577, checked in by jgriffin, 8 years ago
File size: 4.7 KB
Line 
1"""
2Generates ascii grids of nominated areas -
3Input: sww file from run_model.py
4       boundaries for grids from project.py
5Outputs: ascii grids of specified variables
6Stored in the 'outputs_folder' 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
23
24#Specify output directories
25time_dir1 = '20090601_172248_run_final_0.0_58284__250m_jgriffin'
26##time_dir2 = '20090529_143458_run_final_0.0_58346_jgriffin'
27
28time_dirs = [time_dir1]#, time_dir2]   
29
30# sww filename extensions ie. if batemans_bay_time_37860_0.sww, input into list 37860
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 = 250   #dependent on data resolution in area of interest.
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 = None    # None means no timestep!
42##timestep = 0
43
44######
45# Set the special areas of interest.  If none, do: area='All'
46######
47
48#area = ['', '']  # strings must match keys in var_equations below
49area = ['All']      # 'All' means no special areas - the whole thing
50
51######
52# Define allowed variable names and associated equations to generate values.
53# This would not normally change.
54######
55var_equations = {'stage':     'stage',
56                 'momentum':  '(xmomentum**2 + ymomentum**2)**0.5',
57                 'depth':     'stage-elevation',
58                 'speed':     '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)',
59                 'elevation': 'elevation' }
60
61# one or more key strings from var_equations above
62#var = ['depth', 'speed','stage']
63var = ['stage','speed','elevation']
64######
65# Start script, running through variables, area, folder, sww file (determine by times)
66# Then creates a maximum asci if there is more than one sww file
67######
68
69for which_var in var:
70    if which_var not in var_equations:
71        print 'Unrecognized variable name: %s' % which_var
72        break
73
74    for which_area in area:
75        if which_area == 'All':
76            easting_min = None
77            easting_max = None
78            northing_min = None
79            northing_max = None
80        else:
81            try:
82                easting_min = eval('project.xmin%s' % which_area)
83                easting_max = eval('project.xmax%s' % which_area)
84                northing_min = eval('project.ymin%s' % which_area)
85                northing_max = eval('project.ymax%s' % which_area)
86            except AttributeError:
87                print 'Unrecognized area name: %s' % which_area
88                break
89
90        for time_dir in time_dirs:
91            names = [join(directory, time_dir, project.scenario_name)]
92            for time in times:
93                names.append(join(directory, time_dir, project.scenario_name)+ '_time_' + str(time) + '_0')
94     
95            asc_name = []   
96               
97            for name in names:
98                         
99                outname = name + '_' + which_area + '_' + which_var
100                quantityname = var_equations[which_var]
101
102                print 'start sww2dem: time_dir=%s' % time_dir
103               
104                sww2dem(name, basename_out = outname,
105                            quantity = quantityname,
106                            timestep = timestep,
107                            cellsize = cellsize,     
108                            easting_min = easting_min,
109                            easting_max = easting_max,
110                            northing_min = northing_min,
111                            northing_max = northing_max,       
112                            reduction = max, 
113                            verbose = True,
114                            format = 'asc')
115
116                asc_name.append(outname + '.asc')
117   
118            if len(names) >1:
119                maxasc_outname = join(directory, time_dir, project.scenario_name)+'_'+which_area+'_'+which_var+'_max.asc'
120
121                print 'max asc outname ', maxasc_outname
122                print 'asc_name ', str(asc_name)
123           
124                MaxAsc(maxasc_outname, asc_name)
125            else:
126                print 'only one sww input'
Note: See TracBrowser for help on using the repository browser.