Example #1
0
def locAcquire(
    Naves=1,
    Nds=1,
):
    numAttempts = 1
    while 1:
        numAttempts += 1
        try:
            if 0:
                while acq.glbSOCKET_PUBSUB.poll(50):
                    while acq.glbSOCKET_PUBSUB.poll(50):
                        print("Clearing old data...")
                        acq.checkForPublished()
            sleep(0.2)
            _, out, dt = acq.acquireStreaming(Nmin=Naves,
                                              bNoStale=True)  #Raw()
            #out=MT.smoothalong(out,Nds, axis=-1)[...,::Nds]
            out = MT.downsample_npts(out, Nds, axis=-1)
            #outL.append(out)
            #out=np.mean(out, axis=0)
        except DAQError:
            print("trigger stopped, try again")
        else:
            break
    t = np.arange(out.shape[-1]) * dt * Nds
    return t, out
Example #2
0
    def __call__(self, handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, parameter):
        self.streamReady=True
        noOfSamples=int(noOfSamples/self.Nds)*self.Nds #Only take a multiple of the down-sample factor
        #print("start index: {}, nSamps: {}, qvsize: {}".format(startIndex, noOfSamples, self._incData.view().shape))
        if noOfSamples:
            #print("doing things")
            self._incData.advanceEnd(noOfSamples)
            #print("qvsize: {}".format(self._incData.view().shape))
            newDat=self._incData.view()
            trigInds=self.findTrigs(newDat[1])
            if len(trigInds)>1:
                #print("trig0: {}".format(trigInds[0])) 
                if self.NptsPerSegment is None:
                    self.NptsPerSegment=int(np.mean(np.diff(trigInds)))-5
                diffs=np.diff(np.hstack([[0], trigInds]) )-self.NptsPerSegment
                if any(abs(diffs)<0):
                    print("oh no! diffs: {}".format(diffs))
                #print("Npts per seg: {}".format(self.NptsPerSegment))
                #print("len(TrigInds) {} in {} samples".format(len(trigInds), noOfSamples))
                Nprocessed=trigInds[-1]
                self._incData.dumpStart(Nprocessed) #Dump points up until the last trigger
                tA=trigInds*self.sampleInterval+self.tLast 
                self.tLast=tA[-1]
                for t,trgI in zip(tA, [0]+list(trigInds[:-1])):
                    #print(trgI)
                    self.q.put_nowait((t, newDat[0,trgI:trgI+self.NptsPerSegment]) )
                self.totalSegments+=len(trigInds)
            else:
                Nprocessed=0
                
            Nsave=int(Nprocessed/self.Nds)

            if self.curSaveInd+Nsave< self.data.size and Nsave!=0:
                self.data[self.curSaveInd:self.curSaveInd+Nsave]=MT.downsample_npts(newDat[0, :Nprocessed], self.Nds)
                self.curSaveInd+=Nsave
            #else:
            #    self.data[self.curInd:self.curInd+noOfSamples]=ps.data[1,0,startIndex:startIndex+noOfSamples]
            #self._incData.dumpStart(noOfSamples) #Dump points up until the last trigger
        else:
            print("no samples")