Exemple #1
0
 def getAxisIndex (self, axis_spec):
     """Return the index of the axis specificed by axis_spec.
      Argument axis_spec and be as for axisMatches
      Return -1 if no match.
     """
     for i in range(self.rank()):
         if axisMatches(self.getAxis(i), axis_spec):
             return i
     return -1
Exemple #2
0
 def getAxisIndex (self, axis_spec):
     """Return the index of the axis specificed by axis_spec.
      Argument axis_spec and be as for axisMatches
      Return -1 if no match.
     """
     for i in range(self.rank()):
         if axisMatches(self.getAxis(i), axis_spec):
             return i
     return -1
Exemple #3
0
 def specify(self, slab, axes, specifications, confined_by, aux):
     """Doesn't confine but checks for existance."""
     for id in self.ids:
         for i in range(len(axes)):
             if axisMatches(axes[i], id):
                 break
         else:
             raise SelectorError, \
                   'Required axis %s not present in this variable.' % (id,)
     return 0
Exemple #4
0
 def specify (self, slab, axes, specifications, confined_by, aux):
     """Doesn't confine but checks for existance."""
     for id in self.ids:
         for i in range(len(axes)):
             if axisMatches(axes[i], id):
                 break
         else:
             raise SelectorError, \
                   'Required axis %s not present in this variable.' % (id,)
     return 0
Exemple #5
0
 def specify(self, slab, axes, specifications, confined_by, aux):
     "Do specification for axis self.id; skip if axis not present."
     for i in range(len(axes)):
         if axisMatches(axes[i], self.id):
             if confined_by[i] is None:
                 specifications[i] = self.spec
                 confined_by[i] = self
                 return 0
             else:
                 return 1
     return 0
Exemple #6
0
 def specify (self, slab, axes, specifications, confined_by, aux):
     "Do specification for axis self.id; skip if axis not present."
     for i in range(len(axes)):
         if axisMatches(axes[i], self.id):
            if confined_by[i] is None:
                specifications[i] = self.spec
                confined_by[i] = self
                return 0
            else:
                return 1
     return 0
Exemple #7
0
def order2index (axes, order):
    """Find the index permutation of axes to match order.
       The argument order is a string.
       Order elements can be:
          Letters t, x, y, z meaning time, longitude, latitude, level
          Numbers 0-9 representing position in axes
          The letter - meaning insert the next available axis here.
          The ellipsis ... meaning fill these positions with any
            remaining axes.
          (name) meaning an axis whose id is name
    """
    if isinstance(order, types.StringType):
        result = orderparse(order)
    elif isinstance(order, types.ListType):
        result = order
    else:
        raise CDMSError, 'order2index, order specified of bad type:' + str(type(order))
    n = len(axes)
    ie = n
    permutation = [None]*n
    j = 0
    pos = 0
    while j < len(result):
        item = result[j]
        if isinstance(item, types.StringType):
            if item == 't': 
                spec = 'time'
            elif item == 'x': 
                spec = 'longitude'
            elif item == 'y': 
                spec = 'latitude'
            elif item == 'z': 
                spec = 'level'
            elif item == '-':
                pos += 1
                j += 1
                continue
            else:
                spec = item[1:-1]
            for k in range(n):
                if axisMatches(axes[k], spec):
                    if k in permutation:
                        raise CDMSError, 'Duplicate item in order %s' % order
                    permutation[pos] = k
                    pos += 1
                    break
            else:
                raise CDMSError, 'No axis matching order spec %s' %str(item)
        elif isinstance(item, types.IntType):
            if item in permutation:
                raise CDMSError, 'Duplicate item in order %s' % order
            if item >= n:
                raise CDMSError, 'Index %d out of range in order %s' %\
                                 (item,order)
            permutation[pos] = item
            pos += 1
        elif item is Ellipsis:
            nleft = len(result) - j - 1
            pos = n - nleft
        else:
            raise CDMSError, 'List specified for order contains bad item: ' + repr(item)
        j += 1

    for i in range(n):
        if i not in permutation:
            for j in range(n):
                if permutation[j] is None:
                    permutation[j] = i
                    break
    return permutation    
Exemple #8
0
def order2index (axes, order):
    """Find the index permutation of axes to match order.
       The argument order is a string.
       Order elements can be:
          Letters t, x, y, z meaning time, longitude, latitude, level
          Numbers 0-9 representing position in axes
          The letter - meaning insert the next available axis here.
          The ellipsis ... meaning fill these positions with any
            remaining axes.
          (name) meaning an axis whose id is name
    """
    if isinstance(order, types.StringType):
        result = orderparse(order)
    elif isinstance(order, types.ListType):
        result = order
    else:
        raise CDMSError, 'order2index, order specified of bad type:' + str(type(order))
    n = len(axes)
    ie = n
    permutation = [None]*n
    j = 0
    pos = 0
    while j < len(result):
        item = result[j]
        if isinstance(item, types.StringType):
            if item == 't': 
                spec = 'time'
            elif item == 'x': 
                spec = 'longitude'
            elif item == 'y': 
                spec = 'latitude'
            elif item == 'z': 
                spec = 'level'
            elif item == '-':
                pos += 1
                j += 1
                continue
            else:
                spec = item[1:-1]
            for k in range(n):
                if axisMatches(axes[k], spec):
                    if k in permutation:
                        raise CDMSError, 'Duplicate item in order %s' % order
                    permutation[pos] = k
                    pos += 1
                    break
            else:
                raise CDMSError, 'No axis matching order spec %s' %str(item)
        elif isinstance(item, types.IntType):
            if item in permutation:
                raise CDMSError, 'Duplicate item in order %s' % order
            if item >= n:
                raise CDMSError, 'Index %d out of range in order %s' %\
                                 (item,order)
            permutation[pos] = item
            pos += 1
        elif item is Ellipsis:
            nleft = len(result) - j - 1
            pos = n - nleft
        else:
            raise CDMSError, 'List specified for order contains bad item: ' + repr(item)
        j += 1

    for i in range(n):
        if i not in permutation:
            for j in range(n):
                if permutation[j] is None:
                    permutation[j] = i
                    break
    return permutation