当前位置: 首页>>代码示例>>Python>>正文


Python StreamInlet.pull_sample方法代码示例

本文整理汇总了Python中pylsl.StreamInlet.pull_sample方法的典型用法代码示例。如果您正苦于以下问题:Python StreamInlet.pull_sample方法的具体用法?Python StreamInlet.pull_sample怎么用?Python StreamInlet.pull_sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pylsl.StreamInlet的用法示例。


在下文中一共展示了StreamInlet.pull_sample方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_sample [as 别名]
import sys; sys.path.append('..') # help python find pylsl relative to this example program
from pylsl import StreamInlet, resolve_stream

# first resolve an EEG stream on the lab network
print("looking for an EEG stream...")
streams = resolve_stream('type','EEG')

# create a new inlet to read from the stream
inlet = StreamInlet(streams[0])

while True:
	# get a new sample (you can also omit the timestamp part if you're not interested in it)
	sample,timestamp = inlet.pull_sample()
	print(timestamp, sample)
开发者ID:dmedine,项目名称:pupil,代码行数:16,代码来源:ReceiveData.py

示例2: MyOVBox

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_sample [as 别名]
class MyOVBox(OVBox):
  def __init__(self):
    OVBox.__init__(self)

    
  # the initialize method reads settings and outputs the first header
  def initialize(self):
    self.initLabel = 0
    self.debug=self.setting['debug'] == "true"
    print "Debug: ", self.debug
    self.stream_type=self.setting['Stream type']
    self.stream_name=self.setting['Stream name'] 
    # total channels for all streams
    self.channelCount = 0
    #self.stream_name=self.setting['Stream name'] # in case !all_streams
    print "Looking for streams of type: " + self.stream_type
    streams = resolve_stream('type',self.stream_type)
    print "Nb streams: " + str( len(streams))
    self.nb_streams = len(streams)
    if self.nb_streams == 0:
      raise Exception("Error: no stream found.")
    self.inlet = StreamInlet(streams[0], max_buflen=1)
    self.info = self.inlet.info()
    self.channelCount = self.info.channel_count()
    print "Stream name: " + self.info.name()
    stream_freq = self.info.nominal_srate()
    if stream_freq != 0:
	  raise Exception("Error: no irregular stream found.")
    # we append to the box output a stimulation header. This is just a header, dates are 0.
    self.output[0].append(OVStimulationHeader(0., 0.))
    self.init = False
  # The process method will be called by openvibe on every clock tick
  def process(self):
    # A stimulation set is a chunk which starts at current time and end time is the time step between two calls
    # init here and filled within triger()
    self.stimSet = OVStimulationSet(self.getCurrentTime(), self.getCurrentTime()+1./self.getClock())
    if self.init == False :
     local_time = local_clock()
     initSecond=int(local_time) 
     initMillis=int((local_time-initSecond)*1000)
     self.stimSet.append(OVStimulation(self.initLabel, self.getCurrentTime(), 0.))
     self.stimSet.append(OVStimulation(initSecond, self.getCurrentTime(), 0.))
     self.stimSet.append(OVStimulation(initMillis, self.getCurrentTime(), 0.))
     self.init=True
	# read all available stream
    samples=[]
    sample,timestamp = self.inlet.pull_sample(0)
    while sample != None:
     samples += sample
     sample,timestamp = self.inlet.pull_sample(0)
     # every value will be converted to openvibe code and a stim will be create
    for label in samples: 
      label = str(label)
      if self.debug:
        print "Got label: ", label
      self.stimSet.append(OVStimulation(float(label), self.getCurrentTime(), 0.))	
    # even if it's empty we have to send stim list to keep the rest in sync
    self.output[0].append(self.stimSet)

  def uninitialize(self):
    # we send a stream end.
    end = self.getCurrentTime()
    self.output[0].append(OVStimulationEnd(end, end))
    self.inlet.close_stream()
开发者ID:jfrey-xx,项目名称:openMatch,代码行数:66,代码来源:python_lsl_stims.py

示例3: print

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_sample [as 别名]
# first resolve an EEG stream on the lab network
print("Looking for an EEG stream")
streams = resolve_stream("type","EEG",)
inlet = StreamInlet(streams[0])
print("Stream Found")


datastream = []
time.sleep(ignore_first_secs);
timeout = time.time() + float(sys.argv[2]) - ignore_last_secs
while True:
  if time.time() > timeout:
    break
  #sample[0] has the data, sample[1] has a timestamp
  sample = inlet.pull_sample()
  datastream.append(sample[0])

#Build folder structure
zpad = 6
path = os.path.abspath(os.path.join(__file__,sys.argv[1]))
custompath =  "/" + sys.argv[3] + "/" + sys.argv[4] + "/" + "id_" + sys.argv[5].zfill(zpad)
fullpath = path + custompath
#Create folder to save data into
if not os.path.exists(os.path.dirname(fullpath)):
  try:
    os.makedirs(os.path.dirname(fullpath))
  except OSError as exc:
    if exc.errno != errno.EEXIST:
      raise
