Changeset 631 for inundation/ga/storm_surge/pyvolution/interpolate_sww.py
- Timestamp:
- Nov 26, 2004, 12:23:25 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/interpolate_sww.py
r628 r631 23 23 from least_squares import Interpolation 24 24 25 DEFAULT_QUANTITY = "height" 25 26 26 27 class Interpolate_sww: 27 def __init__(self,file_name ):28 def __init__(self,file_name, quantity_name): 28 29 30 #It's bad to have the quantity_name passed in here. 31 # But it works with how the program is currently used. 32 # Refactor when necessary. - DSG 29 33 30 x, y,z, volumes, time, stage = self.read_sww(file_name) 31 34 x, y, volumes, time, quantity = self.read_sww(file_name, quantity_name) 32 35 vertex_coordinates = transpose([x,y]) 33 36 … … 40 43 print y 41 44 print "****************************" 42 print "Z "43 print z44 print "****************************"45 45 print "V " 46 46 print volumes … … 49 49 print time 50 50 print "****************************" 51 print " Stage"52 print stage51 print "quantity " 52 print quantity 53 53 print "****************************" 54 54 print "vertex_coordinates" … … 58 58 self.interp = Interpolation(vertex_coordinates, volumes ) 59 59 self.time = time 60 self.stage = transpose(stage) 61 self. bed_elevation = z62 #print "self.stage",self.stage60 61 self.quantity_name = quantity_name 62 self.quantity = quantity 63 63 64 64 def interpolate_xya(self,file_name): … … 70 70 file_name - the xya file 71 71 """ 72 #73 72 self.point_coordinates = self.read_xya(file_name) 74 73 self.interp.build_interpolation_matrix_A(self.point_coordinates) 75 76 #Change this if you want to generalise this application - 77 # This is height specific 78 point_stage = self.interp.interpolate( self.stage) 79 point_bed_elevation = self.interp.interpolate( self.bed_elevation) 80 self.depth = transpose(transpose(point_stage) - point_bed_elevation) 74 self.interpolated_quantity = self.interp.interpolate( transpose(self.quantity)) 81 75 82 #print "self.depth", self.depth 83 84 def read_sww(self,file_name): 76 def read_sww(self,file_name, quantity_name): 85 77 """ 86 78 Read in an sww file. … … 101 93 #FIXME Have this reader as part of data_manager? 102 94 103 #import time, os104 #from Numeric import array, zeros, allclose, Float, concatenate105 95 from Scientific.IO.NetCDF import NetCDFFile 106 96 … … 112 102 x = fid.variables['x'][:] 113 103 y = fid.variables['y'][:] 114 z = fid.variables['z'][:]115 104 volumes = fid.variables['volumes'][:] 116 105 time = fid.variables['time'][:] 117 stage = fid.variables['stage'][:,:] # 2D 118 106 try: 107 if quantity_name == 'height': 108 z = fid.variables['z'][:] 109 stage = fid.variables['stage'][:,:] 110 quantity = stage - z # 2D, using broadcasting 111 else: 112 quantity = fid.variables[quantity_name][:,:] # 2D 113 except (KeyError, IndexError),e: 114 fid.close() 115 raise KeyError 116 119 117 fid.close() 120 121 return x, y, z, volumes, time, stage 118 return x, y, volumes, time, quantity 122 119 123 120 def read_xya(self,point_file): … … 162 159 xya_dict = {} 163 160 xya_dict['pointlist'] = self.point_coordinates 164 xya_dict['pointattributelist'] = self. depth161 xya_dict['pointattributelist'] = self.interpolated_quantity 165 162 166 163 export_xya_file(point_file, xya_dict, title, delimiter = delimiter) … … 172 169 """ 173 170 import os, sys 174 usage = "usage: %s pyvolution_results.sww points.xya depth.xya" % os.path.basename(sys.argv[0]) 175 171 usage = "usage: %s pyvolution_results.sww points.xya depth.xya [height|stage|(other quantities)]" % os.path.basename(sys.argv[0]) 176 172 if len(sys.argv) < 4: 177 173 print usage … … 180 176 point_file_in = sys.argv[2] 181 177 point_file_out = sys.argv[3] 182 183 interp = Interpolate_sww(sww_file) 178 if len(sys.argv) == 5: 179 quantity_name = sys.argv[4] 180 else: 181 quantity_name = DEFAULT_QUANTITY 182 #print "quantity",quantity 183 try: 184 interp = Interpolate_sww(sww_file, quantity_name) 185 except KeyError: 186 print "Error: Unknown quantity" 187 sys.exit(1) 188 184 189 interp.interpolate_xya(point_file_in) 185 190 interp.write_depth_xya(point_file_out)
Note: See TracChangeset
for help on using the changeset viewer.