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


Python cdo.Cdo类代码示例

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


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

示例1: test_smooth

      def test_smooth(self):
        cdo = Cdo()
        if (parse_version(cdo.version()) >= parse_version('1.7.2') and cdo.hasNetcdf):
          ifile = "-select,level=0 " + DATA_DIR + '/icon/phc.nc'
          cdo = Cdo()
          cdo.debug = DEBUG
          #cdo.merge(input='/home/ram/data/icon/input/phc3.0/PHC__3.0__TempO__1x1__annual.nc /home/ram/data/icon/input/phc3.0/PHC__3.0__SO__1x1__annual.nc',
          #          output=ifile,
          #          options='-O')
          smooth = cdo.smooth(input=" -sellonlatbox,0,30,0,90 -chname,SO,s,TempO,t " + ifile, returnMaArray='s',options='-f nc')
          plot(np.flipud(smooth[0,:,:]),ofile='smooth',title='smooth')

          smooth2 = cdo.smooth('nsmooth=2',input="-sellonlatbox,0,30,0,90 -chname,SO,s,TempO,t " + ifile, returnMaArray='s',options='-f nc')
          plot(np.flipud(smooth2[0,:,:]),ofile='smooth2',title='smooth,nsmooth=2')

          smooth4 = cdo.smooth('nsmooth=4',input="-sellonlatbox,0,30,0,90 -chname,SO,s,TempO,t " + ifile, returnMaArray='s',options='-f nc')
          plot(np.flipud(smooth4[0,:,:]),ofile='smooth4',title='smooth,nsmooth=4')

          smooth9 = cdo.smooth9(input="-sellonlatbox,0,30,0,90 -chname,SO,s,TempO,t " + ifile, returnMaArray='s',options='-f nc')
          plot(np.flipud(smooth9[0,:,:]),ofile='smooth9',title='smooth9')

          smooth3deg = cdo.smooth('radius=6deg',input="-sellonlatbox,0,30,0,90 -chname,SO,s,TempO,t " + ifile, returnMaArray='s',options='-f nc')
          plot(np.flipud(smooth3deg[0,:,:]),ofile='smooth3deg',title='smooth,radius=6deg')

          smooth20 = cdo.smooth('nsmooth=20',input="-sellonlatbox,0,30,0,90 -chname,SO,s,TempO,t " + ifile, returnMaArray='s',options='-f nc')
          plot(np.flipud(smooth20[0,:,:]),ofile='smooth20',title='smooth,nsmooth=20')
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:26,代码来源:test_cdo.py

示例2: test_fillmiss

    def test_fillmiss(self):
        cdo = Cdo()

        if not SHOW:
          return
        if cdo.hasNetcdf:
          if 'CDO' in os.environ:
            cdo.setCdo(os.environ.get('CDO'))

          cdo.debug = DEBUG
          rand = cdo.setname('v',input = '-random,r25x25 ', options = ' -f nc')

          missRange = '0.25,0.85'
          withMissRange = tempfile.NamedTemporaryFile(delete=True,prefix='cdoPy').name
          arOrg = cdo.copy(input = rand,returnMaArray = 'v')
          arWmr = cdo.setrtomiss(missRange,input = rand,output = withMissRange,returnMaArray='v')
          arFm  = cdo.fillmiss(            input = withMissRange,returnMaArray = 'v')
          arFm1s= cdo.fillmiss2(2,         input = withMissRange,returnMaArray = 'v')
          if 'setmisstonn' in cdo.operators:
            arM2NN= cdo.setmisstonn(         input = withMissRange,returnMaArray = 'v')

          pool = multiprocessing.Pool(8)
          pool.apply_async(plot, (arOrg, ),{"title":'org'      })#ofile='fmOrg')
          pool.apply_async(plot, (arWmr, ),{"title":'missing'  })#ofile='fmWmr')
          pool.apply_async(plot, (arFm,  ),{"title":'fillmiss' })#ofile= 'fmFm')
          pool.apply_async(plot, (arFm1s,),{"title":'fillmiss2'})#ofile='fmFm2')
          if 'setmisstonn' in cdo.operators:
            pool.apply_async(plot, (arM2NN,), {"title":'setmisstonn'})#, ofile='fmsetMNN')

          pool.close()
          pool.join()

        else:
          print("test_fillmiss disables because of missing python-netCDF4")
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:34,代码来源:test_cdo.py

