Skip to content

Commit 5e5ffe1

Browse files
committed
MNT: move weather data around and pull data for ORNL
1 parent cbe3997 commit 5e5ffe1

File tree

7 files changed

+45
-30
lines changed

7 files changed

+45
-30
lines changed

weather/04-custom_plotting.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import matplotlib.pyplot as plt
2+
from w_helpers import load_bwi_data, aggregate_by_month
3+
plt.ion()
4+
5+
bwi = load_bwi_data()
6+
bwi_monthly = aggregate_by_month(bwi)
7+
8+
fig, ax = plt.subplots()
9+
10+
11+
def plot_aggregated_errorbar(ax, gb, label, picker=None, **kwargs):
12+
kwargs.setdefault('capsize', 3)
13+
kwargs.setdefault('markersize', 5)
14+
kwargs.setdefault('marker', 'o')
15+
eb = ax.errorbar(gb.index, 'mean',
16+
yerr='std',
17+
data=gb,
18+
label=label,
19+
picker=picker,
20+
**kwargs)
21+
fill = ax.fill_between(gb.index, 'min', 'max', alpha=.5,
22+
data=gb, color=eb[0].get_color())
23+
ax.legend()
24+
ax.figure.canvas.draw_idle()
25+
return eb, fill
26+
27+
28+
arts = plot_aggregated_errorbar(ax, bwi_monthly, 'bwi')
29+
30+
# EXERCISE
31+
# - make the shaded area configurable
32+
# - make center line configurable

05-interactive_temperature.py renamed to weather/05-interactive_temperature.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import matplotlib.pyplot as plt
22
from cycler import cycler
3-
from pddc_helpers import (load_bwi_data, aggregate_by_month, aggregate_by_day,
3+
from w_helpers import (load_ornl_data, aggregate_by_month, aggregate_by_day,
44
extract_day_of_hourly, extract_month_of_daily)
55

66

77
plt.ion()
88

9-
bwi = load_bwi_data()
10-
119

1210
def setup_temperature_figure(**kwargs):
1311
fig, ax_lst = plt.subplots(3, 1, sharey=True, **kwargs)
@@ -22,6 +20,7 @@ def setup_temperature_figure(**kwargs):
2220
fig.tight_layout()
2321
return fig, ax_lst
2422

23+
2524
def plot_aggregated_errorbar(ax, gb, label, picker=None, **kwargs):
2625
kwargs.setdefault('capsize', 3)
2726
kwargs.setdefault('markersize', 5)
@@ -210,8 +209,9 @@ def remove(self):
210209
self.yearly_ax.figure.canvas.mpl_disconnect(self.cid)
211210

212211

212+
ornl = load_ornl_data()
213213
fig, (ax_by_month, ax_by_day, ax_by_hour) = setup_temperature_figure()
214-
bwi_at = AggregatedTimeTrace(bwi, 'bwi', ax_by_month, ax_by_day, ax_by_hour)
214+
ornl_at = AggregatedTimeTrace(ornl, 'ornl', ax_by_month, ax_by_day, ax_by_hour)
215215
fig.suptitle('Temperature')
216216

217217

99-get_data.py renamed to weather/99-get_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
plt.ion()
1818

19+
1920
def get_filtered_isd(data_dir, s_date=None, f_date=None,
2021
allow_download=True):
2122
fname = 'isd-history.csv'
File renamed without changes.

04-custom_plotting.py renamed to weather/key/04-custom_plotting.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,6 @@
77

88
fig, ax = plt.subplots()
99

10-
11-
def plot_aggregated_errorbar(ax, gb, label, picker=None, **kwargs):
12-
kwargs.setdefault('capsize', 3)
13-
kwargs.setdefault('markersize', 5)
14-
kwargs.setdefault('marker', 'o')
15-
eb = ax.errorbar(gb.index, 'mean',
16-
yerr='std',
17-
data=gb,
18-
label=label,
19-
picker=picker,
20-
**kwargs)
21-
fill = ax.fill_between(gb.index, 'min', 'max', alpha=.5,
22-
data=gb, color=eb[0].get_color())
23-
ax.legend()
24-
ax.figure.canvas.draw_idle()
25-
return eb, fill
26-
27-
arts = plot_aggregated_errorbar(ax, bwi_monthly, 'bwi')
28-
29-
# EXERCISE
30-
# - make the shaded area configurable
31-
# - make center line configurable
32-
33-
3410
def plot_aggregated_errorbar(ax, gb, label, picker=None, *,
3511
bands=None,
3612
center_line='mean',

weather/ornl.h5

6.28 MB
Binary file not shown.

pddc_helpers.py renamed to weather/w_helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55

66
def aggregate_by_month(df, col='T'):
7-
gb = df.groupby(('year', 'month'))['T'].describe().unstack()
7+
gb = df.groupby(('year', 'month'))['T'].describe()
88
new_index = [datetime.date(*m, *(15, )) for m in gb.index]
99
gb.reset_index(inplace=True)
1010
gb.index = new_index
1111
return gb
1212

1313

1414
def aggregate_by_day(df, col='T'):
15-
gb = df.groupby(('year', 'month', 'day'))['T'].describe().unstack()
15+
gb = df.groupby(('year', 'month', 'day'))['T'].describe()
1616
new_index = [datetime.date(*m) for m in gb.index]
1717
gb.reset_index(inplace=True)
1818
gb.index = new_index
@@ -56,6 +56,12 @@ def load_bwi_data():
5656
return pd.read_hdf(fname)
5757

5858

59+
def load_ornl_data():
60+
fname = os.path.join(os.path.dirname(os.path.realpath(__file__)),
61+
'ornl.h5')
62+
return pd.read_hdf(fname)
63+
64+
5965
def label_date(ax, label, date, df):
6066
'''Helper function to annotate a date
6167

0 commit comments

Comments
 (0)