From 6e2e726bc289fbe7b84e7fb38042294f4ecc1fce Mon Sep 17 00:00:00 2001 From: James Munroe Date: Mon, 2 Dec 2024 16:51:21 -0500 Subject: [PATCH] Reorder and remove ARM dependent examples --- .../cacti-data-quality-example.ipynb | 384 ----------------- .../fastbarnes_interpolation_rhi.ipynb | 405 ------------------ example-workflows/tracer-example.ipynb | 399 ----------------- index.md | 9 +- myst.yml | 17 +- 5 files changed, 12 insertions(+), 1202 deletions(-) delete mode 100644 example-workflows/cacti-data-quality-example.ipynb delete mode 100644 example-workflows/fastbarnes_interpolation_rhi.ipynb delete mode 100644 example-workflows/tracer-example.ipynb diff --git a/example-workflows/cacti-data-quality-example.ipynb b/example-workflows/cacti-data-quality-example.ipynb deleted file mode 100644 index 7d6ec9e..0000000 --- a/example-workflows/cacti-data-quality-example.ipynb +++ /dev/null @@ -1,384 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "f6eee451-2129-4963-a5cb-5a1b1731ab1b", - "metadata": {}, - "source": [ - "\"Dual-Pol" - ] - }, - { - "cell_type": "markdown", - "id": "b8fb9677-e850-4de6-82d6-de30a51f3fb0", - "metadata": {}, - "source": [ - "# Data Quality Check from the CACTI Field Campaign" - ] - }, - { - "cell_type": "markdown", - "id": "bfb77e7a-c7e3-4ef2-830f-7119e0b153cc", - "metadata": {}, - "source": [ - "## Overview\n", - "\n", - "Within this notebook, we will cover:\n", - "\n", - "1. How to access multiple datasets from the Atmospheric Radiation Measurment (ARM) user facility\n", - "1. How to create a multipanel plot\n", - "1. How to compare uncorrected vs. corrected data" - ] - }, - { - "cell_type": "markdown", - "id": "abe8111d-396a-4a89-b0ac-ba9267ed9004", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "| Concepts | Importance | Notes |\n", - "| --- | --- | --- |\n", - "| [Matplotlib Basics](https://foundations.projectpythia.org/core/matplotlib/matplotlib-basics.html) | Required | Basic plotting |\n", - "| [Introduction to Cartopy](https://foundations.projectpythia.org/core/cartopy/cartopy.html) | Helpful | Adding projections to your plot |\n", - "| [Py-ART Basics](../foundations/pyart-basics) | Required | IO/Visualization |\n", - "| [Py-ART Corrections](../foundations/pyart-corrections) | Required | Radar Corrections |\n", - "---" - ] - }, - { - "cell_type": "markdown", - "id": "54c8c6f4-2cdd-43f1-b8a9-3bfe13228ef4", - "metadata": {}, - "source": [ - "## Imports" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3bfd2ec1-9f41-434b-a8b4-fc12b7ff608b", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "import act\n", - "import matplotlib as mpl\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import cartopy.crs as ccrs\n", - "import pyart\n", - "import glob" - ] - }, - { - "cell_type": "markdown", - "id": "dd3890da-24d6-4750-8746-1f494a647bb5", - "metadata": {}, - "source": [ - "## Grab Data from the ARM Data Portal\n", - "\n", - "One of the better cases of the CACTI field campaign was from November 11, 2018, where several intense storms traversed through the domain.\n", - "\n", - "### The Cloud, Aerosol, and Complex Terrain Interactions (CACTI) Field Campaign\n", - "\n", - "Data is available from the Atmospheric Radiation Measurment user facility, which helped to lead the CACTI field campaign in the Sierras de Cordoba region of Argentina.\n", - "\n", - "The data are available from the ARM data portal (https://adc.arm.gov/).\n", - "\n", - "We are interested in the corrected C-band radar data, which has the original and corrected data, with the datastream name\n", - "* **`corcsapr2cmacppiM1.c1`**" - ] - }, - { - "cell_type": "markdown", - "id": "332bb086-6571-49e8-a110-02e0abfd314b", - "metadata": {}, - "source": [ - "### Use the ARM Live API to Download the Data, using ACT\n", - "\n", - "The Atmospheric Data Community Toolkit (ACT) has a helpful module to interface with the data server:\n", - "* [Download Data API](https://arm-doe.github.io/ACT/API/generated/act.discovery.download_arm_data.html)" - ] - }, - { - "cell_type": "markdown", - "id": "7964cd7e-9791-4e8e-8aba-bd09b40a50e4", - "metadata": {}, - "source": [ - "### Setup our Download Query\n", - "Before downloading our data, we need to make sure we have an ARM Data Account, and ARM Live token. Both of these can be found using this link:\n", - "- [ARM Live Signup](https://adc.arm.gov/armlive/livedata/home)\n", - "\n", - "Once you sign up, you will see your token. Copy and replace that where we have `arm_username` and `arm_password` below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "039fc162-d05a-4022-b077-a6f65237b2c5", - "metadata": {}, - "outputs": [], - "source": [ - "arm_username = os.getenv(\"ARM_USERNAME\")\n", - "arm_password = os.getenv(\"ARM_PASSWORD\")\n", - "\n", - "datastream = \"corcsapr2cmacppiM1.c1\"\n", - "\n", - "start_date = \"2018-11-11T03:00:00\"\n", - "end_date = \"2018-11-11T03:15:00\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cd4bee72-2dd0-417d-8169-6181a373643c", - "metadata": {}, - "outputs": [], - "source": [ - "csapr_files = act.discovery.download_arm_data(arm_username,\n", - " arm_password,\n", - " datastream,\n", - " start_date,\n", - " end_date,\n", - " )" - ] - }, - { - "cell_type": "markdown", - "id": "86c9755d-b029-49e9-a00b-7212edfb6e8f", - "metadata": {}, - "source": [ - "## Read in and Investigate our Radar Data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b94fd0d5-720d-4466-bd0a-f38357969d52", - "metadata": {}, - "outputs": [], - "source": [ - "radar = pyart.io.read(csapr_files[0])" - ] - }, - { - "cell_type": "markdown", - "id": "5d11ecd6-a7ab-4e17-80d6-b043d02779fb", - "metadata": {}, - "source": [ - "### List the available fields and plot the corrected and uncorrected data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d30e2202-3585-4d10-8d65-c9d40b48ba76", - "metadata": {}, - "outputs": [], - "source": [ - "sorted(list(radar.fields))" - ] - }, - { - "cell_type": "markdown", - "id": "98b28456-a3af-4e65-addb-e3b380ce6000", - "metadata": {}, - "source": [ - "### Plot a Quick-Look of Reflectivity and Velocity\n", - "Let's start by plotting our reflectivity and velocity fields, using a four panel plot showing the uncorrected and corrected fields. Notice how the data is masked, and the radial velocities are unfolded." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "647a03b1-5482-4651-b32b-69367e87879d", - "metadata": {}, - "outputs": [], - "source": [ - "fig = plt.figure(figsize=(12,10))\n", - "display = pyart.graph.RadarDisplay(radar)\n", - "ax1 = plt.subplot(221)\n", - "display.plot_ppi(\"reflectivity\", ax=ax1)\n", - "\n", - "ax2 = plt.subplot(222)\n", - "display.plot_ppi(\"corrected_reflectivity\", ax=ax2)\n", - "\n", - "ax3 = plt.subplot(223)\n", - "display.plot_ppi(\"mean_doppler_velocity\", vmin=-30, vmax=30, cmap='pyart_balance', ax=ax3)\n", - "\n", - "ax4 = plt.subplot(224)\n", - "display.plot_ppi(\"corrected_velocity\", vmin=-30, vmax=30, cmap='pyart_balance', ax=ax4)\n", - "\n", - "plt.tight_layout()" - ] - }, - { - "cell_type": "markdown", - "id": "1fc486cc-1f1b-41e2-bcce-e8bc826b273d", - "metadata": {}, - "source": [ - "## Investigate Dual-Pol Variables\n", - "Several of the variables in this file are dual-polarization products, meaning it uses pulses in both the horizontal and vertical direction, and derives fields from this additional information.\n", - "\n", - "![Dual pol idea](https://www.weather.gov/images/ffc/dualpol_radar.gif)\n", - "\n", - "### Differential Phase Shift (PhiDP) and Specific Differential Phase (KDP)\n", - "One of these dual-pol variables is called the **Differential Phase Shift (PhiDP)**, which is the difference in 2-way attenuation for the horizontal and vertical radar pulses moving through some target. This gives us information about the shape and concentration of the features we are interested in! It is also used to calculate the specific differential phase (KDP), which is the gradient in PhiDP, where positive KDP values indicate greater phase shift in the horizontal. Higher values of KDP can indicate an increase in the size and concentration of rain drops." - ] - }, - { - "cell_type": "markdown", - "id": "2f3f5c01-7c1c-4df6-addd-5d53800235fc", - "metadata": {}, - "source": [ - "### Compare Uncorrected and Corrected PhiDP and KDP\n", - "We start with the uncorrected fields, `specific_differential_phase` and `uncorrected_differential_phase`, and compare to the corrected fields `filtered_corrected_specific_diff_phase` and `filtered_corrected_differential_phase`.\n", - "\n", - "Notice how much cleaner the corrected fields are, and how the noise has been filtered, leading a more analysis-ready dataset." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "03ee75e7-e594-4eb3-8610-8791027ff918", - "metadata": {}, - "outputs": [], - "source": [ - "display = pyart.graph.RadarMapDisplay(radar)\n", - "fig = plt.figure(figsize=(18,10))\n", - "\n", - "# Extract the latitude and longitude of the radar and use it for the center of the map\n", - "lat_center = round(radar.latitude['data'][0], 2)\n", - "lon_center = round(radar.longitude['data'][0], 2)\n", - "\n", - "# Set the projection - in this case, we use a general PlateCarree projection\n", - "projection = ccrs.PlateCarree()\n", - "\n", - "# Determine the ticks\n", - "lat_ticks = np.arange(lat_center-2, lat_center+2, .5)\n", - "lon_ticks = np.arange(lon_center-2, lon_center+2, 1.5)\n", - "\n", - "ax1 = plt.subplot(231, projection=projection)\n", - "display.plot_ppi_map(\"reflectivity\", 0, resolution='10m', ax=ax1, lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "\n", - "ax3 = plt.subplot(232,projection=projection)\n", - "display.plot_ppi_map(\"differential_phase\", 0, resolution='10m', ax=ax3, vmin=0, vmax=360, lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "ax3 = plt.subplot(233,projection=projection)\n", - "display.plot_ppi_map(\"specific_differential_phase\", 0, resolution='10m', ax=ax3, vmin=-1, vmax=4, cmap='pyart_Carbone42', lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "ax4 = plt.subplot(234, projection=projection)\n", - "display.plot_ppi_map(\"corrected_reflectivity\", 0, resolution='10m', ax=ax4, lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "\n", - "ax5 = plt.subplot(235, projection=projection)\n", - "display.plot_ppi_map(\"filtered_corrected_differential_phase\", 0, resolution='10m', ax=ax5, vmin=0, vmax=360, cmap='pyart_Wild25', lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "ax6 = plt.subplot(236,projection=projection)\n", - "display.plot_ppi_map(\"filtered_corrected_specific_diff_phase\", 0, resolution='10m', ax=ax6, vmin=0, vmax=4, cmap='pyart_Carbone42', lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "plt.tight_layout()\n", - "plt.savefig('phidp_kdp_comparison_cacti.png', dpi=300, transparent=False)" - ] - }, - { - "cell_type": "markdown", - "id": "05a27ba9-c025-479e-980d-649bcbf4e3c8", - "metadata": {}, - "source": [ - "### Create a Three Panel Figure Visualizing Reflectivity, Gate ID, and KDP\n", - "Now that we understand how valuable these corrections can be, let's create a summary figure, giving a quick overview of the scatterers and associated polarimetric fields." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "99199a24-40fd-4ed0-aab3-5b76339a923f", - "metadata": {}, - "outputs": [], - "source": [ - "display = pyart.graph.RadarMapDisplay(radar)\n", - "fig = plt.figure(figsize=(18,5))\n", - "\n", - "# Extract the latitude and longitude of the radar and use it for the center of the map\n", - "lat_center = round(radar.latitude['data'][0], 2)\n", - "lon_center = round(radar.longitude['data'][0], 2)\n", - "\n", - "projection = ccrs.PlateCarree()\n", - "\n", - "# Determine the ticks\n", - "lat_ticks = np.arange(lat_center-2, lat_center+2, .5)\n", - "lon_ticks = np.arange(lon_center-2, lon_center+2, .5)\n", - "\n", - "ax1 = plt.subplot(131, projection=projection)\n", - "display.plot_ppi_map(\"corrected_reflectivity\", 0, resolution='10m', ax=ax1, lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "\n", - "ax2 = plt.subplot(132, projection=projection)\n", - "gate_ids = radar.fields[\"gate_id\"][\"flag_meanings\"].split(\" \")\n", - "ticks = np.arange(len(gate_ids))\n", - "boundaries = np.arange(-0.5, len(gate_ids))\n", - "norm = mpl.colors.BoundaryNorm(boundaries, 256)\n", - "display.plot_ppi_map(\"gate_id\", 0, ax=ax2, lat_lines=lat_ticks, resolution='10m', lon_lines=lon_ticks, cmap='pyart_LangRainbow12', ticks=ticks, norm=norm, ticklabs=gate_ids)\n", - "\n", - "ax3 = plt.subplot(133,projection=projection)\n", - "display.plot_ppi_map(\"filtered_corrected_specific_diff_phase\", 0, resolution='10m', ax=ax3, vmin=0, vmax=4, cmap='pyart_Carbone42', lat_lines=lat_ticks, lon_lines=lon_ticks)\n", - "\n", - "plt.tight_layout()\n", - "plt.savefig('three_panel_summary_cacti.png', dpi=300, transparent=False)" - ] - }, - { - "cell_type": "markdown", - "id": "a557625d-e3d9-448b-a17c-38091294d0f1", - "metadata": {}, - "source": [ - "---\n", - "## Summary\n", - "Within this example, we walked through how to access ARM data from a field campaign in Argentina, plot a quick look of the data, and compare corrected and uncorrected dual-pol variables!\n", - "\n", - "### What's Next?\n", - "We will showcase other data workflow examples, including field campaigns in other regions and data access methods from other data centers." - ] - }, - { - "cell_type": "markdown", - "id": "e6508b08-441b-48dd-b3ff-271b97f85392", - "metadata": {}, - "source": [ - "## Resources and References\n", - "* [ARM Data Discovery](https://adc.arm.gov/discovery)\n", - "* [CACTI Field Campaign](https://www.arm.gov/research/campaigns/amf2018cacti)\n", - "* CSAPR Radar Data:\n", - " - Bharadwaj, N., Collis, S., Hardin, J., Isom, B., Lindenmaier, I., Matthews, A., & Nelson, D. C-Band Scanning ARM Precipitation Radar (CSAPR2CFR). Atmospheric Radiation Measurement (ARM) User Facility. https://doi.org/10.5439/1467901\n", - "* Py-ART:\n", - " - Helmus, J.J. & Collis, S.M., (2016). The Python ARM Radar Toolkit (Py-ART), a Library for Working with Weather Radar Data in the Python Programming Language. Journal of Open Research Software. 4(1), p.e25. DOI: http://doi.org/10.5334/jors.119\n", - "* ACT:\n", - " - Adam Theisen, Ken Kehoe, Zach Sherman, Bobby Jackson, Alyssa Sockol, Corey Godine, Max Grover, Jason Hemedinger, Jenni Kyrouac, Maxwell Levin, Michael Giansiracusa (2022). The Atmospheric Data Community Toolkit (ACT). Zenodo. DOI: https://doi.org/10.5281/zenodo.6712343" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.16" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/example-workflows/fastbarnes_interpolation_rhi.ipynb b/example-workflows/fastbarnes_interpolation_rhi.ipynb deleted file mode 100644 index a04a0f0..0000000 --- a/example-workflows/fastbarnes_interpolation_rhi.ipynb +++ /dev/null @@ -1,405 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 2D objective analysis of weather radar RHI scan: Fast Barnes Interpolation Example\n", - "\n", - "This example uses the Fast Barnes interpolation methods as presented in [Zürcher (2023)](https://doi.org/10.5194/gmd-16-1697-2023) available at [fast-barnes-py](https://github.com/MeteoSwiss/fast-barnes-py.git).\n", - "\n", - "The notebook applies the fast Barnes interpolation methods to RHI scan data from the ARM-CSAPR2 radar data from the [TRACER] (https://www.arm.gov/research/campaigns/amf2021tracer) field campaign." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Overview\n", - "\n", - "This notebook shows how to download the ARM-CSAPR2 RHI data from ARM data repository and grid radar variables on a two-dimensional Cartesian grid using Python." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "\n", - "| Concepts | Importance | Notes |\n", - "| --- | --- | --- |\n", - "| [Intro to Xarray](https://foundations.projectpythia.org/core/xarray/xarray-intro.html) | Necessary | |\n", - "| [Matplotlib Basics](https://foundations.projectpythia.org/core/matplotlib/matplotlib-basics.html) | Required | Basic plotting |\n", - "| [Py-ART Basics](../foundations/pyart-basics) | Required | IO/Visualization |\n", - "| [Understanding of NetCDF](https://foundations.projectpythia.org/core/data-formats/netcdf-cf.html) | Helpful | Familiarity with metadata structure |\n", - "\n", - "- **Time to learn**: 10 minutes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Imports" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "import pyart\n", - "import act\n", - "import glob\n", - "import os\n", - "import numpy as np\n", - "import xarray as xr\n", - "import matplotlib.pyplot as plt\n", - "from pathlib import Path\n", - "from copy import deepcopy\n", - "from fastbarnes.interpolation import barnes\n", - "from datetime import timedelta" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup our Download Query\n", - "Before downloading our data, we need to make sure we have an ARM Data Account, and ARM Live token. Both of these can be found using this link:\n", - "- [ARM Live Signup](https://adc.arm.gov/armlive/livedata/home)\n", - "\n", - "Once you sign up, you will see your token. Copy and replace that where we have `arm_username` and `arm_password` below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "arm_username = os.getenv(\"ARM_USERNAME\")\n", - "arm_password = os.getenv(\"ARM_PASSWORD\")\n", - "\n", - "datastream = \"houcsapr2cfrS2.a1\"\n", - "\n", - "start_date = \"2022-08-07T18:39:04\"\n", - "end_date = \"2022-08-07T18:39:05\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Grab Data\n", - "We use the ARM Live API, accessible through ACT!\n", - "* [Download Data API](https://arm-doe.github.io/ACT/API/generated/act.discovery.download_arm_data.html)\n", - "\n", - "We are interested in the C-band radar, which is utilizing a cell-tracking algorithm, with the datastream\n", - "- `houcsapr2cfrS2.a1`\n", - "\n", - "One of the better cases was from June 2, 2022.\n", - "\n", - "This line will download data into the a new directory with the datastream name (`/houcsapr2cfrS2.a1`)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "aug7_csapr_files = act.discovery.download_arm_data(arm_username,\n", - " arm_password,\n", - " datastream,\n", - " start_date,\n", - " end_date)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Read in and Plot the Data\n", - "Before following running the next cells, make sure you have created the following directories:\n", - "- `quicklooks`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "!mkdir quicklooks" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "radar_file = \"houcsapr2cfrS2.a1/houcsapr2cfrS2.a1.20220807.183904.nc\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Plot one of the RHI scans\n", - "We read in the data corresponding to 7 August 2022 18:39:04 UTC, and plot a basic `RadarDisplay` which will automatically detect whether the plot is a vertical cross section (RHI or VPT), or a horizontal scan (PPI)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "radar = pyart.io.read(radar_file)\n", - "display = pyart.graph.RadarDisplay(radar)\n", - "display.plot(\"reflectivity\", 0)\n", - "plt.savefig(f\"quicklooks/{Path(radar_file).stem}.png\", dpi=200)\n", - "plt.xlim(0,45)\n", - "plt.ylim(0,12)\n", - "plt.show()\n", - "plt.close() " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Define a function to grid the RHI data from polar (antenna) coordinates to a two-dimensional Caretsian grid\n", - "We use numba to vectorize the `dist_func` function to calculate the distance of each range gate from the radar. This makes our code run faster than simply executing this function for each gate in a for loop.\n", - "\n", - "Next, we use the `barnes` function from the fastbarnes Python package to interpolate the radar fields such as `equivalent reflectivity factor` ($Z_{H}$), `differential_reflectivity` ($Z_{DR}$), and `specific_differential_phase` ($K_{DP}$) to a uniform range-height Cartesian grid." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "def grid_rhi(file,z_res = 100,rng_res = 100,z_limits = (0,15000),rng_limits = (0,109900.0),fields=None):\n", - " \n", - " \"\"\"\n", - " Input:\n", - " -------\n", - " file (str): Path of the RHI scan file that needs to be gridded.\n", - " z_res (float): Vertical grid spacing of the Cartesian grid.\n", - " rng_res (float): Horizontal grid spacing of the Cartesian grid.\n", - " z_limits (tuple): Lower and upper height limits within which radar data needs to be gridded. \n", - " rng_limits (tuple): Lower and upper range limits within which radar data needs to be gridded. \n", - " \n", - " Output:\n", - " -------\n", - " grid_ds (xarray Dataset): Xarray dataset containing radar fields on the Cartesian grid\n", - " \"\"\"\n", - " \n", - " z_pts = np.arange(z_limits[0],z_limits[1]+z_res,z_res)\n", - " rng_pts = np.arange(rng_limits[0],rng_limits[1]+rng_res,rng_res)\n", - " \n", - " \n", - " rhi = xr.open_dataset(file)\n", - " radar = pyart.io.read(file)\n", - " rhi = rhi.swap_dims({'time':'elevation'})\n", - "\n", - " lat = float(radar.latitude[\"data\"])\n", - " lon = float(radar.longitude[\"data\"])\n", - "\n", - " grid_origin = (lat, lon)\n", - " grid_origin_lat, grid_origin_lon = grid_origin\n", - "\n", - " grid_projection = {\"proj\": \"pyart_aeqd\", \"_include_lon_0_lat_0\": True}\n", - " projparams = grid_projection.copy()\n", - "\n", - " if projparams.pop(\"_include_lon_0_lat_0\", False):\n", - " projparams[\"lon_0\"] = grid_origin_lon\n", - " projparams[\"lat_0\"] = grid_origin_lat\n", - "\n", - " rg_loc = np.tile(radar.range['data'],len(radar.elevation['data'])).reshape(len(radar.elevation['data']),len(radar.range['data']))\n", - "\n", - " zg_loc = radar.gate_altitude[\"data\"] - 12 # CSAPR2 antenna altitude = 12 m in this example\n", - "\n", - " \n", - " # one of [ 'naive', 'radius', 'convolution', 'optimized_convolution' ]\n", - " method = \"optimized_convolution\"\n", - "\n", - " # one of [ 0.25, 0.5, 1.0, 2.0, 4.0 ]\n", - " sigma = 1.0\n", - "\n", - " # applies only to 'convolution' interpolations: one of [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 50 ]\n", - " num_iter = 4\n", - " \n", - " if fields is None:\n", - " fields = ['reflectivity','differential_reflectivity','specific_differential_phase',\n", - " 'copol_correlation_coeff','mean_doppler_velocity','spectral_width']\n", - " \n", - " res_field = np.empty((len(z_pts),len(rng_pts),len(fields)))\n", - "\n", - " for j in range(len(fields)):\n", - "\n", - " data = deepcopy(np.array(radar.fields[fields[j]]['data']))\n", - " # data = data.filled(np.nan)\n", - "\n", - " res_field[:,:,j] = barnes(np.asarray([rg_loc.ravel(),radar.gate_altitude['data'].ravel()]).transpose(),\n", - " data.ravel(),\n", - " 100,\n", - " np.asarray([0,0]),\n", - " 100,\n", - " (len(z_pts),len(rng_pts)),\n", - " method=method,\n", - " num_iter = num_iter,\n", - " min_weight=0.0002\n", - " )\n", - " \n", - "\n", - " data_dict = {}\n", - " for k in range(len(fields)):\n", - " data_dict[fields[k]] = ([\"z\",\"range\"],res_field[:,:,k])\n", - "\n", - " grid_ds = xr.Dataset(data_vars=data_dict,\n", - " coords=dict(z=([\"z\"], z_pts),\n", - " range=([\"range\"],rng_pts),\n", - " ),\n", - " attrs=dict(description=\"Gridded RHI data.\"),\n", - " )\n", - " \n", - " return grid_ds" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Apply the gridding function to your radar RHI data file\n", - "\n", - "Now, we are ready to grid the RHI data. The `grid_rhi` function requires the user to specify the vertical and horizontal grid spacing (`z_res` and `rng_res`, respectively), as well as the lower and upper limits of the Cartesian grid in the vertical and horizontal dimensions (`z_limits` and `rng_limits`, respectively). Custom fields of interest can be specified through the `fields` parameter. Otherwise, the function grids five radar fields by default i.e., ($Z_{H}$, $Z_{DR}$, $\\rho_{hv}$, $K_{DP}$, and $\\sigma$)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "grid_ds = grid_rhi(radar_file)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Grid and plot the RHI data\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# Finally, plot the gridded reflectivity\n", - "fig,ax = plt.subplots()\n", - "grid_ds['reflectivity'].plot(vmin=0,vmax=70,cmap='pyart_HomeyerRainbow',ax=ax)\n", - "ax.set_xlim(0,55000)\n", - "ax.set_ylim(0,10000)\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Summary\n", - "Within this example, we walked through how to access ARM data from a field campaign in Texas, plot a quick look of the RHI scan data, and grid our RHI data from native (polar) coordinates to a uniform range-height Caretsian grid." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Resources and References\n", - "* [ARM Data Discovery](https://adc.arm.gov/discovery)\n", - "* [TRACER Field Campaign](https://www.arm.gov/research/campaigns/amf2021tracer)\n", - "* CSAPR Radar Data:\n", - " - Bharadwaj, N., Collis, S., Hardin, J., Isom, B., Lindenmaier, I., Matthews, A., & Nelson, D. C-Band Scanning ARM Precipitation Radar (CSAPR2CFR). Atmospheric Radiation Measurement (ARM) User Facility. https://doi.org/10.5439/1467901\n", - "* Py-ART:\n", - " - Helmus, J.J. & Collis, S.M., (2016). The Python ARM Radar Toolkit (Py-ART), a Library for Working with Weather Radar Data in the Python Programming Language. Journal of Open Research Software. 4(1), p.e25. DOI: http://doi.org/10.5334/jors.119\n", - "* ACT:\n", - " - Adam Theisen, Ken Kehoe, Zach Sherman, Bobby Jackson, Alyssa Sockol, Corey Godine, Max Grover, Jason Hemedinger, Jenni Kyrouac, Maxwell Levin, Michael Giansiracusa (2022). The Atmospheric Data Community Toolkit (ACT). Zenodo. DOI: https://doi.org/10.5281/zenodo.6712343" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.16" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/example-workflows/tracer-example.ipynb b/example-workflows/tracer-example.ipynb deleted file mode 100644 index bd6b802..0000000 --- a/example-workflows/tracer-example.ipynb +++ /dev/null @@ -1,399 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "1b50afbd-665c-4fd9-8e6e-f7039c2b84ee", - "metadata": {}, - "source": [ - "\"TRACER\n", - "# Plotting Data from a Field Campaign (TRACER)" - ] - }, - { - "cell_type": "markdown", - "id": "84c6a08e-e1eb-4358-9991-4ecec6810482", - "metadata": {}, - "source": [ - "## Overview\n", - "\n", - "Within this notebook, we will cover:\n", - "\n", - "1. How to access data from the Atmospheric Radiation Measurment (ARM) user facility\n", - "1. How to setup a workflow to plot both cross sections (RHIs) and horizontal scans (PPIs)" - ] - }, - { - "cell_type": "markdown", - "id": "b3770751-dc1f-404b-918b-dfe14e05e035", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "| Concepts | Importance | Notes |\n", - "| --- | --- | --- |\n", - "| [Matplotlib Basics](https://foundations.projectpythia.org/core/matplotlib/matplotlib-basics.html) | Required | Basic plotting |\n", - "| [Py-ART Basics](../foundations/pyart-basics) | Required | IO/Visualization |" - ] - }, - { - "cell_type": "markdown", - "id": "75fd5b88-7e2f-4455-ab6d-27f3c2114d22", - "metadata": {}, - "source": [ - "---\n", - "## Imports" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5c4490ba-188b-4700-84db-de827efd2734", - "metadata": {}, - "outputs": [], - "source": [ - "import glob\n", - "import os\n", - "from pathlib import Path\n", - "\n", - "import act\n", - "import imageio.v2 as imageio\n", - "import matplotlib\n", - "import matplotlib.pyplot as plt\n", - "import pyart" - ] - }, - { - "cell_type": "markdown", - "id": "4e4ddb9b-dd3d-4eba-ad32-814cdc7590cb", - "metadata": { - "tags": [] - }, - "source": [ - "## Grab Data from ARM\n", - "\n", - "One of the better cases was from June 2, 2022, where several cold pools and single-cell storms traversed through the domain." - ] - }, - { - "cell_type": "markdown", - "id": "d6dc342b-b5b3-443a-b7b4-e40388dbc5c1", - "metadata": {}, - "source": [ - "### The Tracking Aerosol Convection Interactions ExpeRiment (TRACER) Field Campaign\n", - "\n", - "Data is available from the Atmospheric Radiation Measurment user facility, which helped to lead the TRACER field campaign in Houston, Texas.\n", - "\n", - "The data are available from the ARM data portal (https://adc.arm.gov/).\n", - "\n", - "We are interested in the C-band radar, which is utilizing a cell-tracking algorithm, with the datastream\n", - "* **`houcsapr2cfrS2.a1`**" - ] - }, - { - "cell_type": "markdown", - "id": "e9dab624-06a6-4f7a-af60-6a9ce2694552", - "metadata": {}, - "source": [ - "### Use the ARM Live API to Download the Data, using ACT\n", - "\n", - "The Atmospheric Data Community Toolkit (ACT) has a helpful module to interface with the data server:\n", - "* [Download Data API](hhttps://arm-doe.github.io/ACT/API/generated/act.discovery.download_arm_data.html)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b36e5eb5-96bd-4dab-8523-540266006e13", - "metadata": {}, - "outputs": [], - "source": [ - "act.discovery.download_arm_data?" - ] - }, - { - "cell_type": "markdown", - "id": "8cc87bac-cbc8-4c74-ae90-0be3e1bb04cc", - "metadata": {}, - "source": [ - "### Setup our Download Query\n", - "Before downloading our data, we need to make sure we have an ARM Data Account, and ARM Live token. Both of these can be found using this link:\n", - "- [ARM Live Signup](https://adc.arm.gov/armlive/livedata/home)\n", - "\n", - "Once you sign up, you will see your token. Copy and replace that where we have `arm_username` and `arm_password` below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "01c11f87-1b25-4f5b-95ce-2e31240ffe0b", - "metadata": {}, - "outputs": [], - "source": [ - "arm_username = os.getenv(\"ARM_USERNAME\")\n", - "arm_password = os.getenv(\"ARM_PASSWORD\")\n", - "\n", - "datastream = \"houcsapr2cfrS2.a1\"\n", - "\n", - "start_date = \"2022-06-02T11:30:00\"\n", - "end_date = \"2022-06-02T11:40:00\"\n", - "\n", - "print(len(arm_username), len(arm_password))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5628b84c-8c79-4ecc-9ed0-6488192f6340", - "metadata": {}, - "outputs": [], - "source": [ - "june2_csapr_files = act.discovery.download_arm_data(arm_username,\n", - " arm_password,\n", - " datastream,\n", - " start_date,\n", - " end_date,\n", - " )" - ] - }, - { - "cell_type": "markdown", - "id": "948e9742-6b2a-46c9-bf51-61b92aabb8fe", - "metadata": {}, - "source": [ - "## Read in and Plot the Data\n", - "Before following running the next cells, make sure you have created the following directories:\n", - "- `quicklooks/ppi`\n", - "- `quicklooks/rhi`\n", - "- `quicklooks/vpt`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ea82b09c-9813-40c6-b462-93e8943804d5", - "metadata": {}, - "outputs": [], - "source": [ - "!mkdir quicklooks\n", - "!mkdir quicklooks/rhi\n", - "!mkdir quicklooks/ppi\n", - "!mkdir quicklooks/vpt" - ] - }, - { - "cell_type": "markdown", - "id": "1bcdf4ab-061c-40e3-bed4-7a4ef23ef7d8", - "metadata": {}, - "source": [ - "### Loop through and plot\n", - "We read in the data, check the scan type, and plot a basic `RadarDisplay` which will automatically detect whether the plot is a vertical cross section (RHI or VPT), or a horizontal scan (PPI).\n", - "\n", - "This offers a solid \"quick look\", or initial visualization of the data." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b232ed23-1d40-471c-b488-870aa48fd527", - "metadata": {}, - "outputs": [], - "source": [ - "for file in june2_csapr_files:\n", - " radar = pyart.io.read(file)\n", - " print(radar.scan_type)\n", - " display = pyart.graph.RadarDisplay(radar)\n", - " display.plot(\"reflectivity\", 0)\n", - " plt.savefig(f\"quicklooks/{radar.scan_type}/{Path(file).stem}.png\", dpi=200)\n", - " plt.show()\n", - " plt.close() " - ] - }, - { - "cell_type": "markdown", - "id": "c1123d60-6439-4cdd-8f06-2f27278d3fba", - "metadata": { - "tags": [] - }, - "source": [ - "### Refine our Plot, Plot Velocity\n", - "Let's focus on the vertical scans of the data, or the RHIs.\n", - "\n", - "You'll notice that we had some cells around 60 km from the radar, with the vertical axis less than 6 km.\n", - "\n", - "Let's reflect that in the plots!" - ] - }, - { - "cell_type": "markdown", - "id": "ab7e20f4-2f2d-44e9-97d8-baca12079d22", - "metadata": {}, - "source": [ - "#### Customize our plot look\n", - "Before we plot, we can change the size of our font, and style using the following parameters:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1348da70-b550-439a-adb2-26784a685c67", - "metadata": {}, - "outputs": [], - "source": [ - "font = {'family' : 'serif',\n", - " 'weight' : 'bold',\n", - " 'size' : 16}\n", - "\n", - "matplotlib.rc('font', **font)" - ] - }, - { - "cell_type": "markdown", - "id": "00757253-6bae-4294-b913-d9e347114356", - "metadata": {}, - "source": [ - "#### Apply our Plotting Loop\n", - "We:\n", - "- Check to see if the scan is an RHI\n", - "- Plot the reflectivity on one subplot\n", - "- Plot velocity on the other\n", - "- Save our plots" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6cdf280a-a316-4ed5-983a-f65532f67b5c", - "metadata": {}, - "outputs": [], - "source": [ - "for file in june2_csapr_files:\n", - " radar = pyart.io.read(file)\n", - " if radar.scan_type == 'rhi':\n", - " fig = plt.figure(figsize=(20,8))\n", - " display = pyart.graph.RadarDisplay(radar)\n", - " ax = plt.subplot(121)\n", - " display.plot(\"reflectivity\",\n", - " 0,\n", - " ax=ax,\n", - " vmin=-20,\n", - " vmax=70)\n", - " plt.xlim(62,68)\n", - " plt.ylim(0, 6)\n", - " \n", - " ax2 = plt.subplot(122)\n", - " display.plot(\"mean_doppler_velocity\",\n", - " 0,\n", - " ax=ax2, \n", - " cmap='pyart_balance',\n", - " vmin=-15,\n", - " vmax=15)\n", - " plt.xlim(62,68)\n", - " plt.ylim(0, 6)\n", - " plt.savefig(f\"quicklooks/{radar.scan_type}/{Path(file).stem}.png\", dpi=200)\n", - " plt.show()\n", - " plt.close() " - ] - }, - { - "cell_type": "markdown", - "id": "97d6443f-8748-4c05-a9fb-91b523934563", - "metadata": {}, - "source": [ - "### Create a GIF of teh RHI images" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "aa460eae-069a-44c3-afe6-5fecb3a7c68c", - "metadata": {}, - "outputs": [], - "source": [ - "rhi_images = sorted(glob.glob(\"quicklooks/rhi/*\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "92b86399-d894-4940-a839-774951f10fdb", - "metadata": {}, - "outputs": [], - "source": [ - "with imageio.get_writer('storm-animation.gif', mode='I') as writer:\n", - " for filename in rhi_images:\n", - " image = imageio.imread(filename)\n", - " writer.append_data(image)" - ] - }, - { - "cell_type": "markdown", - "id": "80f42034-36af-4ae8-a5ef-deb2048fdd85", - "metadata": {}, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "id": "f0d1170d-2b89-463b-94b5-ea3229550272", - "metadata": {}, - "source": [ - "---\n", - "## Summary\n", - "Within this example, we walked through how to access ARM data from a field campaign in Texas, plot a quick look of the data, and refine our plots to investigate a storm!\n", - "\n", - "### What's Next?\n", - "We will showcase other data workflow examples, including field campaigns in other regions and data access methods from other data centers." - ] - }, - { - "cell_type": "markdown", - "id": "c70225df-ce45-4fb8-a2b9-1a2f70d030c0", - "metadata": {}, - "source": [ - "## Resources and References\n", - "* [ARM Data Discovery](https://adc.arm.gov/discovery)\n", - "* [TRACER Field Campaign](https://www.arm.gov/research/campaigns/amf2021tracer)\n", - "* CSAPR Radar Data:\n", - " - Bharadwaj, N., Collis, S., Hardin, J., Isom, B., Lindenmaier, I., Matthews, A., & Nelson, D. C-Band Scanning ARM Precipitation Radar (CSAPR2CFR). Atmospheric Radiation Measurement (ARM) User Facility. https://doi.org/10.5439/1467901\n", - "* Py-ART:\n", - " - Helmus, J.J. & Collis, S.M., (2016). The Python ARM Radar Toolkit (Py-ART), a Library for Working with Weather Radar Data in the Python Programming Language. Journal of Open Research Software. 4(1), p.e25. DOI: http://doi.org/10.5334/jors.119\n", - "* ACT:\n", - " - Adam Theisen, Ken Kehoe, Zach Sherman, Bobby Jackson, Alyssa Sockol, Corey Godine, Max Grover, Jason Hemedinger, Jenni Kyrouac, Maxwell Levin, Michael Giansiracusa (2022). The Atmospheric Data Community Toolkit (ACT). Zenodo. DOI: https://doi.org/10.5281/zenodo.6712343" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b61cb262-26ba-47dc-8d52-3225f084aaef", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.16" - }, - "vscode": { - "interpreter": { - "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/index.md b/index.md index 1241559..2ac1de0 100644 --- a/index.md +++ b/index.md @@ -1,6 +1,5 @@ # Project Pythia - Radar Cookbook - The [Radar Cookbook](https://projectpythia.org/radar-cookbook) from [Project Pythia](https://projectpythia.org/) covers the basics of working with weather radar data in Python. @@ -25,3 +24,11 @@ Project Pythia is a home for Python-centered learning resources that are _open-s https://projectpythia.org/ ::: + +:::{note} +# Attribution + +The material for this demo is adapted from Project Pythia’s Radar Cookbook and is licensed for free and open consumption and reuse. All code is served under Apache 2.0, while all non-code content is licensed under Creative Commons BY 4.0 (CC BY 4.0). + +Grover, M., Sherman, Z., Sharma, M., Ladino, A., Camron, C., & Radar Cookbook contributors. (2023). Radar Cookbook (v2023.06.23). Zenodo. https://doi.org/10.5281/zenodo.8075855 +::: \ No newline at end of file diff --git a/myst.yml b/myst.yml index f17b82e..05db7b0 100644 --- a/myst.yml +++ b/myst.yml @@ -6,11 +6,6 @@ project: id: 7ea1a004-9dee-454c-aeca-eedfd0dc6e36 title: Project Pythia - Radar Cookbook description: Cookbooks to demonstrate reproducible geoscientific computing - # keywords: [] - authors: - - name: Max Grover - - name: Zachary Sherman - - name: Milind Sharma jupyter: binder: repo: https://github.com/2i2c-org/demo-Project-Pythia @@ -23,14 +18,10 @@ project: - file: index.md - title: Radar Cookbook Workflows children: - - file: example-workflows/cacti-data-quality-example.ipynb - - file: example-workflows/echo_top_height.ipynb - - file: example-workflows/fastbarnes_interpolation_rhi.ipynb - - file: >- - example-workflows/interactive-radar-visualization-jmaradar-cfradial1.ipynb - - file: example-workflows/kdp-comparison.ipynb - file: example-workflows/moore-oklahoma-tornado.ipynb - - file: example-workflows/tracer-example.ipynb + - file: example-workflows/kdp-comparison.ipynb + - file: example-workflows/echo_top_height.ipynb + - file: example-workflows/interactive-radar-visualization-jmaradar-cfradial1.ipynb abbreviations: ARM: Atmospheric Radiation Measurement @@ -38,4 +29,4 @@ abbreviations: site: template: book-theme options: - logo_text: Project Pythia + logo_text: Radar Cookbook Demo