1 import numpy as np
2 import pandas as p
3 import Nio
4
5 nc1 = Nio.open_file('10147-precip.nc')
6 nc2 = Nio.open_file('10015-precip.nc')
7
8 time1 = nc1.variables['time'][:]
9 time2 = nc2.variables['time'][:]
10
11 rain1 = nc1.variables['rainfall_rate_hour'][:]
12 rain2 = nc2.variables['rainfall_rate_hour'][:]
13
14
15
16
17
18
19 dates1 = num2date(epoch2num(time1))
20 dates2 = num2date(epoch2num(time2))
21
22
23 ds1 = p.Series(rain1, index = dates1)
24 ds2 = p.Series(rain2, index = dates2)
25
26
27
28
29 ds1 = np.where(ds1<0, nan, ds1)
30 ds2 = np.where(ds2<0, nan, ds2)
31
32
33 ds1.plot()
34 ds2.plot()
35
36
37
38
39 ds1=ds1[ds1==ds1]
40 ds2=ds2[ds2==ds2]
41
42
43 print ds1.shape[0], ds2.shape[0]
44
45
46
47 ds2_nan = ds2.reindex(ds1.index)
48 ds2_backfill = ds2.reindex(ds1.index, method = 'backfill')
49
50
51 print "Max: %.2f Min: %.2f Mean: %.2f Median: %.2f Count: %.2f" % (ds2.max(), ds2.min(), ds2.mean(), ds2.median(), ds2.count())
52
53
54 ds2.cumsum()
55
56
57 df=p.DataFrame({"helgoland":ds2, "hamburg":ds1})
58
59
60 print ds1.fillna(0).count(), ds2.fillna(0).count()
61 print df['hamburg'].fillna(0).count(), df['helgoland'].fillna(0).count()
62
63
64 df.dropIncompleteRows()
65
66
67 df.corr()
68
69
70
71 start=datetime.datetime(2004,5,1)
72 end = datetime.datetime(2007,9,1)
73
74
75 dr1Hour = p.DateRange(start, end, offset = p.datetools.Hour())
76 dr5Day = p.DateRange(start, end, offset=5 * p.datetools.day)
77 drMonth = p.DateRange(start, end, offset= p.datetools.monthEnd)
78
79
80 df5Day = df.groupby(dr5Day.asof)