spt = obsFile.tickDuration
masks = {}
pickle.dump(offsets,pickleFile)
for offset in offsets:
    print "begin offset=",offset
    masks[offset] = interval()

    for sec in range(beginTime,beginTime+expTime):
        tl = sec+obsFile.tickDuration*(offset-2)
        tr = sec+obsFile.tickDuration*(offset+3)
        masks[offset] = masks[offset] | interval([sec,tl]) | interval([tr,sec+1])

    obsFile.cosmicMask = masks[offset]
    obsFile.switchOnCosmicTimeMask()

    nPhotonSum = 0
    rows = np.zeros(0,dtype=np.int)
    cols = np.zeros(0,dtype=np.int)
    dts  = np.zeros(0,dtype=np.double)
    secs = np.zeros(0,dtype=np.int)
    phs  = np.zeros(0,dtype=np.double)
    for iRow in range(iRow0, iRow1):
        for iCol in range(iCol0, iCol1):
            #tpl = obsFile.getTimedPacketList(iRow, iCol, firstSec=beginTime, integrationTime=expTime)
            tpl = obsFile.getPackets(iRow, iCol, firstSec=beginTime, integrationTime=expTime, fields=['peakHeights'])
            nPhoton = len(tpl['timestamps'])
            if nPhoton>0:
                print "offset=",offset,"row=",iRow, "iCol=",iCol, "nPhotons=",nPhoton
                rows = np.append(rows, iRow*np.ones(nPhoton,dtype=np.int))