Changeset 2591
- Timestamp:
- Mar 24, 2006, 3:13:02 PM (18 years ago)
- Location:
- inundation/geospatial_data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/geospatial_data/geospatial_data.py
r2590 r2591 59 59 60 60 else: 61 # print 'from init file name:', file_name62 61 if access(file_name, F_OK) == 0 : 63 msg = 'File %s does not exist or is not access able' %file_name62 msg = 'File %s does not exist or is not accessible' %file_name 64 63 raise msg 65 64 else: 66 65 data = {} 67 # watch for case where file name and points, attributes etc are provided!!68 # if file name then all provided info will be removed!66 # watch for case where file name and points, attributes etc are provided!! 67 # if file name then all provided info will be removed! 69 68 self.file_name = file_name 70 69 data = import_points_file(self.file_name) 71 70 72 #print 'data: point in init', data['pointlist']73 #print 'attrib: point in init', data['attributelist']74 #print 'geo_ref: point in init', data['geo_reference']71 # print 'data: point in init', data['pointlist'] 72 # print 'attrib: point in init', data['attributelist'] 73 # print 'geo_ref: point in init', data['geo_reference'] 75 74 76 75 data_points = data['pointlist'] 77 76 attributes = data['attributelist'] 78 ge t_reference = data['geo_reference']77 geo_reference = data['geo_reference'] 79 78 80 79 self.check_data_points(data_points) … … 596 595 that are shared. This will require some work and maybe __subtract__ function 597 596 ''' 597 598 598 G1 = Geospatial_data(file_name = add_file1) 599 599 G2 = Geospatial_data(file_name = add_file2) -
inundation/geospatial_data/test_geospatial_data.py
r2590 r2591 684 684 G = Geospatial_data(file_name = FN) 685 685 686 assert allclose(G.get_geo_reference().get_xllcorner(), 0.0) 687 assert allclose(G.get_geo_reference().get_yllcorner(), 0.0) 688 689 686 690 assert allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]]) 687 691 assert allclose(G.get_attributes(), [10.0, 0.0, 10.4]) 688 692 os.remove(FN) 689 690 def test_add_points_files(self): 693 694 def test_create_from_pts_file_with_geo(self): 695 """This test reveals if Geospatial data is correctly instantiated from a pts file. 696 """ 697 698 from Scientific.IO.NetCDF import NetCDFFile 699 700 701 FN = 'test_points.pts' 702 # NetCDF file definition 703 outfile = NetCDFFile(FN, 'w') 704 705 # Make up an arbitrary georef 706 xll = 0.1 707 yll = 20 708 geo_reference = Geo_reference(56, xll, yll) 709 geo_reference.write_NetCDF(outfile) 710 711 712 # dimension definitions 713 outfile.createDimension('number_of_points', 3) 714 outfile.createDimension('number_of_dimensions', 2) #This is 2d data 715 716 # variable definitions 717 outfile.createVariable('points', Float, ('number_of_points', 718 'number_of_dimensions')) 719 outfile.createVariable('elevation', Float, ('number_of_points',)) 720 721 # Get handles to the variables 722 points = outfile.variables['points'] 723 elevation = outfile.variables['elevation'] 724 725 726 points[0, :] = [1.0,0.0] 727 elevation[0] = 10.0 728 points[1, :] = [0.0,1.0] 729 elevation[1] = 0.0 730 points[2, :] = [1.0,0.0] 731 elevation[2] = 10.4 732 733 outfile.close() 734 735 G = Geospatial_data(file_name = FN) 736 737 738 739 assert allclose(G.get_geo_reference().get_xllcorner(), xll) 740 assert allclose(G.get_geo_reference().get_yllcorner(), yll) 741 742 743 assert allclose(G.get_data_points(), [[1.0+xll, 0.0+yll], 744 [0.0+xll, 1.0+yll], 745 [1.0+xll, 0.0+yll]]) 746 747 assert allclose(G.get_attributes(), [10.0, 0.0, 10.4]) 748 os.remove(FN) 749 750 751 def xtest_add_points_files(self): 691 752 '''adds an xya and pts files and checks resulting file is correct 692 753 ''' 754 755 #FIXME (Ole): I changed the georeference arbitrarily, but the test still passes. 693 756 694 757 # create files … … 699 762 att_dict1['brightness'] = array([10.0, 0.0, 10.4]) 700 763 dict1['attributelist'] = att_dict1 701 dict1['geo_reference'] = Geo_reference(56, 1.9,1.9)764 dict1['geo_reference'] = Geo_reference(56, 1.9, 1.9) 702 765 703 766 dict2 = {} … … 707 770 att_dict2['brightness'] = array([14.0, 1.0, -12.4]) 708 771 dict2['attributelist'] = att_dict2 709 dict2['geo_reference'] = Geo_reference(56,1.9,1.9) 772 dict2['geo_reference'] = Geo_reference(56, 1.0, 1.0) #FIXME (Ole): I changed this, why does it still pass 773 #OK - it fails now, after the fix revealed by test_create_from_pts_file_with_geo') 710 774 711 775 fileName1 = tempfile.mktemp(".xya") … … 714 778 export_points_file(fileName1, dict1) 715 779 export_points_file(fileName2, dict2) 716 # export_points_file('hello.xya', dict1)717 # export_points_file('hello.pts', dict2)718 780 719 781 results_file = 'resulting_points.pts' … … 721 783 # add files 722 784 add_points_files(fileName1, fileName2, results_file ) 723 # add_points_files('hello.xya', 'hello.pts', results_file )724 785 725 786 #read results 726 787 results_dict = import_points_file(results_file) 727 788 728 assert allclose(results_dict['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0],[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]]) 729 assert allclose(results_dict['attributelist']['elevation'], [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4]) 789 assert allclose(results_dict['pointlist'], 790 [[1.0, 0.0],[0.0, 1.0], 791 [1.0, 0.0],[2.0, 1.0], 792 [1.0, 2.0],[2.0, 1.0]]) 793 assert allclose(results_dict['attributelist']['elevation'], 794 [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4]) 795 730 796 answer = [10.0, 0.0, 10.4, 14.0, 1.0, -12.4] 731 797 assert allclose(results_dict['attributelist']['brightness'], answer) 732 #print "dict2['geo_reference']",dict2['geo_reference']798 733 799 self.failUnless(results_dict['geo_reference'] == dict2['geo_reference'], 734 800 'test_writepts failed. Test geo_reference') … … 738 804 os.remove(results_file) 739 805 806 807 740 808 if __name__ == "__main__": 741 suite = unittest.makeSuite(Test_Geospatial_data,'test') 809 #suite = unittest.makeSuite(Test_Geospatial_data, 'test_create_from_pts_file_with_geo') 810 suite = unittest.makeSuite(Test_Geospatial_data, 'test') 742 811 runner = unittest.TextTestRunner() 743 812 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.