Beispiel #1
0
    def __init__(self, config, zmqContext=None):
        if zmqContext is None:
            zmqContext = zmq.Context()

        # make clock synchronizer
        pathFunc = lambda i: config.get('pixel clock', 'socketTemplate') % i
        channels = range(config.getint('pixel clock', 'socketStart'),
                         config.getint('pixel clock', 'socketEnd'))
        #self.clockSync = ClockSync(pathFunc, channels, zmqContext=zmqContext, maxErr=config.getint('pixel clock', 'maxError'))
        self.clockSync = ClockSync()

        # make stim spike syncer
        self.stimSpikeSyncer = StimSpikeSyncer()

        # make mworks conduit
        self.mw_conduit = IPCClientConduit(config.get('mworks', 'conduitname'))
        self.mw_conduit.initialize()
        self.mw_conduit.register_local_event_code(0, '#stimDisplayUpdate')
        self.mw_conduit.register_local_event_code(1, '#pixelClockOffset')
        self.mw_conduit.register_callback_for_name(
            '#stimDisplayUpdate', self.process_mw_display_event)
        self.mw_conduit.register_callback_for_name(
            '#pixelClockOffset', self.process_mw_pixel_clock_event)

        # make spike listener
        # pathFunc = lambda i : "tcp://127.0.0.1:%i" % (i+8000)
        pathFunc = lambda i: config.get('audio', 'socketTemplate') % i
        channels = range(config.getint('audio', 'socketStart'),
                         config.getint('audio', 'socketEnd'))
        self.spikeListener = SpikeListener(pathFunc,
                                           channels,
                                           zmqContext=zmqContext)
        self.spikeListener.register_callback(self.process_spike)

        self.sampRate = float(config.getint('audio', 'sampRate'))
 def __init__(self, conduitName):
     self.conduit = Conduit(conduitName)
     self.conduit.initialize()
     self.conduit.register_local_event_code(0,'#stimDisplayUpdate')
     self.conduit.register_callback_for_name('#stimDisplayUpdate', self.receive_event)
     self.codes = []
     self.cond = Condition()
     self.maxCodes = 100
 def __init__(self, conduitName):
     self.conduit = Conduit(conduitName)
     self.conduit.initialize()
     self.conduit.register_local_event_code(0, '#stimDisplayUpdate')
     self.conduit.register_callback_for_name('#stimDisplayUpdate',
                                             self.receive_event)
     self.codes = []
     self.cond = Condition()
     self.maxCodes = 100
class MWPixelClock(object):
    def __init__(self, conduitName):
        self.conduit = Conduit(conduitName)
        self.conduit.initialize()
        self.conduit.register_local_event_code(0, '#stimDisplayUpdate')
        self.conduit.register_callback_for_name('#stimDisplayUpdate',
                                                self.receive_event)
        self.codes = []
        self.cond = Condition()
        self.maxCodes = 100

    def receive_event(self, event):
        for s in event.data:
            if s is None:
                continue
            if s.has_key('bit_code'):
                self.cond.acquire()
                self.codes.append((s['bit_code'], event.time / 1000000.))
                # if len(self.codes) > 2:
                #     #logging.debug('MW bit_code = %i' % s['bit_code'])
                #     #print s['bit_code']
                #     #logging.debug("MW Delta: %s" % delta_code(self.codes[-1][0], self.codes[-2][0]))
                while len(self.codes) > self.maxCodes:
                    self.codes.pop(0)
                self.cond.notifyAll()
                self.cond.release()
class MWPixelClock(object):
    def __init__(self, conduitName):
        self.conduit = Conduit(conduitName)
        self.conduit.initialize()
        self.conduit.register_local_event_code(0,'#stimDisplayUpdate')
        self.conduit.register_callback_for_name('#stimDisplayUpdate', self.receive_event)
        self.codes = []
        self.cond = Condition()
        self.maxCodes = 100
    
    def receive_event(self, event):
        for s in event.data:
            if s is None:
                continue
            if s.has_key('bit_code'):
                self.cond.acquire()
                self.codes.append((s['bit_code'],event.time/1000000.))
                # if len(self.codes) > 2:
                #     #logging.debug('MW bit_code = %i' % s['bit_code'])
                #     #print s['bit_code']
                #     #logging.debug("MW Delta: %s" % delta_code(self.codes[-1][0], self.codes[-2][0]))
                while len(self.codes) > self.maxCodes:
                    self.codes.pop(0)
                self.cond.notifyAll()
                self.cond.release()
Beispiel #6
0
    #         offset = cs.offset
    #         print offset, cs.matchLength, cs.err

    # setup stim spike syncer
    global stimSpikeSyncer
    stimSpikeSyncer = StimSpikeSyncer()
    # process_spike(self, channel, time)
    # get_stim_spikes(self, channel, stimI)
    # process_event(self, event, conv=1./1000000.)
    # find_stim(self, stim)

    # setup psth

    # setup mworks conduit
    conduitName = 'server_event_conduit'
    conduit = IPCClientConduit(conduitName)
    conduit.initialize()
    conduit.register_local_event_code(0, '#stimDisplayUpdate')

    def process_mw_event(event):
        global stimSpikeSyncer, clockSync
        if event is None:
            return
        else:
            event.value = event.data
        stimSpikeSyncer.process_mw_event(event)
        clockSync.process_mw_event(event)

    conduit.register_callback_for_name('#stimDisplayUpdate', process_mw_event)

    # setup spike listener
Beispiel #7
0
class Core(object):
    def __init__(self, config, zmqContext=None):
        if zmqContext is None:
            zmqContext = zmq.Context()

        # make clock synchronizer
        pathFunc = lambda i: config.get('pixel clock', 'socketTemplate') % i
        channels = range(config.getint('pixel clock', 'socketStart'),
                         config.getint('pixel clock', 'socketEnd'))
        #self.clockSync = ClockSync(pathFunc, channels, zmqContext=zmqContext, maxErr=config.getint('pixel clock', 'maxError'))
        self.clockSync = ClockSync()

        # make stim spike syncer
        self.stimSpikeSyncer = StimSpikeSyncer()

        # make mworks conduit
        self.mw_conduit = IPCClientConduit(config.get('mworks', 'conduitname'))
        self.mw_conduit.initialize()
        self.mw_conduit.register_local_event_code(0, '#stimDisplayUpdate')
        self.mw_conduit.register_local_event_code(1, '#pixelClockOffset')
        self.mw_conduit.register_callback_for_name(
            '#stimDisplayUpdate', self.process_mw_display_event)
        self.mw_conduit.register_callback_for_name(
            '#pixelClockOffset', self.process_mw_pixel_clock_event)

        # make spike listener
        # pathFunc = lambda i : "tcp://127.0.0.1:%i" % (i+8000)
        pathFunc = lambda i: config.get('audio', 'socketTemplate') % i
        channels = range(config.getint('audio', 'socketStart'),
                         config.getint('audio', 'socketEnd'))
        self.spikeListener = SpikeListener(pathFunc,
                                           channels,
                                           zmqContext=zmqContext)
        self.spikeListener.register_callback(self.process_spike)

        self.sampRate = float(config.getint('audio', 'sampRate'))

    def process_mw_display_event(self, event):
        # global stimSpikeSyncer, clockSync
        if event is None:
            return
        else:
            event.value = event.data
        self.stimSpikeSyncer.process_mw_event(event)

    def process_mw_pixel_clock_event(self, event):
        if event is None:
            return
        else:
            event.value = event.data
        self.clockSync.process_mw_event(event)

    def process_spike(self, wb):
        # global stimSpikeSyncer, clockSync

        if not (self.clockSync.offset is None):
            # spikeMWTime = clockSync.clockSync.au_to_mw(wb.time_stamp/44100.)
            self.stimSpikeSyncer.process_spike(
                wb.channel_id,
                self.clockSync.au_to_mw(wb.time_stamp / self.sampRate))
        else:
            logging.warning("Clock not synced!! dropping spike on %i" %
                            wb.channel_id)

    def update(self):
        """
        Updates the various components of the physio_online core, should be called in the main loop
        """
        logging.debug("Core updating")
        # global clockSync, sl, stimSpikeSyncer
        while self.spikeListener.update():
            pass
        # while self.clockSync.update():
        #     pass
        # self.clockSync.match()
        # if self.clockSync.offset is None:
        #     logging.debug("MW: %s" % str([e[1] for e in self.clockSync.mwEvents]))
        #     logging.debug("AU: %s" % str([e[1] for e in self.clockSync.auEvents]))

    def clear_spikes(self):
        """
        Clears all spikes accumulated so far
        """
        self.stimSpikeSyncer.clear_spikes()

    def clear_stimuli(self):
        self.stimSpikeSyncer.clear_stimuli()
 # setup mworks conduit
 # setup mworks conduit
 def receive_event(event):
     global mwEventColors, mwTimeOffset, raster #, rasterCond, startTime
     #print event.time, event.data, event.code
     # rasterCond.acquire()
     if mwTimeOffset == None:
         mwTimeOffset = time.time() - event.time/1000000.
     # print "MW:", event.code, event.time/1000000. + mwTimeOffset
     raster.add_event(event.time/1000000. + mwTimeOffset, event.code, mwEventColors[event.code-NChannels])
     # 
     # if raster.cursorX == startTime:
     #     raster.reset(raster.newEvents[0][0])
     # rasterCond.notifyAll()
     # rasterCond.release()
 mwconduit = IPCClientConduit(conduitName)
 mwconduit.initialize()
 
 for (i,eventName) in enumerate(mwEventNames):
     print "registering %s" % eventName
     mwconduit.register_callback_for_name(eventName, receive_event)
     # register local code?
     mwconduit.register_local_event_code(i+NChannels,eventName)
 
 # print len(mwconduit.codec), mwconduit.codec
 # print len(mwconduit.reverse_codec), mwconduit.reverse_codec
 
 # setup spike listener
 global sl
 pathFunc = lambda i : "tcp://127.0.0.1:%i" % (i+8000) 
 sl = SpikeListener(pathFunc, xrange(32))
