{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Global & Local Temperature\n",
"This example uses historical data since 1880 on average global surface temperature changes from [NASA'sGISS Surface Temperature Analysis (GISTEMP)](http://data.giss.nasa.gov/gistemp/) ([original file](http://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts+dSST.csv)) That site has lots of other data sets in csv format, too.\n",
"#### Step 1: Click on the \"Save Icon\". If you have a problem and need to completely restart, then click \"File\" and \"Revert to Checkpoint\" to reset.\n",
"\n",
"Click the \"play\" icon or press shift+enter to execute each cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Pre-Questions\n",
"Answer questions 1 & 2 from your coding booklet."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# import the software packages needed\n",
"import pandas as pd\n",
"import numpy as np\n",
"%matplotlib inline\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"inline_rc = dict(mpl.rcParams)\n",
"import datetime as dt\n",
"import matplotlib.dates as mdates"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Importing a data set\n",
"\n",
"This next cell may take a little while to run if it's grabbing a pretty big data set. The cell label to the left will look like \"In [*]\" while it's still thinking and \"In [2]\" when it's finished."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Combined land and ocean temperature averages (LOTI: Land Ocean Temperature Index)\n",
"data1 = pd.read_csv('http://github.com/scpsscience/data/raw/master/LOTI.csv', header=1).replace(to_replace=\"***\", value=np.NaN)\n",
"data_LOTI = data1.apply(lambda x: pd.to_numeric(x, errors='ignore'))\n",
"\n",
"# Only land temperature averages\n",
"data2 = pd.read_csv('http://github.com/scpsscience/data/raw/master/LAND.csv', header=1).replace(to_replace=\"***\", value=np.NaN)\n",
"data_LAND = data2.apply(lambda x: pd.to_numeric(x, errors='ignore'))\n",
"\n",
"# Temperature Data for Orlando, Florida\n",
"data3 = pd.read_csv('http://github.com/scpsscience/data/raw/master/Orlando_Temps.csv')\n",
"\n",
"dates = ['1/1/1975','1/2/1975','01/3/1975']\n",
"x = [dt.datetime.strptime(d,'%m/%d/%Y').date() for d in dates]\n",
"y = \"range(len(x))\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PART 1: Local Temperature Changes & Climate\n",
"\n",
"#### This section will be used for questions 3-5.\n",
"\n",
"We can view the first few rows of data from the file we just imported."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# The .head(n) command displays the first n rows of the local temperature data file.\n",
"data3.head(4)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data3.columns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code below will display a graph displaying the average temperatures at Orlando International Airport. You can double click on the graph to make it bigger."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"ax = data3.plot('date', 'avg', title=\"Average Temperature at Orlando International Airport (1975 - Present)\", legend=False, color='b')\n",
"ax.set(xlabel=\"Date\", ylabel=\"Average Temperature (Fahrenheit)\")\n",
"\n",
"\n",
"# Get current size\n",
"fig_size = plt.rcParams[\"figure.figsize\"]\n",
"\n",
" \n",
"# Set figure width to 20 and height to 6.5\n",
"fig_size[0] = 100\n",
"fig_size[1] = 6.5\n",
"plt.rcParams[\"figure.figsize\"] = fig_size\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code below can show you the Highest and Lowest Temperatures Recorded at Orlando International Airport"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#This section of code will show you the lowest temperatures at Orlando International Airport. \n",
"data3.sort_values('low', ascending=True).head(5)\n",
"\n",
"#This section of code will show you the Highest temperatures at Orlando International Airport. \n",
"#Add a # above and remove the one below to see the highest temperatures.\n",
"\n",
"#data3.sort_values('high', ascending=False).head(5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PART 2: Global Temperature Changes & Climate\n",
"\n",
"This section will be used for questions 6-8."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"# The .head(n) command displays the first n rows of the file.\n",
"data_LAND.head(5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x1 = data_LOTI.Year\n",
"y1 = data_LOTI.JanDec\n",
"\n",
"# plt.plot() makes a line graph, by default\n",
"fig = plt.figure(figsize=(10, 5))\n",
"plt.plot(x1, y1)\n",
"plt.title('Average land and ocean temperature readings')\n",
"plt.xlabel('Year')\n",
"plt.ylabel('Percent temp change')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x2 = data_LAND.Year\n",
"y2 = data_LAND.JanDec\n",
"\n",
"# plt.plot() makes a line graph, by default\n",
"fig = plt.figure(figsize=(10, 5))\n",
"plt.plot(x2, y2)\n",
"plt.title('Land temperature readings')\n",
"plt.xlabel('Year')\n",
"plt.ylabel('Percent temp change')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Wow, this needs a title and axis labels!\n",
"fig = plt.figure(figsize=(10, 5))\n",
"plt.plot(x1, y1, label=\"Land and Ocean\")\n",
"plt.plot(x2, y2, label=\"Land only\")\n",
"\n",
"\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 3: Unstructured Coding\n",
"\n",
"Modify the codes for Part 1 above to answer questions 9-12. The graph in Part 1 will be useful to view precipitaion. You can modify the data charts to view the precipation totals as well!"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"#### DONE?!?!\n",
"\n",
"Try editing some code and re-running the cell to see the effects. For more information on formatting the markdown text in a cell like this one, go to Help > Markdown > Basic Writing and Formatting Text.\n",
"\n",
"To save your work: go to File > Save and Checkpoint. That only saves your edits as long as you're working inthis notebook. All is lost after 10 minutes of inactivity.\n",
"\n",
"To really save your work: go to File > Download as > iPython notebook (or save as pdf if you just want to show someone a snapshot of what your code and output look like."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## References\n",
"- GISTEMP Team, 2017: GISS Surface Temperature Analysis (GISTEMP). NASA Goddard Institute for Space Studies. Dataset accessed 20YY-MM-DD at [https://data.giss.nasa.gov/gistemp/](https://data.giss.nasa.gov/gistemp/).\n",
"- Hansen, J., R. Ruedy, M. Sato, and K. Lo, 2010: [Global surface temperature change](https://pubs.giss.nasa.gov/abs/ha00510u.html), Rev. Geophys., 48, RG4004, doi:10.1029/2010RG000345.\n"
]
}
],
"metadata": {
"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.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}