Size: 115
Comment:
|
Size: 1022
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
* Series | |
Line 5: | Line 4: |
* DateRange | |
Line 6: | Line 6: |
* Apply common numpy statistics * Data alignment |
|
Line 10: | Line 12: |
import pandas as p import Nio nc1 = Nio.open_file('10147-precip.nc') # hamburg nc2 = Nio.open_file('10015-precip.nc') # helgoland time1 = nc1.variables['time'][:] time2 = nc2.variables['time'][:] rain1 = nc1.variables['rainfall_rate_hour'][:] rain2 = nc2.variables['rainfall_rate_hour'][:] # plot data plot(rain1, 'g', rain2, 'b') # Timestamps shall be python dates dates1 = num2date(epoch2num(time1)) dates2 = num2date(epoch2num(time2)) # Indexed arrays - p.Series ds1 = p.Series(rain1, index = dates1) ds2 = p.Series(rain2, index = dates2) # Pandas is using numpy.na representation of not-a-number, while Nio returns masked arrays # Many basic array operations are valid for pandas Series ds1 = np.where(ds1<0, nan, ds1) ds2 = np.where(ds2<0, nan, ds2) # plotting functions ds1.plot() ds2.plot() }}} |
Pandas
1 import numpy as np
2 import pandas as p
3 import Nio
4
5
6 nc1 = Nio.open_file('10147-precip.nc') # hamburg
7 nc2 = Nio.open_file('10015-precip.nc') # helgoland
8
9 time1 = nc1.variables['time'][:]
10 time2 = nc2.variables['time'][:]
11
12 rain1 = nc1.variables['rainfall_rate_hour'][:]
13 rain2 = nc2.variables['rainfall_rate_hour'][:]
14
15
16 # plot data
17 plot(rain1, 'g', rain2, 'b')
18
19 # Timestamps shall be python dates
20 dates1 = num2date(epoch2num(time1))
21 dates2 = num2date(epoch2num(time2))
22
23 # Indexed arrays - p.Series
24 ds1 = p.Series(rain1, index = dates1)
25 ds2 = p.Series(rain2, index = dates2)
26
27 # Pandas is using numpy.na representation of not-a-number, while Nio returns masked arrays
28 # Many basic array operations are valid for pandas Series
29 ds1 = np.where(ds1<0, nan, ds1)
30 ds2 = np.where(ds2<0, nan, ds2)
31
32 # plotting functions
33 ds1.plot()
34 ds2.plot()