Changeset 2941 for inundation/coordinate_transforms
- Timestamp:
- May 23, 2006, 9:11:57 AM (19 years ago)
- Location:
- inundation/coordinate_transforms
- Files:
-
- 2 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__":
Note: See TracChangeset
for help on using the changeset viewer.