[6770] | 1 | """Build the elevation data to run a tsunami inundation scenario |
---|
| 2 | for Busselton, WA, Australia. |
---|
| 3 | |
---|
| 4 | Input: elevation data from project.py |
---|
| 5 | Output: pts file stored in project.topographies_dir |
---|
| 6 | The run_model.py is reliant on the output of this script. |
---|
| 7 | |
---|
| 8 | """ |
---|
| 9 | |
---|
| 10 | #------------------------------------------------------------------------------ |
---|
| 11 | # Import necessary modules |
---|
| 12 | #------------------------------------------------------------------------------ |
---|
| 13 | |
---|
| 14 | # Standard modules |
---|
| 15 | import os |
---|
| 16 | from os.path import join |
---|
| 17 | |
---|
| 18 | # Related major packages |
---|
| 19 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf |
---|
| 20 | from anuga.shallow_water.data_manager import dem2pts |
---|
| 21 | from anuga.shallow_water.data_manager import start_screen_catcher |
---|
| 22 | from anuga.shallow_water.data_manager import copy_code_files |
---|
| 23 | from anuga.geospatial_data.geospatial_data import Geospatial_data |
---|
| 24 | |
---|
| 25 | # Application specific imports |
---|
| 26 | from setup_model import project # Definition of file names and polygons |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | #------------------------------------------------------------------------------ |
---|
| 30 | # Copy scripts to time stamped output directory and capture screen |
---|
| 31 | # output to file |
---|
| 32 | #------------------------------------------------------------------------------ |
---|
| 33 | copy_code_files(project.output_build,__file__, |
---|
| 34 | os.path.dirname(project.__file__)+os.sep+\ |
---|
| 35 | project.__name__+'.py' ) |
---|
| 36 | start_screen_catcher(project.output_build) |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | #------------------------------------------------------------------------------ |
---|
| 40 | # Preparation of topographic data |
---|
| 41 | # |
---|
| 42 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
| 43 | # Do for coarse and fine data |
---|
| 44 | # Fine pts file to be clipped to area of interest |
---|
| 45 | #------------------------------------------------------------------------------ |
---|
| 46 | |
---|
| 47 | print 'project.bounding_polygon', project.bounding_polygon |
---|
| 48 | print 'project.combined_elevation_basename', project.combined_elevation_basename |
---|
| 49 | |
---|
| 50 | # Create Geospatial data from ASCII files |
---|
| 51 | geospatial_data = {} |
---|
| 52 | if not project.ascii_grid_filenames == []: |
---|
| 53 | for filename in project.ascii_grid_filenames: |
---|
| 54 | absolute_filename = join(project.topographies_folder, filename) |
---|
| 55 | convert_dem_from_ascii2netcdf(absolute_filename, |
---|
| 56 | basename_out=absolute_filename, |
---|
| 57 | use_cache=True, |
---|
| 58 | verbose=True) |
---|
| 59 | dem2pts(absolute_filename, use_cache=True, verbose=True) |
---|
| 60 | |
---|
| 61 | G_grid = Geospatial_data(file_name=absolute_filename+'.pts', |
---|
| 62 | verbose=True) |
---|
| 63 | print 'Clip geospatial object' |
---|
| 64 | geospatial_data[filename] = G_grid.clip(project.bounding_polygon) |
---|
| 65 | |
---|
| 66 | # Create Geospatial data from TXT files |
---|
| 67 | if not project.point_filenames == []: |
---|
| 68 | for filename in project.point_filenames: |
---|
| 69 | absolute_filename = join(project.topographies_folder, filename) |
---|
| 70 | G_points = Geospatial_data(file_name=absolute_filename, |
---|
| 71 | verbose=True) |
---|
| 72 | print 'Clip geospatial object' |
---|
| 73 | geospatial_data[filename] = G_points.clip(project.bounding_polygon) |
---|
| 74 | |
---|
| 75 | #------------------------------------------------------------------------------- |
---|
| 76 | # Combine, clip and export dataset |
---|
| 77 | #------------------------------------------------------------------------------- |
---|
| 78 | |
---|
| 79 | print 'Add geospatial objects' |
---|
| 80 | G = None |
---|
| 81 | for key in geospatial_data: |
---|
| 82 | G += geospatial_data[key] |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | print 'Export combined DEM file' |
---|
| 86 | G.export_points_file(project.combined_elevation + '.pts') |
---|
| 87 | print 'Do txt version too' |
---|
| 88 | # Use for comparision in ARC |
---|
| 89 | G.export_points_file(project.combined_elevation + '.txt') |
---|
| 90 | |
---|