Changeset 2940
- Timestamp:
- May 22, 2006, 2:36:04 PM (19 years ago)
- Location:
- inundation/geospatial_data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/geospatial_data/geospatial_data.py
r2935 r2940 86 86 dic['attributelist']['elevation'] = [[7.0,5.0] 87 87 88 delimiter: 88 delimiter: is the file delimiter that will be used when 89 importing the file 89 90 90 91 verbose: … … 95 96 # assume data point is really a file name 96 97 file_name = data_points 98 99 self.set_verbose(verbose) 97 100 98 101 if file_name is None: … … 100 103 msg = 'No file specified yet a delimiter is provided!' 101 104 raise ValueError, msg 102 self.file_name = None105 file_name = None 103 106 self.check_data_points(data_points) 104 107 self.set_attributes(attributes) … … 106 109 self.set_default_attribute_name(default_attribute_name) 107 110 108 109 else: 110 if access(file_name, F_OK) == 0 : 111 msg = 'File %s does not exist or is not accessible' %file_name 112 raise IOError, msg 113 else: 114 data = {} 111 else: 112 ### data = {} 115 113 # watch for case where file name and points, attributes etc are provided!! 116 114 # if file name then all provided info will be removed! 117 self.file_name = file_name 118 self.delimiter = delimiter 119 self.import_points_file(file_name, delimiter) 115 self.import_points_file(file_name, delimiter, verbose) 120 116 121 117 self.check_data_points(self.data_points) … … 183 179 self.default_attribute_name = default_attribute_name 184 180 185 def set_file_name(self, file_name = None):186 if file_name is None:187 self.file_name = None188 else:189 if access(file_name, F_OK) == 0 :190 msg = 'Geospatial_data object needs have either data_points \n'191 msg += ' or a file with data points'192 raise msg193 else:194 self.file_name = file_name195 print 'file name from set', self.file_name196 197 181 def set_verbose(self, verbose = False): 198 182 if verbose is not False: … … 319 303 ### 320 304 321 def import_points_file(self, ofile, delimiter = None, verbose = False):305 def import_points_file(self, file_name, delimiter = None, verbose = False): 322 306 """ load an .xya or .pts file 323 307 Note: will throw an IOError if it can't load the file. … … 325 309 """ 326 310 311 if access(file_name, F_OK) == 0 : 312 msg = 'File %s does not exist or is not accessible' %file_name 313 raise IOError, msg 314 327 315 attributes = {} 328 if ofile[-4:]== ".xya":316 if file_name[-4:]== ".xya": 329 317 try: 330 318 if delimiter == None: 331 319 try: 332 fd = open( ofile)320 fd = open(file_name) 333 321 data_points, attributes, geo_reference = _read_xya_file(fd, ',') 334 322 except SyntaxError: 335 323 fd.close() 336 fd = open( ofile)324 fd = open(file_name) 337 325 data_points, attributes, geo_reference = _read_xya_file(fd, ' ') 338 326 else: 339 fd = open( ofile)327 fd = open(file_name) 340 328 data_points, attributes, geo_reference = _read_xya_file(fd, delimiter) 341 329 fd.close() 342 330 except (IndexError,ValueError,SyntaxError): 343 331 fd.close() 344 msg = 'Could not open file %s ' % ofile332 msg = 'Could not open file %s ' %file_name 345 333 raise IOError, msg 346 334 except IOError, e: 347 335 # Catch this to add an error message 348 msg = 'Could not open file or incorrect file format %s:%s' %( ofile, e)336 msg = 'Could not open file or incorrect file format %s:%s' %(file_name, e) 349 337 raise IOError, msg 350 338 351 elif ofile[-4:]== ".pts":339 elif file_name[-4:]== ".pts": 352 340 try: 353 data_points, attributes, geo_reference = _read_pts_file( ofile, verbose)341 data_points, attributes, geo_reference = _read_pts_file(file_name, verbose) 354 342 except IOError, e: 355 msg = 'Could not open file %s ' % ofile343 msg = 'Could not open file %s ' %file_name 356 344 raise IOError, msg 357 345 else: 358 msg = 'Extension %s is unknown' % ofile[-4:]346 msg = 'Extension %s is unknown' %file_name[-4:] 359 347 raise IOError, msg 360 348 … … 368 356 # return all_data 369 357 370 def export_points_file(self, ofile, absolute=False):371 372 """ 373 write a points file, ofile, as a text (.xya) or binary (.pts) file374 ofile is the file name, including the extension358 def export_points_file(self, file_name, absolute=True): 359 360 """ 361 write a points file, file_name, as a text (.xya) or binary (.pts) file 362 file_name is the file name, including the extension 375 363 The point_dict is defined at the top of this file. 376 364 … … 382 370 """ 383 371 384 if ( ofile[-4:] == ".xya"):372 if (file_name[-4:] == ".xya"): 385 373 if absolute is True: 386 _write_xya_file( ofile, self.get_data_points(absolute),374 _write_xya_file(file_name, self.get_data_points(absolute=True), 387 375 self.get_all_attributes()) 388 376 else: 389 _write_xya_file( ofile, self.get_data_points(absolute),377 _write_xya_file(file_name, self.get_data_points(absolute=False), 390 378 self.get_all_attributes(), 391 379 self.get_geo_reference()) 392 380 393 elif ( ofile[-4:] == ".pts"):381 elif (file_name[-4:] == ".pts"): 394 382 if absolute is True: 395 _write_pts_file( ofile, self.get_data_points(absolute),383 _write_pts_file(file_name, self.get_data_points(absolute), 396 384 self.get_all_attributes()) 397 385 else: 398 _write_pts_file( ofile, self.get_data_points(absolute),386 _write_pts_file(file_name, self.get_data_points(absolute), 399 387 self.get_all_attributes(), 400 388 self.get_geo_reference()) 401 389 else: 402 msg = 'Unknown file type %s ' % ofile390 msg = 'Unknown file type %s ' %file_name 403 391 raise IOError, msg 404 392 … … 462 450 463 451 def _read_xya_file( fd, delimiter): 464 # print 'hello from read xya data'465 452 points = [] 466 453 pointattributes = [] 467 454 title = fd.readline() 468 455 att_names = clean_line(title,delimiter) 469 470 456 att_dict = {} 471 457 line = fd.readline() … … 480 466 numbers.pop(0) 481 467 numbers.pop(0) 482 #attributes = []483 #print "att_names",att_names484 #print "numbers",numbers485 468 if len(att_names) != len(numbers): 486 469 fd.close() … … 493 476 #attributes.append(float(num)) 494 477 att_dict.setdefault(att_names[i],[]).append(float(num)) 495 496 478 except ValueError: 497 479 raise SyntaxError 498 480 line = fd.readline() 499 481 numbers = clean_line(line,delimiter) 500 501 482 if line == '': 502 483 # end of file 503 484 geo_reference = None 485 504 486 else: 505 487 geo_reference = Geo_reference(ASCIIFile=fd,read_title=line) 506 507 # xya_dict = {} 508 # xya_dict['pointlist'] = array(points).astype(Float) 488 489 509 490 pointlist = array(points).astype(Float) 510 511 491 for key in att_dict.keys(): 512 492 att_dict[key] = array(att_dict[key]).astype(Float) 513 # xya_dict['attributelist'] = att_dict 514 515 # xya_dict['geo_reference'] = geo_reference 516 #print "xya_dict",xya_dict 493 517 494 return pointlist, att_dict, geo_reference 518 519 520 def _old_read_pts_file(file_name, verbose = False):521 """Read .pts NetCDF file522 523 Return a dic of array of points, and dic of array of attribute524 eg525 dic['points'] = [[1.0,2.0],[3.0,5.0]]526 dic['attributelist']['elevation'] = [[7.0,5.0]527 """528 #FIXME: (DSG) This format has issues.529 # There can't be an attribute called points530 # consider format change531 532 # print 'hi for read points file'533 from Scientific.IO.NetCDF import NetCDFFile534 535 if verbose: print 'Reading ', file_name536 537 538 # see if the file is there. Throw a QUIET IO error if it isn't539 fd = open(file_name,'r')540 fd.close()541 542 #throws prints to screen if file not present543 fid = NetCDFFile(file_name, 'r')544 545 point_atts = {}546 # Get the variables547 point_atts['pointlist'] = array(fid.variables['points'])548 keys = fid.variables.keys()549 if verbose: print 'Got %d variables: %s' %(len(keys), keys)550 try:551 keys.remove('points')552 except IOError, e:553 fid.close()554 msg = 'Expected keyword "points" but could not find it'555 raise IOError, msg556 557 attributes = {}558 for key in keys:559 if verbose: print "reading attribute '%s'" %key560 561 attributes[key] = array(fid.variables[key])562 563 point_atts['attributelist'] = attributes564 565 try:566 geo_reference = Geo_reference(NetCDFObject=fid)567 point_atts['geo_reference'] = geo_reference568 except AttributeError, e:569 #geo_ref not compulsory570 point_atts['geo_reference'] = None571 572 fid.close()573 return point_atts574 575 576 def _old_read_xya_file( fd, delimiter):577 points = []578 pointattributes = []579 title = fd.readline()580 att_names = clean_line(title,delimiter)581 582 att_dict = {}583 line = fd.readline()584 numbers = clean_line(line,delimiter)585 #print 'read xya numbers', numbers586 while len(numbers) > 1:587 if numbers != []:588 try:589 x = float(numbers[0])590 y = float(numbers[1])591 points.append([x,y])592 numbers.pop(0)593 numbers.pop(0)594 #attributes = []595 #print "att_names",att_names596 #print "numbers",numbers597 if len(att_names) != len(numbers):598 fd.close()599 # It might not be a problem with the title600 #raise TitleAmountError601 raise IOError602 for i,num in enumerate(numbers):603 num.strip()604 if num != '\n' and num != '':605 #attributes.append(float(num))606 att_dict.setdefault(att_names[i],[]).append(float(num))607 608 except ValueError:609 raise SyntaxError610 line = fd.readline()611 numbers = clean_line(line,delimiter)612 613 if line == '':614 # end of file615 geo_reference = None616 else:617 geo_reference = Geo_reference(ASCIIFile=fd,read_title=line)618 619 xya_dict = {}620 xya_dict['pointlist'] = array(points).astype(Float)621 622 for key in att_dict.keys():623 att_dict[key] = array(att_dict[key]).astype(Float)624 xya_dict['attributelist'] = att_dict625 626 xya_dict['geo_reference'] = geo_reference627 #print "xya_dict",xya_dict628 return xya_dict629 630 495 631 496 def _write_pts_file(file_name, write_data_points, … … 686 551 delimiter = ','): 687 552 """ 688 export a file, ofile, with the xya format553 export a file, file_name, with the xya format 689 554 690 555 """ … … 782 647 return numbers 783 648 784 def add_points_files(add_file1, add_file2, results_file):649 def xxx_add_points_files(add_file1, add_file2, results_file): 785 650 """ adds the points and attruibutes of 2 pts or xya files and 786 651 writes it to a pts file -
inundation/geospatial_data/test_geospatial_data.py
r2928 r2940 52 52 attributes = [2, 4] 53 53 G = Geospatial_data(points, attributes, 54 geo_reference =Geo_reference(56, 100, 200))54 geo_reference=Geo_reference(56, 100, 200)) 55 55 56 56 assert G.geo_reference.zone == 56 … … 64 64 attributes = [2, 4] 65 65 G = Geospatial_data(points, attributes, 66 geo_reference =Geo_reference(56, 100, 200))67 68 69 P = G.get_data_points(absolute =False)66 geo_reference=Geo_reference(56, 100, 200)) 67 68 69 P = G.get_data_points(absolute=False) 70 70 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 71 71 72 P = G.get_data_points(absolute =True)72 P = G.get_data_points(absolute=True) 73 73 assert allclose(P, [[101.0, 202.1], [103.0, 205.3]]) 74 74 … … 87 87 attributes = {'a0': [0, 0], 'a1': [2, 4], 'a2': [79.4, -7]} 88 88 G = Geospatial_data(points, attributes, 89 geo_reference =Geo_reference(56, 100, 200),90 default_attribute_name ='a1')91 92 93 P = G.get_data_points(absolute =False)89 geo_reference=Geo_reference(56, 100, 200), 90 default_attribute_name='a1') 91 92 93 P = G.get_data_points(absolute=False) 94 94 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 95 95 … … 122 122 attributes = {'a0': [0, 0], 'a1': [2, 4], 'a2': [79.4, -7]} 123 123 G = Geospatial_data(points, attributes, 124 geo_reference =Geo_reference(56, 100, 200),125 default_attribute_name ='a1')124 geo_reference=Geo_reference(56, 100, 200), 125 default_attribute_name='a1') 126 126 127 127 … … 165 165 G = points_dictionary2geospatial_data(points_dict) 166 166 167 P = G.get_data_points(absolute =False)167 P = G.get_data_points(absolute=False) 168 168 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 169 169 … … 342 342 G1 = Geospatial_data(points, att_dict, geo_ref) 343 343 344 G1.export_points_file(FN, absolute =True)344 G1.export_points_file(FN, absolute=True) 345 345 346 346 #Create object from file 347 347 G = Geospatial_data(file_name = FN) 348 348 349 assert allclose(G.get_data_points(absolute =True),350 G1.get_data_points(absolute =True))349 assert allclose(G.get_data_points(absolute=True), 350 G1.get_data_points(absolute=True)) 351 351 assert allclose(G.get_attributes('att1'), attributes) 352 352 assert allclose(G.get_attributes('att2'), array(attributes) + 1) … … 365 365 1.0, 0.0, 10.4, 40.0\n") 366 366 file.close() 367 results = Geospatial_data(fileName, delimiter =',')367 results = Geospatial_data(fileName, delimiter=',') 368 368 os.remove(fileName) 369 369 # print 'data', results.get_data_points() 370 370 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 371 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.0, 0.0, 10.4])372 assert allclose(results.get_attributes(attribute_name ='speed'), [0.0, 10.0, 40.0])371 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 372 assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0]) 373 373 374 374 def test_loadxya2(self): … … 386 386 file.close() 387 387 388 results = Geospatial_data(fileName, delimiter =' ')388 results = Geospatial_data(fileName, delimiter=' ') 389 389 390 390 os.remove(fileName) 391 391 392 392 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 393 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.0, 0.0, 10.4])394 assert allclose(results.get_attributes(attribute_name ='speed'), [0.0, 10.0, 40.0])393 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 394 assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0]) 395 395 396 396 def test_loadxya3(self): … … 412 412 file.close() 413 413 414 results = Geospatial_data(fileName, delimiter =' ')415 416 os.remove(fileName) 417 assert allclose(results.get_data_points(absolute =False), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])418 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.0, 0.0, 10.4])419 assert allclose(results.get_attributes(attribute_name ='speed'), [0.0, 10.0, 40.0])414 results = Geospatial_data(fileName, delimiter=' ') 415 416 os.remove(fileName) 417 assert allclose(results.get_data_points(absolute=False), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 418 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 419 assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0]) 420 420 421 421 def test_read_write_points_file_bad2(self): … … 424 424 att_dict['elevation'] = array([10.0, 0.0, 10.4]) 425 425 att_dict['brightness'] = array([10.0, 0.0, 10.4]) 426 geo_reference =Geo_reference(56,1.9,1.9)426 geo_reference=Geo_reference(56,1.9,1.9) 427 427 428 428 G = Geospatial_data(pointlist, att_dict, geo_reference) … … 451 451 #print fileName 452 452 try: 453 results = Geospatial_data(fileName, delimiter =' ')453 results = Geospatial_data(fileName, delimiter=' ') 454 454 except IOError: 455 455 pass … … 473 473 #print fileName 474 474 try: 475 results = Geospatial_data(fileName, delimiter =' ')475 results = Geospatial_data(fileName, delimiter=' ') 476 476 except IOError: 477 477 pass … … 495 495 file.close() 496 496 try: 497 results = Geospatial_data(fileName, delimiter =' ')497 results = Geospatial_data(fileName, delimiter=' ') 498 498 except IOError: 499 499 pass … … 505 505 def test_loadxy_bad4(self): 506 506 """ 507 specifying wrong delimiter507 specifying wrong delimiter 508 508 """ 509 509 import os 510 511 510 fileName = tempfile.mktemp(".xya") 512 511 file = open(fileName,"w") … … 515 514 0.0 1.0 0.0 10.0\n\ 516 515 1.0 0.0 10.4 40.0\n\ 517 #geocrap") 516 #geo\n\ 517 56\n\ 518 1.1\n\ 519 1.0\n") 520 518 521 file.close() 519 522 try: 520 # dict = import_points_file(fileName,delimiter = ' ') 521 # results = Geospatial_data() 522 results = Geospatial_data(fileName, delimiter = ',') 523 # results.import_points_file(fileName, delimiter = ' ') 523 results = Geospatial_data(fileName, delimiter=',') 524 524 except IOError: 525 525 pass … … 528 528 raise msg 529 529 530 # self.failUnless(0 ==1,531 # 'bad xya file did not raise error!')532 530 os.remove(fileName) 533 531 … … 548 546 file.close() 549 547 try: 550 # dict = import_points_file(fileName,delimiter =' ')548 # dict = import_points_file(fileName,delimiter=' ') 551 549 # results = Geospatial_data() 552 results = Geospatial_data(fileName, delimiter = ' ')553 # results.import_points_file(fileName, delimiter =' ')550 results = Geospatial_data(fileName, delimiter=' ', verbose=True) 551 # results.import_points_file(fileName, delimiter=' ') 554 552 except IOError: 555 553 pass … … 567 565 fileName = tempfile.mktemp(".xya") 568 566 try: 569 results = Geospatial_data(fileName, delimiter =' ')567 results = Geospatial_data(fileName, delimiter=' ') 570 568 except IOError: 571 569 pass … … 590 588 att_dict['brightness'] = array([10.0, 0.0, 10.4]) 591 589 # dict['attributelist'] = att_dict 592 geo_reference =Geo_reference(56,1.9,1.9)590 geo_reference=Geo_reference(56,1.9,1.9) 593 591 594 592 595 593 fileName = tempfile.mktemp(".xya") 596 594 G = Geospatial_data(pointlist, att_dict, geo_reference) 597 G.export_points_file(fileName )595 G.export_points_file(fileName, False) 598 596 599 597 # dict2 = import_points_file(fileName) … … 603 601 604 602 assert allclose(results.get_data_points(absolute=False),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 605 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.0, 0.0, 10.4])603 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 606 604 answer = [10.0, 0.0, 10.4] 607 assert allclose(results.get_attributes(attribute_name ='brightness'), answer)605 assert allclose(results.get_attributes(attribute_name='brightness'), answer) 608 606 #print "dict2['geo_reference']",dict2['geo_reference'] 609 607 self.failUnless(results.get_geo_reference() == geo_reference, … … 637 635 att_dict['elevation'] = array([10.0, 0.0, 10.4]) 638 636 att_dict['brightness'] = array([10.0, 0.0, 10.4]) 639 geo_reference =Geo_reference(56,1.9,1.9)637 geo_reference=Geo_reference(56,1.9,1.9) 640 638 641 639 … … 650 648 assert allclose(results.get_data_points(), 651 649 [[2.9, 1.9],[1.9, 2.9],[2.9, 1.9]]) 652 assert allclose(results.get_attributes(attribute_name ='elevation'),650 assert allclose(results.get_attributes(attribute_name='elevation'), 653 651 [10.0, 0.0, 10.4]) 654 652 answer = [10.0, 0.0, 10.4] 655 assert allclose(results.get_attributes(attribute_name ='brightness'), answer)653 assert allclose(results.get_attributes(attribute_name='brightness'), answer) 656 654 self.failUnless(results.get_geo_reference() == geo_reference, 657 655 'test_writepts failed. Test geo_reference') … … 676 674 677 675 assert allclose(results.get_data_points(),[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 678 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.1, 0.0, 10.4])676 assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4]) 679 677 answer = [10.0, 1.0, 10.4] 680 assert allclose(results.get_attributes(attribute_name ='brightness'), answer)678 assert allclose(results.get_attributes(attribute_name='brightness'), answer) 681 679 682 680 def test_new_export_absolute_pts_file(self): … … 698 696 699 697 assert allclose(results.get_data_points(), G.get_data_points(True)) 700 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.1, 0.0, 10.4])698 assert allclose(results.get_attributes(attribute_name='elevation'), [10.1, 0.0, 10.4]) 701 699 answer = [10.0, 1.0, 10.4] 702 assert allclose(results.get_attributes(attribute_name ='brightness'), answer)700 assert allclose(results.get_attributes(attribute_name='brightness'), answer) 703 701 704 702 def test_loadpts(self): … … 736 734 answer = [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]] 737 735 assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 738 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.0, 0.0, 10.4])736 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 739 737 740 738 def test_writepts(self): … … 743 741 att_dict['elevation'] = array([10.0, 0.0, 10.4]) 744 742 att_dict['brightness'] = array([10.0, 0.0, 10.4]) 745 geo_reference =Geo_reference(56,1.9,1.9)743 geo_reference=Geo_reference(56,1.9,1.9) 746 744 747 745 fileName = tempfile.mktemp(".pts") … … 749 747 G = Geospatial_data(pointlist, att_dict, geo_reference) 750 748 751 G.export_points_file(fileName )749 G.export_points_file(fileName, False) 752 750 753 751 results = Geospatial_data(file_name = fileName) … … 837 835 xll = 0.1 838 836 yll = 20 839 geo_reference =Geo_reference(56, xll, yll)837 geo_reference=Geo_reference(56, xll, yll) 840 838 geo_reference.write_NetCDF(outfile) 841 839 … … 875 873 876 874 877 def test_add_points_files(self): 878 '''adds an xya and pts files and checks resulting file is correct 875 def test_add_(self): 876 '''adds an xya and pts files, reads the files and adds them 877 checking results are correct 879 878 ''' 880 879 … … 882 881 883 882 # create files 884 # dict1 = {}885 883 att_dict1 = {} 886 884 pointlist1 = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 887 885 att_dict1['elevation'] = array([-10.0, 0.0, 10.4]) 888 886 att_dict1['brightness'] = array([10.0, 0.0, 10.4]) 889 # dict1['attributelist'] = att_dict1890 887 geo_reference1 = Geo_reference(56, 2.0, 1.0) 891 888 892 # dict2 = {}893 889 att_dict2 = {} 894 890 pointlist2 = array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]]) 895 891 att_dict2['elevation'] = array([1.0, 15.0, 1.4]) 896 892 att_dict2['brightness'] = array([14.0, 1.0, -12.4]) 897 # dict2['attributelist'] = att_dict2898 893 geo_reference2 = Geo_reference(56, 1.0, 2.0) #FIXME (Ole): I changed this, why does it still pass 899 894 #OK - it fails now, after the fix revealed by test_create_from_pts_file_with_geo') … … 918 913 919 914 #read results 920 assert allclose(G.get_data_points(absolute = False), 921 [[2.0, 0.0],[1.0, 1.0], 922 [2.0, 0.0],[2.0, 2.0], 923 [1.0, 3.0],[2.0, 2.0]]) 924 assert allclose(G.get_attributes(attribute_name = 'elevation'), 915 # print'res', G.get_data_points() 916 # print'res1', G.get_data_points(False) 917 assert allclose(G.get_data_points(), 918 [[ 3.0, 1.0], [ 2.0, 2.0], 919 [ 3.0, 1.0], [ 3.0, 3.0], 920 [ 2.0, 4.0], [ 3.0, 3.0]]) 921 922 assert allclose(G.get_attributes(attribute_name='elevation'), 925 923 [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4]) 926 924 927 925 answer = [10.0, 0.0, 10.4, 14.0, 1.0, -12.4] 928 assert allclose(G.get_attributes(attribute_name ='brightness'), answer)926 assert allclose(G.get_attributes(attribute_name='brightness'), answer) 929 927 930 928 self.failUnless(G.get_geo_reference() == geo_reference1, … … 962 960 #print "data_points",data_points 963 961 new_points = ensure_absolute(data_points, 964 geo_reference =mesh_origin)962 geo_reference=mesh_origin) 965 963 #print "new_points",new_points 966 964 #print "ab_points",ab_points … … 972 970 data_points = geo.change_points_geo_ref(ab_points) 973 971 new_points = ensure_absolute(data_points, 974 geo_reference =geo)972 geo_reference=geo) 975 973 #print "new_points",new_points 976 974 #print "ab_points",ab_points … … 985 983 #print "geo in points", points 986 984 G = Geospatial_data(points, attributes, 987 geo_reference =geo_reference)985 geo_reference=geo_reference) 988 986 989 987 new_points = ensure_absolute(G) … … 1011 1009 results = Geospatial_data(fileName) 1012 1010 1013 assert allclose(results.get_data_points(absolute =False), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])1014 assert allclose(results.get_attributes(attribute_name ='elevation'), [10.0, 0.0, 10.4])1015 assert allclose(results.get_attributes(attribute_name ='speed'), [0.0, 10.0, 40.0])1011 assert allclose(results.get_data_points(absolute=False), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 1012 assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4]) 1013 assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0]) 1016 1014 1017 1015 os.remove(fileName) … … 1020 1018 1021 1019 try: 1022 G = Geospatial_data(delimiter =',')1020 G = Geospatial_data(delimiter=',') 1023 1021 # results = Geospatial_data(file_name = fileName) 1024 1022 # dict = import_points_file(fileName) … … 1042 1040 raise msg 1043 1041 1042 def xxx_test_check_geo_reference(self): 1043 """ 1044 checks geo reference details are OK. eg can be called '#geo reference' 1045 if not throws a clear error message 1046 """ 1047 import os 1048 fileName = tempfile.mktemp(".xya") 1049 file = open(fileName,"w") 1050 file.write(" elevation \n\ 1051 1.0 0.0 10.0\n\ 1052 0.0 1.0 0.0\n\ 1053 1.0 0.0 10.4\n\ 1054 #geo reference\n\ 1055 56\n\ 1056 1.1\n\ 1057 1.0\n") 1058 1059 file.close() 1060 results = Geospatial_data(fileName) 1061 assert allclose(results.get_geo_reference().get_xllcorner(), 1.1) 1062 assert allclose(results.get_geo_reference().get_yllcorner(), 1.0) 1063 1064 def xxx_test_check_geo_reference1(self): 1065 """ 1066 checks geo reference details are OK. eg can be called '#geo reference' 1067 if not throws a clear error message 1068 """ 1069 import os 1070 fileName = tempfile.mktemp(".xya") 1071 file = open(fileName,"w") 1072 file.write(" elevation \n\ 1073 1.0 0.0 10.0\n\ 1074 0.0 1.0 0.0\n\ 1075 1.0 0.0 10.4\n\ 1076 #geo reference\n\ 1077 56\n\ 1078 1.1\n" 1079 ) 1080 file.close() 1081 1082 # try: 1083 results = Geospatial_data(fileName) 1084 # except ValueError or SyntaxError: 1085 # pass 1086 # else: 1087 # msg = 'Geo reference data format is incorrect' 1088 # raise msg 1089 1090 1091 1092 assert allclose(results.get_geo_reference().get_xllcorner(), 1.1) 1093 assert allclose(results.get_geo_reference().get_yllcorner(), 1.0) 1094 1044 1095 1045 1096
Note: See TracChangeset
for help on using the changeset viewer.