Example #1
0
    def genMatch(self, axis, interval, matchnames):
        """Helper function for expertPaths.

        Parameters
        ----------

        axis : is a partitioned axis, either time or vertical level or forecast.

        interval : is an index interval (istart, iend).

        matchnames : is a partially filled list [id, timestart, timeend, levstart, levend, fc] If a filemap
                is used, matchnames has indices, otherwise has coordinates.

        Function : modifies matchnames based on axis and interval, returns the modified matchnames tuple.
        """
        if axis.isTime():
            if hasattr(self.parent, 'cdms_filemap'):
                start = interval[0]
                end = interval[1]
            else:                       # Use template method
                time0 = axis[interval[0]]
                time1 = axis[interval[1] - 1]
                isabs = (string.find(axis.units, " as ") != -1)
                if isabs:
                    start = cdtime.abstime(time0, axis.units)
                    end = cdtime.abstime(time1, axis.units)
                else:
                    cal = axis.getCalendar()
                    start = cdtime.reltime(time0, axis.units).tocomp(cal)
                    end = cdtime.reltime(time1, axis.units).tocomp(cal)
            matchnames[1] = start
            matchnames[2] = end
        elif axis.isForecast():
            start = axis.getValue()[interval[0]]
            end = axis.getValue()[interval[1] - 1]
            matchnames[5] = start
            matchnames[6] = end
        else:
            if hasattr(self.parent, 'cdms_filemap'):
                start = interval[0]
                end = interval[1]
            else:
                start = int(axis[interval[0]])
                end = int(axis[interval[1] - 1])
            matchnames[3] = start
            matchnames[4] = end

        return matchnames
Example #2
0
    def genMatch(self, axis, interval, matchnames):
        """Helper function for expertPaths.
        axis is a partitioned axis, either time or vertical level or forecast.
        interval is an index interval (istart, iend).
        matchnames is a partially filled list [id, timestart, timeend, levstart, levend, fc]
          If a filemap is used, matchnames has indices, otherwise has coordinates.

        Function modifies matchnames based on axis and interval,
        returns the modified matchnames tuple.
        """
        if axis.isTime():
            if hasattr(self.parent,'cdms_filemap'):
                start = interval[0]
                end = interval[1]
            else:                       # Use template method
                time0 = axis[interval[0]]
                time1 = axis[interval[1]-1]
                isabs = (string.find(axis.units," as ")!=-1)
                if isabs:
                    start = cdtime.abstime(time0,axis.units)
                    end = cdtime.abstime(time1,axis.units)
                else:
                    cal = axis.getCalendar()
                    start = cdtime.reltime(time0,axis.units).tocomp(cal)
                    end = cdtime.reltime(time1,axis.units).tocomp(cal)
            matchnames[1] = start
            matchnames[2] = end
        elif axis.isForecast():
            start = axis.getValue()[interval[0]]
            end   = axis.getValue()[interval[1]-1]
            matchnames[5] = start
            matchnames[6] = end
        else:
            if hasattr(self.parent,'cdms_filemap'):
                start = interval[0]
                end = interval[1]
            else:
                start = int(axis[interval[0]])
                end = int(axis[interval[1]-1])
            matchnames[3] = start
            matchnames[4] = end

        return matchnames
Example #3
0
def varFiles(var):
    npart = 0
    ndim = 0
    for (axis, start, length, true_length) in var.domain:
        if hasattr(axis, 'partition'):
            npart = npart + 1
            if npart == 1:
                part1 = axis
                npart1 = ndim
            elif npart == 2:
                part2 = axis
                npart2 = ndim
            else:
                raise TooManyPartitions, variable.id
        ndim = ndim + 1

    pathlist = []
    timeInterval = levelInterval = None
    # No partitioning
    if npart == 0:
        matchnames = [var.id, None, None, None, None]
        template = var.getTemplate()
        filename = cdms.variable.getPathFromTemplate(template, matchnames)
        pathlist.append((filename, matchnames[:], timeInterval, levelInterval))

    elif npart == 1:
        (axis, startelem, length, true_length) = var.domain[npart1]
        template = var.getTemplate()
        partition = axis.partition
        for interval in partition:
            if axis.isTime():
                time0 = axis[interval[0]]
                time1 = axis[interval[1] - 1]
                isabs = (string.find(axis.units, " as ") != -1)
                if isabs:
                    start = cdtime.abstime(time0, axis.units)
                    end = cdtime.abstime(time1, axis.units)
                else:
                    cal = axis.getCalendar()
                    start = cdtime.reltime(time0, axis.units).tocomp(cal)
                    end = cdtime.reltime(time1, axis.units).tocomp(cal)
                matchnames = [var.id, start, end, None, None]
                timeInterval = interval
            else:
                start = int(axis[interval[0]])
                end = int(axis[interval[1] - 1])
                matchnames = [var.id, None, None, start, end]
                levelInterval = interval

            filename = cdms.variable.getPathFromTemplate(template, matchnames)
            pathlist.append(
                (filename, matchnames[:], timeInterval, levelInterval))

    elif npart == 2:
        axis1 = var.domain[npart1][0]
        axis2 = var.domain[npart2][0]
        partition1 = axis1.partition
        partition2 = axis2.partition
        template = var.getTemplate()
        for interval1 in partition1:
            if axis1.isTime():
                isabs = (string.find(axis1.units, " as ") != -1)
                time0 = axis1[interval1[0]]
                time1 = axis1[interval1[1] - 1]
                if isabs:
                    start = cdtime.abstime(time0, axis1.units)
                    end = cdtime.abstime(time1, axis1.units)
                else:
                    cal = axis1.getCalendar()
                    start = cdtime.reltime(time0, axis1.units).tocomp(cal)
                    end = cdtime.reltime(time1, axis1.units).tocomp(cal)
                matchnames = [var.id, start, end, None, None]
                timeInterval = interval1
            else:
                start = int(axis1[interval1[0]])
                end = int(axis1[interval1[1] - 1])
                matchnames = [var.id, None, None, start, end]
                levelInterval = interval1

            for interval2 in partition2:
                if axis2.isTime():
                    isabs = (string.find(axis2.units, " as ") != -1)
                    time0 = axis2[interval2[0]]
                    time1 = axis2[interval2[1] - 1]
                    if isabs:
                        start = cdtime.abstime(time0, axis2.units)
                        end = cdtime.abstime(time1, axis2.units)
                    else:
                        cal = axis2.getCalendar()
                        start = cdtime.reltime(time0, axis2.units).tocomp(cal)
                        end = cdtime.reltime(time1, axis2.units).tocomp(cal)
                    matchnames[1] = start
                    matchnames[2] = end
                    timeInterval = interval2
                else:
                    start = int(axis2[interval2[0]])
                    end = int(axis2[interval2[1] - 1])
                    matchnames[3] = start
                    matchnames[4] = end
                    levelInterval = interval2

                filename = cdms.variable.getPathFromTemplate(
                    template, matchnames)
                pathlist.append(
                    (filename, matchnames[:], timeInterval, levelInterval))

    return pathlist
