Changeset 2591


Ignore:
Timestamp:
Mar 24, 2006, 3:13:02 PM (18 years ago)
Author:
ole
Message:

New tests revealed georeferencing bug in geospatial constructor. Bug fixed.

Location:
inundation/geospatial_data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r2590 r2591  
    5959       
    6060        else:
    61 #            print 'from init file name:', file_name
    6261            if access(file_name, F_OK) == 0 :
    63                 msg = 'File %s does not exist or is not accessable' %file_name
     62                msg = 'File %s does not exist or is not accessible' %file_name
    6463                raise msg
    6564            else:
    6665                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!
    6968                self.file_name = file_name
    7069                data = import_points_file(self.file_name)
    7170               
    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']
    7574               
    7675                data_points = data['pointlist']
    7776                attributes = data['attributelist']
    78                 get_reference = data['geo_reference']
     77                geo_reference = data['geo_reference']
    7978               
    8079                self.check_data_points(data_points)
     
    596595    that are shared. This will require some work and maybe __subtract__ function
    597596    '''
     597   
    598598    G1 = Geospatial_data(file_name = add_file1)
    599599    G2 = Geospatial_data(file_name = add_file2)
  • inundation/geospatial_data/test_geospatial_data.py

    r2590 r2591  
    684684        G = Geospatial_data(file_name = FN)
    685685
     686        assert allclose(G.get_geo_reference().get_xllcorner(), 0.0)
     687        assert allclose(G.get_geo_reference().get_yllcorner(), 0.0)
     688       
     689
    686690        assert allclose(G.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
    687691        assert allclose(G.get_attributes(), [10.0, 0.0, 10.4])
    688692        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):
    691752        '''adds an xya and pts files and checks resulting file is correct
    692753        '''
     754
     755        #FIXME (Ole): I changed the georeference arbitrarily, but the test still passes.
    693756       
    694757        # create files
     
    699762        att_dict1['brightness'] = array([10.0, 0.0, 10.4])
    700763        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)
    702765       
    703766        dict2 = {}
     
    707770        att_dict2['brightness'] = array([14.0, 1.0, -12.4])
    708771        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')
    710774       
    711775        fileName1 = tempfile.mktemp(".xya")
     
    714778        export_points_file(fileName1, dict1)
    715779        export_points_file(fileName2, dict2)
    716 #        export_points_file('hello.xya', dict1)
    717 #        export_points_file('hello.pts', dict2)
    718780       
    719781        results_file = 'resulting_points.pts'
     
    721783        # add files
    722784        add_points_files(fileName1, fileName2, results_file )
    723 #        add_points_files('hello.xya', 'hello.pts', results_file )
    724785       
    725786        #read results
    726787        results_dict = import_points_file(results_file)
    727788       
    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       
    730796        answer = [10.0, 0.0, 10.4, 14.0, 1.0, -12.4]
    731797        assert allclose(results_dict['attributelist']['brightness'], answer)
    732         #print "dict2['geo_reference']",dict2['geo_reference']
     798       
    733799        self.failUnless(results_dict['geo_reference'] == dict2['geo_reference'],
    734800                         'test_writepts failed. Test geo_reference')
     
    738804        os.remove(results_file)
    739805
     806       
     807
    740808if __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')
    742811    runner = unittest.TextTestRunner()
    743812    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.