Example #1
0
 def testConcatenate (self):
     "test concatenate"
     assert eq (MA.concatenate((self.a[:3], self.a[3:])), [0,1,2,3,4,5])
     m = self.m
     assert eq (MA.concatenate((m, m)), [[1,2,3], [11,12,13], [1,2,3], [11,12,13]])
     assert eq (MA.concatenate((m, m), axis = 1), 
                [[1,2,3,1,2,3],[11,12,13,11,12,13]])
Example #2
0
def accumulate24Hourly(data):
    """Returns 12-hourly data accumulated to 24-hours."""
    newTimeValues=[]
    taxis=data.getTime()
    tunits=data.units
    print len(data.getTime())
    newarray=[]

    for i in range((tlen/2)):
        p1=data(time=slice(i,i+1))
        p2=data(time=slice(i+1,i+2))
        accum=p1+p2
        newarray.append(accum)
        newTimeValues.append(p2.getTime()[0])

    array=MA.concatenate(newarray)
    array=MA.array(array, 'f', fill_value=data.getMissing())
    axes=data.getAxisList()
    newTimeAxis=cdms.createAxis(newTimeValues)
    newTimeAxis.units=tunits
    newTimeAxis.designateTime()
    newTimeAxis.id=newTimeAxis.long_name=newTimeAxis.title="time"
    
    newaxes=[newTimeAxis]+axes[1:]
    var=cdms.createVariable(array, axes=newaxes, id=data.id)
    for att in ("units", "long_name"):
        setattr(var, att, getattr(data, att))
    return var 
Example #3
0
def getNewLonAxis(oldLonAxis, startLon=-180):
    assert (oldLonAxis.isLongitude())
    oldLonVals = oldLonAxis.getData()

    newLonVals = (oldLonVals - startLon
                  ) % 360 + startLon  # range "startLon" to "startLon + 360"
    lonValShift = newLonVals - oldLonVals
    nlon = len(newLonVals)
    ##
    ## identify shift by jump in longitude values
    for i in range(1, nlon):
        if newLonVals[i] < newLonVals[i - 1]:
            nShift = i
            break
    else:
        nShift = 0

## create array with new longitude values
    newLonVals = MA.concatenate((newLonVals[nShift:], newLonVals[:nShift]))

    ##    print oldLonVals
    ##    print newLonVals

    newLonAxis = cdms.createAxis(newLonVals)
    newLonAxis.designateLongitude()
    newLonAxis.replace_external_attributes(oldLonAxis.attributes)
    #
    return newLonAxis, nShift, lonValShift