Skip to content

Instantly share code, notes, and snippets.

@dopplershift
Created September 12, 2018 22:53
Show Gist options
  • Save dopplershift/48001c3102b1583b78c2c6542618beac to your computer and use it in GitHub Desktop.
Save dopplershift/48001c3102b1583b78c2c6542618beac to your computer and use it in GitHub Desktop.
Notebook visualizing data from Hurricane Florence.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"import metpy.calc as mpcalc\n",
"from metpy.plots import StationPlot, add_metpy_logo, add_unidata_logo, add_timestamp\n",
"from metpy.units import units\n",
"from siphon.catalog import TDSCatalog\n",
"from siphon.simplewebservice.ndbc import NDBC\n",
"\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"import matplotlib.patheffects as mpatheffects\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlopen\n",
"import fiona\n",
"\n",
"def get_zip(url):\n",
" data = urlopen(url).read()\n",
" return fiona.BytesCollection(data)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"best_track = get_zip('https://www.nhc.noaa.gov/gis/best_track/al062018_best_track.zip')\n",
"forecast = get_zip('https://www.nhc.noaa.gov/gis/forecast/archive/al062018_5day_latest.zip')\n",
"track_x, track_y = np.array(list(zip(*([item['geometry']['coordinates'] for _, item in best_track.items()]\n",
" + list(forecast.items())[0][1]['geometry']['coordinates']))))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"buoy = NDBC.latest_observations()\n",
"buoy.dropna(subset=['pressure', 'wind_speed', 'wind_direction'], inplace=True)\n",
"buoy_u, buoy_v = mpcalc.wind_components(buoy['wind_speed'].values, buoy['wind_direction'].values * units.degree)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"cat = TDSCatalog('http://thredds-test.unidata.ucar.edu/thredds/catalog/satellite/goes16/GOES16/CONUS/Channel02/current/catalog.xml')\n",
"sat = cat.datasets[-1].remote_access(use_xarray=True)\n",
"var = sat.metpy.parse_cf('Sectorized_CMI')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"sst_cat = TDSCatalog('https://www.ncei.noaa.gov/thredds/catalog/OisstBase/NetCDF/AVHRR/201809/catalog.xml')\n",
"sst = sst_cat.datasets[-1].remote_access(use_xarray=True)\n",
"sst_data = sst.metpy.parse_cf('sst')"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/rmay/repos/metpy/metpy/plots/station_plot.py:299: RuntimeWarning: invalid value encountered in subtract\n",
" u, v = self.ax.projection.transform_vectors(trans, self.x, self.y, u, v)\n"
]
},
{
"data": {
@francho3
Copy link

The code runs in python 2.7?

@djhoese
Copy link

djhoese commented Sep 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment