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.10-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af34ca3c781014763f91ff4695b9d8553a2917f057a1fb172a07198c936eec4 |
|
MD5 | 765d98e94b18f66b1296a750d0825b7f |
|
BLAKE2b-256 | c1c011e8ab8b190dcfcd73e2747b7d9173ee1a867cffa6f9a1f90bb1c09666c9 |
Hashes for rpgPy-0.15.10-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6ca48c5d92e59fb8d89e7860e4153f7fe6ab54fc882f0d00d7f9c2a8ecabaff |
|
MD5 | 705becc1f3e8a707667b7ad96b813d91 |
|
BLAKE2b-256 | db13c4bf39e5ceae1b7d6af133869d142d24047a203ab1f1c8381439485c224f |
Hashes for rpgPy-0.15.10-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23b631aaa81c5d3120cb4a1d090047a16a8f7457c675292e5675762d550d07b3 |
|
MD5 | 800dd92c34dd7d1b1b9867ee246633d3 |
|
BLAKE2b-256 | a763fd46bbc50140bc9280284d339dd706b33ad6952575118dd378b214dddbc4 |
Hashes for rpgPy-0.15.10-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5269a8e4e546dd314ac0ce5e30c9f90b2f18a8cddcf7221513e373271ce40d0d |
|
MD5 | 7655b70577c2cb0eee105894a967761a |
|
BLAKE2b-256 | 8052609478b6b364c352bc0e3a9ef9228be300fb6685b40096c753b5d072a094 |
Hashes for rpgPy-0.15.10-pp310-pypy310_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e69dfe9a4b0b93400fc06ea047fe8569f60b216394570bd206c1e3c30f428e3 |
|
MD5 | 162d3dfca58831b1b7f823195812c66a |
|
BLAKE2b-256 | 84544be1e0176623e8239704fa447fb342aff4ca86c1db5c826ecdaed4fb1115 |
Hashes for rpgPy-0.15.10-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 682ca119b58bad700122505e861ebb6d86ebe4ee3faf3cd02660a1f7eb3e8cd5 |
|
MD5 | e10acee16f9b4825703c24a0072e2501 |
|
BLAKE2b-256 | d4656be532d0c187ed14838f4b60d02301ac11b4fa5fa6b2a92ee5f821d4c9ed |
Hashes for rpgPy-0.15.10-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 809cd35d2af3991f67396c083cb877bf7cd21f7065cd9a3d3252a0b199ade057 |
|
MD5 | 9e48b83d07273f13ca7ff814e88eae5d |
|
BLAKE2b-256 | d27731df7713eec6b27c63895375d37026fd89a3d9335d069c17f6965d306d8d |
Hashes for rpgPy-0.15.10-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a850e7ba59c23690db045098616d3c8188a9aa8c40471852bf14cba97749e259 |
|
MD5 | 480672d04af15d2b9596071067fa4a75 |
|
BLAKE2b-256 | 6de544715a87bbe709e4fc4dea155241010e8088042ae1dd08453b9346bb3b61 |
Hashes for rpgPy-0.15.10-cp312-cp312-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c919958f259ccb35d683e019f4fbf0379fb580d6d90527e6854d51e12a02434b |
|
MD5 | c2de5383f9b07331fe6919c742a08dae |
|
BLAKE2b-256 | e3d05bdf96e1a87d4f9b6aafe8c09dae8d69477357191342b734f8fe0a2d6b34 |
Hashes for rpgPy-0.15.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a97dc6fba51b47198d4e2a6506ba57e6ba15056104d25cea87415d6a1341ad7 |
|
MD5 | 18929d48aaaaf594f66777a400a1980f |
|
BLAKE2b-256 | 9bd1bbd79f15f3a749eabb51930bc140051ff30c968e8b0dde391f1fec344da7 |
Hashes for rpgPy-0.15.10-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b387fc1231b93d5d78422fa6aa290e15fdbbab592124bc6fd35ea66db870bb0e |
|
MD5 | 413f53373d95e4cc4f84fc21b4d63642 |
|
BLAKE2b-256 | 5017f1164fc15e309fb913dbfa6532677fcc68e68bb91160ad721aeeabd1dd1f |
Hashes for rpgPy-0.15.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 899f6ec3e169585280eb0576118c2da51086bbb1fc3f28c992bac403a50d6635 |
|
MD5 | db58ad2032b6f0ff7f837a1bcb73c30a |
|
BLAKE2b-256 | afbba96219f1d5c47226cddb4ce686778f0df14442956161aee371c3f48153fa |
Hashes for rpgPy-0.15.10-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b1d4827cca1ab143193886d03926b91aea54e11923805e193da9636541c1786 |
|
MD5 | 5d21297b039e02b53eb4f9148a30f2cd |
|
BLAKE2b-256 | 0aef555180c8b68cabe2ca7c6c1c8627fbdbc63eded2808ac8c66825a3d7650a |
Hashes for rpgPy-0.15.10-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 530c278ca72192eb60b5d3bf2f957963f1d74e6ae7730b5e0f3d86a96d1918d7 |
|
MD5 | ae5affc38ec24c8fee4b215d00de40cc |
|
BLAKE2b-256 | 330aabcd3a027e2784195beab2d46868e62186e5eb4a4daf7790f5442b971c4d |
Hashes for rpgPy-0.15.10-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b656bd1520005629540c59d60c42a09c3d43a315142deca296dc3eed9ba708c6 |
|
MD5 | f1201ba3d6fcab0860a2e795111d7964 |
|
BLAKE2b-256 | b0a25ea7e1c95a99b0944972cadf54ec140f978a7c1e137723fa06c8f2218015 |
Hashes for rpgPy-0.15.10-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84e83fed3c9fe9fa0d046a5412ff9e8a24f705815fd391581f363f59313d852e |
|
MD5 | a8ece09688928003c3b0afa2fcce4274 |
|
BLAKE2b-256 | 2aa03dabc4f419284b0b689c9f540258185555ba63ae82a26033612938f8a0cb |
Hashes for rpgPy-0.15.10-cp311-cp311-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1eb62449a78b75b21d3df82af434964a26816ab00a088eb409d3cd8bde32763 |
|
MD5 | 731186109bf1f5ce6d35a77b7cbcda1a |
|
BLAKE2b-256 | 7a8bd20384086953a0a6ed14e42c5ef3089493a1004c170068f0db8a5844f72c |
Hashes for rpgPy-0.15.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb36a77f756ee5b00d0b21825a4f9b511d7b034842edcb3941c2b2393832cf06 |
|
MD5 | 351ccfef2231df3cbbc23c7870f2603a |
|
BLAKE2b-256 | 46f90abe210b8202156060a451957408f05c2c7acea149e1e9e6d10cfca3f900 |
Hashes for rpgPy-0.15.10-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7718d1b8fb46b74b5cdd5bc648dbe9c9771812e80db66a61852c7c697861250 |
|
MD5 | 92c816dc5bf05e7e19cb94b4f377a379 |
|
BLAKE2b-256 | 50147ce346462968b59ede71ad86d3a7c2c80e52d1d2478762c1446f06e263c6 |
Hashes for rpgPy-0.15.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597b34ed6092f9417f15607e42adca2b5a0c893dd2c8e218b14c951c1a55127c |
|
MD5 | cce7cd33dcee6f5fc81e5195b01e4782 |
|
BLAKE2b-256 | d4752b60d5c4cc3661c57ac926d6b079f502a24ec35ee2017b40cc0ad5b0a4ff |
Hashes for rpgPy-0.15.10-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1e644893a7684e22b5ef02a6cbe21437d92e722e8932c51d2661abc1a002bef |
|
MD5 | b3dfc133c71f4a6a65f6c5a051d78688 |
|
BLAKE2b-256 | 681752832876acb44bbba75cf5ae235a8a4a30e5887b831474182fe1fec0eff5 |
Hashes for rpgPy-0.15.10-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5817eb70b21e5aaa8c0e811b0d952b6d9ce9ab3f71098a64d7498f4408e6fa24 |
|
MD5 | 773d6ce124aca528c61eba007220a76d |
|
BLAKE2b-256 | 5b42f8ba47506d0ab896cf2fb62d09fb9880637adb2f8ed157367d70f3ce1456 |
Hashes for rpgPy-0.15.10-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39235f9e6135d005d88a2b18fd6725c1a2a54b1d844ad6de567d03a498151cc3 |
|
MD5 | cad1de99355fb2c260ff06729b59d3f3 |
|
BLAKE2b-256 | 3c419be4894cb2c6d44957f06f5d12a254e8236c04b9db1fa76403fcf81b998f |
Hashes for rpgPy-0.15.10-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c68169940b13aa6781ca021efd542d2add9fa567d3ca9d7ea90ac52199a863c |
|
MD5 | 58b050c05f4811d010dab025d54eda50 |
|
BLAKE2b-256 | 64536a1496385f036c8c2485c466d25b3255dc4231cfcb60e409f051b7cfcb83 |
Hashes for rpgPy-0.15.10-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d138ae781acd9096cf66fe545823771e13316777482ad1bbc4fefd8c7cd4b219 |
|
MD5 | 51091c6240b2376f3a2e781c076be6bf |
|
BLAKE2b-256 | 18e37421cf4586fe102bd48ba1d45f5b3139b26ad169c36d9b38d07598edd601 |
Hashes for rpgPy-0.15.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a1dbd053cddcd31cc19146cc9ad4bf7bc6894f17f0b0a6e1dff353fbcb17105 |
|
MD5 | b217330032993d7fb8a59a4690b83f1a |
|
BLAKE2b-256 | 2969eef38af9267d456e46e100b47027c44033f1b5836f3f8e0f12aac26983d8 |
Hashes for rpgPy-0.15.10-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8cdca6dabe068a128e47fa38e7ee781a096436091015d1e49346dd2641a8367 |
|
MD5 | 8f0d4d02b16a747a902db732c043c73f |
|
BLAKE2b-256 | 9706cbbb51902ffe47037540acb33b1af722187bd25afd8609d437be2029d3df |
Hashes for rpgPy-0.15.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be842df188e41b3ad081aa7d26b3d29c0859c3bbc953d252e5533866bb7eb3d6 |
|
MD5 | 7d31e610c6326f10d197403b573bb83d |
|
BLAKE2b-256 | 5843c0b07f6bbc5e06e56c2abf0597ef9766b77c4217288dc4b8a4d88481bc5f |
Hashes for rpgPy-0.15.10-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ab9dee74da0e6c7f4412e4c6fdeebb1113a349d1ffb3cf5af99ffcfd2aca811 |
|
MD5 | 2a3a0514e37e2d4a1c96b576041dd04e |
|
BLAKE2b-256 | 75a7d4ae2a18a37e4f9972dd5861a8f06c4bcb99d94f75848d67b5106f794b1e |