Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Welcome to the scripting interfaces of CDO! This repository contains interfaces for Ruby and Python. If you are not sure, wether this is useful or not, please have a look at: Why the .... should I use this???
Currently this package is in a re-design phase. The target is a 2.0 release that will not be compatible with the exising release 1.5.x:
.
as much as possiblekwargs
keysReleases are distributed via pypi and rubygems:
gem install cdo (--user-install)
pip install cdo (--user)
conda -c conda-forge install python-cdo
Cdo.{rb,py} requires a working CDO binary and Ruby 2.x or Python 2.7/3.x
PLEASE NOTE: python-2.7 is unmaintained since January 2021 Many dependencies dropped support for 2.7 so I do manual testing with it,only.
Multi-dimensional arrays (numpy for python, narray for ruby) require addtional netcdf-io modules. These are scipy or python-netcdf4 for python and ruby-netcdf for ruby. Because scipy has some difficulties with netcdf, I dropped the support of it with release 1.5.0.
Thx to Alexander Winkler there is also an IO option for XArray.
You can find a lot of examples in the unit tests for both languages. Here are the direct links to the ruby tests and the python tests.
The following describes the basic features for both languages
Befor calling operators, you have to create an object first:
cdo = Cdo.new #ruby
cdo = Cdo() #python
Please check the documentation for constructor paramaters. I try to have equal interfaces in both languages for all public methods.
By default the cdo-bindings use the 'cdo' binary found in your $PATH variable. To change that, you can
module command
or another package manager like conda
or spack
)cdo.setCdo('/path/to/the/CDO/executable/you/want')
. By this technique you can create different objects for different CDO versions.For debugging purpose, both interfaces provide a "debug" attribute. If it is set to a boolian true, the complete commands and the return values will be printed during execution
cdo.debug = true #ruby
cdo.debug = True #python
The default is false of cause.
cdo.infov(input: ifile) #ruby
cdo.showlevels(input: ifile)
cdo.infov(input=ifile) #python
cdo.showlevels(input=ifile)
cdo.timmin(input: ifile ,output: ofile) #ruby
cdo.timmin(input = ifile,output = ofile) #python
By default the return value of each call is the name of the output files (no matter if its a temporary file or not)
If the output key is left out, one or more (depending on the operator) temporary files are generated and used as return value(s). In a regular script or a regularly closed interactive session, these files are removed at the end automatically.
tminFile = cdo.timmin(input: ifile) #ruby
tminFile = cdo.timmin(input = ifile) #python
However these tempfiles remain if the session/script is killed with SIGKILL or if the bindings are used via Jupyter notebooks. Those session are usually long lasting and the heavy usage of tempfiles can easily fill the system tempdir - your system will become unusable then. The bindings offer two ways to cope with that
cdo = Cdo(tempdir=tempPath) #python
cdo = Cdo.new(tempdir: tempPath) #ruby
tempdir
from above cdo.cleanTempDir() #python
cdo.cleanTempDir #ruby
Alternatively you can use environment variables to set this. Python's and Ruby's tempfile
libraries support the variables 'TMPDIR', 'TEMP' and 'TMP' in their current versions (python-3.8.2, ruby-2.7.0). This feature might be used by administrators to keep users from filling up system directories.
cdo.remap([gridfile,weightfile],input: ifile, output: ofile) #ruby
cdo.remap([gridfile,weightfile],input => ifile, output => ofile) #python
cdo = Cdo.new(logging: true, logFile: 'cdo_commands.log') #ruby
cdo = Cdo(logging=True, logFile='cdo_commands.log') #python
cdo.copy(input: ifile, output: ofile,options: "-f nc4") #ruby
cdo.copy(input = ifile, output = ofile,options = "-f nc4") #python
cdo.splitname(input: ifile.join(' '),
output: 'splitTag',
env: {'CDO_FILE_SUFFIX' => '.nc'}) #or
cdo.env = {'CDO_FILE_SUFFIX' => '.nc'}
cdo.splitname(input = ' '.join(ifiles),
output = 'splitTag',
env={"CDO_FILE_SUFFIX": ".nc"}) #or
cdo.env = {'CDO_FILE_SUFFIX': '.nc'}
t = cdo.fldmin(:input => ifile,:returnArray => true).var('T').get #rb, version < 1.2.0
t = cdo.fldmin(:input => ifile,:returnCdf => true).var('T').get #rb, version >= 1.2.0
t = cdo.fldmin(:input => ifile,:returnArray => 'T') #rb, version >= 1.2.0
t = cdo.fldmin(input = ifile,returnArray = True).variables['T'][:] #py, version < 1.2.0
t = cdo.fldmin(input = ifile,returnCdf = True).variables['T'][:] #py, version >= 1.2.0
t = cdo.fldmin(input = ifile,returnArray = 'T') #py, version >= 1.2.0
Other options are so-called masked arrays (use returnMaArray
) for ruby and python and XArray/XDataset for python-only: use returnXArray
or returnXDataset
for that.
*) If you use scipy >= 0.14 as netcdf backend, you have to use following code instead to avoid possible segmentation faults:
cdf = cdo.fldmin(input = ifile,returnCdf = True)
temperatures = cdf.variables['T'][:]
More examples can be found in test/cdo-examples.rb and on the homepage
If you do not want to re-compute files, you can set
For more information, please have a look at the unit tests.
Please use the forum or ticket system of CDOs official web page: http://code.mpimet.mpg.de/projects/cdo
cdo.config
holds a dictionary/hash with built-in CDO features (availble sind CDO-1.9.x), empty otherwisecdo -V
. use cdo.config instead
infiles(). This should clean up the lengthy code, which does this
currentlyoperators
atribute is no longer a list, but a dict (python) or hash (ruby) holding the number of output streams as valueCdo.{rb,py} makes use of the BSD-3-clause license
FAQs
python bindings to CDO
We found that cdo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.