示例3: test_longChain

 def test_longChain(self):
   cdo = Cdo()
   if cdo.hasNetcdf:
     ifile = "-enlarge,global_0.3 -settaxis,2000-01-01 -expr,'t=sin(for*3.141529/180.0)' -for,1,10"
     t = cdo.fldmax(input="-div -sub -timmean -seltimestep,2,3 %s -seltimestep,1 %s -gridarea %s"%(ifile,ifile,ifile),
         returnMaArray="t")
     self.assertTrue(abs(8.9813e-09 - t[0][0][0]) < 1.0e-10, 'Found non-zero diff')
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:7,代码来源:test_cdo.py

示例4: test_readCdf

 def test_readCdf(self):
   cdo = Cdo()
   input= "-settunits,days  -setyear,2000 -for,1,4"
   cdfFile = cdo.copy(options="-f nc",input=input)
   if cdo.hasNetcdf:
     cdf     = cdo.readCdf(cdfFile)
     self.assertEqual(sorted(['lat','lon','for','time']),sorted(list(cdf.variables.keys())))
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:7,代码来源:test_cdo.py

示例5: test_CDO_options

 def test_CDO_options(self):
     cdo = Cdo()
     cdo.debug = DEBUG
     names = cdo.showname(input = "-stdatm,0",options = "-f nc")
     self.assertEqual(["P T"],names)
     if cdo.hasLib("sz"):
       ofile = cdo.topo(options = "-z szip")
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:7,代码来源:test_cdo.py

示例6: test_verticalLevels

 def test_verticalLevels(self):
     cdo = Cdo()
     # check, if a given input files has vertival layers of a given thickness array
     targetThicknesses = [50.0,  100.0,  200.0,  300.0,  450.0,  600.0,  800.0, 1000.0, 1000.0, 1000.0]
     sourceLevels = "25 100 250 500 875 1400 2100 3000 4000 5000".split()
     thicknesses = cdo.thicknessOfLevels(input = "-selname,T " + cdo.stdatm(','.join(sourceLevels),options = "-f nc"))
     self.assertEqual(targetThicknesses,thicknesses)
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:7,代码来源:test_cdo.py

示例7: test_bndLevels

 def test_bndLevels(self):
     cdo = Cdo()
     ofile = cdo.stdatm(25,100,250,500,875,1400,2100,3000,4000,5000,options = "-f nc")
     self.assertEqual([0, 50.0, 150.0, 350.0, 650.0, 1100.0, 1700.0, 2500.0, 3500.0, 4500.0, 5500.0],
                 cdo.boundaryLevels(input = "-selname,T " + ofile))
     self.assertEqual([50.0, 100.0, 200.0, 300.0, 450.0, 600.0, 800.0, 1000.0, 1000.0, 1000.0],
                  cdo.thicknessOfLevels(input = ofile))
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:7,代码来源:test_cdo.py

示例8: test_outputOperators

    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,代码行数:33,代码来源:test_cdo.py

示例9: __getLonLat

 def __getLonLat(self, ifile):
     """
     Get vectors with lon and lat values from a netdf file using cdo.griddes
     Was introduced because we were using a damaged grid
     lon,lat valued are located in the center of a gridbox
     
     :param ifile: netcdf fn
     :result: lon,lat vectors
     """
     def searchGriddes(grid, needle):
         tmp = [x for x in grid if x.find(needle) != -1]
         return float(tmp[0].split(' ')[-1])
     
     from cdo import Cdo
     cdo = Cdo()  
     grid = cdo.griddes(input=ifile)
     try:
         xinc = searchGriddes(grid, 'xinc')
         xsize = searchGriddes(grid, 'xsize')
         xfirst = searchGriddes(grid, 'xfirst')
     except:
         xinc = searchGriddes(grid, 'yinc')
         xsize = searchGriddes(grid, 'ysize')
         xfirst = searchGriddes(grid, 'yfirst')
     yfirst = searchGriddes(grid, 'yfirst')
     ysize = searchGriddes(grid, 'ysize')
     yinc = searchGriddes(grid, 'yinc')
     lon = np.arange(xfirst+xinc/2, xsize*xinc+xfirst+xinc/2, xinc, dtype=float)
     lat = np.arange(yfirst+yinc/2, ysize*yinc+yfirst+yinc/2, yinc, dtype=float)
     lon = np.arange(xfirst, xsize*xinc+xfirst, xinc, dtype=float)
     lat = np.arange(yfirst, ysize*yinc+yfirst, yinc, dtype=float)
     return lon, lat
开发者ID:illing2005,项目名称:murcss,代码行数:32,代码来源:significance2.py

示例10: seacyc

