Skip to content

Commit e1fdf59

Browse files
authored
Update README.rst
included a more detailed example
1 parent 7b1598d commit e1fdf59

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

README.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,40 @@ You can also fetch data from Portland's Hydra Network of rain gauges:
4141
or from the command line ::
4242
4343
$ cloudside get-hydra Beaumont
44+
45+
Bigger Example
46+
--------------
47+
48+
.. code:: python
49+
50+
import pandas
51+
import cloudside
52+
53+
def summarizer(g):
54+
return pandas.Series({
55+
'start': g['datetime'].min(),
56+
'end': g['datetime'].max(),
57+
'duration_hours': (g['datetime'].max() - g['datetime'].min()).total_seconds() / 3600,
58+
precip_col: g[precip_col].sum()
59+
})
60+
61+
62+
def storm_totaller(df):
63+
return (
64+
df.query('storm > 0')
65+
.reset_index()
66+
.groupby(by=['storm'])
67+
.apply(summarizer)
68+
.assign(antecedent_hours=lambda df: (df['start'] - df['end'].shift()).dt.total_seconds() / 3600)
69+
.assign(ends_on_weekday=lambda df: df['end'].dt.weekday < 5)
70+
)
71+
72+
data = cloudside.asos.get_data('KPDX', '2012-12-01', '2015-05-01, 'me@mydomain.com')
73+
storms = cloudside.storms.parse_record(data, intereventHours=6, outputfreqMinutes=5, precipcol='precip_inches')
74+
storm_stats = storm_totaller(storms)
75+
with pandas.ExcelWriter('output.xlsx') as xl:
76+
data.to_excel(xl, sheet_name='Weather Data')
77+
storm_stats.to_excel(xl, sheet_name='Storm Stats')
4478
4579
4680
Basic History

0 commit comments

Comments
 (0)