Changeset 2407
- Timestamp:
- Feb 14, 2006, 5:19:29 PM (19 years ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/data_manager.py
r2344 r2407 1074 1074 1075 1075 1076 def dem2pts(basename_in, basename_out=None, verbose=False,1076 def dem2pts(basename_in, basename_out=None, 1077 1077 easting_min=None, easting_max=None, 1078 northing_min=None, northing_max=None): 1078 northing_min=None, northing_max=None, 1079 use_cache=False, verbose=False,): 1079 1080 """Read Digitial Elevation model from the following NetCDF format (.dem) 1080 1081 … … 1093 1094 points: (Nx2) Float array 1094 1095 elevation: N Float array 1096 """ 1097 1098 1099 1100 kwargs = {'basename_out': basename_out, 1101 'easting_min': easting_min, 1102 'easting_max': easting_max, 1103 'northing_min': northing_min, 1104 'northing_max': northing_max, 1105 'verbose': verbose} 1106 1107 if use_cache is True: 1108 from caching import cache 1109 result = cache(_dem2pts, basename_in, kwargs, 1110 dependencies = [basename_in + '.dem'], 1111 verbose = verbose) 1112 1113 else: 1114 result = apply(_dem2pts, [basename_in], kwargs) 1115 1116 return result 1117 1118 1119 def _dem2pts(basename_in, basename_out=None, verbose=False, 1120 easting_min=None, easting_max=None, 1121 northing_min=None, northing_max=None): 1122 """Read Digitial Elevation model from the following NetCDF format (.dem) 1123 1124 Internal function. See public function dem2pts for details. 1095 1125 """ 1096 1126 … … 1831 1861 1832 1862 1833 1834 1863 def convert_dem_from_ascii2netcdf(basename_in, basename_out = None, 1835 verbose=False): 1836 """Read Digitial Elevation model from the following ASCII format (.asc) 1864 use_cache = False, 1865 verbose = False): 1866 """Read Digitial Elevation model from the following ASCII format (.asc) 1837 1867 1838 1868 Example: … … 1864 1894 Yshift 10000000.0000000000 1865 1895 Parameters 1896 """ 1897 1898 1899 1900 kwargs = {'basename_out': basename_out, 'verbose': verbose} 1901 1902 if use_cache is True: 1903 from caching import cache 1904 result = cache(_convert_dem_from_ascii2netcdf, basename_in, kwargs, 1905 dependencies = [basename_in + '.asc'], 1906 verbose = verbose) 1907 1908 else: 1909 result = apply(_convert_dem_from_ascii2netcdf, [basename_in], kwargs) 1910 1911 return result 1912 1913 1914 1915 1916 1917 1918 def _convert_dem_from_ascii2netcdf(basename_in, basename_out = None, 1919 verbose = False): 1920 """Read Digitial Elevation model from the following ASCII format (.asc) 1921 1922 Internal function. See public function convert_dem_from_ascii2netcdf for details. 1866 1923 """ 1867 1924 -
inundation/pyvolution/general_mesh.py
r1894 r2407 50 50 """ 51 51 52 #FIXME: It would be a good idea to use geospatial data as an alternative 53 #input 52 54 def __init__(self, coordinates, triangles, 53 55 geo_reference=None): -
inundation/pyvolution/pmesh2domain.py
r2325 r2407 16 16 vertex_coordinates, vertices, tag_dict, vertex_quantity_dict \ 17 17 ,tagged_elements_dict, geo_reference = \ 18 _pmesh_to_domain(mesh_instance=mesh)18 _pmesh_to_domain(mesh_instance=mesh) 19 19 20 20 … … 36 36 return domain 37 37 38 def pmesh_to_domain_instance(file_name, DomainClass): 38 39 40 def pmesh_to_domain_instance(file_name, DomainClass, use_cache = False, verbose = False): 39 41 """ 40 42 Converts a mesh file(.tsh or .msh), to a Domain instance. … … 44 46 DomainClass is the Class that will be returned. 45 47 It must be a subclass of Domain, with the same interface as domain. 46 48 49 use_cache: True means that caching is attempted for the computed domain. 50 """ 51 52 if use_cache is True: 53 from caching import cache 54 result = cache(_pmesh_to_domain_instance, (file_name, DomainClass), 55 dependencies = [file_name], 56 verbose = verbose) 57 58 else: 59 result = apply(_pmesh_to_domain_instance, (file_name, DomainClass)) 60 61 return result 62 63 64 65 66 def _pmesh_to_domain_instance(file_name, DomainClass): 67 """ 68 Converts a mesh file(.tsh or .msh), to a Domain instance. 69 70 Internal function. See public interface pmesh_to_domain_instance for details 47 71 """ 48 72 … … 52 76 vertex_coordinates, vertices, tag_dict, vertex_quantity_dict \ 53 77 ,tagged_elements_dict, geo_reference = \ 54 _pmesh_to_domain(file_name=file_name)78 _pmesh_to_domain(file_name=file_name) 55 79 56 80 … … 98 122 generated segment list: [(point1,point2),(p3,p4),...] (Tuples of integers) 99 123 generated segment tag list: [S1Tag, S2Tag, ...] (list of ints) 100 triangle list: [(point1, point2, point3),(p5,p4, p1),...] (Tuples of integers)124 triangle list: [(point1, point2, point3),(p5,p4, p1),...] (Tuples of integers) 101 125 triangle neighbor list: [(triangle1,triangle2, triangle3),(t5,t4, t1),...] (Tuples of integers) -1 means there's no triangle neighbor 102 126 triangle attribute list: [T1att, T2att, ...] (list of strings) … … 146 170 sides = calc_sides(triangles) 147 171 tag_dict = {} 148 for seg, tag in map(None, mesh_dict['segments'],149 172 for seg, tag in map(None, mesh_dict['segments'], 173 mesh_dict['segment_tags']): 150 174 v1 = seg[0] 151 175 v2 = seg[1] -
production/sydney_2006/project.py
r2403 r2407 3 3 """ 4 4 5 from os import sep 5 from os import sep, environ 6 6 from os.path import expanduser 7 from utilities.polygon import read_polygon 7 8 import sys 9 10 from pmesh.create_mesh import convert_points_from_latlon_to_utm 11 12 13 8 14 9 15 #Making assumptions about the location of scenario data … … 14 20 finename = 'bathy_dem25' # get from Neil/Ingo (DEM or topo data) Wed 25 Jan 15 21 22 23 16 24 # creating easting and northing max and min for fine data - region of interest 17 25 eastingmin = 332090 … … 29 37 30 38 if sys.platform == 'win32': 31 home = '..\..\..\..\..'#Sandpit's parent dir39 home = environ['INUNDATIONHOME'] #Sandpit's parent dir 32 40 else: 33 41 home = expanduser('~') 42 34 43 35 44 … … 38 47 datadir = home+sep+scenario_dir_name+sep+'topographies'+sep 39 48 outputdir = home+sep+scenario_dir_name+sep+'output'+sep 49 polygondir = home+sep+scenario_dir_name+sep+'polygons'+sep 40 50 41 51 meshname = meshdir + basename … … 44 54 combineddemname = datadir + 'sydneytopo' 45 55 outputname = outputdir + basename #Used by post processing 56 57 #csv file of coastline 50m epsilon belt 58 manly_polygonname = polygondir + 'manly_polygon_UTM56_coarse' 59 manly_polygon = read_polygon(manly_polygonname + '.csv') 60 #print manly_polygon 61 46 62 gauge_filename = outputdir + 'sydney_gauges.xya' 47 63 gauge_outname = outputdir + 'gauges_max_output.xya' … … 51 67 52 68 # define clipping polygon 69 south = degminsec2decimal_degrees(-34,05,0) 70 north = degminsec2decimal_degrees(-33,33,0) 71 west = degminsec2decimal_degrees(151,1,0) 72 east = degminsec2decimal_degrees(151,30,0) 73 p0 = [south, west] 74 p1 = [south, east] 75 p2 = [north, east] 76 p3 = [north, west] 77 78 polygonall, zone = convert_points_from_latlon_to_utm([p0, p1, p2, p3]) 79 refzone = zone 80 81 print 'Got refzone', refzone 82 53 83 dsouth = degminsec2decimal_degrees(-34,05,0) 54 84 dnorth = degminsec2decimal_degrees(-33,33,0) … … 72 102 dp8 = [dnorth, dwest] 73 103 74 diffpolygonall = [dp0, dp1, dp2, dp3, dp4, dp5, dp6, dp7] 75 104 diffpolygonall, zone = convert_points_from_latlon_to_utm([dp0, dp1, dp2, dp3, dp4, dp5, dp6, dp7]) 105 # to put chunk back in 106 #diffpolygonall = [dp0, dp1, dp2, dp3, dp4, dp8] 107 108 109 110 #Interior regions - the Harbour - take 2 76 111 #Interior regions - the Harbour 77 112 harbour_1x = degminsec2decimal_degrees(-33,51,0) … … 122 157 k142 = [harbour_15x, harbour_15y] 123 158 124 harbour_polygon_2 = [k02, k112, k122, k12, k22, k62, k72, k82, k102, k42, k52] #worked 159 harbour_polygon_2, zone = convert_points_from_latlon_to_utm([k02, k112, k122, k12, k22, k62, k72, k82, k102, k42, k52]) #worked 160 assert zone == refzone 161 125 162 126 163 #Interior region - Botany Bay 164 165 #Interior region - Botany Bay - take 2 127 166 bb_1x = degminsec2decimal_degrees(-34,3,0) 128 167 bb_1y = degminsec2decimal_degrees(151,2,30) … … 157 196 j92 = [bb_10x, bb_10y] 158 197 159 botanybay_polygon_2 = [j92, j12, j22, j62, j82, j72, j42] # worked 160 161 # around 42km across from harbour(385000,6255000) 198 botanybay_polygon_2, zone = convert_points_from_latlon_to_utm([j92, j12, j22, j62, j82, j72, j42]) # worked 199 200 201 # close to botany bay opening (340000,6236000) 202 # x0 = 25964 203 # y0 = 11049 204 # around 10km from botany bay opening (350000,6236000) 205 # x0 = 35964 206 # y0 = 11049 207 # around 21km from botany bay opening (361000,6236000) 208 #x0 = 46964 209 #y0 = 11049 210 211 # not used for sydney scenario, original interior regions listed though 212 # setting up problem area for doing just around the harbour 213 hsouth = degminsec2decimal_degrees(-33,54,0) 214 hnorth = degminsec2decimal_degrees(-33,48,0) 215 hwest = degminsec2decimal_degrees(151,0,0) 216 heast = degminsec2decimal_degrees(151,30,0) 217 218 hp0 = [hsouth, hwest] 219 hp1 = [hsouth, heast] 220 hp2 = [hnorth, heast] 221 hp3 = [hnorth, hwest] 222 polygon_h, zone = convert_points_from_latlon_to_utm([hp0, hp1, hp2, hp3]) 223 224 #Interior regions - the Harbour - take 1 225 harbour_south = degminsec2decimal_degrees(-33,53,0) 226 harbour_north = degminsec2decimal_degrees(-33,47,0) 227 harbour_west = degminsec2decimal_degrees(151,5,0) 228 harbour_east = degminsec2decimal_degrees(151,19,0) 229 230 #harbour_south1 = degminsec2decimal_degrees(-33,53,0) 231 #harbour_south2 = degminsec2decimal_degrees(-33,52,0) 232 #harbour_north1 = degminsec2decimal_degrees(-33,45,0) 233 #harbour_north2 = degminsec2decimal_degrees(-33,48,0) 234 #harbour_west = degminsec2decimal_degrees(151,5,0) 235 #harbour_east = degminsec2decimal_degrees(151,19,0) 236 237 k0 = [harbour_south, harbour_west] 238 k1 = [harbour_south, harbour_east] 239 k2 = [harbour_north, harbour_east] 240 k3 = [harbour_north, harbour_west] 241 242 harbour_polygon, zone = convert_points_from_latlon_to_utm([k0, k1, k2, k3]) 243 244 # setting up problem area for doing just around Botany Bay 245 bsouth = degminsec2decimal_degrees(-33,56,0) 246 bnorth = degminsec2decimal_degrees(-34,3,0) 247 bwest = degminsec2decimal_degrees(151,0,0) 248 beast = degminsec2decimal_degrees(151,30,0) 249 250 bp0 = [bsouth, bwest] 251 bp1 = [bsouth, beast] 252 bp2 = [bnorth, beast] 253 bp3 = [bnorth, bwest] 254 polygon_bb, zone = convert_points_from_latlon_to_utm([bp0, bp1, bp2, bp3]) 255 256 #Interior region - Botany Bay - take 1 257 botanybay_south = degminsec2decimal_degrees(-33,58,0) 258 botanybay_north = degminsec2decimal_degrees(-34,1,0) 259 botanybay_west = degminsec2decimal_degrees(151,5,0) 260 botanybay_east = degminsec2decimal_degrees(151,18,0) 261 262 j0 = [botanybay_south, botanybay_west] 263 j1 = [botanybay_south, botanybay_east] 264 j2 = [botanybay_north, botanybay_east] 265 j3 = [botanybay_north, botanybay_west] 266 267 botanybay_polygon, zone = convert_points_from_latlon_to_utm([j0, j1, j2, j3]) 268 assert zone == refzone 269 162 270 #x0 = 28964 + 42000 163 271 #y0 = 30049 -
production/sydney_2006/run_sydney_smf.py
r2400 r2407 6 6 7 7 The scenario is defined by a triangular mesh created from project.polygon, 8 the elevation data and boundary data obtained from a tsunami simulation done with MOST.8 the elevation data and a simulated submarine landslide. 9 9 10 Ole Nielsen , GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 200610 Ole Nielsen and Duncan Gray, GA - 2005 and Adrian Hitchman and Jane Sexton, GA - 2006 11 11 """ 12 12 13 tide = 0 #Australian Height Datum (mean sea level)14 13 14 #-------------------------------------------------------------------------------# Import necessary modules 15 #------------------------------------------------------------------------------- 16 17 # Standard modules 15 18 import os 16 19 import time 17 20 21 # Related major packages 22 from pyvolution.shallow_water import Domain, Reflective_boundary 23 from pyvolution.data_manager import convert_dem_from_ascii2netcdf, dem2pts 24 from pyvolution.combine_pts import combine_rectangular_points_files 25 from pyvolution.pmesh2domain import pmesh_to_domain_instance 18 26 19 from pyvolution.shallow_water import Domain, Reflective_boundary, File_boundary,\ 20 Dirichlet_boundary, Time_boundary, Transmissive_boundary 21 from pyvolution.data_manager import convert_dem_from_ascii2netcdf,\ 22 dem2pts 23 from pyvolution.pmesh2domain import pmesh_to_domain_instance 24 from pyvolution.combine_pts import combine_rectangular_points_files 25 from caching import cache 26 import project 27 from math import pi, sin 28 from smf import slump_tsunami, slide_tsunami, Double_gaussian 29 from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA 27 # Application specific imports 28 import project # Definition of file names and polygons 29 from smf import slump_tsunami # Function for submarine mudslide 30 30 31 # Data preparation 31 32 #------------------------------------------------------------------------------- 33 # Preparation of topographic data 34 # 32 35 # Convert ASC 2 DEM 2 PTS using source data and store result in source data 33 36 # Do for coarse and fine data 34 37 # Fine pts file to be clipped to area of interest 38 #------------------------------------------------------------------------------- 39 40 # filenames 35 41 coarsedemname = project.coarsedemname 36 42 finedemname = project.finedemname … … 38 44 39 45 # coarse data 40 cache(convert_dem_from_ascii2netcdf, coarsedemname, {'verbose': True}, 41 dependencies = [coarsedemname + '.asc'], 42 verbose = True) 43 #evaluate = True) 46 convert_dem_from_ascii2netcdf(coarsedemname, use_cache=True, verbose=True) 47 dem2pts(coarsedemname, use_cache=True, verbose=True) 44 48 45 cache(dem2pts, coarsedemname, {'verbose': True}, 46 dependencies = [coarsedemname + '.dem'], 47 verbose = True) 49 # fine data (clipping the points file to smaller area) 50 convert_dem_from_ascii2netcdf(finedemname, use_cache=True, verbose=True) 51 dem2pts(finedemname, 52 easting_min=project.eastingmin, 53 easting_max=project.eastingmax, 54 northing_min=project.northingmin, 55 northing_max= project.northingmax, 56 use_cache=True, 57 verbose=True) 48 58 49 # fine data50 cache(convert_dem_from_ascii2netcdf, finedemname, {'verbose': True},51 dependencies = [finedemname + '.asc'],52 verbose = True)53 #evaluate = True)54 55 # clipping the fine data56 cache(dem2pts, finedemname, {'verbose': True,57 'easting_min': project.eastingmin,58 'easting_max': project.eastingmax,59 'northing_min': project.northingmin,60 'northing_max': project.northingmax},61 dependencies = [finedemname + '.dem'],62 #evaluate = True,63 verbose = True)64 59 65 60 # combining the coarse and fine data … … 67 62 project.coarsedemname + '.pts', 68 63 project.combineddemname + '.pts') 69 70 # Create Triangular Mesh 71 # Overall clipping polygon and interior regions defined in project.py 64 65 66 #------------------------------------------------------------------------------- 67 # Create the triangular mesh based on overall clipping polygon with a tagged 68 # boundary and interior regions defined in project.py along with 69 # resolutions (maximal area of per triangle) for each polygon 70 #------------------------------------------------------------------------------- 71 72 72 from pmesh.create_mesh import create_mesh_from_regions 73 73 74 # for whole region 75 interior_res = 5000 # maximal area of per triangle 74 interior_res = 5000 76 75 interior_regions = [[project.harbour_polygon_2, interior_res], 77 [project.botanybay_polygon_2, interior_res]] 76 [project.botanybay_polygon_2, interior_res]] 78 77 79 m = cache(create_mesh_from_regions,80 project.diffpolygonall,81 {'boundary_tags': {'bottom': [0],82 'right1': [1], 'right0': [2],83 'right2': [3], 'top': [4], 'left1': [5],84 'left2': [6], 'left3': [7]},85 'resolution': 100000,86 'filename': meshname,87 'interior_regions': interior_regions},88 #evaluate=True,89 verbose = True)90 78 91 # Setup domain 92 domain = cache(pmesh_to_domain_instance, (meshname, Domain), 93 dependencies = [meshname], 94 verbose = True) 79 #FIXME: Fix caching of this one once the mesh_interface is ready 80 from caching import cache 81 _ = cache(create_mesh_from_regions, 82 project.diffpolygonall, 83 {'boundary_tags': {'bottom': [0], 84 'right1': [1], 'right0': [2], 85 'right2': [3], 'top': [4], 'left1': [5], 86 'left2': [6], 'left3': [7]}, 87 'resolution': 100000, 88 'filename': meshname, 89 'interior_regions': interior_regions, 90 'UTM': True, 91 'refzone': project.refzone}, 92 verbose = True) 95 93 96 # Bring in elevation data 97 domain.set_quantity('elevation', 98 filename = project.combineddemname + '.pts', 99 use_cache = True, 100 verbose = True) 101 94 95 #------------------------------------------------------------------------------- 96 # Setup computational domain 97 #------------------------------------------------------------------------------- 98 99 domain = pmesh_to_domain_instance(meshname, Domain, 100 use_cache = True, 101 verbose = True) 102 102 103 print 'Number of triangles = ', len(domain) 103 104 print 'The extent is ', domain.get_extent() … … 105 106 domain.set_name(project.basename) 106 107 domain.set_datadir(project.outputdir) 107 domain.store = True 108 domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] 108 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum']) 109 109 110 # Setup Initial conditions 111 t = slump_tsunami(length=30000.0, 112 depth=400.0, 113 slope=6.0, 114 thickness=176.0, 115 radius=3330, 116 dphi=0.23, 117 x0=project.slump_origin[0], 118 y0=project.slump_origin[1], 119 alpha=0.0, 120 domain=domain) 121 domain.set_quantity('stage', t) 110 111 #------------------------------------------------------------------------------- 112 # Set up scenario (tsunami_source is a callable object used with set_quantity) 113 #------------------------------------------------------------------------------- 114 115 tsunami_source = slump_tsunami(length=30000.0, 116 depth=400.0, 117 slope=6.0, 118 thickness=176.0, 119 radius=3330, 120 dphi=0.23, 121 x0=project.slump_origin[0], 122 y0=project.slump_origin[1], 123 alpha=0.0, 124 domain=domain) 125 126 127 #------------------------------------------------------------------------------- 128 # Setup initial conditions 129 #------------------------------------------------------------------------------- 130 131 domain.set_quantity('stage', tsunami_source) 122 132 domain.set_quantity('friction', 0) 123 124 # Setup Boundary Conditions 125 print domain.get_boundary_tags() 133 domain.set_quantity('elevation', 134 filename = project.combineddemname + '.pts', 135 use_cache = True, 136 verbose = True) 137 138 139 #------------------------------------------------------------------------------- 140 # Setup boundary conditions (all reflective) 141 #------------------------------------------------------------------------------- 142 143 print 'Available boundary tags', domain.get_boundary_tags() 126 144 127 145 Br = Reflective_boundary(domain) 128 Bt = Transmissive_boundary(domain)129 Bd = Dirichlet_boundary([0,0,0])130 # 10 min square wave starting at 1 min, 6m high131 Bw = Time_boundary(domain=domain,132 f=lambda t: [(6<t<606)*6, 0, 0])133 134 146 domain.set_boundary( {'bottom': Br, 'right1': Br, 'right0': Br, 135 147 'right2': Br, 'top': Br, 'left1': Br, 136 148 'left2': Br, 'left3': Br} ) 137 149 138 # Evolve 150 151 #------------------------------------------------------------------------------- 152 # Evolve system through time 153 #------------------------------------------------------------------------------- 154 139 155 import time 140 156 t0 = time.time()
Note: See TracChangeset
for help on using the changeset viewer.