當前位置: 首頁>>代碼示例>>Python>>正文


Python MA.average方法代碼示例

本文整理匯總了Python中MA.average方法的典型用法代碼示例。如果您正苦於以下問題:Python MA.average方法的具體用法?Python MA.average怎麽用?Python MA.average使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MA的用法示例。


在下文中一共展示了MA.average方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _subSampleByAveraging

# 需要導入模塊: import MA [as 別名]
# 或者: from MA import average [as 別名]
    def _subSampleByAveraging(self, var, timeVar, flagVar, samplingRate, flagsToUse):
        """
        Returns a new variable which is 'var' sub-sampled by averaging
        at the given samplingRate with data selected according to flagVar
        including the flag values specified in flagsToUse (defaults are 0 and 1).
        """
        maskedArray = self._getMaskedArray(var, flagVar, flagsToUse)
        shape = var.shape
        if shape[1] == 1:
            newNumArray = MV.ravel(maskedArray)
            newArrayMask = MV.ravel(maskedArray.mask())
            newArray = MA.masked_array(newNumArray, mask=newArrayMask, fill_value=maskedArray.fill_value())
        else:
            newArray = Numeric.zeros(shape[0], "f")
            for t0 in range(shape[0]):
                # Set as missing if less than half are valid
                t1Array = maskedArray[t0]

                if samplingRate == 1:
                    # If half or more are good values then calculate the mean
                    if t1Array.count() >= (shape[1] / 2.0):
                        newArray[t0] = MA.average(t1Array)
                    # otherwise set as missing value
                    else:
                        newArray[t0] = maskedArray.fill_value()

                else:
                    raise "Averaging for non 1Hz sampling rates not yet supported!"

        # Now re-construct variable axes etc
        newTimeAxis = self._flatten2DTimeAxis(timeVar, samplingRate)
        newVar = self._recreateVariable(
            var,
            newArray,
            newTimeAxis,
            flagVar,
            max(flagsToUse),
            missingValue=maskedArray.fill_value(),
            sampleBy="averaging",
        )
        return newVar
開發者ID:eufarn7sp,項目名稱:egads-eufar,代碼行數:43,代碼來源:aircraftData.py

示例2: processRainfall

# 需要導入模塊: import MA [as 別名]
# 或者: from MA import average [as 別名]
def processRainfall(file, outdir, var, north, west, south, east):
    "Subsets, averages, writes to binary files."
    f=cdms.open(file)
    v=f(var, lat=(south, north), lon=(west, east))
    timevalues=v.getTime()[:]
    t0=timevalues[0]
    # I need to test if step 0 always has only missing values
    # remove -50 values???
    v=MA.masked_less(v,0)
    # create average of all ensemble members
    av=MA.average(v, axis=1)

    # get stuff for name
    datetime=os.path.split(file)[-1].split(".")[1]

    outpaths=[]

    # now step through time dimension (0)
    count=0
    for dslice in av:
        ts=timevalues[count]-t0
        outfile="rainfall.%s.%dh.dat" % (datetime, ts)
        outpath=os.path.join(outdir, outfile)
        count=count+1
        numarray=Numeric.array(dslice._data)
        sh=numarray.shape
        length=sh[0]*sh[1]
        flatarray=Numeric.resize(numarray, [length])
        output=open(outpath, "wb")
        arr=array.array('f', flatarray)
        arr.tofile(output)
        output.close()
        print "Written:", outpath
        outpaths.append(outpath)

    return outpaths
開發者ID:arsen3d,項目名稱:wepoco-web,代碼行數:38,代碼來源:createTiles.py

示例3:

# 需要導入模塊: import MA [as 別名]
# 或者: from MA import average [as 別名]
# How to use numpy with 'None' value in Python?
import MA
a = MA.array([1, 2, None], mask = [0, 0, 1])
print "average =", MA.average(a)
開發者ID:fiolbs,項目名稱:code_extraction,代碼行數:6,代碼來源:python_594.py

示例4: xrange

# 需要導入模塊: import MA [as 別名]
# 或者: from MA import average [as 別名]
hlat = ice1.variables["hlat"]  # hlat[49]
hlon = ice1.variables["hlon"]  # hlon[100]


dimf     = fice.shape  # Define an array to hold long-term monthly means.
ntime    = fice.shape[0]
nhlat    = fice.shape[1]
nhlon    = fice.shape[2]

nmo    = 0
month  = nmo+1

icemon = MA.zeros((nhlat,nhlon),MA.Float0)
for i in xrange(fice_masked.shape[0]):
  for j in xrange(fice_masked.shape[1]):
    icemon[i,j] = MA.average(fice_masked[i,j,0:ntime:12])

#
#  Fill the places where icemon is zero with the fill value.
#
icemon = MA.masked_values(icemon,0.,rtol=0.,atol=1.e-15)
icemon = MA.filled(icemon,value=fill_value)

                       # Calculate the January (nmo=0) average.


nsub = 16 # Subscript location of northernmost hlat to be plotted.

cmap = Numeric.array([                                         \
         [1.00,1.00,1.00], [0.00,0.00,0.00], [1.00,1.00,0.50], \
         [0.00,0.00,0.50], [0.50,1.00,1.00], [0.50,0.00,0.00], \
開發者ID:akrherz,項目名稱:me,代碼行數:33,代碼來源:ngl09p.py


注:本文中的MA.average方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。