Ignore:
Timestamp:
15/01/10 08:44:39 (11 years ago)
Author:
pnorton
Message:

Applied the fix to _mergeBounds so that it will cope with reversed bounds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • qesdi/geoplot/trunk/lib/geoplot/grid_builder_base.py

    r6104 r6308  
    267267        right-hand edge of grid box (x, y) is the same as the left-hand 
    268268        edge of grid box (x + 1, y) and similarly in y. 
    269      
     269 
     270        There are 4 different types of bounds that might be received: 
     271 
     272            1. Descending with each bound low-to-high 
     273            2. Descending with each bound high-to-low 
     274            3. Ascending with each bound low-to-high 
     275            4. Ascending with each bound high-to-low 
     276 
     277        In order to cater for these we just use all unique values in the bounds 
     278        (which is fine given that we assume grid boxes are contiguous) and sort them. 
     279        If bounds are in descending order then we reverse the 1D array so it is also 
     280        descending. 
     281  
    270282        @param lonBounds: The longitude bounds array 
    271283        @param latBounds: the latitude bounds array 
    272284        """ 
    273      
    274         # Get grid dimensions 
    275         n = bounds.shape[0] 
    276      
    277         # Take the lower bounds as the mesh point 
    278         # except for the last index where the upper bounds is taken 
    279         merged = N.resize(bounds[:, 0], (n + 1,)) 
    280         merged[-1] = bounds[-1, 1] 
    281      
    282         return merged 
     285 
     286        # Set whether descending 
     287        descending = False 
     288        if bounds[0, 0] > bounds[-1, 0]: 
     289            descending = True 
     290 
     291        unique_bounds = N.unique(bounds) 
     292                
     293        # Check length is correct 
     294        if len(unique_bounds) != (bounds.shape[0] + 1): 
     295            log.error("Length of merged bounds ('%s') does not equal length of bounds + 1 ('%s')." % (len(unique_bounds), bounds.shape[0]))  
     296 
     297        # Sort it and then reverse it if descending  
     298        unique_bounds.sort()          
     299         
     300        if descending == True: 
     301            merged = unique_bounds[::-1] 
     302        else: 
     303            merged = unique_bounds 
     304 
     305        return merged  
    283306     
    284307     
Note: See TracChangeset for help on using the changeset viewer.