In [1]:
%run basics

In [2]:
ncname=qcio.get_filename_dialog()

In [3]:
ncfile=netCDF4.Dataset(ncname)
ts=30

In [4]:
time=ncfile.variables["time"][:]
time_units=getattr(ncfile.variables["time"],"units")
ldt=list(netCDF4.num2date(time,time_units))
ldt=qcutils.RoundDateTime(ldt,ts=ts)

In [32]:
si = qcutils.GetDateIndex(ldt,"2000-01-01",default=0,ts=ts,match="startnexthour")
ei = qcutils.GetDateIndex(ldt,"2015-01-01",default=-1,ts=ts,match="endprevioushour")
print ldt[si],ldt[ei]


2000-01-01 00:30:00 2014-03-01 00:00:00

In [33]:
ldt_30=ldt[si:ei+1]
minutes=[ldt_30[i].minute for i in range(len(ldt_30))]

In [34]:
var=ncfile.variables["SWdown"][:]
Fsd_30=numpy.squeeze(var[si:ei+1])

In [35]:
Fsd_30_2d=numpy.reshape(Fsd_30,(len(Fsd_30)/2,2))
Fsd_60=numpy.average(Fsd_30_2d,axis=1)

In [36]:
ldt_60=[ldt_30[i] for i in range(len(ldt_30)) if ldt_30[i].minute==0]
print ldt_60[0],ldt_60[1]


2000-01-01 01:00:00 2000-01-01 02:00:00

In [37]:
fig=plt.figure()
plt.plot(ldt_30,Fsd_30,'b.')
plt.plot(ldt_60,Fsd_60,'r+')
plt.show()

In [38]:
si_30=qcutils.GetDateIndex(ldt_30,"2006-01-08",default=0,ts=ts,match="startnexthour")
ei_30=qcutils.GetDateIndex(ldt_30,"2006-01-09",default=-1,ts=ts,match="endprevioushour")
si_60=qcutils.GetDateIndex(ldt_60,"2006-01-08",default=0,ts=ts,match="startnexthour")
ei_60=qcutils.GetDateIndex(ldt_60,"2006-01-09",default=-1,ts=ts,match="endprevioushour")


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-38-2d7210c72fa1> in <module>()
      1 si_30=qcutils.GetDateIndex(ldt_30,"2006-01-08",default=0,ts=ts,match="startnexthour")
      2 ei_30=qcutils.GetDateIndex(ldt_30,"2006-01-09",default=0,ts=ts,match="endprevioushour")
----> 3 si_60=qcutils.GetDateIndex(ldt_60,"2006-01-08",default=0,ts=ts,match="startnexthour")
      4 ei_60=qcutils.GetDateIndex(ldt_60,"2006-01-09",default=0,ts=ts,match="endprevioushour")

/home/peter/OzFlux/OzFluxQC/scripts/qcutils.py in GetDateIndex(datetimeseries, date, ts, default, match)
    563             # if the time step is 60 then it is always the start of the next hour
    564             # we assume here that the time period ends on the datetime stamp
--> 565             while datetimeseries[i].minute!=ts:
    566                 # iterate until the minutes equal the time step
    567                 i = i + 1

IndexError: list index out of range

In [ ]:
print Fsd_30[si_30:ei_30+1]

In [ ]: