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 and converting to netCDF4.
Installation
From PyPI
$ python3 -m pip install rpgpy
NOTE: You need to have a C-compiler because Cython code is compiled locally during the rpgPy installation.
If you get an error about missing Python.h
, you need to install the missing header files with $ sudo apt install python3-dev
(or similar).
From source
$ git clone https://github.com/actris-cloudnet/rpgpy/
$ cd rpgpy/
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ python3 -m pip install --upgrade pip
(venv) $ python3 -m pip install .
(venv) $ python3 setup.py build_ext --inplace
Usage
Reading RPG binary file
>>> from rpgpy import read_rpg
>>> header, data = read_rpg('rpg_file.LV0')
By default, the header
and data
dictionary key names are taken from the RPG manual. Optionally,
more explicit key names can be chosen:
>>> header, data = read_rpg('rpg_file.LV0', rpg_names=False)
Converting single file to single netCDF4
>>> from rpgpy import rpg2nc
>>> rpg2nc('rpg_file.LV0', 'rpg_file.nc')
This works for both Level 0 and Level 1 files.
In addition to the default global attributes, it is possible to provide additional ones via a dictionary:
>>> attr = {'attr1': 'foo', 'attr2': 42}
>>> rpg2nc('rpg_file.LV0', 'rpg_file.nc', global_attr=attr)
Converting multiple files to single netCDF4
Several RPG files can be concatenated to singe netCDF file using wildcard. With Level 0 data, this can lead to a very large netCDF file.
>>> rpg2nc('/path/to/files/*.LV0', 'huge_file.nc')
Converting multiple files to corresponding netCDF4 files
Several RPG files can be converted to corresponding individual netCDF4 files using rpg2nc_multi
function.
Every file with extension .LV0
, .lv0
, .LV1
or .lv1
in every subdirectory of the specified path will be converted.
Optionally, the user can exclude Level 0 files by switching the argument of include_lv0
parameter to False
.
>>> from rpgpy import rpg2nc_multi
>>> rpg2nc_multi('/path/to/myfiles', include_lv0=True, base_name"foo")
If no path is made explicit, the function will by default take as argument the current directory
and write the converted files in it.
If the parameter base_name
is specified, the function will rename the new files as basename_oldname
.
Tests
Run unit tests:
(venv) $ pytest
Run end-to-end tests:
(venv) $ for f in tests/e2e/*/main.py; do $f; done
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.