# import the software packages needed
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
inline_rc = dict(mpl.rcParams)
import datetime as dt
import matplotlib.dates as mdates

"""
Explanation: Global & Local Temperature
This example uses historical data since 1880 on average global surface temperature changes from NASA'sGISS Surface Temperature Analysis (GISTEMP) (original file) That site has lots of other data sets in csv format, too.
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.
Click the "play" icon or press shift+enter to execute each cell.
<span style="color:magenta">Pre-Questions</span>
Answer questions 1 & 2 from your coding booklet.
End of explanation
"""


# Combined land and ocean temperature averages (LOTI: Land Ocean Temperature Index)
data1 = pd.read_csv('http://github.com/scpsscience/data/raw/master/LOTI.csv', header=1).replace(to_replace="***", value=np.NaN)
data_LOTI = data1.apply(lambda x: pd.to_numeric(x, errors='ignore'))

# Only land temperature averages
data2 = pd.read_csv('http://github.com/scpsscience/data/raw/master/LAND.csv', header=1).replace(to_replace="***", value=np.NaN)
data_LAND = data2.apply(lambda x: pd.to_numeric(x, errors='ignore'))

# Temperature Data for Orlando, Florida
data3 = pd.read_csv('http://github.com/scpsscience/data/raw/master/Orlando_Temps.csv')

dates = ['1/1/1975','1/2/1975','01/3/1975']
x = [dt.datetime.strptime(d,'%m/%d/%Y').date() for d in dates]
y = "range(len(x))"

"""
Explanation: Importing a data set
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.
End of explanation
"""


# The .head(n) command displays the first n rows of the local temperature data file.
data3.head(4)


data3.columns

"""
Explanation: <span style="color:magenta">PART 1: Local Temperature Changes & Climate</span>
This section will be used for questions 3-5.
We can view the first few rows of data from the file we just imported.
End of explanation
"""


ax = data3.plot('date', 'avg', title="Average Temperature at Orlando International Airport (1975 - Present)", legend=False, color='b')
ax.set(xlabel="Date", ylabel="Average Temperature (Fahrenheit)")


# Get current size
fig_size = plt.rcParams["figure.figsize"]

 
# Set figure width to 20 and height to 6.5
fig_size[0] = 100
fig_size[1] = 6.5
plt.rcParams["figure.figsize"] = fig_size

plt.show()

"""
Explanation: 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.
End of explanation
"""


#This section of code will show you the lowest temperatures at Orlando International Airport. 
data3.sort_values('low', ascending=True).head(5)

#This section of code will show you the Highest temperatures at Orlando International Airport. 
#Add a # above and remove the one below to see the highest temperatures.

#data3.sort_values('high', ascending=False).head(5)

"""
Explanation: The code below can show you the Highest and Lowest Temperatures Recorded at Orlando International Airport
End of explanation
"""


# The .head(n) command displays the first n rows of the file.
data_LAND.head(5)

x1 = data_LOTI.Year
y1 = data_LOTI.JanDec

# plt.plot() makes a line graph, by default
fig = plt.figure(figsize=(10, 5))
plt.plot(x1, y1)
plt.title('Average land and ocean temperature readings')
plt.xlabel('Year')
plt.ylabel('Percent temp change')

x2 = data_LAND.Year
y2 = data_LAND.JanDec

# plt.plot() makes a line graph, by default
fig = plt.figure(figsize=(10, 5))
plt.plot(x2, y2)
plt.title('Land temperature readings')
plt.xlabel('Year')
plt.ylabel('Percent temp change')

# Wow, this needs a title and axis labels!
fig = plt.figure(figsize=(10, 5))
plt.plot(x1, y1, label="Land and Ocean")
plt.plot(x2, y2, label="Land only")


plt.legend()
plt.show()

"""
Explanation: <span style="color:magenta">PART 2: Global Temperature Changes & Climate</span>
This section will be used for questions 6-8.
End of explanation
"""


