Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #277 from jrleeman/exercise_format_update
Browse files Browse the repository at this point in the history
Exercise format update
  • Loading branch information
dopplershift authored Mar 20, 2018
2 parents f25a6ac + 3542d6d commit ec2edd7
Show file tree
Hide file tree
Showing 58 changed files with 971 additions and 965 deletions.
56 changes: 51 additions & 5 deletions notebooks/Animation/Creating Animations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,58 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"# %load solutions/animation.py"
"<button data-toggle=\"collapse\" data-target=\"#sol1\" class='btn btn-primary'>View Solution</button>\n",
"<div id=\"sol1\" class=\"collapse\">\n",
"```python\n",
"from netCDF4 import num2date\n",
"\n",
"# Load data\n",
"cat = TDSCatalog('http://thredds-test.unidata.ucar.edu/thredds/catalog/casestudies/irma/model/gfs/catalog.xml')\n",
"best_ds = cat.datasets['Best GFS Half Degree Forecast Time Series']\n",
"\n",
"# Access the best dataset using the subset service and request data\n",
"ncss = best_ds.subset()\n",
"\n",
"# Set up query\n",
"query = ncss.query().accept('netcdf4')\n",
"query.lonlat_box(west=-90, east=-55, south=15, north=30)\n",
"query.variables('Pressure_surface', 'Wind_speed_gust_surface')\n",
"query.time_range(datetime(2017, 9, 6, 12), datetime(2017, 9, 11, 12))\n",
"\n",
"# Pull useful pieces out of nc\n",
"nc = ncss.get_data(query)\n",
"lon = nc.variables['longitude'][:]\n",
"lat = nc.variables['latitude'][:]\n",
"press = nc.variables['Pressure_surface']\n",
"winds = nc.variables['Wind_speed_gust_surface']\n",
"time_var = nc.variables['time1']\n",
"times = num2date(time_var[:], time_var.units)\n",
"\n",
"# Create a figure for plotting\n",
"proj = ccrs.LambertConformal(central_longitude=-70)\n",
"fig = plt.figure(figsize=(10, 5))\n",
"ax = fig.add_subplot(1, 1, 1, projection=proj)\n",
"ax.coastlines()\n",
"add_metpy_logo(fig, x=15, y=15)\n",
"\n",
"# Setup up the animation, looping over data to do the plotting that we want\n",
"pressure_levels = np.arange(95000, 105000, 800)\n",
"wind_levels = np.arange(0., 100., 10.)\n",
"artists = []\n",
"\n",
"for press_slice, wind_slice, time in zip(press, winds, times):\n",
" press_contour = ax.contour(lon, lat, press_slice, pressure_levels,\n",
" transform=ccrs.PlateCarree(), colors='black')\n",
" wind_contour = ax.contour(lon, lat, wind_slice, wind_levels,\n",
" transform=ccrs.PlateCarree(), colors='blue')\n",
" text = ax.text(0.5, 1.01, time, transform=ax.transAxes, ha='center')\n",
" artists.append(press_contour.collections + wind_contour.collections + [text])\n",
"\n",
"manimation.ArtistAnimation(fig, artists, interval=100)\n",
"```"
]
},
{
Expand Down Expand Up @@ -504,7 +550,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
"version": "3.6.4"
}
},
"nbformat": 4,
Expand Down
45 changes: 0 additions & 45 deletions notebooks/Animation/solutions/animation.py

This file was deleted.

21 changes: 17 additions & 4 deletions notebooks/CartoPy/CartoPy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,25 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"# %load solutions/map.py"
"<button data-toggle=\"collapse\" data-target=\"#sol1\" class='btn btn-primary'>View Solution</button>\n",
"<div id=\"sol1\" class=\"collapse\">\n",
"```python\n",
"fig = plt.figure(figsize=(10, 8))\n",
"ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mercator())\n",
"\n",
"ax.add_feature(cfeature.COASTLINE)\n",
"ax.add_feature(cfeature.LAND, facecolor='tab:brown')\n",
"ax.add_feature(cfeature.OCEAN, facecolor='tab:cyan')\n",
"ax.add_feature(cfeature.BORDERS, linewidth=2)\n",
"ax.add_feature(cfeature.STATES, linestyle=\"--\", edgecolor='black')\n",
"\n",
"ax.plot(-101.877, 33.583, marker='o', color='tab:green', transform=ccrs.PlateCarree())\n",
"\n",
"ax.set_extent([-108, -93, 25, 37])\n",
"```"
]
}
],
Expand Down
12 changes: 0 additions & 12 deletions notebooks/CartoPy/solutions/map.py

This file was deleted.

