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.5-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e7222ef2eb5cc660d4a80063de23e3cfdac1b5f394279c1dbba88c66071f1cf |
|
MD5 | 8bb4d467a209fdf5df9818763e405e69 |
|
BLAKE2b-256 | 9f9687b9bd97d9f39f13b899a91085be8acc9dc07eb5ea0029a7de69073cbdfd |
Hashes for rpgPy-0.15.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 725525c27aa10ef0a478fd8eea0843a2fc458ea77fe73aeeccafd5e26d2636c1 |
|
MD5 | 04a45baf2e995d54cdf05e51554e220a |
|
BLAKE2b-256 | c86a3255e0970fc03cfa4d935bfdff08476be6b351abbc6e6d776b83e05d62b4 |
Hashes for rpgPy-0.15.5-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab41a57446a0aff4ec32e3fa54b328adc8fc0514f6bd1f45dbdd4bf1a63d9d1e |
|
MD5 | 8151db9b3c2a354910324d274bb15d6a |
|
BLAKE2b-256 | 3ec837ec45dd957e94910f4012e7fe4c5241b14c17a780ddfae7ed10df8506be |
Hashes for rpgPy-0.15.5-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b79f87ff7d8cf5fdad3a2b0f4281ced7647bce9bfcb57b5056fff57aa9e965c7 |
|
MD5 | 1175d73e31db5ad94a11d4aba9a16b17 |
|
BLAKE2b-256 | 5f4e62457feb5cb58bb25259cb0d7282c436175e250d8188034e72c387df3b24 |
Hashes for rpgPy-0.15.5-pp310-pypy310_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e9c8c5dc1cbe803bfb0314b9c818ee15ec61f1f27a556821c7ee24b23073d42 |
|
MD5 | a59fbfb11eb442d63c5b993c92647d7f |
|
BLAKE2b-256 | eab34b045fd194bf8322b57c43cadb76634b4e506e21ef7bcb7098919db5a144 |
Hashes for rpgPy-0.15.5-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7380a73c461ee7db20716cc61ace5099da7702d19dc25ab91bd7b0cb7e50796 |
|
MD5 | 0a8956ed9466bbb4781b765bfeb8825c |
|
BLAKE2b-256 | e684ff3ec25d1949711378824aeb524238c5297bd391f92b7f3840f7d45f23a0 |
Hashes for rpgPy-0.15.5-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc394b0fc36b3faca78c0ad3dec39f3e105760999776cc4b533975f4f49807c0 |
|
MD5 | 4957aa8160ef1bb76407cf3f2d633443 |
|
BLAKE2b-256 | 3099b4ac8e5949edb5b589d1ed3f89ee0c739d5ae11026af38a07f16c7ac8a92 |
Hashes for rpgPy-0.15.5-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39e20295ef27a6dc6de0160e474f08eaa3cf3373ca8bcd513d093a84c59811d9 |
|
MD5 | 040101b9e74f4eaaaa41615f2ee8cbe9 |
|
BLAKE2b-256 | e8a2d2380e451bd27922b8cd8a0de18cd1617c55b1b52ea6eeb13a670b079f78 |
Hashes for rpgPy-0.15.5-cp312-cp312-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f606f1d606d3f7a2cb9b6d6fdfa4edc44d518ed598c07bcc23576668d4f2a845 |
|
MD5 | a67911b45cbffa7645eab44e661044e0 |
|
BLAKE2b-256 | 52e9a2d3a109ab30ccf3df49caf28f707d5d91cba305840564a12d0516220097 |
Hashes for rpgPy-0.15.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10587fca7ddc229bb2864e937469976f6d81570faaf6d1733e23d34ce31058ca |
|
MD5 | 9d28b40f30612e8921e8af8c078e3b31 |
|
BLAKE2b-256 | af0e548bee2fdddbbbe03c80e207fa8847b0ab93514a641d419880ec64ffcb5f |
Hashes for rpgPy-0.15.5-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5a4d72352ad2d91fa62ddcb45d25e0df3ddcc61fa1db8ce50ae7a5567717341 |
|
MD5 | bf59ead7e795c35a3f18f99e1ae25851 |
|
BLAKE2b-256 | 5cc4ee30e8117037906235a4b70fb9f4f69438606e724083158c3c0c387db166 |
Hashes for rpgPy-0.15.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eab8a5be35304d952e119afdcc98614c6c50a66b6cef4ecdb9cb265078c5ed8b |
|
MD5 | 85b18f41d4bb0e3baf3c19b91367718f |
|
BLAKE2b-256 | b767cc7cfc3989d8009b71419d4df8fe89eb9789cbeb578e165b4681b0102feb |
Hashes for rpgPy-0.15.5-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a126a732847efa1f4b8ba7c4a2f161b82a1d29083a8ed12c754047c822818dc7 |
|
MD5 | 8e7be79976e7c49f7e5f4738df97aa9f |
|
BLAKE2b-256 | d4d5b6c6c5daa67ff32048760415240e38d14b2e51356686822612d59d9c7aeb |
Hashes for rpgPy-0.15.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ad0b4f8039aa0800665e51a31294de8499ff7219a3af49211dff175ea2ff5d |
|
MD5 | 60a7e371f610c72dbcaf8b108d216b09 |
|
BLAKE2b-256 | 94f69d6ab94594d6208137311025d079a7445aeb5442130ef3cb321ac0825d37 |
Hashes for rpgPy-0.15.5-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9a272b68f8f3028aba292c2830a10bdcd5237c2ad15ac4960d697560d4d6470 |
|
MD5 | 3a53d2f547c2a13800b7338d9b42e97a |
|
BLAKE2b-256 | 5fcd1dbfbb03d02841c2507694ccfc14a864a45cbc4b58e27f9e53e22b4157fd |
Hashes for rpgPy-0.15.5-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe98c350a52130a1d59e780eecc795653be399e34efdd0fa91ae6aa717f9d4bd |
|
MD5 | 6b6af4aa66e82879410669662dc8c3c0 |
|
BLAKE2b-256 | b056fc131f1519d5cbf7af4cfd9ab2d58e8343c3a17a29b7a8cdf22aa1bc9fa1 |
Hashes for rpgPy-0.15.5-cp311-cp311-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3e460114cd337ef4402f18ffdf1135d40f027a80b288682331df7cee3fd769 |
|
MD5 | 9c2eb3de804bcf8b63cf1f51fc114366 |
|
BLAKE2b-256 | 500bcce4379c4396c9e3092807793ecfa11d133ca9260f1139d8f35472ed32c3 |
Hashes for rpgPy-0.15.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de87cfbee86eb093b8963a0e384214ab0c0fc121d32aa984a9b2149fcf394c27 |
|
MD5 | 3e1f641214fceaf5cdc9b931e1a58800 |
|
BLAKE2b-256 | a7dac8a0243f2e434327110dabd46378e090d2d4257280a45229875e4c2a6204 |
Hashes for rpgPy-0.15.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 192580952519f3cbce6fd0852317f876211644f6348c783c58f5b2f934c05074 |
|
MD5 | 0e71c71671b2aa64baa3ff92f4d8142c |
|
BLAKE2b-256 | d84c4354be7cb24a0f887116daf514fedfe1736e73941be36b830868535f1ad4 |
Hashes for rpgPy-0.15.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bf3593b3b446ba031d9b8d5ba5823c3ba14a6a1f578e0aeac3bf031dbef80b2 |
|
MD5 | aab68f8b559a9f6e2d086d4c8e94845b |
|
BLAKE2b-256 | 7fdbeacd1e40f5a583e730e6ea370eb25977964b8bdd5a153cd13827c808aeb9 |
Hashes for rpgPy-0.15.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faf3c6725c595557637c8bf8f2ac42a36500fcc2eaeed4910564177b38f0ad56 |
|
MD5 | c098828aaf232276de72d187411a11e5 |
|
BLAKE2b-256 | a532fe403b11922e23163e3921d483cc9900f3d05137caa1a02bc190accad8de |
Hashes for rpgPy-0.15.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0bf3f66ff8e76926f68b31ae912aaa8c8e3671cb85c66e4f48e1b9a9f8ce976 |
|
MD5 | d2fca90788471c7db231ab1387e03139 |
|
BLAKE2b-256 | 1ae85cc68b260ebb318e9742c94f9bd537fe2e391d88b4716d5b3ec9b148af88 |
Hashes for rpgPy-0.15.5-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e079f9efb67650de758e1bcba6433b33500226d6ba25bfe6f802b71d091f72ed |
|
MD5 | f0fdc15f309f30da947c4bb84e17cc24 |
|
BLAKE2b-256 | 1485927ffd2df833daf67b6843088d07dcc3774430f3ff68eb38aaa6cadad6a9 |
Hashes for rpgPy-0.15.5-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3adf9c836f56b6cbea6197c39711caaad907b0c43671c530cacaf4c2bea2d5b3 |
|
MD5 | 5b0ef04d556b273acca6be0cd8d3bf4e |
|
BLAKE2b-256 | b3452c7b04521057d06cc32612ad18cf1de293b53df81b995b5fd16c33018fac |
Hashes for rpgPy-0.15.5-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9cc6da113d2ca32c7d0b986c2823c2327d35316ebac2348d1583c395aff2615 |
|
MD5 | fb4a63e2a1562d6ac4280b1a0fe4d567 |
|
BLAKE2b-256 | 90016d97586987bd6a180d133d2be70ee4a565d3d467e046b2efa1fa896868e9 |
Hashes for rpgPy-0.15.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62a71957effb8dba78cc5fb07924c97ff4118fda9c1f4687803d3ade0c787562 |
|
MD5 | 8f32f9d5fee0097c54a05ef85ddc9529 |
|
BLAKE2b-256 | a2cbb6d6dd163c6ae50c47dd18e5659555aea3eba612dd3b8b6d5be64513ca88 |
Hashes for rpgPy-0.15.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16bc9bcd98384dd32b26f290ef575dbae9f53ce16f66c41f6b6df9529794e768 |
|
MD5 | 1ff0e7569e7b5004aef036aa276ab6ec |
|
BLAKE2b-256 | b04a0618df4a1ffef85825b32d7dbe70e8e6fc87371bbc1e7d127b4592a6280c |
Hashes for rpgPy-0.15.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a197240a1b42924238c409a532b9a69eb21d2f807bd17b354f29ea973f703c7e |
|
MD5 | 78d032307d2ec058eb80f093b0e477e7 |
|
BLAKE2b-256 | d390aaf9e8b6677ad08208515583cb64930cdb8214b37f0febe36e4fcaeedd5e |
Hashes for rpgPy-0.15.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b31277bcc86d4c64b9835a70bbe778ab087d295df644400d7e2907e60d876dd1 |
|
MD5 | 10a120341f2ef12226d90ce1ac4a361c |
|
BLAKE2b-256 | 153d23ed8b9dcec75acddcdd7c5e99f236d75db08f5fb3f2f9ef383d8baf3d00 |