{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Wind retrievel for RPG radar" ] }, { "cell_type": "markdown", "metadata": { "id": "6-9RSNp7zde7" }, "source": [ "**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.\n", "\n", "You can find more information about lidarwind at: https://lidarwind.readthedocs.io/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Steps:\n", "\n", " 1. Dependence installation\n", " 2. Importing the required packages\n", " 3. Defining useful functions\n", " 4. Getting sample data\n", " 5. Retrieving wind\n", " 6. Visualising the results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Dependence installation" ] }, { "cell_type": "markdown", "metadata": { "id": "ya1i4OsxsEC_" }, "source": [ "The cell below installs an additional package required by lidarwind." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 20632, "status": "ok", "timestamp": 1718263461285, "user": { "displayName": "Christine Unal", "userId": "02384359149360931920" }, "user_tz": -120 }, "id": "MqItOU3p29sg", "outputId": "d8998c19-8541-460f-90e5-8b2e9353e4bc", "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: lidarwind in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (0.2.5.dev27+gd45b3ff.d20240702)\n", "Requirement already satisfied: xarray-datatree==0.0.11 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (0.0.11)\n", "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)\n", "Requirement already satisfied: xrft>=0.3 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.0.1)\n", "Requirement already satisfied: pandas>=1.4 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (2.2.2)\n", "Requirement already satisfied: numpy>=1.22 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.26.4)\n", "Requirement already satisfied: netCDF4>=1.5 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.6.5)\n", "Requirement already satisfied: matplotlib>=3.4.3 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (3.8.4)\n", "Requirement already satisfied: click>=8.1.2 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (8.1.7)\n", "Requirement already satisfied: gdown>=4.5.1 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (5.1.0)\n", "Requirement already satisfied: pooch>=1.6 in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from lidarwind) (1.8.1)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "Requirement already satisfied: cftime in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from netCDF4>=1.5->lidarwind) (1.6.3)\n", "Requirement already satisfied: certifi in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from netCDF4>=1.5->lidarwind) (2024.6.2)\n", "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)\n", "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)\n", "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)\n", "Requirement already satisfied: dask in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from xrft>=0.3->lidarwind) (2024.4.2)\n", "Requirement already satisfied: scipy in /Users/jdiasneto/miniforge3/envs/rpg_post/lib/python3.10/site-packages (from xrft>=0.3->lidarwind) (1.13.0)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install lidarwind xarray-datatree==0.0.11" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**ATTENTION:** \n", "\n", "After executing the previous cell, you may need to restart the kernel in case you get an error message. It is a temporary solution.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Importing required packages" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 76 }, "executionInfo": { "elapsed": 5794, "status": "ok", "timestamp": 1718263486992, "user": { "displayName": "Christine Unal", "userId": "02384359149360931920" }, "user_tz": -120 }, "id": "WBio5B-AvloE", "outputId": "204c3c1e-eea3-4d2b-91bd-e2d59d6552b4", "scrolled": true }, "outputs": [], "source": [ "# genneral imports\n", "import pooch\n", "\n", "import xarray as xr\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 1706, "status": "ok", "timestamp": 1718263500227, "user": { "displayName": "Christine Unal", "userId": "02384359149360931920" }, "user_tz": -120 }, "id": "i2WDSg8Sr5H1", "outputId": "bec445f3-bb0b-4f01-94cf-82985ac51aab" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "lidarwind version: 0.2.5.dev27+gd45b3ff.d20240702\n" ] } ], "source": [ "# importing the data processing package\n", "import lidarwind\n", "\n", "# checking if the version of lidarwind\n", "# it should be equal or greater than 0.2.4\n", "print(f\"lidarwind version: {lidarwind.__version__}\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 1706, "status": "ok", "timestamp": 1718263500227, "user": { "displayName": "Christine Unal", "userId": "02384359149360931920" }, "user_tz": -120 }, "id": "i2WDSg8Sr5H1", "outputId": "bec445f3-bb0b-4f01-94cf-82985ac51aab" }, "outputs": [], "source": [ "# importing the rpg radar related modules\n", "from lidarwind.preprocessing import rpg_radar\n", "from lidarwind.postprocessing import post_rpg_radar" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 3: Defining the processing function" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following is in charge of the main process. Here, the individual PPI files are open and the profiles are retrieved." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "executionInfo": { "elapsed": 294, "status": "ok", "timestamp": 1718263584770, "user": { "displayName": "Christine Unal", "userId": "02384359149360931920" }, "user_tz": -120 }, "id": "kN6o_1BqtpCc" }, "outputs": [], "source": [ "def process_one_file(file_name):\n", " \"\"\"\n", " Function to process a single radar file\n", " \"\"\"\n", "\n", " ds = xr.open_dataset(file_name)\n", " ds = rpg_radar.rpg_slanted_radial_velocity_4_fft(ds)\n", " tmp_wind = post_rpg_radar.get_horizontal_wind(ds)\n", "\n", " return tmp_wind" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 4: Getting sample data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this step, we download a sample dataset needed for this example and create a list of all downloaded files. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "file_list = pooch.retrieve(\n", " url=\"doi:10.5281/zenodo.7312960/rpg_sample_ppi.zip\",\n", " known_hash=\"md5:952f7b50985cc8623933fbc18f72fd73\",\n", " path=\"tmp_data\",\n", " processor=pooch.Unzip(),\n", " )\n", "\n", "file_list = sorted(file_list)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 5: Retrieving wind" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this step, the function defined in Step 3 to process the sample files is applied to the file_list defined in Step 4. " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 114519, "status": "ok", "timestamp": 1718263884825, "user": { "displayName": "Christine Unal", "userId": "02384359149360931920" }, "user_tz": -120 }, "id": "6bgbXMvjt31a", "outputId": "06a23e39-684e-41cb-a4af-c48ea34c01c0" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 47.2 s, sys: 1.17 s, total: 48.4 s\n", "Wall time: 56.1 s\n" ] } ], "source": [ "%%time\n", "\n", "# running the function over the selected files\n", "wind_ds = xr.merge([process_one_file(f) for f in file_list])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 6: Visualising the results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, in this step, we first have a look at the wind dataset structure and later have a loot at some variables." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 564 }, "executionInfo": { "elapsed": 681, "status": "ok", "timestamp": 1718263904959, "user": { "displayName": "Christine Unal", "userId": "02384359149360931920" }, "user_tz": -120 }, "id": "GPOmtydDBulj", "outputId": "a140d206-7350-4f85-c037-a68487e40676" }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 631kB\n",
"Dimensions: (range: 339, chirp: 3, mean_time: 42)\n",
"Coordinates:\n",
" * range (range) float32 1kB 108.0 129.6 ... 1.157e+04\n",
" * chirp (chirp) int64 24B 1 2 3\n",
" * mean_time (mean_time) datetime64[ns] 336B 2022-05-17T10:...\n",
" elevation float32 4B 74.99\n",
" freq_azimuth float64 8B 0.002778\n",
" azimuth_length int64 8B 72\n",
"Data variables:\n",
" horizontal_wind_direction (mean_time, range) float64 114kB 82.05 ... nan\n",
" horizontal_wind_speed (mean_time, range) float64 114kB 4.536 ... nan\n",
" meridional_wind (mean_time, range) float64 114kB -0.6275 ... nan\n",
" zonal_wind (mean_time, range) float64 114kB 4.493 ... nan\n",
" start_scan (mean_time) datetime64[ns] 336B 2022-05-17T10:...\n",
" end_scan (mean_time) datetime64[ns] 336B 2022-05-17T10:...\n",
" zdr_max (mean_time, range) float32 57kB 5.533 ... nan\n",
" nan_percentual (mean_time, range) float64 114kB 0.0 ... 100.0\n",
" chirp_start (mean_time, chirp) float32 504B 111.8 ... 2.03...\n",
" chirp_end (mean_time, chirp) float32 504B 581.3 ... 1.19...\n",
" chirp_azimuth_bias (mean_time, chirp) float64 1kB 0.0 0.0 ... 0.0\n",
" azm_seq (mean_time) float64 336B 1.0 -1.0 ... 1.0 -1.0