In [12]:
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn.apionly as sns
%matplotlib notebook
sns.set(rc={'text.color':'#cdd2e9',
'axes.facecolor':'#262931',
'axes.labelcolor':'#cdd2e9',
'grid.color':'#3b3e45',
'xtick.color':'#cdd2e9',
'ytick.color':'#cdd2e9',
'xtick.labelsize':13,
'ytick.labelsize':13,
'axes.titlesize':15,
'legend.fontsize':14,
'figure.figsize':(10,8)})
sns.set_palette(sns.color_palette("Set2", 8))
In [13]:
# The following code is adopted from Pat's Rolling Rain N-Year Threshold.pynb
# Loading in hourly rain data from CSV, parsing the timestamp, and adding it
# as an index so it's more useful
rain_df = pd.read_csv('data/ohare_full_precip_hourly.csv')
rain_df['datetime'] = pd.to_datetime(rain_df['datetime'])
rain_df = rain_df.set_index(pd.DatetimeIndex(rain_df['datetime']))
rain_df = rain_df['19700101':]
chi_rain_series = rain_df['HOURLYPrecip'].resample('1H').max()
print(rain_df.shape)
In [14]:
n_year_threshes = pd.read_csv('data/n_year_definitions.csv')
n_year_threshes = n_year_threshes.set_index('Duration')
n_year_threshes
Out[14]:
In [15]:
n_year_threshes.loc['5-min', '1-year']
Out[15]:
In [16]:
dur_str_to_hours = {
'5-min':5/60.0,
'10-min':10/60.0,
'15-min':15/60.0,
'30-min':0.5,
'1-hr':1.0,
'2-hr':2.0,
'3-hr':3.0,
'6-hr':6.0,
'12-hr':12.0,
'18-hr':18.0,
'24-hr':24.0,
'48-hr':48.0,
'72-hr':72.0,
'5-day':5*24.0,
'10-day':10*24.0
}
def plot_thresh(duration_str, n_years, ax=None):
'''
TODO
'''
global rain_df
global n_year_threshes
if ax is None:
ax = plt.gca()
thresh = n_year_threshes.loc[duration_str, str(n_years) + '-year']
duration = dur_str_to_hours[duration_str]
duration = max(duration, 1) # cannot upsample to more frequent than hourly
# TODO: want to throw warning?
# Create plot
rain_line = chi_rain_series.rolling(window=int(duration), min_periods=0).sum().plot(
ax=ax, color=sns.color_palette()[0])
x_limits = ax.get_xlim()
ax.plot(x_limits, [thresh, thresh], color=sns.color_palette()[1])
ax.set_ylim([0, ax.get_ylim()[1]])
ax.legend(['moving cumulative rain',
str(n_years) + '-year ' + duration_str + ' threshold'],
loc='best')
return ax
In [27]:
ax = plot_thresh('48-hr', 100)
In [ ]:
def get_independent_storms():
'''
TODO
See page 21 of http://www.isws.illinois.edu/atmos/statecli/PDF/b70-all.pdf,
Section 3: Independence of Observations
To help guard against link-rot, I'm just going to copy the
whole pargraph in...
As in any statistical analysis, the individual ob-
servations or data points should be independent of
each other. With a partial-duration series, one must
be careful that the observations used are not meteor-
ologically dependent; that is, they must be from sepa-
rate storm systems. In the present study, data for
precipitation durations of 24 hours or less were ob-
tained from individual precipitation events, defined
as precipitation periods in which there was no pre-
cipitation for at least 6 hours before and 6 hours
after the precipitation event (Huff, 1967); then, only
the maximum value for the particular duration (6
hours, 12 hours, etc.) within such a precipitation
event was used. This ensures that the precipitation
values are independent of each other and are derived
from individual storms. For precipitation durations
of 2 to 10 days, no time separation criteria were
needed.
'''
pass
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: