Changeset 2941
- Timestamp:
- May 23, 2006, 9:11:57 AM (18 years ago)
- Location:
- inundation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/coordinate_transforms/geo_reference.py
r2608 r2941 10 10 from utilities.numerical_tools import ensure_numeric 11 11 from utilities.anuga_exceptions import ANUGAError 12 13 import exceptions 14 class TitleError(exceptions.IOError): pass 12 15 13 16 DEFAULT_ZONE = -1 … … 34 37 ASCIIFile - a handle to the text file 35 38 read_title - the title of the georeference text, if it was read in. 39 If the function that calls this has already read the title line, 40 it can't unread it, so this info has to be passed. 41 If you know of a way to unread this info, then tell us. 36 42 """ 37 43 … … 106 112 #print "gr TITLE[0:2].upper()",TITLE[0:2].upper() 107 113 if read_title[0:2].upper() != TITLE[0:2].upper(): 108 raise SyntaxError 114 msg = 'File error. Expecting line: %s. Got this line: %s' \ 115 %(TITLE, read_title) 116 raise TitleError, msg 109 117 self.zone = int(fd.readline()) 110 118 self.xllcorner = float(fd.readline()) -
inundation/coordinate_transforms/test_geo_reference.py
r2594 r2941 72 72 self.failUnless(g == new_g, 'test_read_write_ASCII failed') 73 73 74 def test_read_write_ASCII 2(self):74 def test_read_write_ASCII3(self): 75 75 from Scientific.IO.NetCDF import NetCDFFile 76 76 g = Geo_reference(56,1.9,1.9) … … 86 86 fd.close() 87 87 os.remove(file_name) 88 except SyntaxError:88 except TitleError: 89 89 fd.close() 90 90 os.remove(file_name) … … 254 254 msg = 'Should have raised an exception' 255 255 raise msg 256 257 258 259 260 261 256 257 def test_bad_ASCII_title(self): 258 # create an .xya file 259 point_file = tempfile.mktemp(".xya") 260 fd = open(point_file,'w') 261 fd.write("# hey! \n") 262 fd.close() 263 264 fd = open(point_file,'r') 265 # 266 #new_g = Geo_reference(ASCIIFile=fd) 267 try: 268 new_g = Geo_reference(ASCIIFile=fd) 269 fd.close() 270 os.remove(point_file) 271 except TitleError: 272 fd.close() 273 os.remove(point_file) 274 else: 275 self.failUnless(0 ==1, 276 'bad text file did not raise error!') 277 os.remove(point_file) 278 279 def test_read_write_ASCII_test_and_fail(self): 280 from Scientific.IO.NetCDF import NetCDFFile 281 282 # This is to test a fail 283 g = Geo_reference(56,1.9,1.9) 284 file_name = tempfile.mktemp(".geo_referenceTest") 285 fd = open(file_name,'w') 286 g.write_ASCII(fd) 287 fd.close() 288 fd = open(file_name,'r') 289 line = fd.readline() 290 line = " #Geo" 291 try: 292 new_g = Geo_reference(ASCIIFile=fd, read_title=line) 293 fd.close() 294 os.remove(file_name) 295 except TitleError: 296 fd.close() 297 os.remove(file_name) 298 else: 299 self.failUnless(0 ==1, 300 'bad text file did not raise error!') 301 302 # this tests a pass 303 g = Geo_reference(56,1.9,1.9) 304 file_name = tempfile.mktemp(".geo_referenceTest") 305 fd = open(file_name,'w') 306 g.write_ASCII(fd) 307 fd.close() 308 309 fd = open(file_name,'r') 310 line = fd.readline() 311 line = "#geo_yeah" 312 new_g = Geo_reference(ASCIIFile=fd, read_title=line) 313 fd.close() 314 os.remove(file_name) 315 316 self.failUnless(g == new_g, 'test_read_write_ASCII failed') 317 318 # this tests a pass 319 g = Geo_reference(56,1.9,1.9) 320 file_name = tempfile.mktemp(".geo_referenceTest") 321 fd = open(file_name,'w') 322 g.write_ASCII(fd) 323 fd.close() 324 325 fd = open(file_name,'r') 326 line = fd.readline() 327 line = "#geo crap" 328 new_g = Geo_reference(ASCIIFile=fd, read_title=line) 329 fd.close() 330 os.remove(file_name) 331 332 self.failUnless(g == new_g, 'test_read_write_ASCII failed') 333 334 def xxtest_good_title(self): 335 # create an .xya file 336 point_file = tempfile.mktemp(".xya") 337 fd = open(point_file,'w') 338 fd.write("#Geo crap \n 56\n ") 339 fd.close() 340 341 fd = open(point_file,'r') 342 # 343 #new_g = Geo_reference(ASCIIFile=fd) 344 try: 345 new_g = Geo_reference(ASCIIFile=fd) 346 fd.close() 347 os.remove(point_file) 348 except TitleError: 349 fd.close() 350 os.remove(point_file) 351 else: 352 self.failUnless(0 ==1, 353 'bad text file did not raise error!') 354 os.remove(point_file) 355 262 356 #------------------------------------------------------------- 263 357 if __name__ == "__main__": -
inundation/geospatial_data/geospatial_data.py
r2940 r2941 9 9 from Numeric import concatenate, array, Float, shape 10 10 11 from coordinate_transforms.geo_reference import Geo_reference 11 from coordinate_transforms.geo_reference import Geo_reference, TitleError 12 12 13 13 from os import access, F_OK, R_OK … … 320 320 fd = open(file_name) 321 321 data_points, attributes, geo_reference = _read_xya_file(fd, ',') 322 except SyntaxError:322 except TitleError: 323 323 fd.close() 324 324 fd = open(file_name) … … 333 333 raise IOError, msg 334 334 except IOError, e: 335 fd.close() 335 336 # Catch this to add an error message 336 337 msg = 'Could not open file or incorrect file format %s:%s' %(file_name, e) -
inundation/load_mesh/loadASCII.py
r2888 r2941 82 82 from os.path import splitext 83 83 84 from coordinate_transforms.geo_reference import Geo_reference,TITLE 84 from coordinate_transforms.geo_reference import Geo_reference,TITLE, TitleError 85 85 86 86 import exceptions … … 105 105 msg = 'Extension %s is unknown' %ofile[-4:] 106 106 raise IOError, msg 107 except ( SyntaxError,IndexError, ValueError): #FIXME No test for ValueError107 except (TitleError,SyntaxError,IndexError, ValueError): #FIXME No test for ValueError 108 108 msg = 'File could not be opened' 109 109 raise IOError, msg … … 993 993 994 994 #FIXME (Ole): This function should really return a Geospatial_data object. #FIXME (DSG): Do you know it does, in the points dic? 995 #No. Where this function is used, geospatial objects should be used. 995 996 996 997 if ofile[-4:]== ".xya": … … 1000 1001 fd = open(ofile) 1001 1002 points_dict = _read_xya_file(fd, ',') 1002 except SyntaxError:1003 except TitleError: # this is catching the error thrown by geo_ref 1003 1004 fd.close() 1004 1005 fd = open(ofile) … … 1009 1010 fd.close() 1010 1011 except (IndexError,ValueError,SyntaxError): 1011 fd.close() 1012 fd.close() 1013 msg = 'Could not open file %s ' %ofile 1014 raise IOError, msg 1015 except TitleError: 1016 print "reclassifying title error" 1017 fd.close() 1012 1018 msg = 'Could not open file %s ' %ofile 1013 1019 raise IOError, msg -
inundation/pyvolution/cornell_room.py
r773 r2941 15 15 from Numeric import array 16 16 from math import sqrt 17 from least_squares import Interpolation 17 #from least_squares import Interpolation 18 from fit_interpolate.interpolate import Interpolate 18 19 19 20 … … 45 46 #Compute smooth surface on new mesh based on values from old (regrid) 46 47 print 'Interp' 47 interp = Interpolat ion(mesh_points, vertices, data_points, alpha=10)48 mesh_values = interp.fit( data_values)48 interp = Interpolate(mesh_points, vertices, alpha=10) 49 mesh_values = interp.fit( data_points, data_values) # this has not been tested 49 50 print 'Len mesh values', len(mesh_values) 50 51 print 'Len mesh points', len(mesh_points)
Note: See TracChangeset
for help on using the changeset viewer.