[5761] | 1 | """ |
---|
[5784] | 2 | Script for building the elevation data to run a tsunami inundation scenario |
---|
[5761] | 3 | for Perth, WA, Australia. |
---|
[4077] | 4 | |
---|
[5761] | 5 | Input: elevation data from project.py |
---|
| 6 | Output: pts file stored in project.topographies_dir |
---|
[5759] | 7 | The run_perth.py is reliant on the output of this script. |
---|
| 8 | |
---|
[4077] | 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 * |
---|
[5360] | 27 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files |
---|
[4077] | 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 | |
---|
| 40 | start_screen_catcher(project.output_build_time_dir) |
---|
| 41 | |
---|
| 42 | print 'USER: ', project.user |
---|
| 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 | #------------------------------------------------------------------------------- |
---|
[5784] | 51 | print "project.poly_all", project.poly_all |
---|
| 52 | print "project.combined_dir_name", project.combined_dir_name |
---|
[4091] | 53 | |
---|
[5759] | 54 | # input elevation directory filenames |
---|
[4080] | 55 | onshore_in_dir_name = project.onshore_in_dir_name |
---|
| 56 | coast_in_dir_name = project.coast_in_dir_name |
---|
| 57 | island_in_dir_name = project.island_in_dir_name |
---|
| 58 | island_in_dir_name1 = project.island_in_dir_name1 |
---|
| 59 | island_in_dir_name2 = project.island_in_dir_name2 |
---|
| 60 | island_in_dir_name3 = project.island_in_dir_name3 |
---|
| 61 | offshore_in_dir_name = project.offshore_in_dir_name |
---|
[5524] | 62 | offshore_in_dir_name1 = project.offshore_in_dir_name1 |
---|
| 63 | offshore_in_dir_name2 = project.offshore_in_dir_name2 |
---|
[5753] | 64 | offshore_in_dir_name3 = project.offshore_in_dir_name3 |
---|
[4077] | 65 | |
---|
[5759] | 66 | # output elevation directory filenames |
---|
[4077] | 67 | onshore_dir_name = project.onshore_dir_name |
---|
| 68 | coast_dir_name = project.coast_dir_name |
---|
[4080] | 69 | island_dir_name = project.island_dir_name |
---|
| 70 | island_dir_name1 = project.island_dir_name1 |
---|
| 71 | island_dir_name2 = project.island_dir_name2 |
---|
| 72 | island_dir_name3 = project.island_dir_name3 |
---|
[4077] | 73 | offshore_dir_name = project.offshore_dir_name |
---|
[5524] | 74 | offshore_dir_name1 = project.offshore_dir_name1 |
---|
| 75 | offshore_dir_name2 = project.offshore_dir_name2 |
---|
[5753] | 76 | offshore_dir_name3 = project.offshore_dir_name3 |
---|
[4077] | 77 | |
---|
| 78 | # creates DEM from asc data |
---|
[4091] | 79 | print "creates DEMs from asc data" |
---|
[4080] | 80 | convert_dem_from_ascii2netcdf(onshore_in_dir_name, basename_out=onshore_dir_name, use_cache=True, verbose=True) |
---|
| 81 | convert_dem_from_ascii2netcdf(island_in_dir_name, basename_out=island_dir_name, use_cache=True, verbose=True) |
---|
| 82 | convert_dem_from_ascii2netcdf(island_in_dir_name1, basename_out=island_dir_name1, use_cache=True, verbose=True) |
---|
| 83 | convert_dem_from_ascii2netcdf(island_in_dir_name2, basename_out=island_dir_name2, use_cache=True, verbose=True) |
---|
| 84 | convert_dem_from_ascii2netcdf(island_in_dir_name3, basename_out=island_dir_name3, use_cache=True, verbose=True) |
---|
[4077] | 85 | |
---|
[5784] | 86 | # creates pts file for onshore DEM |
---|
[4091] | 87 | print "creates pts file for onshore DEM" |
---|
[5759] | 88 | dem2pts(onshore_dir_name ,use_cache=True,verbose=True) |
---|
[4077] | 89 | |
---|
[5784] | 90 | # creates pts file for island DEM |
---|
[4080] | 91 | dem2pts(island_dir_name, use_cache=True, verbose=True) |
---|
| 92 | dem2pts(island_dir_name1, use_cache=True, verbose=True) |
---|
| 93 | dem2pts(island_dir_name2, use_cache=True, verbose=True) |
---|
| 94 | dem2pts(island_dir_name3, use_cache=True, verbose=True) |
---|
[4077] | 95 | |
---|
[5784] | 96 | # create onshore pts files |
---|
[4091] | 97 | print'create Geospatial data1 objects from topographies' |
---|
[4080] | 98 | G1 = Geospatial_data(file_name = onshore_dir_name + '.pts') |
---|
[4091] | 99 | print'create Geospatial data2 objects from topographies' |
---|
[5759] | 100 | G2 = Geospatial_data(file_name = island_dir_name + '.pts') |
---|
[4091] | 101 | print'create Geospatial data3 objects from topographies' |
---|
[5759] | 102 | G3 = Geospatial_data(file_name = island_dir_name1 + '.pts') |
---|
[4091] | 103 | print'create Geospatial data4 objects from topographies' |
---|
[5759] | 104 | G4 = Geospatial_data(file_name = island_dir_name2 + '.pts') |
---|
[4091] | 105 | print'create Geospatial data5 objects from topographies' |
---|
[5759] | 106 | G5 = Geospatial_data(file_name = island_dir_name3 + '.pts') |
---|
[5784] | 107 | |
---|
| 108 | # create coastal and offshore pts files |
---|
[4091] | 109 | print'create Geospatial data6 objects from topographies' |
---|
[5759] | 110 | G_coast = Geospatial_data(file_name = coast_in_dir_name) |
---|
[4091] | 111 | print'create Geospatial data7 objects from topographies' |
---|
[5759] | 112 | G_off = Geospatial_data(file_name = offshore_in_dir_name) |
---|
[5753] | 113 | print'create Geospatial data8 objects from topographies' |
---|
[5759] | 114 | G_off1 = Geospatial_data(file_name = offshore_in_dir_name1) |
---|
[5753] | 115 | print'create Geospatial data9 objects from topographies' |
---|
[5759] | 116 | G_off2 = Geospatial_data(file_name = offshore_in_dir_name2) |
---|
[5753] | 117 | print'create Geospatial data10 objects from topographies' |
---|
[5759] | 118 | G_off3 = Geospatial_data(file_name = offshore_in_dir_name3) |
---|
[4077] | 119 | |
---|
[5784] | 120 | #------------------------------------------------------------------------------- |
---|
| 121 | # Combine, clip and export dataset |
---|
| 122 | #------------------------------------------------------------------------------- |
---|
[5360] | 123 | |
---|
[4077] | 124 | print'add all geospatial objects' |
---|
[5759] | 125 | G = G1 + G2 + G3 + G4 + G5 + G_coast + G_off + G_off1 + G_off2 + G_off3 |
---|
[4077] | 126 | |
---|
[4080] | 127 | print'clip combined geospatial object by bounding polygon' |
---|
[5386] | 128 | G_clipped = G.clip(project.poly_all) |
---|
[4077] | 129 | |
---|
| 130 | print'export combined DEM file' |
---|
| 131 | if access(project.topographies_dir,F_OK) == 0: |
---|
| 132 | mkdir (project.topographies_dir) |
---|
[5784] | 133 | G_clipped.export_points_file(project.combined_dir_name + '.pts') |
---|
| 134 | #G_clipped.export_points_file(project.combined_dir_name + '.txt') #Use for comparision in ARC |
---|
[4077] | 135 | |
---|