当前位置: 首页>>代码示例>>Python>>正文


Python MA.masked_array方法代码示例

本文整理汇总了Python中MA.masked_array方法的典型用法代码示例。如果您正苦于以下问题:Python MA.masked_array方法的具体用法?Python MA.masked_array怎么用?Python MA.masked_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MA的用法示例。


在下文中一共展示了MA.masked_array方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _getMaskedArray

# 需要导入模块: import MA [as 别名]
# 或者: from MA import masked_array [as 别名]
    def _getMaskedArray(self, var, flagVar=None, flagValues=(0, 1), missingValuesToTest=(-9999.0, -32767.0)):
        """
        Returns a masked array that has the values only present where the flag
        values are acceptable and the data itself is not missing.
        """
        if flagVar:
            flagFillValue = -1
            flagGTValue = max(flagValues)

            flagMaskWhereUnacceptable = MA.masked_greater(flagVar, flagGTValue).mask()
            flagMaskWhereMissing = MA.masked_equal(flagVar, flagFillValue).mask()
            flagMask = flagMaskWhereUnacceptable + flagMaskWhereMissing

        for fv in missingValuesToTest:
            if fv in MV.ravel(var):
                print "Setting missing value for '%s' as: %s" % (var.id, fv)
                varFillValue = fv
        else:
            varFillValue = missingValuesToTest[0]

        if flagVar:
            varMask = MA.masked_array(var, mask=MA.equal(var, varFillValue), fill_value=varFillValue).mask()
            fullmask = MA.bitwise_or(varMask, flagMask)
            maskedArray = MA.masked_array(var, mask=fullmask, fill_value=varFillValue)
        else:
            maskedArray = MA.masked_array(var, mask=MA.equal(var, varFillValue), fill_value=varFillValue)

        # maskedArray=cdms.createVariable(maskedArray, id=var.id, fill_value=varFillValue)
        # maskedArray.missing_value=varFillValue
        return maskedArray
开发者ID:eufarn7sp,项目名称:egads-eufar,代码行数:32,代码来源:aircraftData.py

示例2: _subSampleByAveraging

# 需要导入模块: import MA [as 别名]
# 或者: from MA import masked_array [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


注:本文中的MA.masked_array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。