Cython code for reading binary files from RPG cloud radar.
Project description
rpgPy
RpgPy is a Python / Cython software for
- Reading RPG cloud radar Level 0 and Level 1 binary files
- Calculating spectral moments from RPG Level 0 data
- Converting RPG binary data to netCDF4 format
Installation
From PyPI
python3 -m pip install rpgpy
From source
git clone https://github.com/actris-cloudnet/rpgpy/
cd rpgpy/
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install .
python3 setup.py build_ext --inplace
NOTE: A C-compiler is required because the Cython code is compiled locally during installation.
If you get an error about missing Python.h
, you need to install the missing header files with $ apt install python3-dev
(or similar).
Quickstart
Converting RPG binary files into netCDF4
>>> from rpgpy import rpg2nc
>>> rpg2nc('rpg-data.LV1', 'rpg-file.nc')
This writes a compressed netCDF4 file and works with both Level 0 and Level 1 data.
Several RPG files can be concatenated into singe netCDF file using wildcard. With Level 0 data, this can lead to a very large file.
>>> rpg2nc('/path/to/files/*.LV0', 'huge-file.nc')
Converting multiple files individually
Multiple RPG files can be converted into corresponding individual netCDF4 files using rpg2nc_multi
.
>>> from rpgpy import rpg2nc_multi
>>> filenames = rpg2nc_multi(file_directory='/path/to/files')
Default functionality is that every file with an extension .LV0
, .lv0
, .LV1
or .lv1
in every subdirectory of the specified path will be converted.
Creating custom Level 1 netCDF4 file
rpgpy
can estimate spectral moments from Level 0 data. The estimation is based on the most
prominent peak of each time / range point.
>>> from rpgpy import spectra2nc
>>> spectra2nc('rpg-data.LV0', 'level1.nc')
This calculates spectral moments from Level 0 data and writes the results in a netCDF4 file.
Reading RPG binary file
If you don't need the netCDF4 file:
>>> from rpgpy import read_rpg
>>> header, data = read_rpg('rpg-data.LV1')
Calculating spectral moments
>>> from rpgpy import read_rpg, spectra2moments
>>> header, data = read_rpg('rpg-data.LV0')
>>> moments = spectra2moments(data, header)
This works only with Level 0 data.
API reference of spectra2moments
API reference
Index
rpg2nc
Convert RPG cloud radar file(s) into single netCDF file.
rpg2nc(path_to_files, output_file, **kwargs)
Positional arguments:
Name | Type | Description |
---|---|---|
path_to_files |
str | pathlib.Path |
Filename of single file, or multiple files identified using a wildcard, e.g., /foo/bar/*.LV0 . |
output_file |
str | pathlib.Path |
Output file name. |
Keyword arguments:
Name | Type | Default value | Description |
---|---|---|---|
global_attr |
dict |
None |
Additional global attributes. |
rpg2nc_multi
Convert RPG cloud radar files into several corresponding netCDF files.
filenames = rpg2nc_multi(**kwargs)
Default functionality:
- Input files are searched recursively starting from the current working directory
- Files with the suffix
.LV0
,.lv0
,.LV1
or.lv1
suffix are converted - netCDF4 files are written to the current working directory
Keyword arguments:
Name | Type | Default value | Description |
---|---|---|---|
file_directory |
str | pathlib.Path |
current working directory | Root path of the search. |
output_directory |
str | pathlib.Path |
current working directory | Path name where the netCDF4 files are written. |
include_lv0 |
bool |
True |
If False , excludes Level 0 files. |
recursive |
bool |
True |
If False , does not search input files recursively. |
base_name |
str |
None |
Optional filename prefix for the converted files. |
global_attr |
dict |
None |
Additional global attributes. |
Returns:
Type | Description |
---|---|
list |
Full paths of the successfully created netCDF files. |
spectra2nc
Calculate moments from RPG Level 0 spectra and write a netCDF4 file.
spectra2nc(input_file, output_file, **kwargs)
Positional arguments:
Name | Type | Description |
---|---|---|
input_file |
str | pathlib.Path |
Filename of RGP Level 0 file. |
output_file |
str | pathlib.Path |
Output file name. |
Keyword arguments:
Name | Type | Default value | Description |
---|---|---|---|
global_attr |
dict |
None |
Additional global attributes. |
n_points_min |
int |
4 | Minimum number of points in a proper spectral line. |
read_rpg
Read RPG cloud radar binary file.
header, data = read_rpg(filename, **kwargs)
Positional arguments:
Name | Type | Description |
---|---|---|
filename |
str | pathlib.Path |
Filename of RPG cloud radar Level 1 or Level 0 binary file. |
Keyword arguments:
Name | Type | Default value | Description |
---|---|---|---|
rpg_names |
bool |
True |
If True , uses RPG manual names in the returned dictionary, else uses more human-readable names. |
Returns:
Type | Description |
---|---|
tuple |
2-element tuple containing header and data dictionary. |
spectra2moments
Calculate spectral moments from Level 0 spectral data. A call to read_rpg
is required before using this function.
moments = spectra2moments(data, header, **kwargs)
Positional arguments:
Name | Type | Description |
---|---|---|
data |
dict |
Level 0 data dictionary from read_rpg . |
header |
dict |
Level 0 header dictionary from read_rpg . |
Keyword arguments:
Name | Type | Default value | Description |
---|---|---|---|
spec_var |
str |
"TotSpec" |
Spectral variable to be analyzed: "TotSpec" or "HSpec" . |
fill_value |
float |
-999.0 | Value for the clear sky data points. |
n_points_min |
int |
4 | Minimum number of points in a proper spectral line. |
Returns:
Type | Description |
---|---|
dict |
Dictionary containing Ze (reflectivity), MeanVel (mean velocity), SpecWidth (spectral width), Skewn (skewness) and Kurt (kurtosis), which are 2D numpy arrays (time x range). |
Development
Install test-dependencies and pre-commit hooks:
python3 -m pip install -e .[test,dev]
pre-commit install
Compile Cython (repeat if you change .pyx
files):
python3 setup.py build_ext --inplace
Tests
Run unit tests:
pytest
Run end-to-end tests:
for f in tests/e2e/*/*runner.py; do $f; done
Force pre-commit
checks of all files:
pre-commit run --all
Performance
For reading RPG binary files, depending on the radar settings, RpgPy is roughly 20-30 times faster than equivalent native Python or Matlab implementations.
License
MIT
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
Built Distributions
Hashes for rpgPy-0.15.7-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1155cd6d39cc1ea7ef337128985d4458f1f0fd3bbbf6664f474b8966338dfe78 |
|
MD5 | 0aa0039b7446c4518606d1810562d77b |
|
BLAKE2b-256 | 71f38faa81397e79fe22a4ddb158f0b9476994d188a6e946150dc66057641a4a |
Hashes for rpgPy-0.15.7-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa05443d3afceaa25e2cef1f08737d08f2853cde7c9d47793d8d1ce8b1329106 |
|
MD5 | 3e106d7836751a0321ce1c3201dd8b7d |
|
BLAKE2b-256 | ec470fa65e368bbf1330be6a75b9d5f2591968d6f0426dce758c5e72dcc1c944 |
Hashes for rpgPy-0.15.7-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b68a5ad9f539dfcfdc027dd47c4aa83b3d9d4cfe37d94f46559e545e821c27c |
|
MD5 | caabe3d20ac84fba876769e596eda1b3 |
|
BLAKE2b-256 | 10184e3c0e5bfc26ea75d2c9a6b75679484e42cb0d86c6144db5abb2e48202c6 |
Hashes for rpgPy-0.15.7-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71113a760986648838ea443e922c001572828d7d229441ee4a918083673ad6e0 |
|
MD5 | 9302bf9e5ffe259d7e44a478af2a1b6f |
|
BLAKE2b-256 | 5a05ec0aaced01d4ddbf1f33a1bc9d6ec6b0135d1ca6173e49bf5f85ba5f1b9a |
Hashes for rpgPy-0.15.7-pp310-pypy310_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e31957dce6db4136fc1655cb52d2fd428fe6553ef161eed1f81cddf9ffa7c0f |
|
MD5 | 620c240603bfabafd096606b884156cd |
|
BLAKE2b-256 | 60d1acbbbe3c0c69520a8eec894f150540ea9999d35f22fc630c79f934c549ca |
Hashes for rpgPy-0.15.7-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 070e356cd8be7cd8afc204e46ffb3d1d4843429beb4db1245ba7bb8f5fdad689 |
|
MD5 | 23ddfff2ef66f48d91a9f61c7537cdd3 |
|
BLAKE2b-256 | 6871f464e351a1889e3945bcbb7664d7a94d3b7000afc0816691c4abd243acda |
Hashes for rpgPy-0.15.7-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e1b94dd6480d92cb6bec3dc35ec2074003cf767031f87e6e3b4f412c59121d4 |
|
MD5 | a0b178ddf31a4ea019e9d0de75b25fdc |
|
BLAKE2b-256 | f6a608bcc82c03f2210d4d8c03861f0f8cbedb9d2ccbb5a7093fb26443deb19d |
Hashes for rpgPy-0.15.7-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72c55c509f5c6778fae0e0432bc80a5d28ad96491221277617c48988377d72a3 |
|
MD5 | fe22737a87829049f22a379e3d5c58af |
|
BLAKE2b-256 | 114878b6050e5a5c7bfd1315c9c4a46e814b003a3aac2b97f0f06c50ea420e7b |
Hashes for rpgPy-0.15.7-cp312-cp312-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae927bedc4610556e3ae04d1f6efa32f20d79d22c96a0ea6fee097808a31ecd7 |
|
MD5 | 2786d61641e694dee922bebff4021400 |
|
BLAKE2b-256 | bf9dd4c3cd9a3f6809cea8b823ed77fa20b85c4bbcddacb1a2a5910560769af0 |
Hashes for rpgPy-0.15.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4804bce3ed210678e80167275ddb7f9d845a956657e07ddc90dcc1a049434767 |
|
MD5 | 5d030b921ffe94b3dedf78baf13fb2d5 |
|
BLAKE2b-256 | 13cc6fd96a169626b70f3df92fb499260d95cced1021e0a58fde0c8a20574139 |
Hashes for rpgPy-0.15.7-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64c49e67ee0bd5674b1f02a898a122718bb40441f4f65860c11e8e554ed65499 |
|
MD5 | 9bc181e47fb8171f5ece7c94097f54e9 |
|
BLAKE2b-256 | 5ba65dfb69d9a6781b38fb34cf8e98d0cbd1e82f9096ec80efefa61c1ad30592 |
Hashes for rpgPy-0.15.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 895940111b806007dd6d493add9e7cfef5243f903ec4b34951215c0a9a1126e0 |
|
MD5 | 764da877b7bc639e540239305b48a552 |
|
BLAKE2b-256 | 88dfe0c885b5e0dd7688b33b49ba03871d04035a4e9d0a113b5df337b45f67c3 |
Hashes for rpgPy-0.15.7-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d90ea81b3526b9daebefb9858cd18730f9e95aa2ab6a53fbda8f52dcd40c686 |
|
MD5 | 3562e4f018fa907b2767a0a314a8078c |
|
BLAKE2b-256 | 5acfd9479cb6a94f35ca8480a9c19fc3f9b49dbf62e16dac37e931423c31e17e |
Hashes for rpgPy-0.15.7-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d036a4f178cc05c4a52d6ea58bb959d831936687ca175fa8e625b7d851d99052 |
|
MD5 | daf6db32c21187eb88db687af0198345 |
|
BLAKE2b-256 | b33af71557365dc3846244e5778feb7ae8f53b1871e99a4ce65c632fe0fc7c5e |
Hashes for rpgPy-0.15.7-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5606ddc811f44e2163ec6a6bccea0f65abf2c2b6972d1444eed441b703d9275f |
|
MD5 | 900135942d7df3aab64e5430faf90fc9 |
|
BLAKE2b-256 | c62cb7ed35b5bc9f1a651c0ad162079ea13abdb248fab30994ccb557677b138a |
Hashes for rpgPy-0.15.7-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d29c7610fc0c068ec9f2d94f1eb8c84c0c88e4dd2215404f8d375a8247c26fe |
|
MD5 | bcaacf48f7fa713854aea7ee438eeb60 |
|
BLAKE2b-256 | 6e0a5396776203849f221f07b40679db935d7cb9a0462d4be716570b0bfb9309 |
Hashes for rpgPy-0.15.7-cp311-cp311-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b0a170274f94ac5867cb702b82f2fe21eeca7e74dce9e6b62a60450e487355b |
|
MD5 | 761ff994d297a140e6948e2f623af6cd |
|
BLAKE2b-256 | 154ded9163b8f6ccf3e50c71e0c9ba12547a6a4257ec53130c69a4f63260cb62 |
Hashes for rpgPy-0.15.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a1b8aee8d4d5e4812cef1e64466c3a0dfb8de3fedd7f5cc392a2c841fcc29e |
|
MD5 | ba4b6db8930e893a313a65c0e7767c6c |
|
BLAKE2b-256 | 00367082d191d79d4340dec5c7d86e7cc7ad4e743cf7428334f3475361a30559 |
Hashes for rpgPy-0.15.7-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2653f13c29d823636194b9b24eeb32bf6e650145c17510caaa7eef97792b443f |
|
MD5 | 99b015d73f8b2b599cea8779f2f5d41d |
|
BLAKE2b-256 | e3c5cba03e93f29cba1a272ca5dbf2d8627b2a7b8020ed0b9a64f5d29c595f80 |
Hashes for rpgPy-0.15.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ded920096d1e7df3f84c14d195b8d632edc99ae4ab0c9fe1cb9c48e35f4b61af |
|
MD5 | cb19f38ef8b123c722085501ddb078a2 |
|
BLAKE2b-256 | ef526211d1cae2d1d5177c5ae56e6f047daff9d38c29ea280c065895555eddbf |
Hashes for rpgPy-0.15.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e935aebe05f82267d66ec047c2c1d3dafeee2c341e84ae09c4b7079543ee6ff7 |
|
MD5 | b60c0f3d8dfad9775292b2d362e7bfe1 |
|
BLAKE2b-256 | 4e84100b4dda22c4ef537bf13492af05b29b31387956b318a116261e630373f0 |
Hashes for rpgPy-0.15.7-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ff7348f6d7eb1d522f3958388a7f7635f0acc8fa9781948e75c44bd5ec5a6ff |
|
MD5 | 763a497853301cd720eb9e62bda0754a |
|
BLAKE2b-256 | 342972db2f984c81b75130d814142cc799747999162be7d87d1c5592b06c090d |
Hashes for rpgPy-0.15.7-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb3f63d4fc8fc373f26c1dfde2cac6c8225a7bbb9653b255945227b4bd8719cd |
|
MD5 | bb03e9b0ed43f5cabd858bd1ce67ded2 |
|
BLAKE2b-256 | 9e847e691fe1b235c92a0812f77b521c02376ebeabe261259e3d71bc16bb0048 |
Hashes for rpgPy-0.15.7-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a76c798ed8139e6263b2cc2a94ed2032cc4bdc55c9ed59e43a7b8fcc782a5dc4 |
|
MD5 | fecf8ee7e7974fd3aa217d5cc14fdde4 |
|
BLAKE2b-256 | 1263b5e14f460b955d91ae8b4262a48e4f2e71cba75811b952fed407c1be03b5 |
Hashes for rpgPy-0.15.7-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eebce101f1b8f2ce8b6c811b27c836ff94d8eef38255a1adb714d7cd15a3b88 |
|
MD5 | aae4dd6cc57eb82b36b50836d8cff67b |
|
BLAKE2b-256 | 33a1fecc2dd8661e5256e607bee029f988a36616c766bc94b51712839b82e87b |
Hashes for rpgPy-0.15.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f26ac49d7449d2d24a3fb2b495dcd47d4a5c742513c8b7e43f44eb285eaa7056 |
|
MD5 | 4e884722a8909713afda3af072fcbe41 |
|
BLAKE2b-256 | 2e6b2ec196ee0c1ea93f14e64a5d4022ced02365675bcb21d732875efeee2389 |
Hashes for rpgPy-0.15.7-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ebeabe0dcfb80e07813be3ec1bf36fb493483e46587d6533e1ec350962e273d |
|
MD5 | 7b922120f2660f0c65b50c8971033ee8 |
|
BLAKE2b-256 | ee56e8816ae6ccc5114ae2fe462b71ed8ac1c8a8d4db55357ee64e30a34245a4 |
Hashes for rpgPy-0.15.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c6baef821929fda1395e8739088fe79a09e155063c1abb8d1891072bf9cbc57 |
|
MD5 | fc7759ad2fdd695fcd7ffdd1beb78007 |
|
BLAKE2b-256 | f5cda9271cc230a76d51df3144bdac23adbeba66bdcd8c182a230fa503cad13a |
Hashes for rpgPy-0.15.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 885eb897648a3a7c63e1d19076f3d2a5e7e765a454c4fde702b0a4f68295c6f2 |
|
MD5 | 8a5e68dc2efa09dca5d18963b761f2f3 |
|
BLAKE2b-256 | e9e9902a74c9c90970d7bac8e6ce3101e11f24c69624c7fe6d222d61517c3611 |