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.6-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22667960dadfbee0899aa0a77a60b5a9f2f54fd1fe7d9d4d34fadc709283df4d |
|
MD5 | 8ae95bd17735e535c3c28e587646ecc1 |
|
BLAKE2b-256 | b5879a037cc984431cfb1b102ecd3056118cc3ae641def462b03f32ec35da9b7 |
Hashes for rpgPy-0.15.6-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94ed4c44ec3dbd9dbe1f6124939de0101f9f036b51102654a33877950e0b6dd4 |
|
MD5 | fdae684b7d84b5afb6a8ad72b23f2683 |
|
BLAKE2b-256 | 667d4d36ddfb3fa52cd48ff2facbb6e24acb637ca9e863e0e001681c16fcdaad |
Hashes for rpgPy-0.15.6-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faa6005632a12664f614bd10ce16dc2ab54fc3f987e3d2a620317283b9e6a506 |
|
MD5 | 73aaea7cf69f41c221055e0be99e5440 |
|
BLAKE2b-256 | a66ce563cb471811d4cb27f294f98dae852f0299c0e363bff5ccdc0b0cb020f0 |
Hashes for rpgPy-0.15.6-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cf8ddd2afa557dbb88d5d39d5ee240c8575eefa9af90dc0ba7f4fed80ff88b3 |
|
MD5 | 7d52b7b4bbb8a37e8d24cc7677d93cd1 |
|
BLAKE2b-256 | a05428e1cbc74025d97472cb146270b7a9e196c6fc50cc60aa3a273bd07c3f36 |
Hashes for rpgPy-0.15.6-pp310-pypy310_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 520a60c9da90fa134fef847f2b2177fdfae4398b8df0f9bd3467823fe5973dcb |
|
MD5 | 3c43a2951c2b4dc9a5a8d80b49fbb2d7 |
|
BLAKE2b-256 | 2c3f9f26154377fe5c4658635cb94e4b79416e9836227d6498274cfd31e3565c |
Hashes for rpgPy-0.15.6-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b10c1b73fac14a95f25457263d0d364eeee120be0bb9a660d84a206c7514697 |
|
MD5 | fdaf96e0e0e70665c19d66a7a187a2c3 |
|
BLAKE2b-256 | cccad45f049ad0ea2bcc7ef7b546d249be7b5c727c4d40a6fa3e6e74ea43c8f0 |
Hashes for rpgPy-0.15.6-cp312-cp312-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c5f8409bc5264f4b826848e0b456b6fbec5ed565266efe14f1ac4cbc7fde783 |
|
MD5 | 157bb86af2e9f653071b45bd255744e5 |
|
BLAKE2b-256 | e6713f7b8261bd13912e53a5d3c96f363b4c9c0855b583013017fdc1d6912076 |
Hashes for rpgPy-0.15.6-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1242999fad3eca0e5ddc38faea7b8e449bb2ce4777f5a89826aa1378aa6508f |
|
MD5 | 5143f968c448a7f338fe6f8747f62970 |
|
BLAKE2b-256 | bd6cbd34f937c48a36ff3b151d59da7a7a8fc0d1b40a01225b0b9682a2e71a1a |
Hashes for rpgPy-0.15.6-cp312-cp312-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f52493e2bc681bd5cb836a0302e7e99cbc76807bc8538fa077e1375d60342c3 |
|
MD5 | 54c3d57945519da08e59aea324a1f2e5 |
|
BLAKE2b-256 | dae69dadf9ef6dddcb9f3f42644a091d16f6f5aae57b76f558cbc6ca01a144ba |
Hashes for rpgPy-0.15.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 209a060fce9dd80429322b35013f48c016ed3061cf3226265a5f36c58c5b43d8 |
|
MD5 | bc33be6511718f166acadbfb425814f1 |
|
BLAKE2b-256 | 21a5504fd3e788282bb1d504b2337d9037c27d88c69fdf1c5f9ce8c125ece449 |
Hashes for rpgPy-0.15.6-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70ded4384512cf37ec5530959de0579d85fe0682dd406b982591e70c7ac8cf2b |
|
MD5 | de0064855597a856baa02f4894f574d9 |
|
BLAKE2b-256 | 50ac7fff6c8acb3fa1dc28c6e15e09bbfe6c3704057c2f1b0c21235fa866a4ec |
Hashes for rpgPy-0.15.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78c32d350a48bdecb5fe8e277c406eaa8b1e40715c53669972262d1eb25eb6ca |
|
MD5 | 6656af7f39254a0a10b24e59f90d86fe |
|
BLAKE2b-256 | 4853b07bb19c26e399c456a1eaa9c60f34e24ef349746320f303d67174d9e8a6 |
Hashes for rpgPy-0.15.6-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 699449122e3d8bb55f6ae83f27d3f76fa924332eafee3ff318ee8af81250547f |
|
MD5 | 1b7c849c8d713bd97ae712b3cc00011d |
|
BLAKE2b-256 | faa60c0215e0c51aa7a14a0c6fcc07fc6b8816f08586a30226024d147d7f694e |
Hashes for rpgPy-0.15.6-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb5889dc2c1747ea33adfaf79e4c5ddf3cfdc8775b0a59889e48bba950111a42 |
|
MD5 | 2bf4ec945bbe931490c14e9f65fdea90 |
|
BLAKE2b-256 | af5e934ad629f94a181a1f23c15ed13707073423aa6f5c0be1072d77adb06a81 |
Hashes for rpgPy-0.15.6-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08f75bb2afccb151df24f1dce804f743e88e2fb959722406a0c9af2e27edaa8a |
|
MD5 | 8190e62c4eb786cd73af2e39d233c0d7 |
|
BLAKE2b-256 | f82e6db9518d6caf698a40a087092d7d1b0ddbbcd39da0914dc08c0881ae89ca |
Hashes for rpgPy-0.15.6-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 623329403a1e22e2f9c7d12520b361c21de25de425ac4b38f8a4c8edfc5a2611 |
|
MD5 | ef89b9e4b435b58ece62c65c0661ce24 |
|
BLAKE2b-256 | e240496b553c72b4aabd2364e8463f45cf6256e136bbefae68237cad1c348fc5 |
Hashes for rpgPy-0.15.6-cp311-cp311-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cee75081f7ab15b0412dac77731bb8e22eda311dc07a7c9bcc9c01de767832d |
|
MD5 | c601a7da1b070858e8af7afe3f3ffa50 |
|
BLAKE2b-256 | f7f56b6867ac402feb16abf0c0853de9f7e0374b1864502cfe5ab8146f904b80 |
Hashes for rpgPy-0.15.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b84fd33d41d7be7bea6e7609e70af59fe32b4c89e8f421381cecc074a54cd916 |
|
MD5 | ed663163491f065393c5b9b49f03a9df |
|
BLAKE2b-256 | f080bc6ee6b2c32ff94e5b96d921e2a32f657a238ebafb24d61daecde296762d |
Hashes for rpgPy-0.15.6-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3dcc0e75df8cc31c0a52beafb3f527063b93b1892f29e0246a55497a4e3b8d |
|
MD5 | cc2e44df692c1c59c3aef259213d2d98 |
|
BLAKE2b-256 | 0303540fecc2d1e2e778eed06d8b38f831f08f5a7b5fb7e092fed26f0ca45122 |
Hashes for rpgPy-0.15.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caec558e496931885325f977684ebce6cb447dc54911e38f9a6eb8fb89400f93 |
|
MD5 | 440ca1cf1822f771e4992f5bec3c1ce6 |
|
BLAKE2b-256 | c5ba4832c9594b93d5c3869c9470df3b1c7e17c4f2d8e2ab1a8276d7f038a48d |
Hashes for rpgPy-0.15.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e4155b12b641c70894f47809ae35016d0291af7a71514e6720e98844ad90c7 |
|
MD5 | 368905ef706d754abf9fd0480932348b |
|
BLAKE2b-256 | 3d714c570696a1ac201a9683edb961d9f55745a47e9c89b96a84e89690c98654 |
Hashes for rpgPy-0.15.6-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e623c69a6e8d6c0ebb15c2990a85d3c6d5eedb9a5bc3c54e7bb7cbda9fb08f3 |
|
MD5 | 393b392d8858356595eb991e7e379a39 |
|
BLAKE2b-256 | 1826821625f136ab65e170215efacad53fda05cbc72ba31e7825cd3c03d57315 |
Hashes for rpgPy-0.15.6-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d9552aaf8b6dde728a737059fb362626ca08c5c1c079b376a6e1cdd137ca023 |
|
MD5 | 3504da3eea20943c89a62f7ea485f500 |
|
BLAKE2b-256 | ed663785049e64e1fedac402c2134a475ac4c079b535be0fb8d48885d5e26946 |
Hashes for rpgPy-0.15.6-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 134a0374a8029f31d1ff92ce972a520074d74297992e2f45cd9b2bb5b79a8958 |
|
MD5 | 1b24bb30fb129a87e4adff8196c153ae |
|
BLAKE2b-256 | d2042f9526c01b7265c48455746b47f5a428efb599dfd4e84947f85a61bdee1f |
Hashes for rpgPy-0.15.6-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfeeb6e1e1ef25b73d4abe807f83b020429fd46c8089127900ffcaf93232ae51 |
|
MD5 | 97c255a98022a6790ba45f760a37e4a3 |
|
BLAKE2b-256 | 9bb21c3792ad6b87856ae9d0e75d1e69dcbe6e091222bf6fa6c61d835cb037e3 |
Hashes for rpgPy-0.15.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6764014ba0a94c1399288797638c826c89ab123af9b4a59f88cd4fa23115672 |
|
MD5 | 6b18043202f2a086e2185319d1aa940b |
|
BLAKE2b-256 | 42da174f297939d321af5c1d6575a41666d6ad0e9c3f59197e1808e4e8633653 |
Hashes for rpgPy-0.15.6-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73b9df674cad9bb063873c5b6e30a311711cfc909a564b472ba50d8b6f1ce541 |
|
MD5 | beee19185c9c140a5de7578f86db98ce |
|
BLAKE2b-256 | 68fd93a1f58b80aefe130aaaab0804e63c86a4a08afd7ab9e301614edea6a5e0 |
Hashes for rpgPy-0.15.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6947618d8d4a36fa460e4324cb247de9e1e18fdf70c75561a960f06678204e1b |
|
MD5 | 3eab43047ccc7b0e84c49daa6d5efb95 |
|
BLAKE2b-256 | c3865e4c4c57edff2c9362053717b21ece9a3225f5a5c641109dba074316bf00 |
Hashes for rpgPy-0.15.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5621f70ff4af66d9e3cfafd8157eac46db0463e93ed4c5348ad7eb35b6067a3c |
|
MD5 | 61726c36f80347bd0d432232e0f22bbe |
|
BLAKE2b-256 | a69a7442c1be8fc45808c5949b18e1ef911330548ba0459f30e26280a65dda9f |