Ignore:
Timestamp:
20/02/08 17:18:00 (12 years ago)
Author:
astephen
Message:

Fixed and broken - got 2110 and 2310 writing from NetCDF. But the solution breaks the basic readNA/writeNA cycle. The reason is that the new code writes the data from NX, DX and X rather than A and NAUXV. Maybe the data really needs to be encoded to NAUXV and A in order for this to work unformly. Hmmmm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/cdms_utils/axis_utils.py

    r3442 r3482  
    2020import cdms 
    2121 
    22 def areAxesIdentical(ax1, ax2, is_subset=False): 
     22def areAxesIdentical(ax1, ax2, is_subset=False, check_id=True): 
    2323    """ 
    2424    Takes 2 CDMS axis objects returning True if they are essentially 
     
    2626    If is_subset == True then return True if ax1 is same as ax2 except that it is 
    2727    only defined on a subset of regularly spaced values within ax2. 
     28    If is_subset is used then return value is False or (len(ax2)/len(ax1)). 
     29    If check_id == False then don't compare the ids of the axes. 
    2830    """ 
    2931    for axtype in ("time", "level", "latitude", "longitude"): 
     
    3234 
    3335    # Check ids 
    34     if ax1.id != ax2.id: return False 
     36    if check_id: 
     37        if ax1.id != ax2.id: return False 
     38 
    3539    # Check units 
    3640    if ax1.units != ax2.units: return False 
     
    4448        len1 = len(ax1) 
    4549        len2 = len(ax2) 
     50 
    4651        # Check length of 1 divides into length of 2 
    4752        if len2 % len1 != 0: 
     
    5560            if ax2_value != test_value: 
    5661                return False 
     62         
     63        # If we got here then return len2/len1 
     64        return n 
    5765 
    5866    # OK, I think they are the same axis! 
    5967    return True 
     68 
    6069 
    6170def isAxisRegularlySpacedSubsetOf(ax1, ax2): 
     
    6473    subset of regularly spaced values within ax2. Otherwise returns False. 
    6574    """ 
    66     return areAxesIdentical(ax1, ax2, is_subset=True) 
     75    return areAxesIdentical(ax1, ax2, is_subset=True, check_id=False) 
     76 
     77 
     78def isUniformlySpaced(ax): 
     79    "Returns True is axis values are uniformaly spaced else returns False." 
     80    if len(ax) == 1: return False 
     81    incr = ax[1] - ax[0] 
     82 
     83    for i in range(1, len(ax)): 
     84        i1 = ax[i - 1] 
     85        i2 = ax[i]  
     86        if (i2 - i1) != incr: 
     87            return False 
     88 
     89    return True 
     90 
Note: See TracChangeset for help on using the changeset viewer.