开发者ID:eduardo-elizondo,项目名称:eeg_sampling,代码行数:31,代码来源:start_stream.py

示例4: info

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_sample [as 别名]
# first create a new stream info (here we set the name to BioSemi,
# the content-type to EEG, 8 channels, 100 Hz, and float-valued data) The
# last value would be the serial number of the device or some other more or
# less locally unique identifier for the stream as far as available (you
# could also omit it but interrupted connections wouldn't auto-recover)
fs = 1000
info = StreamInfo('python', 'EEG', 2)

# next make an outlet
outlet = StreamOutlet(info)

from pylsl import StreamInlet, resolve_stream
print('resolving stream')
streams = resolve_stream('name', 'matlab')
# create a new inlet to read from the stream
inlet = StreamInlet(streams[0])
print('resolved')

t = 0
mean_time = 0
while True:
    #time.sleep(0.002)
    t += 1
    clock = local_clock()
    outlet.push_sample([0, 1])
    sample, timestamp = inlet.pull_sample(timeout=1)
    dt = local_clock() - clock
    mean_time += dt
    print(mean_time / t, dt)
    #time.sleep(0.001)
开发者ID:nikolaims,项目名称:nfb,代码行数:32,代码来源:lsl_send_receive.py

示例5: Renderer

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_sample [as 别名]
class Renderer(app.Canvas):
	def __init__(self):
		app.Canvas.__init__(self, title='Use your wheel to zoom!',
							keys='interactive')

		
		# first resolve an EEG stream on the lab network
		print("looking for an EEG stream...")
		streams = resolve_stream('name', 'RandomSpehricalData')
		streamInfo = streams[0]
		# create a new inlet to read from the stream
		self.inlet = StreamInlet(streamInfo)
		# Number of cols and rows in the table.
		self.nrows = streamInfo.channel_count()
		
		n = streamInfo.nominal_srate()
		ncols = 1

		# Number of signals.
		m = self.nrows*ncols

		# Various signal amplitudes.
		amplitudes = .1 + .2 * np.random.rand(m, 1).astype(np.float32)

		# Generate the signals as a (m, n) array.
		self.y = amplitudes * np.random.randn(m, n).astype(np.float32)
		
		color = np.repeat(np.random.uniform(size=(m, 3), low=.5, high=.9),
						  n, axis=0).astype(np.float32)


		# Signal 2D index of each vertex (row and col) and x-index (sample index
		# within each signal).
		index = np.c_[np.repeat(np.repeat(np.arange(ncols), self.nrows), n),
					  np.repeat(np.tile(np.arange(self.nrows), ncols), n),
					  np.tile(np.arange(n), m)].astype(np.float32)


		self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
		self.program['a_position'] = self.y.reshape(-1, 1)
		self.program['a_color'] = color
		self.program['a_index'] = index
		self.program['u_scale'] = (1., 1.)
		self.program['u_size'] = (self.nrows, ncols)
		self.program['u_n'] = n

		gloo.set_viewport(0, 0, *self.physical_size)

		self._timer = app.Timer('auto', connect=self.on_timer, start=True)

		gloo.set_state(clear_color='black', blend=True,
					   blend_func=('src_alpha', 'one_minus_src_alpha'))
		
		self.sampleFromLSL = None
		
		self.show()

	def on_resize(self, event):
		gloo.set_viewport(0, 0, *event.physical_size)

	def on_mouse_wheel(self, event):
		dx = np.sign(event.delta[1]) * .05
		scale_x, scale_y = self.program['u_scale']
		scale_x_new, scale_y_new = (scale_x * math.exp(2.5*dx),
									scale_y * math.exp(0.0*dx))
		self.program['u_scale'] = (max(1, scale_x_new), max(1, scale_y_new))
		self.update()

	def on_timer(self, event):
		"""Add some data at the end of each signal (real-time signals)."""
		k = 0 # need to become the count of samples available on this timer call
		sampleSet = None
		sample, timestamp = self.inlet.pull_sample(0.0)  
		sample = np.array([sample])
		while sample.any():
			k = k + 1
			sample, timestamp = self.inlet.pull_sample(0.0)
			sample = np.array([sample])
			sampleSet = np.c_[ sampleSet, sample ] 

		if k > 0:
			self.y[:, :-k] = self.y[:, k:]
			#y[:, -k:] = amplitudes * np.random.randn(m, k)
			self.y[:, -k:] = sampleSet

		self.program['a_position'].set_data(self.y.ravel().astype(np.float32))
		self.update()

	def on_draw(self, event):
		gloo.clear()
		self.program.draw('line_strip')
开发者ID:xfleckx,项目名称:BeMoBI_Tools,代码行数:93,代码来源:LSL2Vispy.py


注:本文中的pylsl.StreamInlet.pull_sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。