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

Last change on this file since 7606 was 7606, checked in by jgriffin, 14 years ago

Added extra events for probabilistic run

File size: 4.9 KB
RevLine 
[6386]1"""
2Generates ascii grids of nominated areas -
[7327]3Input: sww file from run_model.py
[6386]4       boundaries for grids from project.py
5Outputs: ascii grids of specified variables
[7327]6Stored in the 'outputs_folder' folder for respective .sww file
[6386]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
[7252]24#Specify output directories
[7606]25time_dir1 = '20090528_153025_run_final_0.0_58346_jgriffin'
[7577]26##time_dir2 = '20090529_143458_run_final_0.0_58346_jgriffin'
[6386]27
[7577]28time_dirs = [time_dir1]#, time_dir2]   
[6386]29
[7369]30# sww filename extensions ie. if batemans_bay_time_37860_0.sww, input into list 37860
[7351]31# make sure numbers are in sequential order
[7606]32times = [37860]
[7351]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
[7606]36cellsize = 20   #dependent on data resolution in area of interest.
[6386]37
[7351]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
[6552]41timestep = None    # None means no timestep!
42##timestep = 0
[6386]43
44######
45# Set the special areas of interest.  If none, do: area='All'
46######
47
[7252]48#area = ['', '']  # strings must match keys in var_equations below
[6386]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)',
[7606]59                 'energy':  '(((xmomentum/(stage-elevation+1.e-6))**2 + (ymomentum/(stage-elevation+1.e-6))**2)*0.5*1000*(stage-elevation+1.e-6))+(9.81*stage*1000)',
[6386]60                 'elevation': 'elevation' }
61
62# one or more key strings from var_equations above
[7327]63#var = ['depth', 'speed','stage']
[7606]64var = ['energy']
[6386]65######
[7351]66# Start script, running through variables, area, folder, sww file (determine by times)
67# Then creates a maximum asci if there is more than one sww file
[6386]68######
69
70for which_var in var:
71    if which_var not in var_equations:
72        print 'Unrecognized variable name: %s' % which_var
73        break
74
75    for which_area in area:
76        if which_area == 'All':
77            easting_min = None
78            easting_max = None
79            northing_min = None
80            northing_max = None
81        else:
82            try:
83                easting_min = eval('project.xmin%s' % which_area)
84                easting_max = eval('project.xmax%s' % which_area)
85                northing_min = eval('project.ymin%s' % which_area)
86                northing_max = eval('project.ymax%s' % which_area)
87            except AttributeError:
88                print 'Unrecognized area name: %s' % which_area
89                break
90
91        for time_dir in time_dirs:
[7351]92            names = [join(directory, time_dir, project.scenario_name)]
93            for time in times:
94                names.append(join(directory, time_dir, project.scenario_name)+ '_time_' + str(time) + '_0')
[6386]95     
[6552]96            asc_name = []   
[6386]97               
98            for name in names:
99                         
100                outname = name + '_' + which_area + '_' + which_var
101                quantityname = var_equations[which_var]
102
103                print 'start sww2dem: time_dir=%s' % time_dir
104               
105                sww2dem(name, basename_out = outname,
106                            quantity = quantityname,
107                            timestep = timestep,
108                            cellsize = cellsize,     
109                            easting_min = easting_min,
110                            easting_max = easting_max,
111                            northing_min = northing_min,
112                            northing_max = northing_max,       
113                            reduction = max, 
114                            verbose = True,
115                            format = 'asc')
116
[6552]117                asc_name.append(outname + '.asc')
118   
[7351]119            if len(names) >1:
120                maxasc_outname = join(directory, time_dir, project.scenario_name)+'_'+which_area+'_'+which_var+'_max.asc'
[6552]121
[7351]122                print 'max asc outname ', maxasc_outname
123                print 'asc_name ', str(asc_name)
[6552]124           
[7351]125                MaxAsc(maxasc_outname, asc_name)
126            else:
127                print 'only one sww input'
Note: See TracBrowser for help on using the repository browser.