[5790] | 1 | """ |
---|
| 2 | Script for building the elevation data to run a tsunami inundation scenario |
---|
| 3 | for geraldton, WA, Australia. |
---|
[5005] | 4 | |
---|
[5790] | 5 | Input: elevation data from project.py |
---|
| 6 | Output: pts file stored in project.topographies_dir |
---|
| 7 | The run_geraldton.py is reliant on the output of this script. |
---|
[5005] | 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 * |
---|
[5790] | 27 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files |
---|
[5005] | 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 | |
---|
[5755] | 40 | start_screen_catcher(project.output_build_time_dir) |
---|
[5005] | 41 | |
---|
[5790] | 42 | print 'USER: ', project.user |
---|
[5005] | 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 | #------------------------------------------------------------------------------- |
---|
[5790] | 51 | print "project.poly_all", project.poly_all |
---|
| 52 | print "project.combined_dir_name", project.combined_dir_name |
---|
[5005] | 53 | |
---|
[5790] | 54 | # input elevation directory filenames |
---|
[5005] | 55 | onshore_in_dir_name = project.onshore_in_dir_name |
---|
| 56 | offshore_in_dir_name = project.offshore_in_dir_name |
---|
[5755] | 57 | offshore_in_dir_name1 = project.offshore_in_dir_name1 |
---|
[6024] | 58 | offshore_in_dir_aoi = project.offshore_in_dir_aoi |
---|
| 59 | offshore_in_dir_aos = project.offshore_in_dir_aos |
---|
[5005] | 60 | |
---|
[5790] | 61 | # output elevation directory filenames |
---|
[5005] | 62 | onshore_dir_name = project.onshore_dir_name |
---|
| 63 | offshore_dir_name = project.offshore_dir_name |
---|
[5755] | 64 | offshore_dir_name1 = project.offshore_dir_name1 |
---|
[6024] | 65 | offshore_dir_aoi = project.offshore_dir_aoi |
---|
| 66 | offshore_dir_aos = project.offshore_dir_aos |
---|
[5005] | 67 | |
---|
[5755] | 68 | |
---|
[5005] | 69 | # creates DEM from asc data |
---|
[5790] | 70 | print "creates DEMs from asc data" |
---|
[5005] | 71 | convert_dem_from_ascii2netcdf(onshore_in_dir_name, basename_out=onshore_dir_name, use_cache=True, verbose=True) |
---|
[6024] | 72 | convert_dem_from_ascii2netcdf(offshore_in_dir_aoi, basename_out=offshore_dir_aoi, use_cache=True, verbose=True) |
---|
| 73 | convert_dem_from_ascii2netcdf(offshore_in_dir_aos, basename_out=offshore_dir_aos, use_cache=True, verbose=True) |
---|
[5005] | 74 | |
---|
[5790] | 75 | # creates pts file for onshore DEM |
---|
[5005] | 76 | print "creates pts file for onshore DEM" |
---|
[5790] | 77 | dem2pts(onshore_dir_name ,use_cache=True,verbose=True) |
---|
[6024] | 78 | dem2pts(offshore_dir_aoi ,use_cache=True,verbose=True) |
---|
| 79 | dem2pts(offshore_dir_aos ,use_cache=True,verbose=True) |
---|
[5005] | 80 | |
---|
[6024] | 81 | |
---|
| 82 | |
---|
[5790] | 83 | # create onshore pts files |
---|
[6024] | 84 | print'create Geospatial onshore objects from topographies' |
---|
[5790] | 85 | G1 = Geospatial_data(file_name = onshore_dir_name + '.pts') |
---|
[5005] | 86 | |
---|
[5790] | 87 | # create coastal and offshore txt files |
---|
[6024] | 88 | print'create Geospatial offshore objects from topographies' |
---|
[5790] | 89 | G_off1 = Geospatial_data(file_name = offshore_in_dir_name) |
---|
[6024] | 90 | print'create Geospatial makeup objects from topographies' |
---|
[5790] | 91 | G_off2 = Geospatial_data(file_name = offshore_in_dir_name1) |
---|
[6024] | 92 | print'create Geospatial aoi objects from topographies' |
---|
| 93 | G_offaoi = Geospatial_data(file_name = offshore_dir_aoi+ '.pts') |
---|
| 94 | print'create Geospatial aos objects from topographies' |
---|
| 95 | G_offaos = Geospatial_data(file_name = offshore_dir_aos+ '.pts') |
---|
[5790] | 96 | |
---|
[6024] | 97 | |
---|
[5790] | 98 | #------------------------------------------------------------------------------- |
---|
| 99 | # Combine, clip and export dataset |
---|
| 100 | #------------------------------------------------------------------------------- |
---|
| 101 | |
---|
| 102 | print 'add all bathymetry files' |
---|
[6024] | 103 | G_off = G_off1 + G_off2 |
---|
| 104 | |
---|
[6064] | 105 | ##print 'clipping data to coast' |
---|
| 106 | ##G_ocean = G_off.clip(project.poly_ocean, verbose=True) #mainland |
---|
| 107 | ##G_ocean_b = G_ocean.clip_outside(project.poly_island1, verbose=True) #bernier |
---|
| 108 | ##G_ocean_bd = G_ocean_b.clip_outside(project.poly_island2, verbose=True) #dorne |
---|
| 109 | ## |
---|
| 110 | ##G1_clip_m = G1.clip(project.poly_mainland, verbose=True) |
---|
| 111 | ##G1_clip_b = G1.clip(project.poly_island1, verbose=True) |
---|
| 112 | ##G1_clip_d = G1.clip(project.poly_island2, verbose=True) |
---|
| 113 | ##G1_clip = G1_clip_m + G1_clip_b + G1_clip_d |
---|
[5790] | 114 | |
---|
[5005] | 115 | print'add all geospatial objects' |
---|
[6064] | 116 | G_aos = G1 + G_off |
---|
[6024] | 117 | G_aosclip = G_aos.clip_outside(project.poly_aos_extract, verbose=True) |
---|
| 118 | G_aoi = G_aosclip.clip_outside(project.poly_aoi1, verbose=True) |
---|
[6064] | 119 | G = G_aoi +G_offaoi+G_offaos |
---|
[5005] | 120 | |
---|
| 121 | print'export combined DEM file' |
---|
| 122 | if access(project.topographies_dir,F_OK) == 0: |
---|
| 123 | mkdir (project.topographies_dir) |
---|
[5790] | 124 | G.export_points_file(project.combined_dir_name + '.pts') |
---|
[5804] | 125 | G.export_points_file(project.combined_dir_name + '.txt') #Use for comparision in ARC |
---|
[5005] | 126 | |
---|