Skip to content

Instantly share code, notes, and snippets.

@julienchastang
Created November 23, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julienchastang/04f70c48090e48d5026664db3a8f3bfa to your computer and use it in GitHub Desktop.
Save julienchastang/04f70c48090e48d5026664db3a8f3bfa to your computer and use it in GitHub Desktop.
Metpy NIDS Data Visualization
import numpy as np
import matplotlib.pyplot as plt
from numpy import ma
from matplotlib.colors import ListedColormap
from metpy.cbook import get_test_data
from metpy.io.nexrad import Level3File
from metpy.plots import ctables
import matplotlib as mpl
%matplotlib inline
fig = plt.figure(figsize=(8, 6))
ax = plt.gca()
f = Level3File(
"/tmp/KLIX_SDUS54_N0ULIX_201208301134")
# Pull the data out of the file object
datadict = f.sym_block[0][0]
# Turn into an array, then mask
data = ma.array(datadict['data'])
# Converting to knots according to Ryan's comments
data = (data / 10) * 1.94384
# IDV filters out data < 5
data[data < 5.0] = ma.masked
# Grab azimuths and calculate a range based on number of gates
az = np.array(datadict['start_az'] + [datadict['end_az'][-1]])
rng = np.linspace(0, f.max_range, data.shape[-1] + 1)
# Convert az,range to x,y
xlocs = rng * np.sin(np.deg2rad(az[:, np.newaxis]))
ylocs = rng * np.cos(np.deg2rad(az[:, np.newaxis]))
# IDV Color table
cmap = ListedColormap(
[(0, 0, 0), (0.12, 0.97, 0.97), (0.12, 0.63, 0.63), (0.57, 0.91, 0.40),
(0.47, 0.77, 0.35), (0.37, 0.63, 0.29), (0.27, 0.49, 0.23),
(0.18, 0.35, 0.18), (0.97, 0.80, 0.18), (0.97, 0.57, 0.23),
(0.97, 0.18, 0.23), (0.63, 0.12, 0.12), (0.74, 0.23, 0.57),
(0.83, 0.35, 0.69), (1, 1, 1), (1, 0.57, 0.91)])
norm = mpl.colors.Normalize(vmin=0, vmax=80)
# Plot the data
im = ax.pcolormesh(xlocs, ylocs, data, norm=norm, cmap=cmap)
# im = ax.pcolormesh(xlocs, ylocs, data, cmap=cmap)
ax.set_aspect('equal', 'datalim')
ax.set_xlim(-300, 300)
ax.set_ylim(-300, 300)
cb = plt.colorbar(im, ticks=np.linspace(0, 80, 9))
cb.set_label('Knots')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment