The Global Historical Climatology Network (GHCN) provides access to integrated database of quality reviewed climate data. For these notebooks, we use the GHCN to access historical records for precipitation at International Falls, MN, Station KINL in the NOAA network.
# Display graphics inline with the notebook
%matplotlib inline
# Standard Python modules
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os
import datetime
import seaborn as sns
sns.set_context('talk')
# Modules to display images and data tables
from IPython.display import Image
from IPython.core.display import display
# Directory where data files are stored
dir = "../data/"
# Read .csv file
KINL = pd.read_csv(dir + '434021.csv',index_col=2,parse_dates=True);
# Drop unneeded columns
KINL.drop('STATION',axis=1,inplace=True)
KINL.drop('STATION_NAME',axis=1,inplace=True)
KINL.ix[KINL['SNWD']==-9999,'SNWD'] = float('nan')
KINL.ix[KINL['SNOW']==-9999,'SNOW'] = float('nan')
KINL.ix[KINL['WESD']==-9999,'WESD'] = float('nan')
display(KINL.head())
display(KINL.tail())
PRCP | SNWD | SNOW | WESD | |
---|---|---|---|---|
DATE | ||||
1970-01-01 | 3 | 356.0 | 3.0 | 605.0 |
1970-01-02 | 0 | 356.0 | 0.0 | 607.0 |
1970-01-03 | 10 | 356.0 | 10.0 | 617.0 |
1970-01-04 | 3 | 356.0 | 3.0 | 620.0 |
1970-01-05 | 0 | 356.0 | 0.0 | 620.0 |
PRCP | SNWD | SNOW | WESD | |
---|---|---|---|---|
DATE | ||||
2014-11-16 | 5 | 50.0 | 18.0 | NaN |
2014-11-17 | 3 | 80.0 | 5.0 | NaN |
2014-11-18 | 5 | 80.0 | 18.0 | NaN |
2014-11-19 | 18 | 100.0 | 51.0 | NaN |
2014-11-20 | 0 | 130.0 | 3.0 | NaN |
plt.figure(figsize=(9,8))
plt.subplot(4,1,1)
KINL['PRCP'].plot()
plt.title('Precipitation (PRCP)')
plt.subplot(4,1,2)
KINL['SNWD'].plot()
plt.title('Snow Depth (SNWD)')
plt.subplot(4,1,3)
KINL['SNOW'].plot()
plt.title('Snow (SNOW)')
plt.subplot(4,1,4)
KINL['WESD'].plot()
plt.title('Water Equivalent Snow Depth (WESD)')
plt.tight_layout()
The data series for water equivalent snow depth appears to be incomplete and not useful the present analysis. The data series for precipitation is converted to a Pandas data series and to standard metric units for precipitation, mm of water. The data series is pickled to a file PRCP.pkl
.
plt.figure(figsize=(8,6))
KINL = pd.Series(KINL['PRCP'])/10.0
KINL.name = 'Precipitation at International Falls (KINL)'
KINL.to_pickle(dir+'KINL.pkl')
KINL.plot(lw=1)
plt.title(KINL.name)
plt.ylabel('millimeters')
<matplotlib.text.Text at 0x117811c88>
# Read .csv file
TEMP = pd.read_csv(dir + '528052.csv',index_col=2,parse_dates=True);
# Drop unneeded columns
TEMP.drop('STATION',axis=1,inplace=True)
TEMP.drop('STATION_NAME',axis=1,inplace=True)
TEMP.drop('TOBS',axis=1,inplace=True)
TEMP.ix[TEMP['TMAX']==-9999,'TMAX'] = float('nan')
TEMP.ix[TEMP['TMIN']==-9999,'TMIN'] = float('nan')
# Convert to Celcius
TEMP = TEMP/10.0 # 32.0 + (9.0*TEMP/50.0)
# Create Comparison Sets
Ta = TEMP['1948':'1981']
Ta.columns = ['Tmax 1948-1981', 'Tmin 1948-1981']
display(Ta.head())
Tb = TEMP['1982':'2014']
Tb.columns = ['Tmax 1982-2014', 'Tmin 1982-2014']
display(Tb.head())
# Group by month, plot on same axis
plt.figure(figsize=(10,6))
ax = Ta['Tmax 1948-1981'].groupby(Ta.index.month).mean().plot()
Ta['Tmin 1948-1981'].groupby(Ta.index.month).mean().plot(ax=ax)
Tb['Tmax 1982-2014'].groupby(Tb.index.month).mean().plot(ax=ax)
Tb['Tmin 1982-2014'].groupby(Tb.index.month).mean().plot(ax=ax)
ax.set_xticks(np.arange(1.0,13.0,1.0))
ax.set_xticklabels(('Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'));
plt.title('Monthy Means of Min and Max Temperatures at International Falls, MN')
plt.ylabel('Temperature [C]');
plt.xlabel('Month')
plt.tight_layout()
plt.grid()
fname = '../images/KINL_MonthyMeanTemp.png'
plt.savefig(fname)
!convert $fname -trim $fname
Tmax 1948-1981 | Tmin 1948-1981 | |
---|---|---|
DATE | ||
1948-01-01 | -8.9 | -30.0 |
1948-01-02 | -5.6 | -12.2 |
1948-01-03 | -5.0 | -10.6 |
1948-01-04 | -4.4 | -8.3 |
1948-01-05 | -0.6 | -10.0 |
Tmax 1982-2014 | Tmin 1982-2014 | |
---|---|---|
DATE | ||
1982-01-01 | -21.7 | -31.1 |
1982-01-02 | -8.3 | -22.2 |
1982-01-03 | -12.2 | -28.9 |
1982-01-04 | -18.3 | -26.7 |
1982-01-05 | -10.0 | -26.1 |
# Group by month, plot on same axis
plt.figure(figsize=(10,6))
ax = Ta['Tmax 1948-1981'].groupby(Ta.index.month).std().plot()
Ta['Tmin 1948-1981'].groupby(Ta.index.month).std().plot(ax=ax)
Tb['Tmax 1982-2014'].groupby(Tb.index.month).std().plot(ax=ax)
Tb['Tmin 1982-2014'].groupby(Tb.index.month).std().plot(ax=ax)
ax.set_xticks(np.arange(1.0,13.0,1.0))
ax.set_xticklabels(('Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'));
plt.title('Monthly Standard Deviation of Min and Max Temperatures at International Falls, MN')
plt.ylabel('Temperature [C]');
plt.xlabel('Month')
plt.tight_layout()
fname = '../images/KINL_MonthyStdTemp.png'
plt.savefig(fname)
!convert $fname -trim $fname
b = np.arange(-45,10,1)
plt.figure(figsize=(10,6))
plt.subplot(2,1,1)
Ta['Tmin 1948-1981'][Ta.index.month == 1].hist(
cumulative=True,bins=b,color='blue',normed=1,alpha=0.5)
Tb['Tmin 1982-2014'][Tb.index.month == 1].hist(
cumulative=True,bins=b,color='gold',normed=1,alpha=0.5)
plt.legend(['1948-1981','1982-2014'],loc='best')
plt.axis([-45,10,0,1.05])
plt.title('Cumulative Distributions of Daily Lows and Highs, January, KINL')
plt.ylabel('Fraction Tlow < T')
plt.subplot(2,1,2)
Ta['Tmax 1948-1981'][Ta.index.month == 1].hist(
cumulative=True,bins=b,color='blue',normed=1,alpha=0.5)
Tb['Tmax 1982-2014'][Tb.index.month == 1].hist(
cumulative=True,bins=b,color='gold',normed=1,alpha=0.5)
plt.legend(['1948-1981','1982-2014'],loc='best')
plt.axis([-45,10,0,1.05])
plt.xlabel('Temperature [C]')
plt.ylabel('Fraction Thigh < T')
plt.tight_layout()
fname = '../images/KINL_TempJan.png'
plt.savefig(fname)
!convert $fname -trim $fname
mostr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
xlo = -45
xhi = 25
dx = 0.5
plt.figure(figsize=(10,8))
for mo in range(1,13):
plt.subplot(4,3,mo)
plt.hold(True)
Ta['Tmin 1948-1981'][Ta.index.month == mo].hist(cumulative=True,
normed=True,
bins=np.arange(xlo,xhi+3*dx,3*dx),
color = 'b',
alpha = 0.5)
Tb['Tmin 1982-2014'][Tb.index.month == mo].hist(cumulative=True,
normed=True,
bins=np.arange(xlo,xhi+3*dx,3*dx),
color = 'y',
alpha = 0.5)
plt.legend(['1970-1999','2000-2012'],loc='upper left')
plt.axis([xlo,xhi,0,1.05])
plt.title(mostr[mo-1])
plt.hold(False)
plt.tight_layout()
fname = '../images/KINL_Lows.png'
plt.savefig(fname)
!convert $fname -trim $fname
mostr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
xlo = -45
xhi = 35
dx = 0.5
plt.figure(figsize=(10,8))
for mo in range(1,13):
plt.subplot(4,3,mo)
plt.hold(True)
Ta['Tmax 1948-1981'][Ta.index.month == mo].hist(cumulative=True,
normed=True,
bins=np.arange(xlo,xhi+3*dx,3*dx),
color = 'b',
alpha = 0.5)
Tb['Tmax 1982-2014'][Tb.index.month == mo].hist(cumulative=True,
normed=True,
bins=np.arange(xlo,xhi+3*dx,3*dx),
color = 'y',
alpha = 0.5)
plt.legend(['1970-1999','2000-2012'],loc='upper left')
plt.axis([xlo,xhi,0,1.05])
plt.title(mostr[mo-1])
plt.hold(False)
plt.tight_layout()
fname = '../images/KINL_Highs.png'
plt.savefig(fname)
!convert $fname -trim $fname