Package: rpgPy
rpgPyRpgPy is a Python / Cython software forReadingRPG cloud radarLevel 0 and Level 1 binary filesCalculating spectral moments from RPG Level 0 dataConverting RPG binary data tonetCDF4formatInstallationFrom PyPIpython3 -m pip install rpgpyNOTE: A C-compiler is required because the Cython code is compiled locally during installation.
If you get an error about missingPython.h, you need to install the missing header files with$ apt install python3-dev(or similar).From sourcegit 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 --inplaceQuickstartConverting RPG binary files into netCDF4>>>fromrpgpyimportrpg2nc>>>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')API reference ofrpg2ncConverting multiple files individuallyMultiple RPG files can be converted into corresponding individual netCDF4 files usingrpg2nc_multi.>>>fromrpgpyimportrpg2nc_multi>>>filenames=rpg2nc_multi(file_directory='/path/to/files')Default functionality is that every file with an extension.LV0,.lv0,.LV1or.lv1in every subdirectory of the specified path will be converted.API reference ofrpg2nc_multiCreating custom Level 1 netCDF4 filerpgpycan estimate spectral moments from Level 0 data. The estimation is based on the most
prominent peak of each time / range point.>>>fromrpgpyimportspectra2nc>>>spectra2nc('rpg-data.LV0','level1.nc')This calculates spectral moments from Level 0 data and writes the results in a netCDF4 file.API reference ofspectra2ncReading RPG binary fileIf you don't need the netCDF4 file:>>>fromrpgpyimportread_rpg>>>header,data=read_rpg('rpg-data.LV1')API reference ofread_rpgCalculating spectral moments>>>fromrpgpyimportread_rpg,spectra2moments>>>header,data=read_rpg('rpg-data.LV0')>>>moments=spectra2moments(data,header)This works only with Level 0 data.API reference ofspectra2momentsAPI referenceIndexrpg2ncrpg2nc_multispectra2ncread_rpgspectra2momentsrpg2ncConvert RPG cloud radar file(s) into single netCDF file.rpg2nc(path_to_files,output_file,**kwargs)Positional arguments:NameTypeDescriptionpath_to_filesstr|pathlib.PathFilename of single file, or multiple files identified using a wildcard, e.g.,/foo/bar/*.LV0.output_filestr|pathlib.PathOutput file name.Keyword arguments:NameTypeDefault valueDescriptionglobal_attrdictNoneAdditional global attributes.rpg2nc_multiConvert 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 directoryFiles with the suffix.LV0,.lv0,.LV1or.lv1suffix are convertednetCDF4 files are written to the current working directoryKeyword arguments:NameTypeDefault valueDescriptionfile_directorystr|pathlib.Pathcurrent working directoryRoot path of the search.output_directorystr|pathlib.Pathcurrent working directoryPath name where the netCDF4 files are written.include_lv0boolTrueIfFalse, excludes Level 0 files.recursiveboolTrueIfFalse, does not search input files recursively.base_namestrNoneOptional filename prefix for the converted files.global_attrdictNoneAdditional global attributes.Returns:TypeDescriptionlistFull paths of the successfully created netCDF files.spectra2ncCalculate moments from RPG Level 0 spectra and write a netCDF4 file.spectra2nc(input_file,output_file,**kwargs)Positional arguments:NameTypeDescriptioninput_filestr|pathlib.PathFilename of RGP Level 0 file.output_filestr|pathlib.PathOutput file name.Keyword arguments:NameTypeDefault valueDescriptionglobal_attrdictNoneAdditional global attributes.n_points_minint4Minimum number of points in a proper spectral line.read_rpgRead RPG cloud radar binary file.header,data=read_rpg(filename,**kwargs)Positional arguments:NameTypeDescriptionfilenamestr|pathlib.PathFilename of RPG cloud radar Level 1 or Level 0 binary file.Keyword arguments:NameTypeDefault valueDescriptionrpg_namesboolTrueIfTrue, uses RPG manual names in the returned dictionary, else uses more human-readable names.Returns:TypeDescriptiontuple2-element tuple containingheaderanddatadictionary.spectra2momentsCalculate spectral moments from Level 0 spectral data. A call toread_rpgis required before using this function.moments=spectra2moments(data,header,**kwargs)Positional arguments:NameTypeDescriptiondatadictLevel 0 data dictionary fromread_rpg.headerdictLevel 0 header dictionary fromread_rpg.Keyword arguments:NameTypeDefault valueDescriptionspec_varstr"TotSpec"Spectral variable to be analyzed:"TotSpec"or"HSpec".fill_valuefloat-999.0Value for the clear sky data points.n_points_minint4Minimum number of points in a proper spectral line.Returns:TypeDescriptiondictDictionary containingZe(reflectivity),MeanVel(mean velocity),SpecWidth(spectral width),Skewn(skewness) andKurt(kurtosis), which are 2D numpy arrays (time x range).DevelopmentInstall test-dependencies andpre-commithooks:python3 -m pip install -e .[test,dev]
pre-commit installCompile Cython (repeat if you change.pyxfiles):python3 setup.py build_ext --inplaceTestsRun unit tests:pytestRun end-to-end tests:for f in tests/e2e/*/*runner.py; do $f; doneForcepre-commitchecks of all files:pre-commit run --allPerformanceFor reading RPG binary files, depending on the radar settings, RpgPy is roughly 20-30 times faster
than equivalent native Python or Matlab implementations.LicenseMIT