Ignore:
Timestamp:
Mar 29, 2006, 8:42:34 AM (18 years ago)
Author:
nick
Message:

fixed geospatial_data to not use point_dict in export and updated onslow run to use new geospatial_data methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/test_geospatial_data.py

    r2594 r2624  
    301301        points = [[1.0, 2.1], [3.0, 5.3], [5.0, 6.1], [6.0, 3.3]]
    302302        attributes = [2, 4, 5, 76]
    303 
     303        '''
    304304        # Use old pointsdict format
    305305        pointsdict = {'pointlist': points,
    306306                      'attributelist': {'att1': attributes,
    307307                                        'att2': array(attributes) + 1}}
    308      
     308        '''
     309        att_dict = {'att1': attributes,
     310                    'att2': array(attributes) +1}
     311                   
    309312        # Create points as an xya file
    310313        FN = 'test_points.xya'
    311         export_points_file(FN, pointsdict)
    312 
     314        G1 = Geospatial_data(points, att_dict)
     315        G1.new_export_points_file(FN)
     316#        G1.new_export_points_file(ofile)
    313317
    314318        #Create object from file
     
    397401                        'imaginary file did not raise error!')
    398402 
    399     def Xtest_read_write_points_file_bad(self):
    400         #not used yet as i'm uncertain if "tri_dict" is nesscessary to geospatial_data
    401         dict = self.tri_dict.copy()
    402         fileName = tempfile.mktemp(".xxx")
    403         try:
    404             export_points_file(fileName,dict)
    405         except IOError:
    406             pass
    407         else:
    408             self.failUnless(0 ==1,
    409                         'bad points file extension did not raise error!')
    410 
    411403    def test_read_write_points_file_bad2(self):
    412         dict = {}
     404#        dict = {}
    413405        att_dict = {}
    414         dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     406        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    415407        att_dict['elevation'] = array([10.0, 0.0, 10.4])
    416408        att_dict['brightness'] = array([10.0, 0.0, 10.4])
    417         dict['attributelist'] = att_dict
    418         dict['geo_reference'] = Geo_reference(56,1.9,1.9)
    419         try:
    420             export_points_file("_???/yeah.xya",dict)
     409#        dict['attributelist'] = att_dict
     410        geo_reference = Geo_reference(56,1.9,1.9)
     411       
     412        G = Geospatial_data(pointlist, att_dict, geo_reference)
     413       
     414        try:
     415#            export_points_file("_???/yeah.xya",dict)
     416            G.new_export_points_file("_???/yeah.xya")
     417           
    421418        except IOError:
    422419            pass
    423420        else:
    424             self.failUnless(0 ==1,
     421            self.failUnless(0 == 1,
    425422                        'bad points file extension did not raise error!')
    426423                   
     
    573570       
    574571    def test_export_xya_file(self):
    575         dict = {}
     572#        dict = {}
    576573        att_dict = {}
    577         dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     574        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    578575        att_dict['elevation'] = array([10.0, 0.0, 10.4])
    579576        att_dict['brightness'] = array([10.0, 0.0, 10.4])
    580         dict['attributelist'] = att_dict
    581         dict['geo_reference'] = Geo_reference(56,1.9,1.9)
    582        
    583        
    584         fileName = tempfile.mktemp(".xya")
    585         export_points_file(fileName, dict)
     577#        dict['attributelist'] = att_dict
     578        geo_reference = Geo_reference(56,1.9,1.9)
     579       
     580       
     581        fileName = tempfile.mktemp(".xya")
     582        G = Geospatial_data( pointlist, att_dict, geo_reference, absolute = False)
     583        G.new_export_points_file(fileName)
    586584        dict2 = import_points_file(fileName)
    587585        #print "fileName",fileName
     
    594592        assert allclose(dict2['attributelist']['brightness'], answer)
    595593        #print "dict2['geo_reference']",dict2['geo_reference']
    596         self.failUnless(dict['geo_reference'] == dict2['geo_reference'],
     594        self.failUnless(geo_reference == dict2['geo_reference'],
    597595                         'test_writepts failed. Test geo_reference')
    598596
    599597    def test_export_xya_file2(self):
    600         dict = {}
     598#        dict = {}
    601599        att_dict = {}
    602         dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     600        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    603601        att_dict['elevation'] = array([10.0, 0.0, 10.4])
    604602        att_dict['brightness'] = array([10.0, 0.0, 10.4])
    605         dict['attributelist'] = att_dict
    606        
    607        
    608         fileName = tempfile.mktemp(".xya")
    609         export_points_file(fileName, dict)
     603#        dict['attributelist'] = att_dict
     604       
     605        fileName = tempfile.mktemp(".xya")
     606        G = Geospatial_data(pointlist, att_dict)
     607        G.new_export_points_file(fileName)
    610608        dict2 = import_points_file(fileName)
    611609        #print "fileName",fileName
     
    616614        assert allclose(dict2['attributelist']['elevation'], [10.0, 0.0, 10.4])
    617615        answer = [10.0, 0.0, 10.4]
     616        assert allclose(dict2['attributelist']['brightness'], answer)
     617
     618    def test_new_export_xya_file2(self):
     619        dict = {}
     620        att_dict = {}
     621        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     622        att_dict['elevation'] = array([10.1, 0.0, 10.4])
     623        att_dict['brightness'] = array([10.0, 1.0, 10.4])
     624       
     625        fileName = tempfile.mktemp(".xya")
     626       
     627        G = Geospatial_data(pointlist, att_dict)
     628       
     629        G.new_export_points_file(fileName)
     630
     631        dict2 = import_points_file(fileName)
     632
     633        os.remove(fileName)
     634       
     635        assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     636        assert allclose(dict2['attributelist']['elevation'], [10.1, 0.0, 10.4])
     637        answer = [10.0, 1.0, 10.4]
     638        assert allclose(dict2['attributelist']['brightness'], answer)
     639
     640    def test_new_export_pts_file(self):
     641        att_dict = {}
     642        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     643        att_dict['elevation'] = array([10.1, 0.0, 10.4])
     644        att_dict['brightness'] = array([10.0, 1.0, 10.4])
     645       
     646        fileName = tempfile.mktemp(".pts")
     647       
     648        G = Geospatial_data(pointlist, att_dict)
     649       
     650        G.new_export_points_file(fileName)
     651
     652        dict2 = import_points_file(fileName)
     653
     654        os.remove(fileName)
     655       
     656        assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     657        assert allclose(dict2['attributelist']['elevation'], [10.1, 0.0, 10.4])
     658        answer = [10.0, 1.0, 10.4]
    618659        assert allclose(dict2['attributelist']['brightness'], answer)
    619660
     
    658699       
    659700    def test_writepts(self):
    660         dict = {}
     701#        dict = {}
    661702        att_dict = {}
    662         dict['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     703        pointlist = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    663704        att_dict['elevation'] = array([10.0, 0.0, 10.4])
    664705        att_dict['brightness'] = array([10.0, 0.0, 10.4])
    665         dict['attributelist'] = att_dict
    666         dict['geo_reference'] = Geo_reference(56,1.9,1.9)
    667        
     706#        dict['attributelist'] = att_dict
     707        geo_reference = Geo_reference(56,1.9,1.9)
    668708       
    669709        fileName = tempfile.mktemp(".pts")
    670         export_points_file(fileName, dict)
     710       
     711        G = Geospatial_data(pointlist, att_dict, geo_reference, absolute = False)
     712       
     713        G.new_export_points_file(fileName)
     714       
    671715        dict2 = import_points_file(fileName)
    672         #print "fileName",fileName
    673         os.remove(fileName)
    674         #print "dict2",dict2
    675        
     716
     717        os.remove(fileName)
     718
    676719        assert allclose(dict2['pointlist'],[[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    677720        assert allclose(dict2['attributelist']['elevation'], [10.0, 0.0, 10.4])
     
    682725        #print "dict2['geo_reference']",dict2['geo_reference']
    683726       
    684         self.failUnless(dict['geo_reference'] == dict2['geo_reference'],
     727        self.failUnless(geo_reference == dict2['geo_reference'],
    685728                         'test_writepts failed. Test geo_reference')
    686729       
     
    705748       
    706749        from Scientific.IO.NetCDF import NetCDFFile
    707 
    708750
    709751#        fileName = tempfile.mktemp(".pts")
     
    738780        assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
    739781        assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
    740        
    741782
    742783        assert allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     
    749790       
    750791        from Scientific.IO.NetCDF import NetCDFFile
    751 
    752792
    753793        FN = 'test_points.pts'
     
    761801        geo_reference.write_NetCDF(outfile)
    762802
    763        
    764803        # dimension definitions
    765804        outfile.createDimension('number_of_points', 3)   
     
    775814        elevation = outfile.variables['elevation']
    776815
    777  
    778816        points[0, :] = [1.0,0.0]
    779817        elevation[0] = 10.0
     
    787825        G = Geospatial_data(file_name = FN)
    788826
    789 
    790 
    791827        assert allclose(G.get_geo_reference().get_xllcorner(), xll)
    792828        assert allclose(G.get_geo_reference().get_yllcorner(), yll)
    793        
    794829
    795830        assert allclose(G.get_data_points(), [[1.0+xll, 0.0+yll],
     
    801836
    802837       
    803     def xtest_add_points_files(self):
     838    def test_add_points_files(self):
    804839        '''adds an xya and pts files and checks resulting file is correct
    805840        '''
     
    808843       
    809844        # create files
    810         dict1 = {}
     845#        dict1 = {}
    811846        att_dict1 = {}
    812         dict1['pointlist'] = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     847        pointlist1 = array([[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    813848        att_dict1['elevation'] = array([-10.0, 0.0, 10.4])
    814849        att_dict1['brightness'] = array([10.0, 0.0, 10.4])
    815         dict1['attributelist'] = att_dict1
    816         dict1['geo_reference'] = Geo_reference(56, 1.9, 1.9)
    817        
    818         dict2 = {}
     850#        dict1['attributelist'] = att_dict1
     851        geo_reference1 = Geo_reference(56, 2.0, 1.0)
     852       
     853#        dict2 = {}
    819854        att_dict2 = {}
    820         dict2['pointlist'] = array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]])
     855        pointlist2 = array([[2.0, 1.0],[1.0, 2.0],[2.0, 1.0]])
    821856        att_dict2['elevation'] = array([1.0, 15.0, 1.4])
    822857        att_dict2['brightness'] = array([14.0, 1.0, -12.4])
    823         dict2['attributelist'] = att_dict2
    824         dict2['geo_reference'] = Geo_reference(56, 1.0, 1.0) #FIXME (Ole): I changed this, why does it still pass
     858#        dict2['attributelist'] = att_dict2
     859        geo_reference2 = Geo_reference(56, 1.0, 2.0) #FIXME (Ole): I changed this, why does it still pass
    825860        #OK - it fails now, after the fix revealed by test_create_from_pts_file_with_geo')
     861
     862        G1 = Geospatial_data(pointlist1, att_dict1, geo_reference1)
     863        G2 = Geospatial_data(pointlist2, att_dict2, geo_reference2)
    826864       
    827865        fileName1 = tempfile.mktemp(".xya")
    828866        fileName2 = tempfile.mktemp(".pts")
    829867
    830         export_points_file(fileName1, dict1)
    831         export_points_file(fileName2, dict2)
     868#        G1.new_export_points_file(fileName1)
     869#        G2.new_export_points_file(fileName2)
    832870       
    833871        results_file = 'resulting_points.pts'
    834872       
    835873        # add files
    836         add_points_files(fileName1, fileName2, results_file )
     874       
     875        G = G1 + G2
     876       
     877        G.new_export_points_file(results_file)
     878#        add_points_files(fileName1, fileName2, results_file )
    837879       
    838880        #read results
    839881        results_dict = import_points_file(results_file)
     882#        print 'results points:', results_dict['pointlist']
     883#        print 'results geo_ref:', results_dict['geo_reference']
    840884       
    841885        assert allclose(results_dict['pointlist'],
    842                         [[1.0, 0.0],[0.0, 1.0],
    843                          [1.0, 0.0],[2.0, 1.0],
    844                          [1.0, 2.0],[2.0, 1.0]])
     886                        [[2.0, 0.0],[1.0, 1.0],
     887                         [2.0, 0.0],[2.0, 2.0],
     888                         [1.0, 3.0],[2.0, 2.0]])
    845889        assert allclose(results_dict['attributelist']['elevation'],
    846890                        [-10.0, 0.0, 10.4, 1.0, 15.0, 1.4])
     
    849893        assert allclose(results_dict['attributelist']['brightness'], answer)
    850894       
    851         self.failUnless(results_dict['geo_reference'] == dict2['geo_reference'],
     895        self.failUnless(results_dict['geo_reference'] == geo_reference1,
    852896                         'test_writepts failed. Test geo_reference')
    853897                         
    854         os.remove(fileName1)
    855         os.remove(fileName2)
     898#        os.remove(fileName1)
     899#        os.remove(fileName2)
    856900        os.remove(results_file)
    857901
Note: See TracChangeset for help on using the changeset viewer.