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


Python Cdo.outputkey方法代码示例

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


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

示例1: test_outputOperators

# 需要导入模块: from cdo import Cdo [as 别名]
# 或者: from cdo.Cdo import outputkey [as 别名]
    def test_outputOperators(self):
        cdo = Cdo()
        levels = cdo.showlevel(input = "-stdatm,0")
        info   = cdo.sinfo(input = "-stdatm,0")
        self.assertEqual([0,0],list(map(float,levels)))
        self.assertEqual("GRIB",info[0].split(' ')[-1])

        values = cdo.outputkey("value",input="-stdatm,0")[1::]
        self.assertEqual(["1013.25", "288"],values)
        values = cdo.outputkey("value",input="-stdatm,0,10000")[1::]
        self.assertEqual(["1013.2", "271.9", "288.0", "240.6"],['{:.1f}'.format(float(s)) for s in values])
        values = cdo.outputkey("lev",input="-stdatm,0,10000")[1::]
        self.assertEqual(["0", "10000","0", "10000"],values)

        # test autoSplit usage
        levels = cdo.showlevel(input="-stdatm,0,10,20",autoSplit=' ')
        self.assertEqual([['0','10','20'],['0','10','20']],levels)

        timesExpected = ['2001-01-01T12:00:00',
          '2001-01-01T13:00:00',
          '2001-01-01T14:00:00',
          '2001-01-01T15:00:00',
          '2001-01-01T16:00:00',
          '2001-01-01T17:00:00',
          '2001-01-01T18:00:00',
          '2001-01-01T19:00:00',
          '2001-01-01T20:00:00',
          '2001-01-01T21:00:00']
        self.assertEqual(timesExpected,
                         cdo.showtimestamp(input="-settaxis,2001-01-01,12:00,1hour -for,1,10", autoSplit='  '))

        self.assertEqual(['P T'],cdo.showname(input="-stdatm,0"))
        self.assertEqual(['P','T'],cdo.showname(input="-stdatm,0",autoSplit=' '))
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:35,代码来源:test_cdo.py

示例2: test_operators_with_multiple_output_files

# 需要导入模块: from cdo import Cdo [as 别名]
# 或者: from cdo.Cdo import outputkey [as 别名]
    def test_operators_with_multiple_output_files(self):
      cdo = Cdo()
      self.assertEqual(1 ,cdo.operators['topo'],'wrong output counter for "topo"')
      self.assertEqual(0 ,cdo.operators['sinfo'],'wrong output counter for "sinfo"')
      self.assertEqual(-1,cdo.operators['splitsel'],'wrong output counter for "splitsel"')
      self.assertEqual(2 ,cdo.operators['trend'],'wrong output counter for "trend"')

      if (parse_version(cdo.version()) > parse_version('1.6.4')):
        self.assertEqual(0,cdo.operators['ngridpoints'],'wrong output counter for "sinfo"')

      # create input for eof
      #
      # check automatic generation ot two tempfiles
      aFile, bFile = cdo.trend(input = "-addc,7 -mulc,44 -for,1,100")
      self.assertTrue(os.path.exists(aFile),"cannot find tempfile")
      self.assertTrue(os.path.exists(bFile),"cannot find tempfile")
      self.assertEqual(51.0,float(cdo.outputkey('value',input = aFile)[-1]))
      self.assertEqual(44.0,float(cdo.outputkey('value',input = bFile)[-1]))
      # check usage of 'returnCdf' with these operators
      if cdo.hasNetcdf:
        aFile, bFile = cdo.trend(input = "-addc,7 -mulc,44 -for,1,100",returnCdf = True)
        self.assertEqual(51.0, aFile.variables['for'][0],"got wrong value from cdf handle")
        self.assertEqual(44.0, bFile.variables['for'][0],"got wrong value from cdf handle")

        avar = cdo.trend(input = "-addc,7 -mulc,44 -for,1,100",returnArray = 'for')[0]
        self.assertEqual(51.0, avar,"got wrong value from narray")
      else:
        self.assertRaises(ImportError,cdo.trend, input = "-addc,7 -mulc,44 -for,1,100",returnCdf = True)
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:30,代码来源:test_cdo.py


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