Пример #1
0
    def Initialize(self, indim, outdim):
        self.warp = 1000.0  # let the samples flowing into the ring buffer set the pace
        self.eegfs = self.samplingrate()
        self.hwfs = int(self.params['HardwareSamplingRate'])
        self.chunk = SigTools.msec2samples(
            float(self.params['HardwareChunkMsec']), self.hwfs)
        ringsize = SigTools.msec2samples(
            float(self.params['NIABufferSizeMsec']), self.hwfs)
        self.ring = SigTools.ring(ringsize, indim[0])
        self.ring.allow_overflow = True
        self.nominal['HardwareSamplesPerPacket'] = SigTools.msec2samples(
            self.nominal['SecondsPerPacket'] * 1000.0, self.hwfs)

        cutoff = float(self.params['DSFilterFreqFactor']) * self.eegfs / 2.0
        order = int(self.params['DSFilterOrder'])
        if order > 0 and cutoff > 0.0:
            self.filter = SigTools.causalfilter(
                freq_hz=cutoff,
                samplingfreq_hz=self.hwfs,
                order=order,
                type='lowpass')  #, method=SigTools.firdesign)
        else:
            self.filter = None
        self.dsind = numpy.linspace(0.0,
                                    self.nominal['HardwareSamplesPerPacket'],
                                    self.nominal['SamplesPerPacket'] + 1,
                                    endpoint=True)
        self.dsind = numpy.round(self.dsind).astype(numpy.int).tolist()

        self._threads['listen'].post('start')
        self._threads['listen'].read('ready', wait=True, remove=True)
        self._check_threads()
Пример #2
0
    def initialize(cls, app, indim, outdim):
        if int(app.params['ERPDatabaseEnable'])==1:
            if int(app.params['ShowSignalTime']):
                app.addstatemonitor('LastERPVal')
                app.addstatemonitor('ERPCollected')

            #===================================================================
            # Prepare the buffers for saving the data
            # -leaky_trap contains the data to be saved (trap size defined by pre_stim_samples + post_stim_samples + some breathing room
            # -trig_trap contains only the trigger channel
            #===================================================================
            app.x_vec=np.arange(app.erpwin[0],app.erpwin[1],1000.0/app.eegfs,dtype=float)#Needed when saving trials
            app.post_stim_samples = SigTools.msec2samples(app.erpwin[1], app.eegfs)
            app.pre_stim_samples = SigTools.msec2samples(np.abs(app.erpwin[0]), app.eegfs)
            app.leaky_trap=SigTools.Buffering.trap(app.pre_stim_samples + app.post_stim_samples + 5*app.spb, len(app.params['ERPChan']), leaky=True)
            app.trig_trap = SigTools.Buffering.trap(app.post_stim_samples, 1, trigger_channel=0, trigger_threshold=app.trigthresh[0])

            #===================================================================
            # Prepare the models from the database.
            #===================================================================
            app.subject = Subject.objects.get_or_create(name=app.params['SubjectName'])[0]
            #===================================================================
            # app.period = app.subject.get_or_create_recent_period(delay=0)
            # app.subject.periods.update()
            # app.period = app.subject.periods.order_by('-datum_id').all()[0]
            #===================================================================

            #===================================================================
            # Use a thread for database interactions because sometimes they will be slow.
            # (especially when calculating a trial's features)
            #===================================================================
            app.erp_thread = ERPThread(Queue.Queue(), app)
            app.erp_thread.setDaemon(True) #Dunno, always there in the thread examples.
            app.erp_thread.start() #Starts the thread.

            #===================================================================
            # Setup the ERP feedback elements.
            # -Screen will range from -2*fbthresh to +2*fbthresh
            # -Calculated ERP value will be scaled so 65536(int16) fills the screen.
            #===================================================================
            if int(app.params['ERPFeedbackDisplay'])==2:
                fbthresh = app.params['ERPFeedbackThreshold'].val
                app.erp_scale = (2.0**16) / (4.0*np.abs(fbthresh))
                if fbthresh < 0:
                    fbmax = fbthresh * app.erp_scale
                    fbmin = 2.0 * fbthresh * app.erp_scale
                else:
                    fbmax = 2.0 * fbthresh * app.erp_scale
                    fbmin = fbthresh * app.erp_scale
                m=app.scrh/float(2**16)#Conversion factor from signal amplitude to pixels.
                b_offset=app.scrh/2.0 #Input 0.0 should be at this pixel value.
                app.addbar(color=(1,0,0), pos=(0.9*app.scrw,b_offset), thickness=0.1*app.scrw, fac=m)
                n_bars = len(app.bars)
                #app.stimuli['bartext_1'].position=(50,50)
                app.stimuli['bartext_' + str(n_bars)].color=[0,0,0]
                erp_target_box = Block(position=(0.8*app.scrw,m*fbmin+b_offset), size=(0.2*app.scrw,m*(fbmax-fbmin)), color=(1,0,0,0.5), anchor='lowerleft')
                app.stimulus('erp_target_box', z=1, stim=erp_target_box)
	def Initialize(self, indim, outdim):
		self.warp = 1000.0 # let the samples flowing into the ring buffer set the pace
		self.eegfs = self.samplingrate()
		self.hwfs = int(self.params['HardwareSamplingRate'])
		self.chunk = SigTools.msec2samples(float(self.params['HardwareChunkMsec']), self.hwfs)
		ringsize = SigTools.msec2samples(float(self.params['NIABufferSizeMsec']), self.hwfs)
		self.ring = SigTools.ring(ringsize, indim[0])
		self.ring.allow_overflow = True
		self.nominal['HardwareSamplesPerPacket'] = SigTools.msec2samples(self.nominal['SecondsPerPacket']*1000.0, self.hwfs)
		
		cutoff = float(self.params['DSFilterFreqFactor']) * self.eegfs / 2.0
		order = int(self.params['DSFilterOrder'])
		if order > 0 and cutoff > 0.0:
			self.filter = SigTools.causalfilter(freq_hz=cutoff, samplingfreq_hz=self.hwfs, order=order, type='lowpass') #, method=SigTools.firdesign)
		else:
			self.filter = None
		self.dsind = numpy.linspace(0.0, self.nominal['HardwareSamplesPerPacket'], self.nominal['SamplesPerPacket']+1, endpoint=True)
		self.dsind = numpy.round(self.dsind).astype(numpy.int).tolist()

		self._threads['listen'].post('start')
		self._threads['listen'].read('ready', wait=True, remove=True)
		self._check_threads()
