Changeset 2590


Ignore:
Timestamp:
Mar 24, 2006, 2:43:10 PM (18 years ago)
Author:
ole
Message:

Clean up

Location:
inundation/geospatial_data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r2584 r2590  
    169169       
    170170    def get_data_points(self, absolute = True):
     171        """Get coordinates for all data points as an Nx2 array
     172
     173        If absolute is True absolute UTM coordinates are returned otherwise
     174        returned coordinates are relative to the internal georeference's
     175        xll and yll corners.
     176
     177        Default: absolute is True.
     178        """
    171179        if absolute is True:
    172180            xll = self.geo_reference.xllcorner
    173181            yll = self.geo_reference.yllcorner
    174182            return self.data_points + [xll, yll]
    175            
    176183        else:
    177184            return self.data_points
     
    224231       
    225232        if zone1 == zone2:
    226             a_rel_points = self.get_data_points()
    227             b_rel_points = other.get_data_points()
    228            
    229             # subtracts xll and yll from self's and other's
    230             # reletive data point and concatenates
    231             c_points = concatenate((a_rel_points-[xll, yll],
    232                                     b_rel_points-[xll, yll]), axis = 0)
     233            a_absolute_points = self.get_data_points(absolute=True)
     234            b_absolute_points = other.get_data_points(absolute=True)
     235           
     236            # subtract xll and yll from self's and other's
     237            # absolute data points and concatenate
     238            c_points = concatenate((a_absolute_points-[xll, yll],
     239                                    b_absolute_points-[xll, yll]),
     240                                   axis = 0)
    233241
    234242            new_attributes = {}
     
    388396    line = fd.readline()
    389397    numbers = clean_line(line,delimiter)
    390     print 'read xya numbers', numbers
     398    #print 'read xya numbers', numbers
    391399    while len(numbers) > 1:
    392400        if numbers != []:
     
    588596    that are shared. This will require some work and maybe __subtract__ function
    589597    '''
    590 #    print 'load %s' %add_file1
    591 #    if access(add_file1,F_OK) == 1 :
    592 #        print'file1', add_file1
    593 
    594 #    print'file1 again', add_file1
    595 #    print'file2 again', add_file2
    596     print 'create G1'
    597598    G1 = Geospatial_data(file_name = add_file1)
    598    
    599 #    print 'G1 dict'
    600  #   G1_points_dict = geospatial_data2points_dictionary(G1)
    601 
    602 #    print 'G1 xya file'
    603 #    export_points_file("v:\inundation\onslow_tsunami_scenario_2006\\topographies\onshore.xya", G1_points_dict)
    604 
    605     print 'create G2'
    606 #    print 'load %s' %add_file2
    607 #    if access(add_file2,F_OK) == 1 :
    608 #        print'file2', add_file2
    609599    G2 = Geospatial_data(file_name = add_file2)
    610     print 'G2 dict'
    611 #    G2_points_dict = geospatial_data2points_dictionary(G2)
    612 
    613600    new_add_file2 = add_file2[:-4] + '.pts'
    614     print 'G2 pts file', new_add_file2
    615    
    616 #    export_points_file(new_add_file2, G2_points_dict)
    617     print 'G1+g2'   
     601
    618602    G = G1 + G2
     603   
    619604    #FIXME remove dependance on points to dict in export only!
    620605    G_points_dict = geospatial_data2points_dictionary(G)
    621    
    622606    export_points_file(results_file, G_points_dict)
    623607   
  • inundation/geospatial_data/test_geospatial_data.py

    r2589 r2590  
    202202                                              [1.0, 2.1], [3.0, 5.3]])
    203203       
    204     def test_add1 (self):
     204    def test_add_with_geo (self):
    205205        """
    206206        Difference in Geo_reference resolved
     
    208208        points1 = [[1.0, 2.1], [3.0, 5.3]]
    209209        points2 = [[5.0, 6.1], [6.0, 3.3]]
    210         attributes1= [2, 4]
     210        attributes1 = [2, 4]
    211211        attributes2 = [5, 76]
    212212        geo_ref1= Geo_reference(55, 1.0, 2.0)
    213         geo_ref2 = Geo_reference(zone = 55, xllcorner = 0.1,
    214                                  yllcorner = 3.0, datum = 'wgs84',
    215                                  projection = 'UTM', units = 'm')
     213        geo_ref2 = Geo_reference(zone=55,
     214                                 xllcorner=0.1,
     215                                 yllcorner=3.0,
     216                                 datum='wgs84',
     217                                 projection='UTM',
     218                                 units='m')
    216219                               
    217220        G1 = Geospatial_data(points1, attributes1, geo_ref1)
    218221        G2 = Geospatial_data(points2, attributes2, geo_ref2)
    219222
     223        #Check that absolute values are as expected
     224        P1 = G1.get_data_points(absolute=True)
     225        assert allclose(P1, [[2.0, 4.1], [4.0, 7.3]])
     226
     227        P2 = G2.get_data_points(absolute=True)
     228        assert allclose(P2, [[5.1, 9.1], [6.1, 6.3]])       
     229       
    220230        G = G1 + G2
    221231       
    222232        assert allclose(G.get_geo_reference().get_xllcorner(), 0.1)
    223233        assert allclose(G.get_geo_reference().get_yllcorner(), 2.0)
    224 #        print 'G data points=', G.get_data_points()
    225         assert allclose(G.get_data_points(), [[2.0, 4.1], [4.0, 7.3], [5.1, 9.1], [6.1, 6.3]])                             
    226 
     234
     235        P = G.get_data_points(absolute=True)
     236        assert allclose(P, concatenate( (P1,P2) ))
     237
     238        P_relative = G.get_data_points(absolute=False)
     239        assert allclose(P_relative, P - [0.1, 2.0])                     
     240        assert allclose(P, [[2.0, 4.1], [4.0, 7.3],
     241                            [5.1, 9.1], [6.1, 6.3]])
    227242
    228243
Note: See TracChangeset for help on using the changeset viewer.