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()