Пример #4
0
    def initialize(cls, app, indim, outdim):
        if int(app.params['ERPDatabaseEnable']) == 1:
            if int(app.params['ShowSignalTime']):
                app.addstatemonitor('LastERPVal')
                app.addstatemonitor('ERPCollected')

            #===================================================================
            # Prepare the buffers for saving the data
            # -leaky_trap contains the data to be saved (trap size defined by pre_stim_samples + post_stim_samples + some breathing room
            # -trig_trap contains only the trigger channel
            #===================================================================
            app.x_vec = np.arange(app.erpwin[0],
                                  app.erpwin[1],
                                  1000.0 / app.eegfs,
                                  dtype=float)  #Needed when saving trials
            app.post_stim_samples = SigTools.msec2samples(
                app.erpwin[1], app.eegfs)
            app.pre_stim_samples = SigTools.msec2samples(
                np.abs(app.erpwin[0]), app.eegfs)
            app.leaky_trap = SigTools.Buffering.trap(
                app.pre_stim_samples + app.post_stim_samples + 5 * app.spb,
                len(app.params['ERPChan']),
                leaky=True)
            app.trig_trap = SigTools.Buffering.trap(
                app.post_stim_samples,
                1,
                trigger_channel=0,
                trigger_threshold=app.trigthresh[0])

            #===================================================================
            # Prepare the models from the database.
            #===================================================================
            app.subject = Subject.objects.get_or_create(
                name=app.params['SubjectName'])[0]
            #===================================================================
            # app.period = app.subject.get_or_create_recent_period(delay=0)
            # app.subject.periods.update()
            # app.period = app.subject.periods.order_by('-datum_id').all()[0]
            #===================================================================

            #===================================================================
            # Use a thread for database interactions because sometimes they will be slow.
            # (especially when calculating a trial's features)
            #===================================================================
            app.erp_thread = ERPThread(Queue.Queue(), app)
            app.erp_thread.setDaemon(
                True)  #Dunno, always there in the thread examples.
            app.erp_thread.start()  #Starts the thread.

            #===================================================================
            # Setup the ERP feedback elements.
            # -Screen will range from -2*fbthresh to +2*fbthresh
            # -Calculated ERP value will be scaled so 65536(int16) fills the screen.
            #===================================================================
            if int(app.params['ERPFeedbackDisplay']) == 2:
                fbthresh = app.params['ERPFeedbackThreshold'].val
                app.erp_scale = (2.0**16) / (4.0 * np.abs(fbthresh))
                if fbthresh < 0:
                    fbmax = fbthresh * app.erp_scale
                    fbmin = 2.0 * fbthresh * app.erp_scale
                else:
                    fbmax = 2.0 * fbthresh * app.erp_scale
                    fbmin = fbthresh * app.erp_scale
                m = app.scrh / float(
                    2**16)  #Conversion factor from signal amplitude to pixels.
                b_offset = app.scrh / 2.0  #Input 0.0 should be at this pixel value.
                app.addbar(color=(1, 0, 0),
                           pos=(0.9 * app.scrw, b_offset),
                           thickness=0.1 * app.scrw,
                           fac=m)
                n_bars = len(app.bars)
                #app.stimuli['bartext_1'].position=(50,50)
                app.stimuli['bartext_' + str(n_bars)].color = [0, 0, 0]
                erp_target_box = Block(position=(0.8 * app.scrw,
                                                 m * fbmin + b_offset),
                                       size=(0.2 * app.scrw,
                                             m * (fbmax - fbmin)),
                                       color=(1, 0, 0, 0.5),
                                       anchor='lowerleft')
                app.stimulus('erp_target_box', z=1, stim=erp_target_box)