Changeset 3071


Ignore:
Timestamp:
Jun 5, 2006, 12:02:15 PM (18 years ago)
Author:
ole
Message:

Prettified and added input test for dimensions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/coordinate_transforms/geo_reference.py

    r2942 r3071  
    146146        """
    147147
    148         # FIXME: Use ensure_numeric
    149        
    150148        is_list = False
    151149        if type(points) == types.ListType:
     
    160158            points = reshape(points, (1,2))
    161159
     160        msg = 'Input must be an N x 2 array or list of (x,y) values. '
     161        msg += 'I got an %d x %d array' %points.shape   
     162        assert points.shape[1] == 2, msg               
     163
    162164           
    163165        if points_geo_ref is not self:
     
    183185        return the points as absolute values.
    184186        """
    185        
     187
     188
    186189        is_list = False
    187190        if type(points) == types.ListType:
    188191            is_list = True
    189             if len(points)>0 and type(points[0]) \
    190                    not in [types.ListType,types.TupleType]:
    191                 #a single point is being passed.  make it a list of lists
    192                 points = [points]
    193         elif type(points) == ArrayType:
    194             if len(points.shape) == 1:
    195                 points = [points]       
    196            
    197         # convert into array
    198         points = array(points).astype(Float)
    199         # add primary geo ref from points
     192
     193        points = ensure_numeric(points, Float)
     194       
     195        if len(points.shape) == 1:
     196            #One point has been passed
     197            msg = 'Single point must have two elements'
     198            assert len(points) == 2, msg
     199            points = reshape(points, (1,2))
     200
     201
     202        msg = 'Input must be an N x 2 array or list of (x,y) values. '
     203        msg += 'I got an %d x %d array' %points.shape   
     204        assert points.shape[1] == 2, msg   
     205           
     206
     207        # Old code   
     208        #is_list = False
     209        #if type(points) == types.ListType:
     210        #    is_list = True
     211        #    if len(points)>0 and type(points[0]) \
     212        #           not in [types.ListType,types.TupleType]:
     213        #        #a single point is being passed.  make it a list of lists
     214        #        points = [points]
     215        #elif type(points) == ArrayType:
     216        #    if len(points.shape) == 1:
     217        #        points = [points]       
     218           
     219        ## convert into array
     220        #points = array(points).astype(Float)
     221
     222       
     223        # Add primary geo ref from points
     224
     225
     226       
    200227        points[:,0] += self.xllcorner
    201228        points[:,1] += self.yllcorner
     229
     230       
    202231        if is_list:
    203232            points = points.tolist()
     
    208237    def reconcile_zones(self, other):
    209238
    210         if self.zone == other.zone or self.zone == DEFAULT_ZONE and other.zone == DEFAULT_ZONE:
     239        if self.zone == other.zone or\
     240               self.zone == DEFAULT_ZONE and other.zone == DEFAULT_ZONE:
    211241            pass
    212242        elif self.zone == DEFAULT_ZONE:
     
    216246        else:   
    217247            msg = 'Both geospatial_data objects must be in the same \
    218             ZONE to allow reconciliation. I got zone %d and %d' %(self.zone, other.zone)
     248            ZONE to allow reconciliation. I got zone %d and %d'\
     249            %(self.zone, other.zone)
    219250            raise ANUGAError, msg
    220251   
Note: See TracChangeset for help on using the changeset viewer.