Changeset 3134


Ignore:
Timestamp:
Jun 13, 2006, 10:10:40 AM (18 years ago)
Author:
duncan
Message:

small fixes

Location:
inundation/coordinate_transforms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/coordinate_transforms/geo_reference.py

    r3129 r3134  
    99from Numeric import array, Float, ArrayType, reshape, allclose
    1010from utilities.numerical_tools import ensure_numeric
    11 from utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError
    12 
    13 
    14 #import exceptions
    15 #class TitleError(exceptions.IOError): pass
    16 #class ParsingError(exceptions.IOError): pass
     11from utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError, \
     12     ShapeError
     13
    1714
    1815DEFAULT_ZONE = -1
     
    195192        """
    196193
    197         if self.is_absolute():
    198             return points
     194        #if self.is_absolute():
     195        #    return points
    199196       
    200197
     
    204201
    205202        points = ensure_numeric(points, Float)
    206        
    207203        if len(points.shape) == 1:
    208204            #One point has been passed
    209205            msg = 'Single point must have two elements'
    210             assert len(points) == 2, msg
    211             points = reshape(points, (1,2))
     206            if not len(points) == 2:
     207                raise ShapeError, msg   
     208                #points = reshape(points, (1,2))
    212209
    213210
    214211        msg = 'Input must be an N x 2 array or list of (x,y) values. '
    215212        msg += 'I got an %d x %d array' %points.shape   
    216         assert points.shape[1] == 2, msg   
    217            
    218 
    219         # Old code   
    220         #is_list = False
    221         #if type(points) == types.ListType:
    222         #    is_list = True
    223         #    if len(points)>0 and type(points[0]) \
    224         #           not in [types.ListType,types.TupleType]:
    225         #        #a single point is being passed.  make it a list of lists
    226         #        points = [points]
    227         #elif type(points) == ArrayType:
    228         #    if len(points.shape) == 1:
    229         #        points = [points]       
    230            
    231         ## convert into array
    232         #points = array(points).astype(Float)
    233 
    234        
    235         # Add primary geo ref from points
    236 
    237 
    238        
    239         points[:,0] += self.xllcorner
    240         points[:,1] += self.yllcorner
     213        if not points.shape[1] == 2:
     214            raise ShapeError, msg   
     215           
     216       
     217        # Add geo ref to points
     218        if not self.is_absolute():
     219            points[:,0] += self.xllcorner
     220            points[:,1] += self.yllcorner
    241221
    242222       
  • inundation/coordinate_transforms/test_geo_reference.py

    r3129 r3134  
    107107            self.failUnless(point[0]-x==new_point[0], ' failed')
    108108            self.failUnless(point[1]-y==new_point[1], ' failed')
     109         
    109110       
    110111    def test_change_points_geo_ref2(self):
     
    207208            self.failUnless(point[1]+point_y-y==new_point[1], ' failed')
    208209     
     210
    209211    def test_get_absolute(self):
    210212        x = 7.0
     
    222224            self.failUnless(point[0]+x==new_point[0], ' failed')
    223225            self.failUnless(point[1]+y==new_point[1], ' failed')
    224                        
     226
     227           
     228        g = Geo_reference()
     229        lofl = [[3.0,34.0], [64.0,6.0]]
     230        new_lofl = g.get_absolute(lofl)
     231        #print "lofl",lofl
     232        #print "new_lofl",new_lofl
     233
     234        self.failUnless(type(new_lofl) == types.ListType, ' failed')
     235        self.failUnless(type(new_lofl) == type(lofl), ' failed')
     236        for point,new_point in map(None,lofl,new_lofl):
     237            self.failUnless(point[0]==new_point[0], ' failed')
     238            self.failUnless(point[1]==new_point[1], ' failed')
     239           
    225240    def test_is_absolute(self):
    226241       
     
    364379                        'bad text file did not raise error!')
    365380            os.remove(point_file)
    366          
     381
     382    def test_error_message_ShapeError(self):
     383       
     384        new_g = Geo_reference()
     385        try:
     386            new_g.get_absolute((8.9, 7.8, 9.0))
     387        except ShapeError:
     388            pass
     389        else:
     390            self.failUnless(0 ==1,
     391                        'bad shape did not raise error!')
     392            os.remove(point_file)
     393           
     394        new_g = Geo_reference()
     395        try:
     396            new_g.get_absolute(((8.9, 7.8, 9.0)))
     397        except ShapeError:
     398            pass
     399        else:
     400            self.failUnless(0 ==1,
     401                        'bad shape did not raise error!')
     402            os.remove(point_file)
     403       
    367404#-------------------------------------------------------------
    368405if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.