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, lidar wind 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:

  1. Dependence installation

  2. Importing the required packages

  3. Defining useful functions

  4. Getting sample data

  5. Retrieving wind

  6. Visualising the results

Step 1: Dependence installation

The cell below installs an additional package required by lidarwind.

[1]:
pip install lidarwind xarray-datatree==0.0.11
Requirement already satisfied: lidarwind in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (0.2.5.dev27+gd45b3ff.d20240702)
Requirement already satisfied: xarray-datatree==0.0.11 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (0.0.11)
Requirement already satisfied: xarray>=2022.6.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from xarray-datatree==0.0.11) (2024.3.0)
Requirement already satisfied: xrft>=0.3 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.0.1)
Requirement already satisfied: pandas>=1.4 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (2.2.2)
Requirement already satisfied: numpy>=1.22 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.26.4)
Requirement already satisfied: netCDF4>=1.5 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.6.5)
Requirement already satisfied: matplotlib>=3.4.3 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (3.8.4)
Requirement already satisfied: click>=8.1.2 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (8.1.7)
Requirement already satisfied: gdown>=4.5.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (5.1.0)
Requirement already satisfied: pooch>=1.6 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.8.1)
Requirement already satisfied: beautifulsoup4 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from gdown>=4.5.1->lidarwind) (4.12.3)
Requirement already satisfied: filelock in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from gdown>=4.5.1->lidarwind) (3.13.4)
Requirement already satisfied: requests[socks] in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from gdown>=4.5.1->lidarwind) (2.31.0)
Requirement already satisfied: tqdm in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from gdown>=4.5.1->lidarwind) (4.66.2)
Requirement already satisfied: contourpy>=1.0.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (1.2.1)
Requirement already satisfied: cycler>=0.10 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (4.51.0)
Requirement already satisfied: kiwisolver>=1.3.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (1.4.5)
Requirement already satisfied: packaging>=20.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (24.0)
Requirement already satisfied: pillow>=8 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (10.3.0)
Requirement already satisfied: pyparsing>=2.3.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (3.1.2)
Requirement already satisfied: python-dateutil>=2.7 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from matplotlib>=3.4.3->lidarwind) (2.9.0)
Requirement already satisfied: cftime in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from netCDF4>=1.5->lidarwind) (1.6.3)
Requirement already satisfied: certifi in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from netCDF4>=1.5->lidarwind) (2024.6.2)
Requirement already satisfied: pytz>=2020.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from pandas>=1.4->lidarwind) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from pandas>=1.4->lidarwind) (2024.1)
Requirement already satisfied: platformdirs>=2.5.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from pooch>=1.6->lidarwind) (4.2.1)
Requirement already satisfied: dask in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from xrft>=0.3->lidarwind) (2024.4.2)
Requirement already satisfied: scipy in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from xrft>=0.3->lidarwind) (1.13.0)
Requirement already satisfied: six>=1.5 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.4.3->lidarwind) (1.16.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (2.2.1)
Requirement already satisfied: soupsieve>1.2 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from beautifulsoup4->gdown>=4.5.1->lidarwind) (2.5)
Requirement already satisfied: cloudpickle>=1.5.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from dask->xrft>=0.3->lidarwind) (3.0.0)
Requirement already satisfied: fsspec>=2021.09.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from dask->xrft>=0.3->lidarwind) (2024.3.1)
Requirement already satisfied: partd>=1.2.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from dask->xrft>=0.3->lidarwind) (1.4.1)
Requirement already satisfied: pyyaml>=5.3.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from dask->xrft>=0.3->lidarwind) (6.0.1)
Requirement already satisfied: toolz>=0.10.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from dask->xrft>=0.3->lidarwind) (0.12.1)
Requirement already satisfied: importlib-metadata>=4.13.0 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from dask->xrft>=0.3->lidarwind) (7.1.0)
Requirement already satisfied: PySocks!=1.5.7,>=1.5.6 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from requests[socks]->gdown>=4.5.1->lidarwind) (1.7.1)
Requirement already satisfied: zipp>=0.5 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from importlib-metadata>=4.13.0->dask->xrft>=0.3->lidarwind) (3.17.0)
Requirement already satisfied: locket in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from partd>=1.2.0->dask->xrft>=0.3->lidarwind) (1.0.0)
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 in case you get an error message. 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.

[2]:
# genneral imports
import pooch

import xarray as xr
import matplotlib.pyplot as plt
[3]:
# 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__}")
lidarwind version: 0.2.5.dev27+gd45b3ff.d20240702
[4]:
# 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.

[5]:
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.

[6]:
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)

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.

[7]:
%%time

# running the function over the selected files
wind_ds = xr.merge([process_one_file(f) for f in file_list])
CPU times: user 47.2 s, sys: 1.17 s, total: 48.4 s
Wall time: 56.1 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.

[8]:
# Checking the wind dataset
wind_ds
[8]:
<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
[9]:
# 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()
../_images/examples_lidarwind_4_rpg_radar_serial_24_0.png
../_images/examples_lidarwind_4_rpg_radar_serial_24_1.png
[10]:
# 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()
../_images/examples_lidarwind_4_rpg_radar_serial_25_0.png

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.

[11]:
# wind_ds=to_netcdf('retrieved_wind.nc')