没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
2019/11/4 Cdo{rbpy}CDOProjectManagementService
https://code.mpimet.mpg.de/projects/cdo/wiki/Cdo%7Brbpy%7D 1/7
目
录
Cdo{rb,py}
Whythe...
whatitis(not)...
Usage
online/offlinehelp
IO
Options
OperatorChains
SpecialFeatures
Tempfilehan dling
Con ditionalProcessing
MultithreaddingRuby
MultithreaddingPython
Dataaccessvianumpy/narray/xarray/cdf
Writeyourownoperators
Futureversions
Installation
Ruby
Python
ForMPIMETusers
Cdo{rb,py}
Why the ...
You'rehappywithusingCDOinashell?You'rehesitanttouseascriptinglanguageinstead,becausesh ellsaresoeasy
touse?Herearesomecoolfeature s,you'llh ar dlygetwith inashellcontext:
Directdataaccessvianum py/narray
Ifyouhavepythonnetcdf4orscipyinstalled,youwillhavedirectaccesstothevaluesofyourfields.Pythonand
Rubyofferarichsetofscientificlibrariestoworkwiththesedataarrays,e.g.plotting.
Automatictempfilehandling
Whendealingwithtemporarydata,youwillneverhavetodothingsmanually.Nocleanup,nomanualcreation
andrenamingoffiles.Forwhateveryouwanttosave,givearealoutputfilenametherestisdone
automatically.
Flexibleparallelization
Youhaveahugelongrunningjob,t hatcouldbedoneonparallel?Ingeneralshellsdonotofferenough
parallelismtohavefinegrainedcontrolthe&isnotenoughfor100to1000jobs,becauseyoursystemwill
slowdownverymuchandinaminute,you'llgetyourcallfromtheadministrators.
BothPythonandRubyofferwhatyoujustneed:Run1000routinecallswithonly12concu rrentprocessesor
threads.WithCdo{rb,py}younowcanm akeuseofit!
Conditionalprocessing
Avoidreprocessingiftheoutputfilesisalreadyondisk.Wiselyused,thiscanspeedupyourscript
tremendously.Thisbehaviourcanbeswitchedongloballyorjustforasinglecalls.E.g.whenanalysingoutput
datafromarunningexperimentsyoucanrunthesamescriptoverandoveragainandyou'llalwaysgetthe
latestresults.
writenewoperatorsoutofoldones
PythonandRubybindingsareopenlibraries,t hatcanbeextendedatruntime.Ifyouneedanewoperator,justwriteitinPythonorRuby!
Thereisa githubrepositoryforeasycodesharingandwherethe changelogistracked.
Ifyouhavequestions,pleaseusetheCDOforum.
what it is (not) ...
Thisscriptinglanguagepackageisessen tiallyawrapperaroundtheCDObinary.Itparsesmethodargumentsandoptions,buildsacommandlineandexecutesit.Thereis
nosharedlibrarybackendwhich callsCDOoperators.Thishassomeadvantages:
operatorchainingisfullysupported
multipleCDObinariescanbeusedatthesametimeusingsetCdo()( alt.link)
packagesarehighlyportable,becausetheyarepurepython/rubyimplementations
Usage
Almostallfeaturesarecoveredbyunitstests.Thesesshouldbeagoodstartingpointtogetanimpressioninhowtousethepackage:
Python:source:trunk/cdo/contrib/python/test/test_cdo.pyorat githu b
Ruby:source:trunk/cdo/cont rib/ruby/test/test_cdo.rborat github
Bothbindingsaretestedwiththeunixandthewin32versionofCDO.Pleasenote,th atreturningarraysbysettingreturnCdfisnottestedduetothelackofthe
correspondingnetcdflibraryonwindows.Thereareprecompiledwindowsversion ofnetcdf,butIwillnotspen ttimetogetitrunning.
Beforedoinganythingelse,thelibrariesmusthavebeenloadedintheusualway:
fromcdoimport*#pythonversion
cdo=Cdo()
Inthepythonversionanobjecthastobecreatedforinternalreasons,whereasthisisnotnecessaryforRuby.Thismaychangeinthefuture,butfornowit isonlya
minordifference
require'cdo'#rubyversion
online/offline help
Forallnonoperators,the automaticallygenerat eddocumentationformrubygemsmightbehelpful.Operatordocumentationcanbeviewedonline,directlybycalling
cdo‐h<operatorpattern>
orwithintheinteractivepython/rubyshell.Bothofthefollingexamplesdisplaythebuiltinhelpforsinfov:
Python:
fromcdoimport*
help(Cdo().sinfov)
or
fromcdoimport*
cdo=Cdo()
help(cdo.sinfov)
Ruby
require'cdo'
Cdo.help('sinfov')#orCdo.help(:sinfov)
IO
Inputandoutputfilescanbesetwiththekeyworsinputandoutput
Cdo.infov(:input=>ifile)#rubyversion
cdo.showlevel(:input=>ifile)
cdo.infov(input=ifile)#pythonverson
cdo.showlevel(input=ifile)
2019/11/4 Cdo{rbpy}CDOProjectManagementService
https://code.mpimet.mpg.de/projects/cdo/wiki/Cdo%7Brbpy%7D 2/7
Cdo.timmin(:input=>ifile,:output=>ofile)#rubyversion
cdo.timmin(input=ifile,output=ofile)#pythonversion
Options
Commandlineoption slike'‐f'or'‐P'canbyusedviatheoptionskeyword:
Cdo.timmin(:input=>ifile,:output=>ofile,:options=>'‐fnc')#rubyversion
cdo.timmin(input=ifile,output=ofile,options='‐fnc')#pythonversion
Operatorargumentshavetobegivenasthefirstmethodargument
Cdo.remap(gridFile,weightFile,:input=>ifile,:output=>ofile,:options=>'‐fnc')#rubyversion
cdo.remap(gridFile+","+weighFile,input=ifile,output=ofile,options='‐fnc')#pythonversion
or
Cdo.seltimestep('1/10',:input=>ifile,:output=>ofile,:options=>'‐r‐BF64')#rubyversion
cdo.seltimestep('1/10',input=ifile,output=ofile,options='‐r‐BF64')#pythonversion
Operator Chains
TotakerealadvantageofCDOsinternalparallelism,youshouldworkwithoperatorchainsasmushaspossible:
Cdo.setname('random',:input=>"‐mul‐random,r10x10‐enlarge,r10x10‐setyear,2000‐for,1,4",:output=>ofile,:options=>'‐fnc')#rubyversion
cdo.setname('random',input="‐mul‐random,r10x10‐enlarge,r10x10‐setyear,2000‐for,1,4",output=ofile,options='‐fnc')#pythonversion
AnothergoodexampletakenfromtheTutorialillustratesthedifferentwaysofchaining:Whilethechain
cdosub‐dayavgifile2‐timavgifile1ofile
isrepresentedby
Cdo.sub(:input=>"‐dayavg#{ifile2}‐timavg#{ifile1}",:output=>ofile)#ruby
cdo.sub(input="‐dayavg"+ifile2+"‐timavg"+ifile1,output=ofile)#python
Theserialversion,whichprohibitsinternalparallelism,createsunnecessarytemporalfilesandisj ustmentionedforeducationalreasonswouldlooklike
Cdo.sub(:input=>Cdo.dayavg(:input=>ifile2)+""+Cdo.timavg(:input=>ifile1),:output=>ofile)#ruby
cdo.sub(input=cdo.dayavg(input=ifile2)+""+cdo.timavg(input=ifile1),output=ofile)#python
orusingthejoinmethod:
Cdo.sub(:input=>[Cdo.dayavg(:input=>ifile2),Cdo.timavg(:input=>ifile1)].join(""),:output=>ofile)#ruby
cdo.sub(input="".join([cdo.dayavg(input=ifile2),cdo.timavg(input=ifile1)],output=ofile)#python
Special Features
Tempfile handling
Iftheoutputstreamisomitted,atemporaryfileiswrittenanditsnameisthereturnvalueofthecall:
ofile=Cdo.timmin(:input=>ifile,:options=>'‐fnc')#rubyversion
ofile=cdo.timmin(input=ifile,options='‐fnc')#pythonversion
Here,theoutputfilesareautomaticallyremoved,whenthescriptsfinishes.Manualcleanupisnotnecessaryanymoreunlessyouencounteracrash.Inthatcaseyou
canusethenew(1.4.0)method
cdo.cleanTempDir()
orsetanalternativedirectoryforstoringtemporaryfileswith
cdo=Cdo(tempdir='/path/to/new/tempdir')#python
cdo=Cdo.new(tempdir:'/path/to/new/tempdir')#ruby
Conditional Processing
Whenprocessinglargenumberofinputfilesasitisthecaseinarunningexperiment,itcanbeveryhelpfultosuppressthecreationofintermediateoutputifthesefiles
arealreadythere.Thiscanspeedupyourpostprocessing.Inthedefaultbehavior,outputiscreatednomatterifsomethingisoverwrittenornot.Conditionalprocessing
canbeusedintwodifferentways:
globalsetting
cdo.forceOutput=False#python
or
Cdo.forceOutput=false#ruby
Thisswitchchangesthedefaultbehavior(example)
operatoroption
cdo.stdatm("0,10,20",output=ofile,force=False)#python
or
剩余6页未读,继续阅读
资源评论
清流自诩
- 粉丝: 80
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功