def testing(): dummy_streamer = ble2lsl.Dummy(muse2016) # streams = resolve_byprop( "type", "EEG", timeout=5 ) #type: EEG, minimum return streams = 1, timeout after 5 seconds streamIn = StreamInlet( streams[0], max_chunklen=12, recover=True ) #Grab first stream from streams, MUSE chunk 12, drop lost stream print(streamIn) print(streamIn.info().channel_count()) streamIn.open_stream( ) #This actually isn't required: pull_sample() and pull_chunk() implicitly open the stream. #But it's good to be explicit because it makes the code clearer print("Pull Sample") print(streamIn.pull_sample() ) #Returns a tuple with the actual values we want. #The first element is the list of channel values, the second element is a timestamp. This is a snapshot of our stream #at a certain point in time. print("Pull Chunk") ts = time.time() while (1): x = streamIn.pull_chunk() if all(x): #if not np.shape(x) == (2, 0): print(np.shape(x)) print(np.shape(x[1])) t = [t - ts for t in x[1]] print(t) print(t[-1] - t[0]) # for y in x: # for z in y: # print(z) #print("\n") plt.style.use('ggplot') # data first then time stamps, sick pprint(streamIn.info().as_xml()) #what timeC = streamIn.time_correction() print(timeC) #Clean up time streams.clear() streamIn.close_stream() #calls lsl_close_stream streamIn.__del__() #Not throwing errors dummy_streamer.stop()
def dummy_streamers(request): """Instantiate a dummy streamer for each supported device.""" dummies = [] for device_name in request.param: dummy = b2l.Dummy(globals()[device_name]) device = dummy._device subscriptions = { name for name in device.DEFAULT_SUBSCRIPTIONS if device.PARAMS['streams']['nominal_srate'][name] > 0 } source_id = "{}-{}".format(device.NAME, 'DUMMY') dummies.append((dummy, device, source_id, subscriptions)) def teardown(): for dummy, _, _, _ in dummies: dummy.stop() del (dummy) request.addfinalizer(teardown) return dummies
# %matplotlib inline import ble2lsl from ble2lsl.devices import muse2016 from wizardhat import acquire, transform import numpy as np import matplotlib.pyplot as plt #if we had a device with us, we would use: #streamer = ble2lsl.Streamer(muse2016) #but if you're debugging or learning, use the dummy streamer with the command below: streamer = ble2lsl.Dummy(muse2016) #After writing streamer. you can use the tab key to see a list of properties and methods that streamer has, #for example, streamer.subscriptions shows all the subscribed data streams that the streamer object has picked up #from the device. streamer.subscriptions receiver = acquire.Receiver() receiver.buffers receiver.ch_names receiver.buffers['EEG'].data receiver.buffers['EEG'].data.shape #the default window for seeing data is 10 seconds. You can change that when you call acquire.Receiver(window=15) etc receiver.buffers['EEG'].unstructured #this version of the data has no labels and is just a pure numpy matrix receiver.buffers['EEG'].get_timestamps() our_first_recording = receiver.record(5) #wait 5 seconds after running this command our_first_recording.buffers['EEG'].data #notice it only goes up to 5 seconds channel_to_view = 'TP9'
"""Plot time series data streamed through a dummy LSL outlet. """ import ble2lsl from ble2lsl.devices import muse2016 from wizardhat import acquire, plot device = muse2016 plot_stream = "EEG" if __name__ == '__main__': dummy_outlet = ble2lsl.Dummy(device) receiver = acquire.Receiver() plot.Lines(receiver.buffers[plot_stream])
import ble2lsl from ble2lsl.devices import muse2016 from wizardhat import acquire, plot, transform import pylsl as lsl device = muse2016 plot_stream = 'EEG' if __name__ == '__main__': streamer = ble2lsl.Dummy(device) receiver = acquire.Receiver() psd_transformer = transform.PSD(receiver.buffers['EEG'], n_samples=256) psd_averaged = transform.MovingAverage(psd_transformer.buffer_out, n_avg=5) plotter = plot.Spectra(psd_averaged.buffer_out)
import ble2lsl from ble2lsl.devices import muse2016 import pylsl #Note that this is not at all what the final product will look like: it's just a simple script and a demonstration of how pylsl works dummy_streamer = ble2lsl.Dummy( muse2016) #Using a dummy for now. We need some Muses print( "Dummy streamer: " + str(dummy_streamer) ) #Prints the address of the streamer to see if it was initialized correctly pylslResolvedStreams = pylsl.resolve_streams(wait_time=2.0) #wait time is how long pylsl spends searching for streams. Make it higher if your streamer isn't working. #if you need to go higher than 5 then that means the problem is likely elsewhere #note that resolve_byprop is preferred over resolve_streams streams = [[stream.source_id(), stream.type(), stream] for stream in pylslResolvedStreams] #Makes a list of lists. Each list has three elements: the ID of the device the stream is coming from, #the type of stream, and the StreamInfo object. for stream in streams: print(stream) #resolve_streams returned a list of stream objects. We then expanded those stream objects #into lists to easily see more detail. The above for loop prints this expanded list for each stream. for stream in streams: if stream[1] == 'EEG': EEGStreamInfo = stream[ 2] #finds the StreamInfo object of the EEG stream
import ble2lsl from ble2lsl.devices import muse2016 # Why do I have to import this seperately? This is dumb import pylsl import time import numpy as np import time from functions import plotTimeDomain, plotFreqDomain, fft ######################## ## Create a stream ######################## dummy_streamer = ble2lsl.Dummy(muse2016) #Using a dummy for now. We need some f****n Muses. Why does most of the DEV TEAM not have any muses??? ######################## ## Find (Resolve) Stream ######################## streams = pylsl.resolve_byprop("type", "EEG", timeout=5) #type: EEG, minimum return streams = 1, timeout after 5 seconds stream = streams[0] #stream_info = getStream_info(dummy_streamer) #sam trying his new code with your thing fft(stream) #plotTimeDomain(stream, 12, title='EEG Data') dummy_streamer.stop()