def varFiles(var):
    npart = 0
    ndim = 0
    for (axis,start,length,true_length) in var.domain:
        if hasattr(axis,'partition'):
            npart = npart+1
            if npart==1:
                part1 = axis
                npart1 = ndim
            elif npart==2:
                part2 = axis
                npart2 = ndim
            else:
                raise TooManyPartitions, variable.id
        ndim = ndim+1

    pathlist = []
    timeInterval = levelInterval = None
    # No partitioning
    if npart==0:
        matchnames = [var.id,None,None,None,None]
        template = var.getTemplate()
        filename = cdms.variable.getPathFromTemplate(template,matchnames)
        pathlist.append((filename, matchnames[:], timeInterval, levelInterval))

    elif npart==1:
        (axis,startelem,length,true_length) = var.domain[npart1]
        template = var.getTemplate()
        partition = axis.partition
        for interval in partition:
            if axis.isTime():
                time0 = axis[interval[0]]
                time1 = axis[interval[1]-1]
                isabs = (string.find(axis.units," as ")!=-1)
                if isabs:
                    start = cdtime.abstime(time0,axis.units)
                    end = cdtime.abstime(time1,axis.units)
                else:
                    cal = axis.getCalendar()
                    start = cdtime.reltime(time0,axis.units).tocomp(cal)
                    end = cdtime.reltime(time1,axis.units).tocomp(cal)
                matchnames = [var.id,start,end,None,None]
                timeInterval = interval
            else:
                start = int(axis[interval[0]])
                end = int(axis[interval[1]-1])
                matchnames = [var.id,None,None,start,end]
                levelInterval = interval

            filename = cdms.variable.getPathFromTemplate(template,matchnames)
            pathlist.append((filename, matchnames[:], timeInterval, levelInterval))

    elif npart==2:
        axis1 = var.domain[npart1][0]
        axis2 = var.domain[npart2][0]
        partition1 = axis1.partition
        partition2 = axis2.partition
        template = var.getTemplate()
        for interval1 in partition1:
            if axis1.isTime():
                isabs = (string.find(axis1.units," as ")!=-1)
                time0 = axis1[interval1[0]]
                time1 = axis1[interval1[1]-1]
                if isabs:
                    start = cdtime.abstime(time0,axis1.units)
                    end = cdtime.abstime(time1,axis1.units)
                else:
                    cal = axis1.getCalendar()
                    start = cdtime.reltime(time0,axis1.units).tocomp(cal)
                    end = cdtime.reltime(time1,axis1.units).tocomp(cal)
                matchnames = [var.id,start,end,None,None]
                timeInterval = interval1
            else:
                start = int(axis1[interval1[0]])
                end = int(axis1[interval1[1]-1])
                matchnames = [var.id,None,None,start,end]
                levelInterval = interval1

            for interval2 in partition2:
                if axis2.isTime():
                    isabs = (string.find(axis2.units," as ")!=-1)
                    time0 = axis2[interval2[0]]
                    time1 = axis2[interval2[1]-1]
                    if isabs:
                        start = cdtime.abstime(time0,axis2.units)
                        end = cdtime.abstime(time1,axis2.units)
                    else:
                        cal = axis2.getCalendar()
                        start = cdtime.reltime(time0,axis2.units).tocomp(cal)
                        end = cdtime.reltime(time1,axis2.units).tocomp(cal)
                    matchnames[1] = start
                    matchnames[2] = end
                    timeInterval = interval2
                else:
                    start = int(axis2[interval2[0]])
                    end = int(axis2[interval2[1]-1])
                    matchnames[3] = start
                    matchnames[4] = end
                    levelInterval = interval2

                filename = cdms.variable.getPathFromTemplate(template,matchnames)
                pathlist.append((filename, matchnames[:], timeInterval, levelInterval))

    return pathlist