[5971] | 1 | """Common filenames and locations for elevation, meshes and outputs. |
---|
| 2 | This script is the heart of all scripts in the folder |
---|
| 3 | """ |
---|
| 4 | #------------------------------------------------------------------------------ |
---|
| 5 | # Import necessary modules |
---|
| 6 | #------------------------------------------------------------------------------ |
---|
| 7 | |
---|
| 8 | from os import sep, environ, getenv, getcwd |
---|
| 9 | from os.path import expanduser |
---|
| 10 | import sys |
---|
| 11 | from time import localtime, strftime, gmtime |
---|
| 12 | from anuga.utilities.polygon import read_polygon, plot_polygons, is_inside_polygon, number_mesh_triangles |
---|
| 13 | from anuga.utilities.system_tools import get_user_name, get_host_name |
---|
| 14 | from anuga.shallow_water.data_manager import urs2sts,create_sts_boundary |
---|
| 15 | from anuga.utilities.polygon import read_polygon, plot_polygons, polygon_area, is_inside_polygon |
---|
| 16 | |
---|
| 17 | #------------------------------------------------------------------------------ |
---|
| 18 | # Directory setup |
---|
| 19 | #------------------------------------------------------------------------------ |
---|
| 20 | # Note: INUNDATIONHOME is the inundation directory, not the data directory. |
---|
| 21 | |
---|
| 22 | home = getenv('INUNDATIONHOME') + sep +'data'+sep #Sandpit's parent diruser = get_user_name() |
---|
| 23 | user = get_user_name() |
---|
| 24 | host = get_host_name() |
---|
| 25 | |
---|
| 26 | # determines time for setting up output directories |
---|
| 27 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
| 28 | gtime = strftime('%Y%m%d_%H%M%S',gmtime()) |
---|
| 29 | build_time = time+'_build' |
---|
| 30 | run_time = time+'_run' |
---|
| 31 | |
---|
| 32 | #------------------------------------------------------------------------------ |
---|
| 33 | # Initial Conditions |
---|
| 34 | #------------------------------------------------------------------------------ |
---|
| 35 | |
---|
| 36 | # this section needs to be updated to reflect the modelled community. |
---|
| 37 | # Note, the user needs to set up the directory system accordingly |
---|
| 38 | state = 'thailand' |
---|
| 39 | scenario_name = 'patong' |
---|
| 40 | scenario = 'patong_tsunami_scenario' |
---|
| 41 | |
---|
| 42 | # Model specific parameters. One or all can be changed each time the |
---|
| 43 | # run_scenario script is executed |
---|
[6028] | 44 | tide = 0.8 #0.8 |
---|
[5971] | 45 | alpha = 0.1 # smoothing parameter for mesh |
---|
| 46 | friction=0.01 # manning's friction coefficient |
---|
| 47 | starttime=0 |
---|
| 48 | finaltime=15000 # final time for simulation 15000 |
---|
| 49 | |
---|
[6322] | 50 | setup='final' # Final can be replaced with trial or basic. |
---|
[5971] | 51 | # Either will result in a coarser mesh that will allow a |
---|
| 52 | # faster, but less accurate, simulation. |
---|
| 53 | |
---|
| 54 | if setup =='trial': |
---|
| 55 | print'trial' |
---|
| 56 | res_factor=10 |
---|
| 57 | time_thinning=48 |
---|
| 58 | yieldstep=240 |
---|
| 59 | if setup =='basic': |
---|
| 60 | print'basic' |
---|
| 61 | res_factor=4 |
---|
[6225] | 62 | time_thinning=24 |
---|
[5971] | 63 | yieldstep=120 |
---|
| 64 | if setup =='final': |
---|
| 65 | print'final' |
---|
| 66 | res_factor=1 |
---|
[6225] | 67 | time_thinning=4 |
---|
[6322] | 68 | yieldstep=5 |
---|
[5971] | 69 | |
---|
[6264] | 70 | use_buildings = True |
---|
| 71 | |
---|
[5971] | 72 | #------------------------------------------------------------------------------ |
---|
| 73 | # Output Filename |
---|
| 74 | #------------------------------------------------------------------------------ |
---|
| 75 | # Important to distinguish each run - ensure str(user) is included! |
---|
| 76 | # Note, the user is free to include as many parameters as desired |
---|
[6264] | 77 | if use_buildings: |
---|
| 78 | dir_comment='_'+setup+'_'+str(tide)+'_buildings_'+str(user) |
---|
| 79 | else: |
---|
| 80 | dir_comment='_'+setup+'_'+str(tide)+'_nobuildings_'+str(user) |
---|
[5971] | 81 | |
---|
| 82 | #------------------------------------------------------------------------------ |
---|
| 83 | # Input Data |
---|
| 84 | #------------------------------------------------------------------------------ |
---|
| 85 | |
---|
| 86 | # elevation data used in build_patong.py |
---|
| 87 | # four textfiles, with different resolutions |
---|
[6168] | 88 | elevation1 = 'patong_10m_grid_msl_Project.txt' |
---|
| 89 | elevation2 = 'patong_10m_small_grid_for_anuga_sub_Project.txt' |
---|
| 90 | elevation3 = 'patong_bay_1s_grid_Project.txt' |
---|
[6271] | 91 | elevation4 = 'andaman_3s_grid_Clip2_Project.txt' |
---|
[5971] | 92 | |
---|
| 93 | # gauges - used in get_timeseries.py |
---|
[6321] | 94 | gauge_name = 'gauges.csv' |
---|
[5971] | 95 | |
---|
| 96 | # BOUNDING POLYGON - used in build_boundary.py and run_patong.py respectively |
---|
| 97 | # NOTE: when files are put together the points must be in sequence - for ease go clockwise! |
---|
| 98 | # Check the run_patong.py for boundary_tags |
---|
| 99 | # thinned ordering file from Hazard Map: format is index,latitude,longitude (with title) |
---|
[6321] | 100 | order_filename = 'urs_order.csv' |
---|
[5971] | 101 | #landward bounding points |
---|
[6321] | 102 | landward = 'landward_bounding_polygon2.csv' |
---|
[5971] | 103 | |
---|
| 104 | #------------------------------------------------------------------------------ |
---|
| 105 | # Output Elevation Data |
---|
| 106 | #------------------------------------------------------------------------------ |
---|
| 107 | # Output filename for elevation |
---|
| 108 | # this is a combination of all the data (utilisied in build_boundary) |
---|
[6321] | 109 | combined_name ='patong_combined_elevation_large' |
---|
[5971] | 110 | combined_smaller_name = 'patong_combined_elevation_smaller' |
---|
| 111 | |
---|
| 112 | #------------------------------------------------------------------------------ |
---|
| 113 | # Directory Structure |
---|
| 114 | #------------------------------------------------------------------------------ |
---|
| 115 | anuga_dir = home+state+sep+scenario+sep+'anuga'+sep |
---|
| 116 | topographies_in_dir = home+state+sep+scenario+sep+'elevation_final'+sep+'points'+sep |
---|
| 117 | topographies_dir = anuga_dir+'topographies'+sep |
---|
| 118 | polygons_dir = anuga_dir+'polygons'+sep |
---|
| 119 | tide_dir = anuga_dir+'tide_data'+sep |
---|
| 120 | boundaries_dir = anuga_dir+'boundaries'+ sep |
---|
| 121 | output_dir = anuga_dir+'outputs'+sep |
---|
| 122 | gauges_dir = anuga_dir+'gauges'+sep |
---|
| 123 | meshes_dir = anuga_dir+'meshes'+sep |
---|
| 124 | |
---|
| 125 | #------------------------------------------------------------------------------ |
---|
| 126 | # Location of input and output data |
---|
| 127 | #------------------------------------------------------------------------------ |
---|
| 128 | # where the input data sits |
---|
| 129 | elevation_in_dir_name1 = topographies_in_dir + elevation1 |
---|
| 130 | elevation_in_dir_name2 = topographies_in_dir + elevation2 |
---|
| 131 | elevation_in_dir_name3 = topographies_in_dir + elevation3 |
---|
| 132 | elevation_in_dir_name4 = topographies_in_dir + elevation4 |
---|
| 133 | |
---|
| 134 | # where the output data sits |
---|
| 135 | elevation_dir_name1 = topographies_dir + elevation1 |
---|
| 136 | elevation_dir_name2 = topographies_dir + elevation2 |
---|
| 137 | elevation_dir_name3 = topographies_dir + elevation3 |
---|
| 138 | elevation_dir_name4 = topographies_dir + elevation4 |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | # where the combined elevation file sits |
---|
[6203] | 142 | combined_dir_name = topographies_dir + combined_name + '_data' |
---|
[5971] | 143 | combined_smaller_name_dir = topographies_dir + combined_smaller_name |
---|
| 144 | |
---|
| 145 | # where the mesh sits (this is created during the run_patong.py) |
---|
[6203] | 146 | meshes_dir_name = meshes_dir + scenario_name+'_poly.msh' |
---|
[5971] | 147 | |
---|
| 148 | # where the boundary ordering files sit (this is used within build_boundary.py) |
---|
| 149 | order_filename_dir = boundaries_dir + order_filename |
---|
| 150 | |
---|
| 151 | # where the landward points of boundary extent sit (this is used within run_patong.py) |
---|
| 152 | landward_dir = boundaries_dir + landward |
---|
| 153 | |
---|
| 154 | # where the directory of the output filename sits |
---|
| 155 | output_build_time_dir = output_dir+build_time+dir_comment+sep #used for build_patong.py |
---|
| 156 | output_run_time_dir = output_dir+run_time+dir_comment+sep #used for run_patong.py |
---|
| 157 | output_run_time_dir_name = output_run_time_dir + scenario_name #Used by post processing |
---|
| 158 | |
---|
| 159 | # where the directory of the gauges sit |
---|
| 160 | gauges_dir_name = gauges_dir + gauge_name #used for get_timeseries.py |
---|
| 161 | |
---|
| 162 | #------------------------------------------------------------------------------ |
---|
| 163 | # Interior region definitions |
---|
| 164 | #------------------------------------------------------------------------------ |
---|
| 165 | |
---|
| 166 | # extents of elevation datasets |
---|
| 167 | extent_elev_dir1 = read_polygon(polygons_dir + 'patong_10m.txt') |
---|
| 168 | extent_elev_dir2 = read_polygon(polygons_dir + 'saddle_10m.txt') |
---|
| 169 | extent_elev_dir3 = read_polygon(polygons_dir + 'patong_1s.txt') |
---|
[6028] | 170 | extent_elev_dir4 = read_polygon(polygons_dir + 'patong_10m_aos.txt') |
---|
[5971] | 171 | |
---|
| 172 | #Land, to set the initial stage/water to be offcoast only |
---|
| 173 | poly_mainland = read_polygon(polygons_dir+'initial_conditions.csv') |
---|
| 174 | |
---|
| 175 | # Initial bounding polygon for data clipping |
---|
[6321] | 176 | poly_all = read_polygon(polygons_dir+'bounding_polygon.csv') |
---|
[6334] | 177 | res_poly_all = 160000*res_factor |
---|
[5971] | 178 | |
---|
[6264] | 179 | |
---|
| 180 | # Inundation area |
---|
| 181 | poly_ia = read_polygon(polygons_dir+'inundation_area.csv') |
---|
[6334] | 182 | res_ia = 75*res_factor |
---|
[6264] | 183 | poly_saddle = read_polygon(polygons_dir+'saddle_10m.txt') |
---|
| 184 | |
---|
[5971] | 185 | # Area of Interest 1 elevation from -10m to 20m |
---|
| 186 | poly_aoi1 = read_polygon(polygons_dir+'aoi.csv') |
---|
[6334] | 187 | res_aoi1 = 200*res_factor |
---|
[5971] | 188 | |
---|
| 189 | # Area of Significance 1 elevation from -20m to a 200m buffer of the 20m contour |
---|
| 190 | poly_aos1 = read_polygon(polygons_dir+'aos.csv') |
---|
[6334] | 191 | res_aos1 = 900*res_factor |
---|
[5971] | 192 | |
---|
[6264] | 193 | |
---|
[6028] | 194 | # Area of Shallow water and coastal land that needs a finer res than 1000000 |
---|
| 195 | poly_sw = read_polygon(polygons_dir+'sw.csv') |
---|
[6334] | 196 | res_sw = 7000*res_factor |
---|
[6028] | 197 | |
---|
[6192] | 198 | |
---|
[6264] | 199 | |
---|
[6192] | 200 | # Area of buildings |
---|
| 201 | building_main = read_polygon(polygons_dir+'building_main.csv') |
---|
| 202 | building_main_small = read_polygon(polygons_dir+'building_main_small.csv') |
---|
| 203 | building_main_south = read_polygon(polygons_dir+'building_main_south.csv') |
---|
| 204 | building_saddle = read_polygon(polygons_dir+'building_saddle.csv') |
---|
[6225] | 205 | building_area_polygons = [building_main, building_main_small, building_main_south, building_saddle] |
---|
[6322] | 206 | bld_res = 20*res_factor |
---|
[6192] | 207 | |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | |
---|
[5971] | 211 | # Combined all regions, must check that all are included! |
---|
[6264] | 212 | interior_regions = [[poly_ia, res_ia], |
---|
| 213 | #[poly_saddle, res_ia], |
---|
| 214 | [poly_aoi1,res_aoi1], |
---|
[6192] | 215 | [poly_aos1,res_aos1], |
---|
| 216 | [poly_sw,res_sw], |
---|
| 217 | [building_main, bld_res], |
---|
| 218 | [building_main_small, bld_res], |
---|
| 219 | [building_main_south, bld_res], |
---|
| 220 | [building_saddle, bld_res]] |
---|
[5971] | 221 | |
---|
| 222 | |
---|
| 223 | trigs_min = number_mesh_triangles(interior_regions, poly_all, res_poly_all) |
---|
| 224 | print 'min estimated number of triangles', trigs_min |
---|
[6133] | 225 | |
---|
[5971] | 226 | #------------------------------------------------------------------------------ |
---|
[6133] | 227 | # Building polygons |
---|
| 228 | #------------------------------------------------------------------------------ |
---|
| 229 | |
---|
| 230 | building_polygon_file = polygons_dir+'buildings.csv' |
---|
| 231 | |
---|
| 232 | #------------------------------------------------------------------------------ |
---|
[5971] | 233 | # Clipping regions for export to asc and regions for clipping data |
---|
| 234 | # Final inundation maps should only be created in regions of the finest mesh |
---|
| 235 | #------------------------------------------------------------------------------ |
---|
| 236 | |
---|
[6225] | 237 | #CBD extract ascii grid - coordinates from patong_1s extent |
---|
[5971] | 238 | xminCBD = 417445.1119 |
---|
| 239 | xmaxCBD = 425601.7881 |
---|
| 240 | yminCBD = 870663.4547 |
---|
| 241 | ymaxCBD = 876965.3856 |
---|
| 242 | |
---|
| 243 | |
---|