|
476 | 476 | "metadata": {}, |
477 | 477 | "outputs": [], |
478 | 478 | "source": [ |
479 | | - "# %load solutions/animation.py\n", |
480 | | - "from netCDF4 import num2date\n", |
481 | | - "\n", |
482 | | - "# Load data\n", |
483 | | - "cat = TDSCatalog('http://thredds-test.unidata.ucar.edu/thredds/catalog/casestudies/irma/model/gfs/catalog.xml')\n", |
484 | | - "best_ds = cat.datasets['Best GFS Half Degree Forecast Time Series']\n", |
485 | | - "\n", |
486 | | - "# Access the best dataset using the subset service and request data\n", |
487 | | - "ncss = best_ds.subset()\n", |
488 | | - "\n", |
489 | | - "# Set up query\n", |
490 | | - "query = ncss.query().accept('netcdf4')\n", |
491 | | - "query.lonlat_box(west=-90, east=-55, south=15, north=30)\n", |
492 | | - "query.variables('Pressure_surface', 'Wind_speed_gust_surface')\n", |
493 | | - "query.time_range(datetime(2017, 9, 6, 12), datetime(2017, 9, 11, 12))\n", |
494 | | - "\n", |
495 | | - "# Pull useful pieces out of nc\n", |
496 | | - "nc = ncss.get_data(query)\n", |
497 | | - "lon = nc.variables['longitude'][:]\n", |
498 | | - "lat = nc.variables['latitude'][:]\n", |
499 | | - "press = nc.variables['Pressure_surface']\n", |
500 | | - "winds = nc.variables['Wind_speed_gust_surface']\n", |
501 | | - "time_var = nc.variables['time1']\n", |
502 | | - "times = num2date(time_var[:], time_var.units)\n", |
503 | | - "\n", |
504 | | - "# Create a figure for plotting\n", |
505 | | - "proj = ccrs.LambertConformal(central_longitude=-70)\n", |
506 | | - "fig = plt.figure(figsize=(10, 5))\n", |
507 | | - "ax = fig.add_subplot(1, 1, 1, projection=proj)\n", |
508 | | - "ax.coastlines()\n", |
509 | | - "add_metpy_logo(fig, x=15, y=15)\n", |
510 | | - "\n", |
511 | | - "# Setup up the animation, looping over data to do the plotting that we want\n", |
512 | | - "pressure_levels = np.arange(95000, 105000, 800)\n", |
513 | | - "wind_levels = np.arange(0., 100., 10.)\n", |
514 | | - "artists = []\n", |
515 | | - "\n", |
516 | | - "for press_slice, wind_slice, time in zip(press, winds, times):\n", |
517 | | - " press_contour = ax.contour(lon, lat, press_slice, pressure_levels,\n", |
518 | | - " transform=ccrs.PlateCarree(), colors='black')\n", |
519 | | - " wind_contour = ax.contour(lon, lat, wind_slice, wind_levels,\n", |
520 | | - " transform=ccrs.PlateCarree(), colors='blue')\n", |
521 | | - " text = ax.text(0.5, 1.01, time, transform=ax.transAxes, ha='center')\n", |
522 | | - " artists.append(press_contour.collections + wind_contour.collections + [text])\n", |
523 | | - "\n", |
524 | | - "manimation.ArtistAnimation(fig, artists, interval=100)\n" |
| 479 | + "# %load solutions/animation.py" |
525 | 480 | ] |
526 | 481 | }, |
527 | 482 | { |
|
535 | 490 | ], |
536 | 491 | "metadata": { |
537 | 492 | "kernelspec": { |
538 | | - "display_name": "Python [conda env:unidata-workshop]", |
| 493 | + "display_name": "Python 3", |
539 | 494 | "language": "python", |
540 | | - "name": "conda-env-unidata-workshop-py" |
| 495 | + "name": "python3" |
541 | 496 | }, |
542 | 497 | "language_info": { |
543 | 498 | "codemirror_mode": { |
|
0 commit comments