TDS Radar Query Service

Use Siphon to get NEXRAD Level 3 data from a TDS.

from datetime import datetime

import matplotlib.pyplot as plt
import numpy as np

from siphon.cdmr import Dataset
from siphon.radarserver import get_radarserver_datasets, RadarServer

First, point to the top-level thredds radar server accessor to find what datasets are available.

ds = get_radarserver_datasets('http://thredds.ucar.edu/thredds/')
print(list(ds))

Out:

['NEXRAD Level II Radar for Case Study CCS039', 'NEXRAD Level II Radar from IDD', 'NEXRAD Level III Radar for Case Study CCS039', 'NEXRAD Level III Radar from IDD', 'TDWR Level III Radar from IDD']

Now create an instance of RadarServer to point to the appropriate radar server access URL. This is pulled from the catalog reference url.

url = ds['NEXRAD Level III Radar from IDD'].follow().catalog_url
rs = RadarServer(url)

Look at the variables available in this dataset

print(rs.variables)

Out:

{'DU3', 'N0K', 'DSP', 'NAQ', 'N2C', 'DSD', 'N0H', 'N3X', 'N0S', 'N2S', 'NAK', 'EET', 'N3M', 'OHA', 'NVL', 'N3Q', 'NAC', 'N0Q', 'NBM', 'N0M', 'N1S', 'DTA', 'DAA', 'N2K', 'N1C', 'NAH', 'N3C', 'N0Z', 'DHR', 'DOD', 'N0U', 'NTP', 'DVL', 'N0V', 'N2H', 'N2M', 'N1Q', 'N1M', 'PTA', 'NBH', 'N2U', 'N3S', 'NAU', 'NBU', 'DPR', 'N1K', 'DPA', 'N0R', 'N0C', 'NST', 'N1U', 'NAX', 'NAM', 'N3K', 'N2X', 'N3H', 'NBC', 'N1H', 'NBX', 'NCR', 'N2Q', 'HHC', 'N1X', 'DU6', 'NET', 'NBQ', 'NVW', 'N0X', 'N3U', 'NMD', 'N1P', 'NBK'}

Create a new query object to help request the data. Using the chaining methods, ask for data from radar FTG (Denver) for now for the product N0Q, which is reflectivity data for the lowest tilt. We see that when the query is represented as a string, it shows the encoded URL.

query = rs.query()
query.stations('FTG').time(datetime.utcnow()).variables('N0Q')

We can use the RadarServer instance to check our query, to make sure we have required parameters and that we have chosen valid station(s) and variable(s)

rs.validate_query(query)

Make the request, which returns an instance of TDSCatalog. This handles parsing the catalog

catalog = rs.get_catalog(query)

We can look at the datasets on the catalog to see what data we found by the query. We find one NIDS file in the return.

print(catalog.datasets)

Out:

['Level3_FTG_N0Q_20180814_2112.nids']

We can pull that dataset out of the dictionary and look at the available access URLs. We see URLs for OPeNDAP, CDMRemote, and HTTPServer (direct download).

ds = list(catalog.datasets.values())[0]
print(ds.access_urls)

Out:

{'OPENDAP': 'http://thredds.ucar.edu/thredds/dodsC/nexrad/level3/IDD/N0Q/FTG/20180814/Level3_FTG_N0Q_20180814_2112.nids', 'HTTPServer': 'http://thredds.ucar.edu/thredds/fileServer/nexrad/level3/IDD/N0Q/FTG/20180814/Level3_FTG_N0Q_20180814_2112.nids', 'CdmRemote': 'http://thredds.ucar.edu/thredds/cdmremote/nexrad/level3/IDD/N0Q/FTG/20180814/Level3_FTG_N0Q_20180814_2112.nids'}

We’ll use the CDMRemote reader in Siphon and pass it the appropriate access URL.

data = Dataset(ds.access_urls['CdmRemote'])

The CDMRemote reader provides an interface that is almost identical to the usual python NetCDF interface. We pull out the variables we need for azimuth and range, as well as the data itself.

rng = data.variables['gate'][:] / 1000.
az = data.variables['azimuth'][:]
ref = data.variables['BaseReflectivityDR'][:]

Then convert the polar coordinates to Cartesian

x = rng * np.sin(np.deg2rad(az))[:, None]
y = rng * np.cos(np.deg2rad(az))[:, None]
ref = np.ma.array(ref, mask=np.isnan(ref))

Finally, we plot them up using matplotlib.

fig, ax = plt.subplots(1, 1, figsize=(9, 8))
ax.pcolormesh(x, y, ref)
ax.set_aspect('equal', 'datalim')
ax.set_xlim(-460, 460)
ax.set_ylim(-460, 460)
../_images/sphx_glr_Radar_Server_Level_3_001.png

Total running time of the script: ( 0 minutes 2.524 seconds)

Gallery generated by Sphinx-Gallery