[5786] | 1 | """ |
---|
| 2 | Script for building the elevation data to run a tsunami inundation scenario |
---|
| 3 | for busselton, WA, Australia. |
---|
[4132] | 4 | |
---|
[5786] | 5 | Input: elevation data from project.py |
---|
| 6 | Output: pts file stored in project.topographies_dir |
---|
| 7 | The run_busselton.py is reliant on the output of this script. |
---|
[4132] | 8 | |
---|
| 9 | """ |
---|
| 10 | |
---|
| 11 | #------------------------------------------------------------------------------ |
---|
| 12 | # Import necessary modules |
---|
| 13 | #------------------------------------------------------------------------------ |
---|
| 14 | |
---|
| 15 | # Standard modules |
---|
| 16 | from os import sep |
---|
| 17 | from os.path import dirname, basename |
---|
| 18 | from os import mkdir, access, F_OK |
---|
| 19 | from shutil import copy |
---|
| 20 | import time |
---|
| 21 | import sys |
---|
| 22 | |
---|
| 23 | # Related major packages |
---|
| 24 | from anuga.shallow_water import Domain |
---|
| 25 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
| 26 | from anuga.geospatial_data.geospatial_data import * |
---|
[5786] | 27 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files |
---|
[4132] | 28 | |
---|
| 29 | # Application specific imports |
---|
| 30 | import project # Definition of file names and polygons |
---|
| 31 | |
---|
| 32 | #------------------------------------------------------------------------------ |
---|
| 33 | # Copy scripts to time stamped output directory and capture screen |
---|
| 34 | # output to file |
---|
| 35 | #------------------------------------------------------------------------------ |
---|
| 36 | |
---|
| 37 | copy_code_files(project.output_build_time_dir,__file__, |
---|
| 38 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
| 39 | |
---|
[5415] | 40 | start_screen_catcher(project.output_build_time_dir) |
---|
[4132] | 41 | |
---|
[5786] | 42 | print 'USER: ', project.user |
---|
[4132] | 43 | |
---|
| 44 | #------------------------------------------------------------------------------- |
---|
| 45 | # Preparation of topographic data |
---|
| 46 | # |
---|
| 47 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 48 | # Do for coarse and fine data |
---|
| 49 | # Fine pts file to be clipped to area of interest |
---|
| 50 | #------------------------------------------------------------------------------- |
---|
[5786] | 51 | print "project.poly_all", project.poly_all |
---|
| 52 | print "project.combined_dir_name", project.combined_dir_name |
---|
[4132] | 53 | |
---|
[5786] | 54 | # input elevation directory filenames |
---|
[4132] | 55 | onshore_in_dir_name = project.onshore_in_dir_name |
---|
| 56 | coast_in_dir_name = project.coast_in_dir_name |
---|
[5149] | 57 | coast_in_dir_name1 = project.coast_in_dir_name1 |
---|
[4132] | 58 | offshore_in_dir_name = project.offshore_in_dir_name |
---|
[5415] | 59 | offshore_in_dir_name1 = project.offshore_in_dir_name1 |
---|
| 60 | offshore_in_dir_name2 = project.offshore_in_dir_name2 |
---|
[5525] | 61 | offshore_in_dir_name3 = project.offshore_in_dir_name3 |
---|
[5646] | 62 | offshore_in_dir_name4 = project.offshore_in_dir_name4 |
---|
| 63 | offshore_in_dir_name5 = project.offshore_in_dir_name5 |
---|
[6560] | 64 | offshore_in_dir_name6 = project.offshore_in_dir_name6 |
---|
| 65 | offshore_in_dir_name7 = project.offshore_in_dir_name7 |
---|
[4132] | 66 | |
---|
[5786] | 67 | # output elevation directory filenames |
---|
[4132] | 68 | onshore_dir_name = project.onshore_dir_name |
---|
| 69 | coast_dir_name = project.coast_dir_name |
---|
[5149] | 70 | coast_dir_name1 = project.coast_dir_name1 |
---|
[4132] | 71 | offshore_dir_name = project.offshore_dir_name |
---|
[5415] | 72 | offshore_dir_name1 = project.offshore_dir_name1 |
---|
| 73 | offshore_dir_name2 = project.offshore_dir_name2 |
---|
[5525] | 74 | offshore_dir_name3 = project.offshore_dir_name3 |
---|
[5646] | 75 | offshore_dir_name4 = project.offshore_dir_name4 |
---|
| 76 | offshore_dir_name5 = project.offshore_dir_name5 |
---|
[6560] | 77 | offshore_dir_name6 = project.offshore_dir_name6 |
---|
| 78 | offshore_dir_name7 = project.offshore_dir_name7 |
---|
| 79 | |
---|
[4132] | 80 | # creates DEM from asc data |
---|
[5786] | 81 | print "creates DEMs from asc data" |
---|
[4132] | 82 | convert_dem_from_ascii2netcdf(onshore_in_dir_name, basename_out=onshore_dir_name, use_cache=True, verbose=True) |
---|
[6560] | 83 | convert_dem_from_ascii2netcdf(offshore_in_dir_name7, basename_out=offshore_dir_name7, use_cache=True, verbose=True) |
---|
[4132] | 84 | |
---|
[5786] | 85 | # creates pts file for onshore DEM |
---|
[4132] | 86 | print "creates pts file for onshore DEM" |
---|
[5786] | 87 | dem2pts(onshore_dir_name ,use_cache=True,verbose=True) |
---|
[6560] | 88 | dem2pts(offshore_dir_name7 ,use_cache=True,verbose=True) |
---|
[4132] | 89 | |
---|
[5786] | 90 | # create onshore pts files |
---|
| 91 | print'create Geospatial data1 objects from topographies' |
---|
| 92 | G1 = Geospatial_data(file_name = onshore_dir_name + '.pts') |
---|
[4132] | 93 | |
---|
[5786] | 94 | # create coastal and offshore pts files |
---|
| 95 | print'create Geospatial data2 objects from topographies' |
---|
[5829] | 96 | G2 = Geospatial_data(file_name = coast_in_dir_name) |
---|
[5786] | 97 | print'create Geospatial data3 objects from topographies' |
---|
[5829] | 98 | G3 = Geospatial_data(file_name = coast_in_dir_name1) |
---|
[5786] | 99 | print'create Geospatial data4 objects from topographies' |
---|
| 100 | G_off = Geospatial_data(file_name = offshore_in_dir_name) |
---|
| 101 | print'create Geospatial data5 objects from topographies' |
---|
| 102 | G_off1 = Geospatial_data(file_name = offshore_in_dir_name1) |
---|
| 103 | print'create Geospatial data6 objects from topographies' |
---|
| 104 | G_off2 = Geospatial_data(file_name = offshore_in_dir_name2) |
---|
| 105 | print'create Geospatial data7 objects from topographies' |
---|
| 106 | G_off3 = Geospatial_data(file_name = offshore_in_dir_name3) |
---|
| 107 | print'create Geospatial data8 objects from topographies' |
---|
| 108 | G_off4 = Geospatial_data(file_name = offshore_in_dir_name4) |
---|
| 109 | print'create Geospatial data9 objects from topographies' |
---|
[6560] | 110 | G_off5 = Geospatial_data(file_name = offshore_in_dir_name5) |
---|
| 111 | print'create Geospatial data9 objects from topographies' |
---|
| 112 | G_off6 = Geospatial_data(file_name = offshore_in_dir_name6) |
---|
| 113 | print'create Geospatial data9 objects from topographies' |
---|
| 114 | G_off7 = Geospatial_data(file_name = offshore_dir_name7 + '.pts') |
---|
[5786] | 115 | |
---|
| 116 | |
---|
[6560] | 117 | |
---|
| 118 | |
---|
[5786] | 119 | #------------------------------------------------------------------------------- |
---|
| 120 | # Combine, clip and export dataset |
---|
| 121 | #------------------------------------------------------------------------------- |
---|
| 122 | |
---|
[4132] | 123 | print'add all geospatial objects' |
---|
[6560] | 124 | G = G1 + G2 + G3 + G_off + G_off1 + G_off2 + G_off3 + G_off4 |
---|
[4132] | 125 | |
---|
| 126 | print'clip combined geospatial object by bounding polygon' |
---|
[6062] | 127 | G_clip = G.clip_outside(project.poly_aoi1) |
---|
[6560] | 128 | G_all = G_clip + G_off5 + G_off6 + G_off7 |
---|
[6062] | 129 | G_clipped = G_all.clip(project.poly_all) |
---|
[4132] | 130 | |
---|
| 131 | print'export combined DEM file' |
---|
| 132 | if access(project.topographies_dir,F_OK) == 0: |
---|
| 133 | mkdir (project.topographies_dir) |
---|
[5786] | 134 | G_clipped.export_points_file(project.combined_dir_name + '.pts') |
---|
[6062] | 135 | G_clipped.export_points_file(project.combined_dir_name + '.txt') #Use for comparision in ARC |
---|
[4132] | 136 | |
---|