Wind retrievel for RPG radar¶
lidarwind is the package name used to retrieve wind profiles from the radar PPI scans. The package was initially developed to process wind lidar data (https://doi.org/10.21105/joss.04852). Because the physical principle of retrieving wind from lidar and radar observations is the same, lidarwind was extended to support the RPG radar data. Below, you will find an example of lidarwind applied to RPG PPI radar data.
You can find more information about lidarwind at: https://lidarwind.readthedocs.io/
Steps:¶
- Dependence installation
- Importing the required packages
- Defining useful functions
- Getting sample data
- Retrieving wind
- Visualising the results
Step 1: Dependence installation¶
The cell below installs an additional package required by lidarwind.
pip install lidarwind xarray==2024.3.0 xarray-datatree==0.0.14
Requirement already satisfied: lidarwind in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (1.0.1) Requirement already satisfied: xarray==2024.3.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (2024.3.0) Requirement already satisfied: xarray-datatree==0.0.14 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (0.0.14) Requirement already satisfied: numpy>=1.23 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from xarray==2024.3.0) (2.4.6) Requirement already satisfied: packaging>=22 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from xarray==2024.3.0) (26.2) Requirement already satisfied: pandas>=1.5 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from xarray==2024.3.0) (3.0.3) Requirement already satisfied: xrft>=0.3 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from lidarwind) (1.0.1) Requirement already satisfied: netCDF4>=1.5 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from lidarwind) (1.7.4) Requirement already satisfied: matplotlib>=3.4.3 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from lidarwind) (3.10.9) Requirement already satisfied: click>=8.1.2 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from lidarwind) (8.4.1) Requirement already satisfied: gdown>=4.5.1 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from lidarwind) (6.0.0) Requirement already satisfied: pooch>=1.6 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from lidarwind) (1.9.0) Requirement already satisfied: beautifulsoup4 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from gdown>=4.5.1->lidarwind) (4.14.3) Requirement already satisfied: filelock in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from gdown>=4.5.1->lidarwind) (3.29.0) Requirement already satisfied: requests[socks] in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from gdown>=4.5.1->lidarwind) (2.34.2) Requirement already satisfied: tqdm in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from gdown>=4.5.1->lidarwind) (4.67.3) Requirement already satisfied: contourpy>=1.0.1 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from matplotlib>=3.4.3->lidarwind) (1.3.3) Requirement already satisfied: cycler>=0.10 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from matplotlib>=3.4.3->lidarwind) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from matplotlib>=3.4.3->lidarwind) (4.63.0) Requirement already satisfied: kiwisolver>=1.3.1 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from matplotlib>=3.4.3->lidarwind) (1.5.0) Requirement already satisfied: pillow>=8 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from matplotlib>=3.4.3->lidarwind) (12.2.0) Requirement already satisfied: pyparsing>=3 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from matplotlib>=3.4.3->lidarwind) (3.3.2) Requirement already satisfied: python-dateutil>=2.7 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from matplotlib>=3.4.3->lidarwind) (2.9.0.post0) Requirement already satisfied: cftime in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from netCDF4>=1.5->lidarwind) (1.6.5) Requirement already satisfied: certifi in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from netCDF4>=1.5->lidarwind) (2026.5.20) Requirement already satisfied: platformdirs>=2.5.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from pooch>=1.6->lidarwind) (4.9.6) Requirement already satisfied: six>=1.5 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from python-dateutil>=2.7->matplotlib>=3.4.3->lidarwind) (1.17.0) Requirement already satisfied: charset_normalizer<4,>=2 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (3.4.7) Requirement already satisfied: idna<4,>=2.5 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (3.15) Requirement already satisfied: urllib3<3,>=1.26 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (2.7.0) Requirement already satisfied: dask in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from xrft>=0.3->lidarwind) (2026.3.0) Requirement already satisfied: scipy in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from xrft>=0.3->lidarwind) (1.17.1) Requirement already satisfied: soupsieve>=1.6.1 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from beautifulsoup4->gdown>=4.5.1->lidarwind) (2.8.3) Requirement already satisfied: typing-extensions>=4.0.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from beautifulsoup4->gdown>=4.5.1->lidarwind) (4.15.0) Requirement already satisfied: cloudpickle>=3.0.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from dask->xrft>=0.3->lidarwind) (3.1.2) Requirement already satisfied: fsspec>=2021.09.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from dask->xrft>=0.3->lidarwind) (2026.4.0) Requirement already satisfied: partd>=1.4.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from dask->xrft>=0.3->lidarwind) (1.4.2) Requirement already satisfied: pyyaml>=5.3.1 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from dask->xrft>=0.3->lidarwind) (6.0.3) Requirement already satisfied: toolz>=0.12.0 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from dask->xrft>=0.3->lidarwind) (1.1.0) Requirement already satisfied: locket in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from partd>=1.4.0->dask->xrft>=0.3->lidarwind) (1.0.0) Requirement already satisfied: PySocks!=1.5.7,>=1.5.6 in /Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (1.7.1) Note: you may need to restart the kernel to use updated packages.
pip list | grep xarray
xarray 2024.3.0 xarray-datatree 0.0.14 Note: you may need to restart the kernel to use updated packages.
ATTENTION:¶
After executing the previous cell, you may need to restart the kernel. It is a temporary solution.
Step 2: Importing required packages¶
Here, we import some basic packages usefull for processing the sample data. Later, lidarwind is also imported and its versions is checked; it should be greater or equal to 0.2.4. After, the RPG related modules are also imported.
# genneral imports
import pooch
import xarray as xr
import matplotlib.pyplot as plt
/Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm
# importing the data processing package
import lidarwind
# checking if the version of lidarwind
# it should be equal or greater than 0.2.4
print(f"lidarwind version: {lidarwind.__version__}")
# if there is a ModuleNotFoundError, run de code bellow and then restart the kernel
# pip install "setuptools<82"
/Users/jdiasneto/miniforge3/envs/ccres/lib/python3.14/site-packages/lidarwind/__init__.py:8: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. from pkg_resources import DistributionNotFound, get_distribution
lidarwind version: 1.0.1
# importing the rpg radar related modules
from lidarwind.preprocessing import rpg_radar
from lidarwind.postprocessing import post_rpg_radar
Step 3: Defining the processing function¶
The following is in charge of the main process. Here, the individual PPI files are open and the profiles are retrieved.
def process_one_file(file_name):
"""
Function to process a single radar file
"""
ds = xr.open_dataset(file_name)
ds = rpg_radar.rpg_slanted_radial_velocity_4_fft(ds)
tmp_wind = post_rpg_radar.get_horizontal_wind(ds)
return tmp_wind
Step 4: Getting sample data¶
In this step, we download a sample dataset needed for this example and create a list of all downloaded files.
file_list = pooch.retrieve(
url="doi:10.5281/zenodo.7312960/rpg_sample_ppi.zip",
known_hash="md5:952f7b50985cc8623933fbc18f72fd73",
path="tmp_data",
processor=pooch.Unzip(),
)
file_list = sorted(file_list)
Downloading data from 'doi:10.5281/zenodo.7312960/rpg_sample_ppi.zip' to file '/Users/jdiasneto/Projects/actris_training/tmp_data/07aeaafc2e521ab168c1a2823840fe77-rpg_sample_ppi.zip'. Unzipping contents of '/Users/jdiasneto/Projects/actris_training/tmp_data/07aeaafc2e521ab168c1a2823840fe77-rpg_sample_ppi.zip' to '/Users/jdiasneto/Projects/actris_training/tmp_data/07aeaafc2e521ab168c1a2823840fe77-rpg_sample_ppi.zip.unzip'
Step 5: Retrieving wind¶
In this step, the function defined in Step 3 to process the sample files is applied to the file_list defined in Step 4.
%%time
# running the function over the selected files
wind_ds = xr.merge([process_one_file(f) for f in file_list])
CPU times: user 35.6 s, sys: 634 ms, total: 36.2 s Wall time: 36.7 s
Step 6: Visualising the results¶
Finally, in this step, we first have a look at the wind dataset structure and later have a loot at some variables.
# Checking the wind dataset
wind_ds
<xarray.Dataset> Size: 631kB
Dimensions: (range: 339, chirp: 3, mean_time: 42)
Coordinates:
* range (range) float32 1kB 108.0 129.6 ... 1.157e+04
* chirp (chirp) int64 24B 1 2 3
* mean_time (mean_time) datetime64[ns] 336B 2022-05-17T10:...
elevation float32 4B 74.99
freq_azimuth float64 8B 0.002778
azimuth_length int64 8B 72
Data variables:
horizontal_wind_direction (mean_time, range) float64 114kB 82.05 ... nan
horizontal_wind_speed (mean_time, range) float64 114kB 4.536 ... nan
meridional_wind (mean_time, range) float64 114kB -0.6275 ... nan
zonal_wind (mean_time, range) float64 114kB 4.493 ... nan
start_scan (mean_time) datetime64[ns] 336B 2022-05-17T10:...
end_scan (mean_time) datetime64[ns] 336B 2022-05-17T10:...
zdr_max (mean_time, range) float32 57kB 5.533 ... nan
nan_percentual (mean_time, range) float64 114kB 0.0 ... 100.0
chirp_start (mean_time, chirp) float32 504B 111.8 ... 2.03...
chirp_end (mean_time, chirp) float32 504B 581.3 ... 1.19...
chirp_azimuth_bias (mean_time, chirp) float64 1kB 0.0 0.0 ... 0.0
azm_seq (mean_time) float64 336B 1.0 -1.0 ... 1.0 -1.0# plotting wind speed and direction
plt.figure(figsize=(10,6))
wind_ds.horizontal_wind_speed.where(wind_ds.nan_percentual<50).plot(y="range", cmap="turbo", vmin=0, vmax=20)
plt.show()
plt.figure(figsize=(10,6))
wind_ds.horizontal_wind_direction.where(wind_ds.nan_percentual<50).plot(y="range", cmap="hsv", vmin=0, vmax=360)
plt.show()
# plotting the maximum ZDR from each scan
plt.figure(figsize=(10,6))
wind_ds.zdr_max.where(wind_ds.nan_percentual<50).plot(y="range", cmap="turbo", vmin=0, vmax=7)
plt.show()
In this last cell, you can save the retrieved wind data as a NetCDF file. To do it, you just need to uncomment the line below.
# wind_ds=to_netcdf('retrieved_wind.nc')