Before working on this assignment please read these instructions fully. In the submission area, you will notice that you can click the link to Preview the Grading for each step of the assignment. This is the criteria that will be used for peer grading. Please familiarize yourself with the criteria before beginning the assignment.
An NOAA dataset has been stored in the file data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89.csv
. This is the dataset to use for this assignment. Note: The data for this assignment comes from a subset of The National Centers for Environmental Information (NCEI) Daily Global Historical Climatology Network (GHCN-Daily). The GHCN-Daily is comprised of daily climate records from thousands of land surface stations across the globe.
Each row in the assignment datafile corresponds to a single observation.
The following variables are provided to you:
For this assignment, you must:
The data you have been given is near Ann Arbor, Michigan, United States, and the stations the data comes from are shown on the map below.
import matplotlib.pyplot as plt
import mplleaflet
import pandas as pd
def leaflet_plot_stations(binsize, hashid):
df = pd.read_csv('data/C2A2_data/BinSize_d{}.csv'.format(binsize))
station_locations_by_hash = df[df['hash'] == hashid]
lons = station_locations_by_hash['LONGITUDE'].tolist()
lats = station_locations_by_hash['LATITUDE'].tolist()
plt.figure(figsize=(8,8))
plt.scatter(lons, lats, c='r', alpha=0.7, s=200)
return mplleaflet.display()
leaflet_plot_stations(400,'fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89')
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# read data file
df = pd.read_csv('data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89.csv')
# convert to datetime format and create columns for month and day of the year
df.loc[:, "Date"] = pd.to_datetime(df["Date"])
df.loc[:, "Day"] = df["Date"].dt.day
df.loc[:, "Month"] = df["Date"].dt.month
df.loc[:, "Year"] = df["Date"].dt.year
# convert to degrees C
df.loc[:, "Data_Value"] = df["Data_Value"]/10
# exclude 29 of Februari for dataset
df_exclude = df.query("Month == 2 and Day == 29")
df = df[~df.index.isin(df_exclude.index)]
# make series for line plots
min_temps = df.query("Year != 2015").query("Element == 'TMIN'").groupby(["Month", "Day"]).min()["Data_Value"]
max_temps = df.query("Year != 2015").query("Element == 'TMAX'").groupby(["Month", "Day"]).max()["Data_Value"]
# make series for scatter plots
min_2015 = df.query("Year == 2015").query("Element == 'TMIN'").groupby(["Month", "Day"]).min()["Data_Value"]
max_2015 = df.query("Year == 2015").query("Element == 'TMAX'").groupby(["Month", "Day"]).max()["Data_Value"]
# adjust for only record highs and record lows
min_2015 = min_2015.mask(min_2015 > min_temps)
max_2015 = max_2015.mask(max_2015 < max_temps)
# set the canvas
plt.figure(figsize=[15.36, 11.52])
plt.xlim(0,365)
plt.ylim(-35,42)
# make plots
pos = np.arange(len(min_temps))
plt.plot(pos, max_temps.values, color="green", linewidth=2, label="record highs 2005-2014")
plt.plot(pos, min_temps.values, color="blue", linewidth=2, label="record lows 2005-2014")
plt.scatter(pos, max_2015.values, color="red", linewidth=2, label="record breaking highs 2015")
plt.scatter(pos, min_2015.values, color="black", linewidth=2, label="record breaking lows 2015")
# tidy up
plt.gca().fill_between(range(len(min_temps)),
min_temps, max_temps,
facecolor='gray',
alpha=0.25)
plt.xlabel('day number')
plt.ylabel('degrees C')
plt.title("2015 record breaking temperatures against the ten year (2005-2014) record temperatures in Ann Arbor, Michigan, United States ")
plt.legend()
#plt.show()
plt.show()