Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting python-training back to buiding #111

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.doit.db.db
*.swp
.vscode/

.idea/*
.ipynb_checkpoints/
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
- jupyter
- metpy
- siphon
- pandas
- pandas<1.1.0
- pip
- xarray
- ipywidgets
- ffmpeg
- boto3
- botocore
- jupyterlab
- pip:
- python-awips
- python-awips
42 changes: 25 additions & 17 deletions pages/gallery/500hPa_Vorticity_Advection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"import matplotlib.gridspec as gridspec\n",
"import matplotlib.pylab as plt\n",
"import matplotlib.pyplot as plt\n",
"import metpy.calc as mpcalc\n",
"from metpy.units import units\n",
"from netCDF4 import num2date\n",
"import numpy as np\n",
"import scipy.ndimage as ndimage\n",
"from siphon.ncss import NCSS"
"\n",
"from metpy.units import units\n",
"from netCDF4 import num2date\n",
"from siphon.catalog import TDSCatalog"
]
},
{
Expand All @@ -62,25 +63,32 @@
"metadata": {},
"outputs": [],
"source": [
"# Open the example netCDF data\n",
"ncss = NCSS('https://www.ncei.noaa.gov/thredds/ncss/grid/namanl/'\n",
" '201604/20160416/namanl_218_20160416_1800_000.grb')\n",
"now = datetime.utcnow()\n",
"dt = datetime(2016, 4, 16, 18)\n",
"\n",
"# Assemble our URL to the THREDDS Data Server catalog,\n",
"# and access our desired dataset within via NCSS\n",
"base_url = 'https://www.ncei.noaa.gov/thredds/catalog/model-namanl-old/'\n",
"cat = TDSCatalog(f'{base_url}{dt:%Y%m}/{dt:%Y%m%d}/catalog.xml')\n",
"ncss = cat.datasets[f'namanl_218_{dt:%Y%m%d}_{dt:%H}00_000.grb'].subset()\n",
"\n",
"# Query for Latest GFS Run\n",
"hgt = ncss.query().time(datetime(2016, 4, 16, 18)).accept('netcdf')\n",
"hgt.variables('Geopotential_height_isobaric', 'u-component_of_wind_isobaric',\n",
" 'v-component_of_wind_isobaric').add_lonlat()\n",
"query = ncss.query()\n",
"\n",
"# Actually getting the data\n",
"ds = ncss.get_data(hgt)\n",
"query.time(dt)\n",
"query.accept('netcdf')\n",
"query.variables('Geopotential_height_isobaric',\n",
" 'u-component_of_wind_isobaric',\n",
" 'v-component_of_wind_isobaric')\n",
"query.add_lonlat()\n",
"\n",
"# Obtain our queried data\n",
"ds = ncss.get_data(query)\n",
"\n",
"lon = ds.variables['lon'][:]\n",
"lat = ds.variables['lat'][:]\n",
"\n",
"times = ds.variables[ds.variables['Geopotential_height_isobaric'].dimensions[0]]\n",
"vtime = num2date(times[:], units=times.units)\n",
"\n",
"vtime = num2date(times[:].squeeze(), units=times.units)\n",
"\n",
"lev_500 = np.where(ds.variables['isobaric'][:] == 500)[0][0]\n",
"\n",
Expand Down Expand Up @@ -153,7 +161,7 @@
"# Plot Titles\n",
"plt.title(r'500-hPa Heights (m), AVOR$*10^5$ ($s^{-1}$), AVOR Adv$*10^8$ ($s^{-2}$)',\n",
" loc='left')\n",
"plt.title('VALID: {}'.format(vtime[0]), loc='right')\n",
"plt.title(f'VALID: {vtime}', loc='right')\n",
"\n",
"# Plot Background\n",
"ax.set_extent([235., 290., 20., 58.], ccrs.PlateCarree())\n",
Expand Down Expand Up @@ -210,7 +218,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
37 changes: 23 additions & 14 deletions pages/gallery/850hPa_Temperature_Advection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
"import matplotlib.gridspec as gridspec\n",
"import matplotlib.pyplot as plt\n",
"import metpy.calc as mpcalc\n",
"from metpy.units import units\n",
"from netCDF4 import num2date\n",
"import numpy as np\n",
"import scipy.ndimage as ndimage\n",
"from siphon.ncss import NCSS"
"\n",
"from cftime import num2pydate\n",
"from metpy.units import units\n",
"from siphon.catalog import TDSCatalog"
]
},
{
Expand Down Expand Up @@ -88,19 +89,26 @@
"metadata": {},
"outputs": [],
"source": [
"base_url = 'https://www.ncei.noaa.gov/thredds/ncss/grid/gfs-g4-anl-files/'\n",
"dt = datetime(2017, 4, 5, 12)\n",
"ncss = NCSS('{}{dt:%Y%m}/{dt:%Y%m%d}/gfsanl_4_{dt:%Y%m%d}_'\n",
" '{dt:%H}00_000.grb2'.format(base_url, dt=dt))\n",
"\n",
"# Create lat/lon box for location you want to get data for\n",
"query = ncss.query().time(dt)\n",
"# Assemble our URL to the THREDDS Data Server catalog,\n",
"# and access our desired dataset within via NCSS\n",
"base_url = 'https://www.ncei.noaa.gov/thredds/model-gfs-g4-anl-files-old/'\n",
"cat = TDSCatalog(f'{base_url}{dt:%Y%m}/{dt:%Y%m%d}/catalog.xml')\n",
"ncss = cat.datasets[f'gfsanl_4_{dt:%Y%m%d}_{dt:%H}00_000.grb2'].subset()\n",
"\n",
"# Create NCSS query for our desired time, region, and data variables\n",
"query = ncss.query()\n",
"\n",
"query.time(dt)\n",
"query.lonlat_box(north=65, south=15, east=310, west=220)\n",
"query.accept('netcdf')\n",
"query.variables('Geopotential_height_isobaric',\n",
" 'Temperature_isobaric',\n",
" 'u-component_of_wind_isobaric',\n",
" 'v-component_of_wind_isobaric')\n",
"\n",
"# Request data for vorticity\n",
"query.variables('Geopotential_height_isobaric', 'Temperature_isobaric',\n",
" 'u-component_of_wind_isobaric', 'v-component_of_wind_isobaric')\n",
"# Obtain the queried data\n",
"data = ncss.get_data(query)\n",
"\n",
"# Pull out variables you want to use\n",
Expand All @@ -121,7 +129,7 @@
"v_wind = units.Quantity(v_wind_var[:].squeeze(), v_wind_var.units)\n",
"\n",
"# Convert number of hours since the reference time into an actual date\n",
"time = num2date(time_var[:].squeeze(), time_var.units)\n",
"time = num2pydate(time_var[:].squeeze(), time_var.units)\n",
"\n",
"lev_850 = np.where(data.variables['isobaric'][:] == 850*100)[0][0]\n",
"hght_850 = hght[lev_850]\n",
Expand All @@ -131,6 +139,7 @@
"\n",
"# Combine 1D latitude and longitudes into a 2D grid of locations\n",
"lon_2d, lat_2d = np.meshgrid(lon, lat)\n",
"\n",
"# Gridshift for barbs\n",
"lon_2d[lon_2d > 180] = lon_2d[lon_2d > 180] - 360"
]
Expand Down Expand Up @@ -194,7 +203,7 @@
"\n",
"# Add the map and set the extent\n",
"ax = plt.subplot(gs[0], projection=plotcrs)\n",
"plt.title('850mb Temperature Advection for {0:%d %B %Y %H:%MZ}'.format(time), fontsize=16)\n",
"plt.title(f'850mb Temperature Advection for {time:%d %B %Y %H:%MZ}', fontsize=16)\n",
"ax.set_extent([235., 290., 20., 55.])\n",
"\n",
"# Add state/country boundaries to plot\n",
Expand Down Expand Up @@ -251,7 +260,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
72 changes: 49 additions & 23 deletions pages/gallery/Ageostrophic_Wind_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime\n",
"from datetime import datetime, timedelta\n",
"\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"import matplotlib.pyplot as plt\n",
"import metpy.calc as mpcalc\n",
"from metpy.units import units\n",
"from netCDF4 import num2date\n",
"import numpy as np\n",
"import scipy.ndimage as ndimage\n",
"from siphon.ncss import NCSS"
"\n",
"from cftime import num2pydate\n",
"from metpy.units import units\n",
"from siphon.catalog import TDSCatalog"
]
},
{
Expand All @@ -65,23 +66,35 @@
"metadata": {},
"outputs": [],
"source": [
"# Create NCSS object to access the NetcdfSubset\n",
"base_url = 'https://www.ncei.noaa.gov/thredds/ncss/grid/gfs-g4-anl-files/'\n",
"dt = datetime(2016, 8, 22, 18)\n",
"ncss = NCSS('{}{dt:%Y%m}/{dt:%Y%m%d}/gfsanl_4_{dt:%Y%m%d}_'\n",
" '{dt:%H}00_003.grb2'.format(base_url, dt=dt))\n",
"forecast_hour = 3\n",
"h = timedelta(hours=forecast_hour)\n",
"\n",
"# Assemble our URL to the THREDDS Data Server catalog,\n",
"# and access our desired dataset within via NCSS\n",
"base_url = 'https://www.ncei.noaa.gov/thredds/model-gfs-g4-anl-files-old/'\n",
"cat = TDSCatalog(f'{base_url}{dt:%Y%m}/{dt:%Y%m%d}/catalog.xml')\n",
"ncss = cat.datasets[f'gfsanl_4_{dt:%Y%m%d}_{dt:%H}00_00{forecast_hour}.grb2'].subset()\n",
"\n",
"# Create lat/lon box for location you want to get data for\n",
"# Create NCSS query for our desired time, region, and data variables\n",
"query = ncss.query()\n",
" \n",
"query.lonlat_box(north=50, south=30, east=-80, west=-115)\n",
"query.time(datetime(2016, 8, 22, 21))\n",
"\n",
"# Request data for geopotential height\n",
"query.variables('Geopotential_height_isobaric', 'u-component_of_wind_isobaric',\n",
"query.time(dt + h)\n",
"query.variables('Geopotential_height_isobaric',\n",
" 'u-component_of_wind_isobaric',\n",
" 'v-component_of_wind_isobaric')\n",
"query.vertical_level(100000)\n",
"data = ncss.get_data(query)\n",
"\n",
" \n",
"data = ncss.get_data(query)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Pull out variables you want to use\n",
"height_var = data.variables['Geopotential_height_isobaric']\n",
"u_wind_var = data.variables['u-component_of_wind_isobaric']\n",
Expand All @@ -105,8 +118,15 @@
"v_wind = v_wind_var[0, 0, :, :].squeeze() * units('m/s')\n",
"\n",
"# Convert number of hours since the reference time into an actual date\n",
"time = num2date(time_var[:].squeeze(), time_var.units)\n",
"\n",
"time = num2pydate(time_var[:].squeeze(), time_var.units)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Combine 1D latitude and longitudes into a 2D grid of locations\n",
"lon_2d, lat_2d = np.meshgrid(lon, lat)\n",
"\n",
Expand All @@ -127,15 +147,22 @@
"\n",
"# Calculate ageostrophic wind components\n",
"ageo_wind_u = u_wind - geo_wind_u\n",
"ageo_wind_v = v_wind - geo_wind_v\n",
"\n",
"ageo_wind_v = v_wind - geo_wind_v"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create new figure\n",
"fig = plt.figure(figsize=(15, 10), facecolor='black')\n",
"\n",
"# Add the map and set the extent\n",
"ax = plt.axes(projection=ccrs.PlateCarree())\n",
"ax.set_extent([-105., -93., 35., 43.])\n",
"ax.background_patch.set_fill(False)\n",
"ax.patch.set_fill(False)\n",
"\n",
"# Add state boundaries to plot\n",
"ax.add_feature(cfeature.STATES, edgecolor='white', linewidth=2)\n",
Expand Down Expand Up @@ -171,8 +198,7 @@
"\n",
"# Add a title to the plot\n",
"plt.title('1000mb Geopotential Heights(m), Wind(blue), Geostrophic Wind(purple), and \\n'\n",
" 'Ageostrophic Wind(green) for {0:%d %B %Y %H:%MZ}'.format(time),\n",
" color='white', size=14)"
" f'Ageostrophic Wind(green) for {time:%d %B %Y %H:%MZ}', color='white', size=14)"
]
}
],
Expand All @@ -197,7 +223,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Loading