示例#1
0
def reddim(data,indices,el = 0):
    #el = repeat(0,len(indices))
    for dim in range(len(shape(data))):
        if (dim in indices):
            SEL[dim] = el
        else:
            SEL[dim] = range(size(data,axis=dim))
    return data[arraysel(SEL,shape(data))]
示例#2
0
def sizeout(data,axisref,deffunc):
    SEL = list(repeat(None,len(shape(data))))
    sizeout = list(repeat(None,len(shape(data))))
    #before calculating the dataout matrix, its dimension has to be acquired
    for dim in range(len(shape(data))):
        if (axisref[dim] == True):
            SEL[dim] = range(size(data,axis=dim))
        else:
            SEL[dim] = [0] 
            sizeout[dim] = size(data,axis=dim)

    # the first item in this list contains dummy data which will not be used; 
    # the other items potentially contain the output coordinates if available

    # print(shape(data[arraysel(SEL,data.shape)]))

    dtempin = data[arraysel(SEL,data.shape)]
    SHAPE = []
    for iSHAPE in range(len(SEL)):
        if (axisref[iSHAPE] == True):  
            SHAPE.append(len(SEL[iSHAPE]))
    dtempin.shape = SHAPE

    dummydataout = deffunc(dtempin)

    dimout = 0
    for dim in range(len(shape(data))):
        if (axisref[dim] == True):
            # if list, get the output data size which is given by the first item in the list
            # if not list (no output coordinates given), just get the size of the data
            if ((type(dummydataout).__name__ == 'list') or (type(dummydataout).__name__ == 'tuple')):
                sizeout[dim] = size(dummydataout[0],axis=dimout)
            else:
                sizeout[dim] = size(dummydataout,axis=dimout)
            dimout = dimout + 1

    # shapedataout = sizeout(ncin.variables[evariable][:],\
    #                        axisref, \
    #                        lambda data: deffunc(data) )
    # get the output coordinates of the processed dimensions and save it as a seperate list
    if ((type(dummydataout).__name__ == 'list') or (type(dummydataout).__name__ == 'tuple')):
        if (type(dummydataout[1]).__name__ == 'list' ): # multiple coordinate set stored as a list
            outcoords = dummydataout[1] 
        else:
            if (dummydataout[1] != None):
                outcoords = list(dummydataout[1])
            else:
                outcoords = None
    else:
        outcoords = None # function doesn't have output coordinates available

    # sizeout: size of the output data if one would apply multifunc
    # outcoords: list of coordinate sets of each dimension where axisref == True
    return sizeout, outcoords