Skip to content

Instantly share code, notes, and snippets.

@swnesbitt
Created December 29, 2017 13:42
Show Gist options
  • Save swnesbitt/a399b8b45edb6b7cd0be4db63e6ebd04 to your computer and use it in GitHub Desktop.
Save swnesbitt/a399b8b45edb6b7cd0be4db63e6ebd04 to your computer and use it in GitHub Desktop.
This gist reads VertiX radar spectra and plots
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/snesbitt/anaconda/lib/python3.6/site-packages/IPython/core/magics/pylab.py:160: UserWarning: pylab import has clobbered these variables: ['interactive']\n",
"`%matplotlib` prevents importing * from pylab and numpy\n",
" \"\\n`%matplotlib` prevents importing * from pylab and numpy\"\n"
]
}
],
"source": [
"%pylab inline\n",
"import xarray as xr\n",
"from ipywidgets import interactive\n",
"from mpl_toolkits.axes_grid1 import make_axes_locatable"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "db53c0b404be42ac884d01d4428ea108",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data = xr.open_dataset('/Users/snesbitt/data/GCPEX_DATA/18Feb12_0900-1400.ncdf')\n",
"def plot_spectra(time):\n",
" data_sub=data.sel(time_spec=time,method='nearest')\n",
" data_sub2=data.sel(time=time,method='nearest')\n",
" plt.figure(figsize=(11,8.5))\n",
" ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3)\n",
" cax1=ax1.contourf(data['time'].values,data['range'].values,data['reflectivity'],levels=np.arange(-10,45,5),cmap='jet')\n",
" ax1.set_ylim([0,6000])\n",
" ax1.set_title('Reflectivity factor')\n",
" plt.axvline(x=time)\n",
" divider = make_axes_locatable(ax1)\n",
" cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n",
" plt.colorbar(cax1, cax=cax)\n",
" ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=3)\n",
" cax2=ax2.contourf(data['time'].values,data['range'].values,data['doppler_velocity'],levels=np.arange(-5,5,.5),cmap='jet')\n",
" ax2.set_ylim([0,6000])\n",
" ax2.set_title('Mean Doppler velocity')\n",
" plt.axvline(x=time)\n",
" divider = make_axes_locatable(ax2)\n",
" cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n",
" plt.colorbar(cax2, cax=cax)\n",
" ax3 = plt.subplot2grid((3, 3), (2, 0))\n",
" ax3.contourf(data_sub['velocity_spec'].values,data_sub['range_spec'].values,data_sub['spectra'].values)\n",
" ax3.set_ylim([0,6000])\n",
" ax3.set_xlim([-5,5])\n",
" ax3.set_title('Doppler spectra')\n",
" ax4 = plt.subplot2grid((3, 3), (2, 1))\n",
" ax4.plot(data_sub2['reflectivity'].values,data_sub2['range'].values)\n",
" ax4.set_xlim([-20,50])\n",
" ax4.set_ylim([0,6000])\n",
" ax4.set_title('Reflectivity factor')\n",
" ax5 = plt.subplot2grid((3, 3), (2, 2))\n",
" ax5.plot(data_sub2['doppler_velocity'].values,data_sub2['range'].values)\n",
" ax5.set_xlim([-5,5])\n",
" ax5.set_ylim([0,6000])\n",
" ax5.set_title('Mean Doppler velocity')\n",
" plt.tight_layout()\n",
" plt.show()\n",
"\n",
" \n",
"interactive_plot = interactive(plot_spectra, time=data['time'].values)\n",
"output = interactive_plot.children[-1]\n",
"output.layout.height = '625px'\n",
"interactive_plot\n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-10. , -9.61538462, -9.23076923, -8.84615385,\n",
" -8.46153846, -8.07692308, -7.69230769, -7.30769231,\n",
" -6.92307692, -6.53846154, -6.15384615, -5.76923077,\n",
" -5.38461538, -5. , -4.61538462, -4.23076923,\n",
" -3.84615385, -3.46153846, -3.07692308, -2.69230769,\n",
" -2.30769231, -1.92307692, -1.53846154, -1.15384615,\n",
" -0.76923077, -0.38461538, 0. , 0.38461538,\n",
" 0.76923077, 1.15384615, 1.53846154, 1.92307692,\n",
" 2.30769231, 2.69230769, 3.07692308, 3.46153846,\n",
" 3.84615385, 4.23076923, 4.61538462, 5. ])"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linspace(-10,5,40)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment