Size: 507
Comment:
|
Size: 1025
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
* Series | |
Line 7: | Line 6: |
* Apply common numpy statistics | |
Line 12: | Line 12: |
import pandas as P | import pandas as p |
Line 15: | Line 15: |
hamNc = Nio.open_file('10147-precip.nc') helNc = Nio.open_file('10015-precip.nc') |
|
Line 18: | Line 16: |
hamTime = hamNc.variables['time'][:] helTime = helNc.variables['time'][:] |
nc1 = Nio.open_file('10147-precip.nc') # hamburg nc2 = Nio.open_file('10015-precip.nc') # helgoland |
Line 21: | Line 19: |
hamRain = hamNc.variables['rainfall_rate_hour'][:] helRain = helNc.variables['rainfall_rate_hour'][:] ham = hamNc.variables['rainfall_rain_rate'][:] |
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,
28 # while Nio returns masked arrays
29 # Many basic array operations are valid for pandas Series
30 ds1 = np.where(ds1<0, nan, ds1)
31 ds2 = np.where(ds2<0, nan, ds2)
32
33 # plotting functions
34 ds1.plot()
35 ds2.plot()