86 changes: 76 additions & 10 deletions notebooks/MetPy_Advanced/Isentropic Analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,58 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# %load solutions/isen_mixing.py"
"<button data-toggle=\"collapse\" data-target=\"#sol1\" class='btn btn-primary'>View Solution</button>\n",
"<div id=\"sol1\" class=\"collapse\">\n",
"```python\n",
"# Needed to make numpy broadcasting work between 1D pressure and other 3D arrays\n",
"pressure_for_calc = press[:, None, None]\n",
"\n",
"# Calculate mixing ratio using something from mpcalc\n",
"mixing = mpcalc.mixing_ratio_from_relative_humidity(rh, temperature, pressure_for_calc)\n",
"\n",
"# Take the return and convert manually to units of 'dimenionless'\n",
"mixing.ito('dimensionless')\n",
"\n",
"# Interpolate all the data\n",
"isen_level = np.array([295]) * units.kelvin\n",
"ret = mpcalc.isentropic_interpolation(isen_level, press, temperature, mixing, u, v)\n",
"isen_press, isen_mixing, isen_u, isen_v = ret\n",
"\n",
"# Squeeze the returned arrays\n",
"isen_press = isen_press.squeeze()\n",
"isen_mixing = isen_mixing.squeeze()\n",
"isen_u = isen_u.squeeze()\n",
"isen_v = isen_v.squeeze()\n",
"\n",
"# Create Plot -- same as before\n",
"fig = plt.figure(figsize=(14, 8))\n",
"ax = fig.add_subplot(1, 1, 1, projection=ccrs.LambertConformal(central_longitude=-100))\n",
"ax.coastlines()\n",
"\n",
"levels = np.arange(300, 1000, 25)\n",
"cntr = ax.contour(lon, lat, isen_press, transform=ccrs.PlateCarree(),\n",
" colors='black', levels=levels)\n",
"ax.clabel(cntr, fmt='%.0f')\n",
"\n",
"lon_slice = slice(None, None, 8)\n",
"lat_slice = slice(None, None, 8)\n",
"ax.barbs(lon[lon_slice], lat[lat_slice],\n",
" isen_u[lon_slice, lat_slice].to('knots').magnitude,\n",
" isen_v[lon_slice, lat_slice].to('knots').magnitude,\n",
" transform=ccrs.PlateCarree(), zorder=2)\n",
"\n",
"# Contourf the mixing ratio values\n",
"mixing_levels = [0.001, 0.002, 0.004, 0.006, 0.010, 0.012, 0.014, 0.016, 0.020]\n",
"ax.contourf(lon, lat, isen_mixing, transform=ccrs.PlateCarree(),\n",
" levels=mixing_levels, cmap='YlGn')\n",
"\n",
"ax.set_extent((-120, -70, 25, 55), crs=ccrs.PlateCarree())\n",
"```"
]
},
{
Expand Down Expand Up @@ -433,20 +477,42 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"# %load solutions/isen_ascent.py"
"<button data-toggle=\"collapse\" data-target=\"#sol1\" class='btn btn-primary'>View Solution</button>\n",
"<div id=\"sol1\" class=\"collapse\">\n",
"```python\n",
"fig = plt.figure(figsize=(14, 8))\n",
"ax = fig.add_subplot(1, 1, 1, projection=ccrs.LambertConformal(central_longitude=-100))\n",
"ax.coastlines()\n",
"\n",
"levels = np.arange(300, 1000, 25)\n",
"cntr = ax.contour(lon, lat, isen_press, transform=ccrs.PlateCarree(), colors='black', levels=levels)\n",
"ax.clabel(cntr, fmt='%.0f')\n",
"\n",
"lon_slice = slice(None, None, 5)\n",
"lat_slice = slice(None, None, 5)\n",
"ax.barbs(lon[lon_slice], lat[lat_slice],\n",
" isen_u[lon_slice, lat_slice].to('knots').magnitude,\n",
" isen_v[lon_slice, lat_slice].to('knots').magnitude,\n",
" transform=ccrs.PlateCarree(), zorder=2)\n",
"\n",
"levels = np.arange(-6, 7)\n",
"cs = ax.contourf(lon, lat, lift.to('microbar/s'), levels=levels, cmap='RdBu',\n",
" transform=ccrs.PlateCarree(), extend='both')\n",
"plt.colorbar(cs)\n",
"\n",
"ax.set_extent((-120, -70, 25, 55), crs=ccrs.PlateCarree())\n",
"```"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:unidata-workshop]",
"display_name": "Python 3",
"language": "python",
"name": "conda-env-unidata-workshop-py"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down
21 changes: 0 additions & 21 deletions notebooks/MetPy_Advanced/solutions/isen_ascent.py

This file was deleted.

43 changes: 0 additions & 43 deletions notebooks/MetPy_Advanced/solutions/isen_mixing.py

This file was deleted.

Loading

0 comments on commit ec2edd7

Please sign in to comment.