Skip to content

Instantly share code, notes, and snippets.

@TaylorMutch
Last active November 23, 2016 23:04
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 TaylorMutch/8f62504859983d3e6b1fbc4037914f61 to your computer and use it in GitHub Desktop.
Save TaylorMutch/8f62504859983d3e6b1fbc4037914f61 to your computer and use it in GitHub Desktop.
An example for showing directions for a night of sodar records.
from sodar_utils import SodarCollection
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as col
sodars = SodarCollection('sodar_data/Primet')
data = sodars.night_array('direction')
def cyclic_colormap():
black = '#000000'
red = '#ff0000'
blue = '#0000ff'
green = '#00ff00'
return col.LinearSegmentedColormap.from_list(
'anglemap', [black, red, blue, green, black], N=256, gamma=1)
# Find the index of the specific night we're interested in
index = [i for i, j in enumerate(data[1]) if j['name']=='0527'][0]
num_rows = 26
#max_height = sodars.heights[num_rows]
# Get the data for just that night
night = np.transpose(data[0][index])[:num_rows]
night[night==-1] = np.nan
# Create the plot, with a color key
fig, ax = plt.subplots(figsize=(8,8))
cax = fig.add_axes()
im = ax.imshow(night, aspect='auto', origin='lower', cmap=cyclic_colormap(), interpolation='none')
ytick_labels = sodars.heights[:num_rows]
ax.set_yticks([i for i in range(num_rows)])
ax.set_yticklabels(ytick_labels)
plt.ylabel('Height [m]')
ax.set_xticks([0, 36, 72, 108, 144])
ax.set_xticklabels(['18:00', '21:00', '00:00', '03:00', '06:00'])
plt.xlabel('Hour (1800 - 0600)')
# Legend and show
cbar = fig.colorbar(im, cax=cax, orientation='vertical')
cbar.set_ticks([0, 90, 180, 270, 359])
cbar.ax.set_yticklabels(['N', 'E', 'S', 'W', 'N'])
labels = [item.get_text() for item in cbar.ax.get_yticklabels()]
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment