A Python package helps to generate complicated cdo expr(computing expression) in pythonic way
Project description
pycdoexpr
CDO (Climate data operator) is a high-efficient command line tool for climate and meteorology data processing. This Python package helps to generate complicated cdo expr(computing expression) in a convenient and pythonic way.
Install
Install via pip
pip install pycdoexpr==0.0.2
Usage
- generate digitize expr (same as np.digitize)
from pycdoexpr import cdoexpr
# EX1: use digitize to generate WIND LEVEL expr
wind_level_bins = [ 0.3, 1.6, 3.4, 5.5, 8. , 10.8, 13.9, 17.2,\
20.8, 24.5, 28.5, 32.6, 36.9, 41.4, 46.1, 50.9, 56. , 61.3]
cexpr = cdoexpr()
cexpr.digitize(varname='WIND_LEVEL', bins=wind_level_bins, right=False)
- convert multi-level conditions string in python syntax to cdo expr
# EX2: use conditions to generate WW (weather code) expr (https://www.jodc.go.jp/data_format/weather-code.html)
s = '''
if PRE1H > 0.001:
if TEM2 >= 3:
if PRE1H < 0.1:
WW = 51
elif PRE1H < 2.5:
WW = 61
elif PRE1H < 8:
WW = 62
else:
WW = 63
elif TEM2 >=0:
if PRE1H < 2.5:
WW = 66
else:
WW = 67
else:
if PRE1H < 0.1:
WW = 71
elif PRE1H < 0.2:
WW = 73
else:
WW = 75
else:
if VIS > 10000:
if TCC > 80:
WW = 3
elif TCC > 40:
WW = 2
else:
WW = 0
elif VIS >= 1000:
if RHU2 > 80:
WW = 45
elif RHU2 > 50:
WW = 48
else:
WW = 31
else:
if WS10 < 1:
WW = 45
else:
if RHU2 >=50:
WW = 45
else:
WW = 34
'''
expr = cexpr.conditions(s, verbose=True)
f"cdo expr,'WW={expr}' infile outfile"
- moore voting
# EX3: generate moore voting cdo expression
expr = cexpr.moore_voting(voters=['a' ,'b', 'c'], varname='MAJOR')
f"cdo -expr,'{expr}' infile outfile"
- convert multi xgboost tree to expr with ensemble method (averaging, boosting, moore_voting) experimental
# EX4: convert a xgb decision trees model to cdo expression
expr = cexpr.xgb_decision_trees('./static/model.pkl',ensemble='averaging')
f"cdo -expr, '{expr}' infile outfile"
Benchmark
cdo expr vs (np.verctorize calc and xarray io)
- TODO
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycdoexpr-0.0.2.tar.gz
(419.1 kB
view details)
Built Distribution
File details
Details for the file pycdoexpr-0.0.2.tar.gz
.
File metadata
- Download URL: pycdoexpr-0.0.2.tar.gz
- Upload date:
- Size: 419.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2775efd0268dc7728e39a909efc0adf6c39f42a00774a44dd4d2ad5f24a24b9c |
|
MD5 | 6c82d3f1c2692bc265061281ff8cdc84 |
|
BLAKE2b-256 | 86dcc7e7ab4b84ba9ffa17843824e8a02a9f8eae57181639fe3b4ecc1a2ebbee |
File details
Details for the file pycdoexpr-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: pycdoexpr-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95dd749d0082f6ddf042ac2c64cf51bb74a14537209a3ec2664b9ecff67df03f |
|
MD5 | 4ee7dadd71bb570dd978cec2c65745d3 |
|
BLAKE2b-256 | ee30d86928922f50fdd87099c8ce4081104885db1d8c9d97b52551c598501f01 |