Please review any and all PUBLIC repositories, groups and associate files. These allow anyone on the Internet to access without authentication. Repository and group owners are responsible for their content and permission settings. Go to your project(s), click on Settings > General and expand the "Visibility, project features, permissions" to change this setting.

Commit 07174e6d authored by Powell, Scott (CIV)'s avatar Powell, Scott (CIV)

add notebook and data

parent cee43b1c
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### MR3522 Lab 4: An Introduction to Microwave Data from SSMI/S\n",
"\n",
"#### Description: Plot a sweep and swath of SSMI/S data at various channels over a West Pacific typhoon."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Import modules."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from glob import glob\n",
"import netCDF4 as nc4\n",
"from matplotlib import pyplot as plt, cm\n",
"import ipywidgets as widgets\n",
"%matplotlib notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Point to directory containing data."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"fdir = '/Users/scott.powell/Public/MR3522/Lab4/data/'\n",
"fname = glob(fdir+'*.nc')[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Open file and read in data."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"Tb = {}\n",
"\n",
"#%% Load the data\n",
"ncid = nc4.Dataset(fname,'r')\n",
"lat = ncid['latitude_lores'][:,:]\n",
"lon = ncid['longitude_lores'][:,:]\n",
"lat92 = ncid['latitude_hires'][:,:]\n",
"lon92 = ncid['longitude_hires'][:,:]\n",
"Tb['H19'] = ncid['fcdr_brightness_temperature_19H'][:,:]\n",
"Tb['V19'] = ncid['fcdr_brightness_temperature_19V'][:,:] \n",
"Tb['V22'] = ncid['fcdr_brightness_temperature_22V'][:,:]\n",
"Tb['H37'] = ncid['fcdr_brightness_temperature_37H'][:,:]\n",
"Tb['V37'] = ncid['fcdr_brightness_temperature_37V'][:,:]\n",
"Tb['H92'] = ncid['fcdr_brightness_temperature_92H'][:,:]\n",
"Tb['V92'] = ncid['fcdr_brightness_temperature_92V'][:,:]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Select the specific area we want. For this file, we're looking over Typhoon Jebi specifically, which was near 20N, 138E.\n",
"\n",
"The first line below plots a subset of the data plotted by the second. Run the code with the first line uncommented first, then when the lab directs you to, comment out the first line below and uncomment the second line to plot a larger swath of data."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"I = np.arange(1100,1102) #This covers just two sweeps.\n",
"#I = np.arange(1000,1200) #This covers the part of the ascending node that covered the typhoon."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Function for plotting."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"def InteractivePlot(band):\n",
"\n",
" plt.close('all')\n",
" \n",
" Tbuse = Tb[band]\n",
" \n",
" fig,ax = plt.subplots(1,1,figsize=(5,7.5))\n",
" \n",
" if band == 'H92' or band == 'V92':\n",
" Xflat, Yflat, Zflat = lon92[I,:].flatten(), lat92[I,:].flatten(), Tbuse[I,:].flatten()\n",
" cf = ax.contourf(lon92[I,:],lat92[I,:],Tbuse[I,:],np.arange(150,290,10),extend=\"both\",cmap=cm.get_cmap('plasma'))\n",
"\n",
" else:\n",
" Xflat, Yflat, Zflat = lon[I,:].flatten(), lat[I,:].flatten(), Tbuse[I,:].flatten()\n",
" cf = ax.contourf(lon[I,:],lat[I,:],Tbuse[I,:],np.arange(150,290,10),extend=\"both\",cmap=cm.get_cmap('plasma'))\n",
"\n",
" cb = fig.colorbar(cf, ax=ax)\n",
" cb.set_label('Brightness Temperature (K)')\n",
" ax.set_xlabel('Longitude')\n",
" ax.set_ylabel('Latitude')\n",
" \n",
" # Function for getting values to show up when hovering over plot.\n",
" def fmt(x, y):\n",
" # get closest point with known data\n",
" dist = np.linalg.norm(np.vstack([Xflat - x, Yflat - y]), axis=0)\n",
" idx = np.argmin(dist)\n",
" z = Zflat[idx]\n",
" return 'Longitude={x:.2f} Latitude={y:.2f} Tb={z:.2f}'.format(x=x, y=y, z=z)\n",
" \n",
" ax.format_coord = fmt"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "56edfacb0e5d4b03affc5c4a505c1cf9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(Dropdown(description='SSMI/S Channels', options=('H19', 'V19', 'V22', 'H37', 'V37', 'H92…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"bands = ['H19','V19','V22','H37','V37','H92','V92']\n",
"varnames = widgets.Dropdown(options=bands,description='SSMI/S Channels')\n",
"widgets.interactive(InteractivePlot,band=varnames)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment