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.8-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6190d8ac387664da79780285be9df7513a795f3646750fe2b854766378206f25 |
|
MD5 | 6ca4288115772aac84e78d58c05478f9 |
|
BLAKE2b-256 | 83abed16e97fc6705d24d0e91a7ccc1ad66b186eb26bce323627a8819ebdea8f |
Hashes for rpgPy-0.15.8-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f0b3b9e72622aefd4b545deeaf08d683683def08caf9a70487bb9aa1e6cd968 |
|
MD5 | 5d328fd3846ca8880fe40c770f9f8ac2 |
|
BLAKE2b-256 | 0794988f67b3b3b9d940164b1bc0e8733dff159e70b1f065cdbd61f6a5c492d1 |
Hashes for rpgPy-0.15.8-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57ec38ede5e5ce08e8417f34c5c90da5df50e5d447f3ef7b0a2b754103268534 |
|
MD5 | 5bea802e9e4dbfcec3a767cf3e004ed8 |
|
BLAKE2b-256 | 0968fb92072f1bca73b6332f32152955d74bdcbd5aa3199ca4b93dfd058aaa58 |
Hashes for rpgPy-0.15.8-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68ded6594de7828f9f5d3b0813c9485d097a2875473c71b305a951738effc09a |
|
MD5 | 9995c96d3d67de50a6a69303b4f90795 |
|
BLAKE2b-256 | a920e3180939452257a7ae16e8665ec6e70520ca5d4b84c8c3bef2c6b0b0821b |
Hashes for rpgPy-0.15.8-pp310-pypy310_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29cc98ad5b931570ba092841c37cc3df95561d6fea6569efb547119273e0ca97 |
|
MD5 | 9d43dec80e9098c18f876d6922703d00 |
|
BLAKE2b-256 | dfcfa8bbc1c36a52de7c1beb7345ef388e04d3f4012177dcce9a301290bf8298 |
Hashes for rpgPy-0.15.8-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc87daf1c68578262169f6c313e343f5b459a1e3702b64b0bd911b502cc4af0d |
|
MD5 | 8f023b7a818091f840ac289281b3f993 |
|
BLAKE2b-256 | 6ec0518eac640dc1e26deeba738a865cd4c6d4a79473d74f30cd1cc711862a45 |
Hashes for rpgPy-0.15.8-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d67bf0dfe1312f4d5200b0a23527259491a64eb7c2a84cec90b66fe82e34f1f |
|
MD5 | f12851a1f6f83d898783f143fa094433 |
|
BLAKE2b-256 | 25448f987dd66166c0f9d4619e0a0d56e318add59a5d85446ee9e7e8b5015035 |
Hashes for rpgPy-0.15.8-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d82be7942025b3a55a4ea4da5a1ce3fd8d0f883684ce380ab05ab97e0273a037 |
|
MD5 | 59d89ece658a1f71546dcb5703d485c5 |
|
BLAKE2b-256 | 09fe46362f12477a312b42d10dc225e46b15ba08d4f3f1a2203eeb019e797970 |
Hashes for rpgPy-0.15.8-cp312-cp312-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d400492527a83b341699e506dd037b3cdb6bf5c5c87f4b95c1dadeab4328ddc |
|
MD5 | 4d0371b119dfad42c2c14aa3cf060386 |
|
BLAKE2b-256 | d4c2df89196a61d3fcb0990593e324cfe80bc4c813dd24b3407a4d4443940a3a |
Hashes for rpgPy-0.15.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7c52563cce1fd8882e65596413fa8ab3774e1441861d2f61f4d2d37046f3aaa |
|
MD5 | ca840c909648ac7c3e8a912a13b38149 |
|
BLAKE2b-256 | ea4d96fb2785429b5cf9e9a86d31ab4e9d76e0777a83d19465f28f5afd23224f |
Hashes for rpgPy-0.15.8-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b7bae34d3db0a34ea46dcdf30ecbb9a7edadd6a0669bfb6c3468df4747ebadf |
|
MD5 | 1422dd5232ad600ef4b4d6ed292fc0af |
|
BLAKE2b-256 | 5e17d7fa7320b689ec981625d4be1c88a52fbb7caf77b1765d1bc2772a40570f |
Hashes for rpgPy-0.15.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eb2103268751406f1723825e2f38f960a418382d161f913f470935bcbe23a80 |
|
MD5 | 90998505e84c65ff741e1e0e3ada717d |
|
BLAKE2b-256 | b9853e8d24e17bdf0cd31f3176cd6e423715a878ff42d75f0ae5c3e6b18cb89f |
Hashes for rpgPy-0.15.8-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdf1f4c3d55994fd82a07514f5c1d1a04573a7ed08290a18fbe5c90d80add29a |
|
MD5 | c461684518e3d1e171e567f29d94b946 |
|
BLAKE2b-256 | 99b60ef7a7f6fd42fe3f7834f7d145c0c7717cd9911cc9a873b6d99cb97e55d0 |
Hashes for rpgPy-0.15.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e95736dc7ad2fe6c7bcc675dec6d1cc659bfc711563f69f98e1b18626238f779 |
|
MD5 | a578f15683f2d18cfe86c90f8925a7d9 |
|
BLAKE2b-256 | b2a6d6aa24891891d68c2c077925ca0b2c4dcc82bb0ec5c8b3c3240ddad952cb |
Hashes for rpgPy-0.15.8-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea943af60547121bcb04b3dbc94f9f80da3120a8c92a87010652b5751f4030c |
|
MD5 | 791afcd8c39133a10aa91ca6266a0142 |
|
BLAKE2b-256 | 7ef137702ae16b0a63dd4227a071658277044e3bb6bd63c6255d96b8aeb9234f |
Hashes for rpgPy-0.15.8-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | befff6482d61aef05210d1602c1d1d56a339dc60aefd1aa84dfce77ad03e62da |
|
MD5 | 8824c94ed54e5e782c8417f51a94d60c |
|
BLAKE2b-256 | ddc9b96111d659985e4093e37f0d80486c149037231bdb2709a4e4b64517542d |
Hashes for rpgPy-0.15.8-cp311-cp311-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41be9918c031fc1bdeb5b3f4ba464a20ebcc2bb460fad3e754d817facee4f235 |
|
MD5 | 24f610e5fe06834d4d189dc9e023a493 |
|
BLAKE2b-256 | 0187342ba25b0058fd6c22de1fc77d4fadd3d175efa9419424d242fbf550dee2 |
Hashes for rpgPy-0.15.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4193b4ca101e8d0d3ddccd65723ea5dd8b09e4deca69f51671c1a4dd2fc57a1 |
|
MD5 | f11e9a6b9eb51156bc6f91dcf681fff4 |
|
BLAKE2b-256 | 19e2b5c2985477a4fd4cd358e524d4f8a611a70a23b480213ca81b3ec7751665 |
Hashes for rpgPy-0.15.8-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 177b32031e49bc931a53ef31707f958afac969decd19a2678ac7d7423c28bf5f |
|
MD5 | a2a75a9ee50ed015aa86a0a0c43a6fe2 |
|
BLAKE2b-256 | 6737b6320957edcacfedf052bd172a44e17485791d7715eb2c39efab3614b057 |
Hashes for rpgPy-0.15.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cf49705571cd33fba58fc75e8f0378d9093793bfa3f5bb719fdbd956137603b |
|
MD5 | b4fe682a7499aba358d8e75b19775363 |
|
BLAKE2b-256 | b95ea19f004df0454325f4f4aa1f89f144d77f0542099cd3bb20632d1e643c30 |
Hashes for rpgPy-0.15.8-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8a8e92f7e8230cf8b86a4fc109a62bb84e9e3798bd34e2c6a7aa405a53e39bb |
|
MD5 | 19312bf2cd763652399e80ab4508bba8 |
|
BLAKE2b-256 | 79f8368a5af684767a862753a6826368633f3cfd3e6a37d2775f0795d511e423 |
Hashes for rpgPy-0.15.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5c04039857d4485cb57f884cd30e077c012a70064d9f53e97bd681dc3d6e24a |
|
MD5 | 979ff7cbea063ddbc8ec5270691e5052 |
|
BLAKE2b-256 | 4de077842cc20001e6511073635444f9b18942e646423f9fae242492c234d615 |
Hashes for rpgPy-0.15.8-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f3dd1f817ff1c62fb8d16eef3d2ae0ee9c84892b36e03e1d43c973d1b292a8e |
|
MD5 | 5fb096629cb09347ab64416ce2b34310 |
|
BLAKE2b-256 | 31c488a93e39b61839f0fbcfcefee41620abe769251dc8fafac4ba6e837de098 |
Hashes for rpgPy-0.15.8-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3babf1262f245ab9c0fd3b7cc71852877b496f8846e8a4cbf6d98d72d42f2005 |
|
MD5 | dea11c6b54171425350e1381f8baf7be |
|
BLAKE2b-256 | 5305dc626c07819f4281d90099b98e345cf4944fdbd58ab45fb01e3232dc364d |
Hashes for rpgPy-0.15.8-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ecf02f324387e5aebadf9bc6285543382a5679ca206bbcd99042bd0093fc776 |
|
MD5 | 11b424940e66edb6cf46176cf10d3300 |
|
BLAKE2b-256 | 90dffe5a84b11abdad52f6c8268193f616b9ae4cbb72c959ca99aa145e4bab05 |
Hashes for rpgPy-0.15.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8530009048969ceca7c9afce72c1a6931e17ef0eb05e6ba9ab42991ff8b193ca |
|
MD5 | 8d2a68317c40692ea1b049c2670e395e |
|
BLAKE2b-256 | ad96eeb09ce3fa21a196d3fb4649586ee741168cbbf522af7f839fba097ac854 |
Hashes for rpgPy-0.15.8-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766ca1b6c45e9cfd8657952146f662c00a74fc1303c1bffe9863e2a1426b18d6 |
|
MD5 | 86e0a7382a6d1b4d8820142a73c6eca5 |
|
BLAKE2b-256 | 1137eaf2d7ad9edb455407566beeea9534ecb98bcb00e38bf8ad2b96615cbfc9 |
Hashes for rpgPy-0.15.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a1a63fa4a2fc377063bfbe3741f04f1d00db803a6e66bb033e49322c0aa5484 |
|
MD5 | efdeeffe3710e2d73ec8624c722bb4ee |
|
BLAKE2b-256 | cac98043d66613544a4f801f4a0f20344892ade4a64a5ad644acf10553b4ef51 |
Hashes for rpgPy-0.15.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d276fb67858abf4ae6d0486835975465865a8864b30e2f6f0fe5c3181ede160 |
|
MD5 | 315a2e7510c26d9736b4297c73f8ec7c |
|
BLAKE2b-256 | ee272147209b80c80585640269f591e9e4bdfc479c3b3ee4b319a9d900081732 |