Skip to content

Instantly share code, notes, and snippets.

@darothen
Forked from JESlaten/Example.ipynb
Created August 3, 2016 19:45
Show Gist options
  • Save darothen/107ea9f1f5d7a16ac0406b503ed85ac2 to your computer and use it in GitHub Desktop.
Save darothen/107ea9f1f5d7a16ac0406b503ed85ac2 to your computer and use it in GitHub Desktop.
WRF Sample Python script.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import xarray as xr\n",
"import matplotlib.pyplot as plt\n",
"import cartopy.crs as ccrs\n",
"\n",
"dataset = xr.open_dataset('wrfout_d01_2016-05-13_00_00_00.nc')\n",
"precip = dataset['QRAIN']\n",
"x = 'west_east'\n",
"y = 'south_north'\n",
"z = 'bottom_top'\n",
"t = 'Time'\n",
"\n",
"total_rain = (precip.load()\n",
" .sum(dim=[y, z], keep_attrs=True)\n",
" .squeeze())\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"fig = plt.figure()\n",
"ax = fig.add_subplot(111, aspect=200.)\n",
"\n",
"lines = ax.plot(total_rain[x], total_rain, color='k', lw=2)\n",
"ax.set_xlabel(x)\n",
"ax.set_ylabel(\"Total rain ({})\".format(total_rain.units))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [Root]",
"language": "python",
"name": "Python [Root]"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment