当前位置: 首页>>代码示例>>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;未经允许,请勿转载。