<jupyter_start><jupyter_text>Pyart 1.0: Importing, Reading and Plotting a Radar File Let us start we an introductory on what is Py-ART, then after we will begin to code away. The Python ARM Radar Toolkit or Py-ART: * Py-ART is a Python module for plotting, correcting and analyzing weather radar data. * Development began to address the needs of ARM with the acquisition of a number of   new scanning cloud and precipitation radar as part of the American Recovery Act. * The project has since expanded to work with a variety of weather radars and a wider user   base including radar researchers and climate modelers. * The software has been released on GitHub as open source software under a BSD license.   Runs on Linux, OS X. It also runs on Windows with more limited functionality.   Contributions from others are always welcome. What can Py-ART do?Py-ART can be used for a variety of tasks from basic plotting to more complexprocessing pipelines. Specific uses for Py-ART include: * Reading radar data in a variety of file formats. * Creating plots and visualization of radar data. * Correcting radar moments while in antenna coordinates, such as:    * Doppler unfolding/de-aliasing.    * Attenuation correction.    * Phase processing using a Linear Programming method. * Mapping data from one or multiple radars onto a Cartesian grid. * Performing retrievals. * Writing radial and Cartesian data to NetCDF files. Py-ART essentials links: * Landing page, [arm-doe.github.io/pyart/](http://arm-doe.github.io/pyart/) * Documentation, [arm-doe.github.io/pyart-docs-travis/](http://arm-doe.github.io/pyart-docs-travis/) * Examples, [arm-doe.github.io/pyart/dev/auto_examples/index.html](http://arm-doe.github.io/pyart/dev/auto_examples/index.html) * Source Code, [github.com/ARM-DOE/pyart](https://github.com/ARM-DOE/pyart) * Mailing list, [groups.google.com/group/pyart-users/](http://groups.google.com/group/pyart-users/) * Issue Tracker, [github.com/ARM-DOE/pyart/issues](https://github.com/ARM-DOE/pyart/issues) Now that we know what Py-ART is, let us began coding. First we want to import any modules that will be needed.<jupyter_code>import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
import pyart<jupyter_output><empty_output><jupyter_text>When reading in a radar file, we use the pyart.io.read module.pyart.io.read can read a variety of different radar formats, such as Cf/Radial, LASSEN, and more. The documentation on what formats can be read by Py-ART can be found here:http://arm-doe.github.io/pyart-docs-travis/user_reference/io.htmlFor most file formats listed on the page, using pyart.io.read should suffice since Py-ART has the ability to automatically detect the file format. To read a radar file:<jupyter_code>radar = pyart.io.read('../inf_tutorial_data/sgpxsaprcmacsurI5.c1.20170801.044013.nc')<jupyter_output><empty_output><jupyter_text>When reading a radar file, there are a few options to add, such as excluding radar fields. Excluding fields becomes useful when you are loading many radar files at a time and want to conserve memory and save time. To see the full list of parameters, in a Jupyter Notebook, simply add a question mark after the function.<jupyter_code>pyart.io.read?<jupyter_output><empty_output><jupyter_text>After reading a file, a radar object is created. The object contains a variety of metadata from the radar.In the next notebook we will go into more detail of the radar object. In the radar object are fields. This is where data such as reflectivity and velocity are stored.To see what fields are present we can add the fields and keys additions to the variable where theradar object is stored.<jupyter_code>radar.fields.keys()<jupyter_output><empty_output><jupyter_text>The fields are stored in a dictionary, each containing coordinates, units and more.All can be accessed by just adding the fields addition to the radar object variable.For an individual field, we add a string in brackets after the fields addition to seethe contents of that field.<jupyter_code>print(radar.fields)
print(radar.fields['reflectivity'])<jupyter_output><empty_output><jupyter_text>We can go even further in the dictionary and a see within the reflectivity field by accessing the units or data itself.For example add the string data in brackets after the reflectivity string bracket.<jupyter_code>print(radar.fields['reflectivity']['data'])
print(radar.fields['reflectivity']['data'][300, 2])<jupyter_output><empty_output><jupyter_text>Finally, for a more condensed view of the radar object, just use radar.info().<jupyter_code>radar.info()<jupyter_output><empty_output><jupyter_text>Now that we have loaded the data and inspected it, the next logical thing to do is to visualize the data! Py-ART's visualiation functionality is done through the objects in the pyart.graph module: http://arm-doe.github.io/pyart-docs-travis/user_reference/graph.htmlIn Py-ART there are 5 visualization classes in pyart.graph:* RadarDisplay	                            * RadarMapDisplay	                        * AirborneRadarDisplay	                    * RadarMapDisplayCartopy                    Plotting grid data* GridMapDisplayFor the examples in this tutorial, we will be using RadarMapDisplayCartopy. There are two main libraries in Python for plotting geographic data that are used by Py-ART: Cartopy and Basemap. For this example, we are going to use Cartopy to plot our data. Basemap will be deprecated in 2020, so it is recommended to use Cartopy whenever possible.  To display a radar image using Cartopy, we create a figure first and then create a RadarMapDisplayCartopy object from the radar. The following example displays the reflectivity from the radar.<jupyter_code>fig = plt.figure(figsize=[8, 8])
display = pyart.graph.RadarMapDisplayCartopy(radar)
display.plot_ppi_map('reflectivity', sweep=2, resolution='50m',
                     vmin=-8, vmax=64, min_lon=-98.25, max_lon=-96.75,
                     min_lat=35.75, max_lat=37.25,
                     projection=ccrs.PlateCarree(), cmap='pyart_LangRainbow12')
plt.show()<jupyter_output><empty_output><jupyter_text>You can change many parameters in the graph by changing the arguments to plot_ppi_map. As you can recall from earlier. simply view these arguments in a Jupyter notebook by typing:<jupyter_code>display.plot_ppi_map?<jupyter_output><empty_output><jupyter_text>For example, let's change the colormap to something different<jupyter_code>fig = plt.figure(figsize=[8, 8])
display = pyart.graph.RadarMapDisplayCartopy(radar)
display.plot_ppi_map('reflectivity', sweep=2, resolution='50m',
                     vmin=-8, vmax=64, min_lon=-98.25, max_lon=-96.75,
                     min_lat=35.75, max_lat=37.25,
                     projection=ccrs.PlateCarree(), cmap='pyart_Gray9')
plt.show()<jupyter_output><empty_output><jupyter_text>Or, let's view a different elevation scan!<jupyter_code>fig = plt.figure(figsize=[8, 8])
display = pyart.graph.RadarMapDisplayCartopy(radar)
display.plot_ppi_map('reflectivity', sweep=0, resolution='50m',
                     vmin=-8, vmax=64, min_lon=-98.25, max_lon=-96.75,
                     min_lat=35.75, max_lat=37.25,
                     projection=ccrs.PlateCarree(), cmap='pyart_LangRainbow12')
plt.show()<jupyter_output><empty_output><jupyter_text>Or, display radial velocity instead of reflectivity.<jupyter_code>fig = plt.figure(figsize=[8, 8])
display = pyart.graph.RadarMapDisplayCartopy(radar)
display.plot_ppi_map('velocity', sweep=2, resolution='50m',
                     vmin=-30, vmax=30, min_lon=-98.25, max_lon=-96.75,
                     min_lat=35.75, max_lat=37.25,
                     projection=ccrs.PlateCarree(), cmap='coolwarm')
plt.show()<jupyter_output><empty_output><jupyter_text>ExerciseNow that the basics of loading and processing Cf/Radial files has been introduced, let's go ahead use what we have learned to load and plot a file from the CPOL radar in Darwin. This file is located on your thumb drives as cfrad.20060120_005000.000_to_20060120_005810.000_CPOL_PPI_level1a.nc. Play around with changing factors such as the field plotted, color scale, color maps, axes limits to get a feel for how to visualize radar data with Py-ART. Press shift-Enter in the below cell for a possible answer. There are many ways to visualize data using Py-ART, so the answer here is not necessarily the only one!<jupyter_code>%load section0_answer.py<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08237796950715046, 'fraction_numerical': 0.019501240988062878, 'mean_word_length': 4.431322207958922, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '170807', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2446, 'n_words': 903, 'path': '1_Introductory_pyart/1.0_Importing_reading_and_plotting_a_radar_file.ipynb', 'repo_name': 'rcjackson/stm_2018_pyart_course', 'size': '8461'}