Beispiel #9
0
    raster = GLRaster(NRows, startTime)
    global rasterCond
    rasterCond = Condition()

    # setup mworks conduit
    def receive_event(event):
        global raster, rasterCond, startTime
        print event.time, event.data, event.code
        rasterCond.acquire()
        raster.add_event(event.time / 1000000., event.code)
        if raster.cursorX == startTime:
            raster.reset(raster.newEvents[0][0])
        rasterCond.notifyAll()
        rasterCond.release()

    mwconduit = Conduit(conduitName)
    mwconduit.initialize()
    print len(mwconduit.codec), mwconduit.codec
    print len(mwconduit.reverse_codec), mwconduit.reverse_codec

    for (i, eventName) in enumerate(eventNames):
        print "registering %s" % eventName
        # register local code?
        mwconduit.register_local_event_code(i, eventName)
        mwconduit.register_callback_for_name(eventName, receive_event)

    print len(mwconduit.codec), mwconduit.codec
    print len(mwconduit.reverse_codec), mwconduit.reverse_codec

    def draw():
        global raster, rasterCond
Beispiel #10
0
            self.eventIndex += 1
            event = FakeEvent(t, t, 0)
            #print "Received Event"
            receive_event('fake', event)
            #print "Sleeping..."
            time.sleep(self.iei)


if __name__ == "__main__":
    if fakeProducer:
        fp = EventProducer(1000, 100)
        fp.start()
    else:
        conduit_resource_name = 'python_bridge_plugin_conduit'

        client = IPCClientConduit(conduit_resource_name)
        client.initialize()
        sys.stdout.write('registering callbacks\n')
        for i in xrange(len(targetEvents)):
            eventName = targetEvents[i]
            #client.register_callback_for_name(eventName, receive_event)
            client.register_local_event_code(i, targetEvents[i])
            client.register_callback_for_name(eventName, receive_event)
            codeToName[i] = targetEvents[i]
        #print codeToName
        sys.stdout.write('waiting for events\n')

    while 1:
        update_plot()
        if fakeProducer:
            if not fp.is_alive():
            continue
    return (0, maxErr * 2, (-1, -1))


# ===============================

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    #pathFunc = lambda i : "ipc:///tmp/pixel_clock/%i" % i
    pathFunc = lambda i: "tcp://localhost:%i" % (11000 + i)
    cs = ClockSync(pathFunc, range(4))

    conduitName = 'server_event_conduit'

    conduit = Conduit(conduitName)
    conduit.initialize()
    conduit.register_local_event_code(0, '#stimDisplayUpdate')
    conduit.register_callback_for_name('#stimDisplayUpdate',
                                       cs.process_mw_event)

    offset = 0
    while 1:
        while cs.update():
            pass
        cs.match()
        mwC = [e[1] for e in cs.mwEvents]
        auC = [e[1] for e in cs.auEvents]
        if len(mwC):
            if np.any(np.array(mwC[1:]) == np.array(mwC[:-1])):
                print "Repeat found!"
Beispiel #12
0
        return mwTime - self.offset

    def au_to_mw(self, auTime):
        return auTime + self.offset


# ===============================

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    cs = ClockSync(pathFunc, range(4))

    conduitName = 'server_event_conduit'

    conduit = Conduit(conduitName)
    conduit.initialize()
    conduit.register_local_event_code(0, '#pixelClockOffset')
    conduit.register_callback_for_name('#pixelClockOffset',
                                       cs.process_mw_event)

    offset = 0
    while 1:
        while cs.update():
            pass
        cs.match()
        mwC = [e[1] for e in cs.mwEvents]
        auC = [e[1] for e in cs.auEvents]
        if len(mwC):
            if np.any(np.array(mwC[1:]) == np.array(mwC[:-1])):
                print "Repeat found!"