def seacyc(archive, simulation, method='base'):
  """
  substracts the seasonal cycle
  :param archive: netCDF file containing the reference period
  :param simulation: netCDF file containg the period to be analysed
  :param method: method to generat the seasonal cycle files
                 base = seasonal cycle generated from reference period
                 sim = seasonal cycle generated from period to be analysed
                 own = seasonal cycle generated for both time windows
                 
  """
  from shutil import copy
  from cdo import Cdo 
  cdo = Cdo()

 # calculate seasonal cycle and add an additional file into the working directory 
 # base) cdo -s ydaymean ${basedir}base_${varname}_${dtrstr}${region}_${datestring1}_${namestring}.nc seasoncyc_base.nc
 #       cp seasoncyc_base.nc seasoncyc_sim.nc ;;
 # sim)  cdo -s ydaymean ${simdir}sim_${varname}_${dtrstr}${region}_${datestring2}_${namestring}.nc seasoncyc_sim.nc
 #       cp seasoncyc_sim.nc seasoncyc_base.nc ;;
 # own)  cdo -s ydaymean ${basedir}base_${varname}_${dtrstr}${region}_${datestring1}_${namestring}.nc seasoncyc_base.nc
 #       cdo -s ydaymean ${simdir}sim_${varname}_${dtrstr}${region}_${datestring2}_${namestring}.nc seasoncyc_sim.nc ;;
  if method == 'base':
    seasoncyc_base = cdo.ydaymean(input=archive, output='seasoncyc_base.nc' )
    seasoncyc_sim = 'seasoncyc_sim.nc'
    copy(seasoncyc_base, seasoncyc_sim)
  if method == 'sim':
    seasoncyc_sim  = cdo.ydaymean(input=simulation, output='seasoncyc_sim.nc' )
    seasoncyc_base = 'seasoncyc_base.nc'
    copy(seasoncyc_sim, seasoncyc_base)
  if method == 'own':
    seasoncyc_base = cdo.ydaymean(input=archive, output='seasoncyc_base.nc' )
    seasoncyc_sim  = cdo.ydaymean(input=simulation, output='seasoncyc_sim.nc' )
  return seasoncyc_base, seasoncyc_sim
开发者ID:mcalvcas,项目名称:flyingpigeon,代码行数:34,代码来源:analogs.py

示例11: testDbg

 def testDbg(self):
     if not 'DEBUG' in os.environ:
       cdo = Cdo()
       self.assertEqual(False,cdo.debug)
       cdo.debug = True
       self.assertEqual(True,cdo.debug)
       cdo.debug = False
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:7,代码来源:test_cdo.py

示例12: test_cdf

 def test_cdf(self):
     cdo = Cdo()
     self.assertTrue(hasattr(cdo, "cdf"))# not in cdo.__dict__)
     if cdo.hasNetcdf:
       sum = cdo.fldsum(input = cdo.stdatm("0",options="-f nc"),returnCdf=True)
       self.assertEqual(1013.25,sum.variables["P"][:])
     else:
       self.assertRaises(ImportError,cdo.fldsum,input = cdo.stdatm("0",options="-f nc"),returnCdf=True)
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:8,代码来源:test_cdo.py

示例13: testOps

 def testOps(self):
     cdo = Cdo()
     self.assertTrue("sinfov" in cdo.operators)
     self.assertTrue("for" in cdo.operators)
     self.assertTrue("mask" in cdo.operators)
     if (parse_version('1.7.0') >= parse_version(cdo.version())):
         self.assertTrue("studentt" in cdo.operators)
     self.assertTrue(len(cdo.operators) > 700)
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:8,代码来源:test_cdo.py

示例14: test_readArray

 def test_readArray(self):
     cdo = Cdo()
     ifile = cdo.enlarge('r44x35',
                         input=' -stdatm,0,100,1000',
                         options='-f nc')
     if cdo.hasNetcdf:
       self.assertEqual((3,35,44), cdo.readArray(ifile, 'T').shape)
     else:
       self.assertRaises(ImportError,cdo.readArray,ifile,'T')
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:9,代码来源:test_cdo.py

示例15: test_returnXDataset

 def test_returnXDataset(self):
     cdo = Cdo()
     if cdo.hasXarray:
       sum = cdo.fldsum(input = cdo.stdatm("0",options="-f nc"),returnXDataset=True)
       self.assertEqual(1013.25,sum.variables["P"][:])
     else:
       self.assertRaises(ImportError,
           cdo.fldsum,
           input = '-topo',returnXDataset=True)
开发者ID:Try2Code,项目名称:cdo-bindings,代码行数:9,代码来源:test_cdo.py


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