What you are looking at is an Jupyter Notebook, a web-based interactive computation enviroment well suited for creating and sharing examples of scientific Python computations.
One of the key features of Jupyter notebooks is that Python code can be written and executed in cells.
Click on the next cell and press shift+enter to execute the Python code.
# This is a Python comment
# the next line is a line of Python code
print "Hello World!"
Hello World!
Cells can also be used to create textual materials using the markup language Markdown.
Double click on this cell (or any others) to see the raw markdown which produces the nicely formatted text.
One of the reasons these Notebooks are so well suited for scientific Python work is that Juypter is well integrated into the Scientific Python ecosystem. For example, plots can be included in notebooks for visualizing data. Execute the next two cells (using ctrl+enter)
# These two lines turn on inline plotting
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2,3])
[<matplotlib.lines.Line2D at 0x1089b33d0>]
We will be using Jupyter notebooks for all the course materials so that you can interactively run Py-ART examples and play with data
Jupyter has a number of additional features and uses which are outside the scope of this introduction. To learn more, see the Jupyter documentation, look at some examples, or checkout the gallery of interesting notebooks.
The Python ARM Radar Toolkit or Py-ART:
Py-ART can be used for a variety of tasks from basic plotting to more complex processing pipelines. Specific uses for Py-ART include:
We will be covering some of these topics in the course.
Before we begin lets change the default size of our figures so they are easier to see.
import matplotlib
matplotlib.rcParams['figure.figsize'] = [12.0, 9.0]
Enough introduction, lets look at some radar data!
First, we need to import Py-ART. This allows us to use the included routines to read in data from radar files.
Use shift+enter to execute the cell
import pyart
radar = pyart.io.read('data/sgpwsacrcwrhiC1.a1.20120820.204016.nc')
radar.info('compact')
# try out 'standard' or 'full' also
altitude: <ndarray of type: float64 and shape: (1,)> altitude_agl: <ndarray of type: float64 and shape: (1,)> antenna_transition: <ndarray of type: int32 and shape: (8367,)> azimuth: <ndarray of type: float32 and shape: (8367,)> elevation: <ndarray of type: float32 and shape: (8367,)> fields: linear_depolarization_ratio: <ndarray of type: float32 and shape: (8367, 949)> spectral_width: <ndarray of type: float32 and shape: (8367, 949)> snr: <ndarray of type: float32 and shape: (8367, 949)> mean_doppler_velocity: <ndarray of type: float32 and shape: (8367, 949)> reflectivity: <ndarray of type: float32 and shape: (8367, 949)> fixed_angle: <ndarray of type: float32 and shape: (17,)> instrument_parameters: radar_measured_transmit_power_h: <ndarray of type: float32 and shape: (8367,)> follow_mode: <ndarray of type: |S1 and shape: (17, 4)> nyquist_velocity: <ndarray of type: float32 and shape: (8367,)> unambiguous_range: <ndarray of type: float32 and shape: (8367,)> radar_antenna_gain_v: <ndarray of type: float32 and shape: (1,)> pulse_width: <ndarray of type: float32 and shape: (8367,)> prt: <ndarray of type: float32 and shape: (8367,)> radar_antenna_gain_h: <ndarray of type: float32 and shape: (1,)> frequency: <ndarray of type: float32 and shape: (1,)> n_samples: <ndarray of type: int32 and shape: (8367,)> prt_mode: <ndarray of type: |S1 and shape: (17, 6)> radar_beam_width_h: <ndarray of type: float32 and shape: (1,)> radar_beam_width_v: <ndarray of type: float32 and shape: (1,)> polarization_mode: <ndarray of type: |S1 and shape: (17, 10)> latitude: <ndarray of type: float64 and shape: (1,)> longitude: <ndarray of type: float64 and shape: (1,)> nsweeps: 17 ngates: 949 nrays: 8367 radar_calibration: r_calib_index: <ndarray of type: int32 and shape: (8367,)> r_calib_noise_hc: <ndarray of type: float32 and shape: (1,)> r_calib_two_way_radome_loss_h: <ndarray of type: float32 and shape: (1,)> r_calib_radar_constant_v: <ndarray of type: float32 and shape: (1,)> r_calib_pulse_width: <ndarray of type: float32 and shape: (1,)> r_calib_noise_source_power_h: <ndarray of type: float32 and shape: (1,)> r_calib_xmit_power_h: <ndarray of type: float32 and shape: (1,)> r_calib_noise_vx: <ndarray of type: float32 and shape: (1,)> r_calib_noise_source_power_v: <ndarray of type: float32 and shape: (1,)> r_calib_radar_constant_h: <ndarray of type: float32 and shape: (1,)> r_calib_receiver_gain_vx: <ndarray of type: float32 and shape: (1,)> r_calib_receiver_gain_hc: <ndarray of type: float32 and shape: (1,)> r_calib_time: <ndarray of type: |S1 and shape: (1, 21)> range: <ndarray of type: float32 and shape: (949,)> scan_rate: <ndarray of type: float32 and shape: (8367,)> scan_type: rhi sweep_end_ray_index: <ndarray of type: int32 and shape: (17,)> sweep_mode: <ndarray of type: |S1 and shape: (17, 24)> sweep_number: <ndarray of type: int32 and shape: (17,)> sweep_start_ray_index: <ndarray of type: int32 and shape: (17,)> target_scan_rate: None time: <ndarray of type: float64 and shape: (8367,)> metadata: instrument_type: radar fft_len: 64 site_name: sgpC1 sampling_interval: variable site_id: sgp asp_chan_1_enabled: 1 double_hop_enabled: 1 references: See SACR Instrument Handbook clutter_filter_enabled: 0 volume_number: 0 process_version: ingest-sacr-2.4-0.el5 dod_version: wsacrcwrhi-a1-1.2 command_line: sacr_ingest -n wsacr -s sgp -f C1 -R antenna_diameter: 0.9 m source: /data-in/wlj/data/collection//sgp/sgpwsacrC1.00/sgpwsacrC1.00.20120820.204016.raw.W_SGP_SACR_MOMENTS_20120820-204016.dat instrument_name: W-SACR serial_number: Not specified platform_is_mobile: false data_level: a1 datastream: sgpwsacrcwrhiC1.a1 asp_chan_2_enabled: 1 facility_id: C1: Lamont, Oklahoma institution: Department of Energy Atmospheric Radiation Measurement Program averaging_interval: None primary_axis: axis_z scan_name: cross-wind RHI title: ARM WSACR Moments Conventions: CF/Radial instrument_parameters radar_parameters radar_calibration chirp_attenuation: 3.00 dB platform_type: fixed input_source: /data-in/wlj/data/collection//sgp/sgpwsacrC1.00/sgpwsacrC1.00.20120820.204016.raw.W_SGP_SACR_MOMENTS_20120820-204016.dat history: created by user dsmgr on machine bds1 at 2014-02-16 15:38:18, using ingest-sacr-2.4-0.el5
From this listing we see that the file contains a volume consisting of 17 RHI scans with five fields:
Let's use Py-ART's RadarDisplay class to plot these fields.
display = pyart.graph.RadarDisplay(radar)
The display variable is an instance of the RadarDisplay class. We can use the plot
method of this class to visualize the reflectivity data from the second sweep in the WSACR radar volume.
display.plot('reflectivity', sweep=1, vmin=-32, vmax=20)
The colormap used here is not ideal. Py-ART comes with colormaps that are more appropiate for plotting radar data
display.plot('reflectivity', sweep=1,
vmin=-32, vmax=20, cmap='pyart_NWSRef')
Zooming in on an interesting region of this plot can be accomplished using the set_limits
method.
display.plot('reflectivity', sweep=1,
vmin=-32, vmax=20, cmap='pyart_NWSRef')
display.set_limits(ylim=(7, 12), xlim=(-18, -10))
Plotting the other radar moments is done in the same manner. Feel free to adjust the luminosity limits by chaning vmin or vmax to your liking and try out other colormaps.
display.plot('snr', sweep=1, vmin=-20, vmax=30)
display.plot('mean_doppler_velocity', sweep=1,
vmin=-4, vmax=4, cmap='pyart_NWSVel')
display.plot('spectral_width', sweep=1,
vmin=0, vmax=0.4)
display.plot('linear_depolarization_ratio',
sweep=1, vmin=-30, vmax=0, cmap='pyart_Carbone17_r')
Before we take a coffee break, here is an example to give you a taste of how easy Py-ART and Python can be combined to create powerful visualization.
The next cell downloads the latest NEXRAD reflectivity scan from the National Weather Service. Then Py-ART is used to read this file and create a plot on a Cartesian map.
Set the nexrad_site variable to the ICOA code for your favorite NEXRAD site. A full list can be found found here. Some of the presenters favorites are:
# The NEXRAD site from which data will be
nexrad_site = 'ktlx'
import urllib
url = ('ftp://tgftp.nws.noaa.gov/SL.us008001/DF.of/'
'DC.radar/DS.p19r0/SI.' + nexrad_site.lower() + '/sn.last')
handle = urllib.urlopen(url)
radar = pyart.io.read_nexrad_level3(handle)
display = pyart.graph.RadarMapDisplay(radar)
display.plot_ppi_map(
'reflectivity', vmin=-32, vmax=80, cmap='pyart_NWSRef',
resolution='c', embelish=False)
display.basemap.drawcounties()
<matplotlib.collections.LineCollection at 0x10fb5ec10>