目
录
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)