Exemple #1
0
    def init(self):
        '''
        Secondary init function. See riglib.experiment.Experiment.init()
        Prior to starting the task, this 'init' sets up DataSource objects for streaming from the Blackrock system.
        For LFP streaming, the data is stored as it is received.
        '''

        from riglib import blackrock, source

        if hasattr(self, "_neural_src_type") and hasattr(
                self, "_neural_src_kwargs") and hasattr(
                    self, "_neural_src_system_type"):
            # for testing only!
            self.neurondata = self._neural_src_type(
                self._neural_src_system_type, **self._neural_src_kwargs)
        elif 'spike' in self.decoder.extractor_cls.feature_type:  # e.g., 'spike_counts'
            self.neurondata = source.DataSource(
                blackrock.Spikes,
                channels=self.blackrock_channels,
                send_data_to_sink_manager=False)
        elif 'lfp' in self.decoder.extractor_cls.feature_type:  # e.g., 'lfp_power'
            self.neurondata = source.MultiChanDataSource(
                blackrock.LFP,
                channels=self.blackrock_channels,
                send_data_to_sink_manager=True)
        else:
            raise Exception(
                "Unknown extractor class, unable to create data source object!"
            )

        from riglib import sink
        sink.sinks.register(self.neurondata)

        super(BlackrockData, self).init()
    def test_rpc(self):
        src = source.DataSource(MockDataSourceSystem,
                                send_data_to_sink_manager=False)
        src.start()

        self.assertEqual(src.procedure(), 42)
        self.assertEqual(src.attr_to_test_access, 43)
Exemple #3
0
    def init(self):
        sys_module = self.sys_module  # e.g., riglib.plexon, riglib.blackrock

        kwargs = dict(send_data_to_sink_manager=self.send_data_to_sink_manager,
                      channels=self.cortical_channels)

        if hasattr(self, "_neural_src_type") and hasattr(
                self, "_neural_src_kwargs") and hasattr(
                    self, "_neural_src_system_type"):
            # for testing only!
            self.neurondata = self._neural_src_type(
                self._neural_src_system_type, **self._neural_src_kwargs)
        elif 'spike' in self.decoder.extractor_cls.feature_type:  # e.g., 'spike_counts'
            self.neurondata = source.DataSource(sys_module.Spikes, **kwargs)
        elif 'lfp' in self.decoder.extractor_cls.feature_type:  # e.g., 'lfp_power'
            self.neurondata = source.MultiChanDataSource(
                sys_module.LFP, **kwargs)
        else:
            raise Exception(
                "Unknown extractor class, unable to create data source object!"
            )

        if self.register_with_sink_manager:
            sink_manager = sink.SinkManager.get_instance()
            sink_manager.register(self.neurondata)

        super(CorticalData, self).init()
Exemple #4
0
 def init(self):
     from riglib import plexon, source
     self.neurondata = source.DataSource(plexon.Spikes,
                                         channels=self.plexon_channels)
     try:
         super(SpikeData, self).init()
     except:
         print "SpikeData: running without a task"
    def init(self):
        super().init()
        self.sensor_src = source.DataSource(SimLFPSensor,
                                            send_data_to_sink_manager=True,
                                            port="/dev/cu.usbmodem1A121",
                                            baudrate=115200,
                                            name="sim_lfp")

        sink.sinks.register(self.sensor_src)
Exemple #6
0
 def init(self):
     '''
     Secondary init function. See riglib.experiment.Experiment.init()
     Prior to starting the task, this 'init' creates a 4-channel DataSource, two channels for each joystick
     -------
     '''
     from riglib import source, phidgets
     System = phidgets.make(4, 1)
     self.dualjoystick = source.DataSource(System)
     super(DualJoystick, self).init()
 def init(self):
     '''
     Secondary init function. See riglib.experiment.Experiment.init()
     Prior to starting the task, this 'init' sets up the DataSource for interacting with the 
     motion tracker system and registers the source with the SinkRegister so that the data gets saved to file as it is collected.
     '''
     from riglib import source
     src, mkw = self.source_class
     self.motiondata = source.DataSource(src, **mkw)
     from riglib import sink
     self.sinks = sink.sinks
     self.sinks.register(self.motiondata)
     super(MotionData, self).init()
 def init(self):
     '''
     Secondary init function. See riglib.experiment.Experiment.init()
     Prior to starting the task, this 'init' sets up the DataSource for interacting with the 
     kinarm system and registers the source with the SinkRegister so that the data gets saved 
     to file as it is collected.
     '''
     from riglib import source
     System  = touch_data.TouchData
     self.touch_data = source.DataSource(System)
     from riglib import sink
     sink_manager = sink.SinkManager.get_instance()
     sink_manager.register(self.touch_data)
     super(TouchDataFeature, self).init()
    def init(self):
        from riglib import blackrock, source

        if 'spike' in extractor_cls.feature_type:  # e.g., 'spike_counts'
            self.neurondata = source.DataSource(blackrock.Spikes, channels=channels)
        elif 'lfp' in extractor_cls.feature_type:  # e.g., 'lfp_power'
            self.neurondata = source.MultiChanDataSource(blackrock.LFP, channels=channels)
        else:
            raise Exception("Unknown extractor class, unable to create data source object!")

        try:
            super(BlackrockData, self).init()
        except:
            print "BlackrockData: running without a task"
 def init(self):
     '''
     Secondary init function. See riglib.experiment.Experiment.init()
     Prior to starting the task, this 'init' sets up the DataSource for interacting with the 
     kinarm system and registers the source with the SinkRegister so that the data gets saved 
     to file as it is collected.
     '''
     from riglib import source
     from riglib import kinarmdata
     System = Motion = kinarmdata.Kinarmdata
     self.kinarmdata = source.DataSource(System)
     from riglib import sink
     self.sinks = sink.sinks
     self.sinks.register(self.kinarmdata)
     super(KinarmData, self).init()
Exemple #11
0
    def init(self):
        '''
        Secondary init function. See riglib.experiment.Experiment.init()
        Prior to starting the task, this 'init' sets up the 'eyedata' DataSource and registers it with the 
        SinkRegister so that the data gets saved to file as it is collected.
        '''
        from riglib import source
        from riglib import sink
        sink_manager = sink.SinkManager.get_instance()

        src, ekw = self.eye_source
        #f = open('/home/helene/code/bmi3d/log/eyetracker', 'a')
        self.eyedata = source.DataSource(src, **ekw)
        sink_manager.register(self.eyedata)
        f.write('instantiated source\n')
        super(EyeData, self).init()
    def test_source_polling2(self):
        src = source.DataSource(MockDataSourceSystem2,
                                send_data_to_sink_manager=False)
        src.start()

        data_all = []
        for k in range(60):
            data = src.get()
            data_all.append(data)
            time.sleep(0.100)

        src.stop()
        del src

        for data in data_all:
            if len(data) > 0:
                self.assertEqual((data[0] + len(data) - 1) % 255, data[-1])
    def test_source_get_all(self):
        """source.get(all=True) should produce a growing output"""
        src = source.DataSource(MockDataSourceSystem,
                                send_data_to_sink_manager=False)
        src.start()

        prev_len = -1
        data_all = []
        for k in range(60):
            data = src.get(all=True)
            data_all.append(data)
            time.sleep(0.100)
            self.assertTrue(len(data) >= prev_len)
            prev_len = len(data)

        src.stop()
        del src
Exemple #14
0
    def init(self):
        '''
        Secondary init function. See riglib.experiment.Experiment.init()
        Prior to starting the task, this 'init' sets up the DataSource for interacting with the 
        motion tracker system and registers the source with the SinkRegister so that the data gets saved to file as it is collected.
        '''

        # Start the fake natnet client
        self.client = optitrack.PlaybackClient(self.filepath)

        # Create a source to buffer the motion tracking data
        from riglib import source
        self.motiondata = source.DataSource(optitrack.make(optitrack.System, self.client, self.optitrack_feature, 1))

        # Save to the sink
        from riglib import sink
        sink_manager = sink.SinkManager.get_instance()
        sink_manager.register(self.motiondata)
        super(Optitrack, self).init()
Exemple #15
0
    def init(self):
        '''
        Secondary init function. See riglib.experiment.Experiment.init()
        Prior to starting the task, this 'init' sets up the DataSource for interacting with the 
        motion tracker system and registers the source with the SinkRegister so that the data gets saved to file as it is collected.
        '''

        # Start the natnet client and recording
        import natnet
        now = datetime.now()
        local_path = "C:/Users/Orsborn Lab/Documents"
        session = "OptiTrack/Session " + now.strftime("%Y-%m-%d")
        take = now.strftime("Take %Y-%m-%d %H:%M:%S")
        logger = Logger(take)
        try:
            client = natnet.Client.connect(logger=logger)
            if self.saveid is not None:
                take += " (%d)" % self.saveid
                client.set_session(os.path.join(local_path, session))
                client.set_take(take)
                self.filename = os.path.join(session, take + '.tak')
                client._send_command_and_wait("LiveMode")
                time.sleep(0.1)
                if client.start_recording():
                    self.optitrack_status = 'recording'
            else:
                self.optitrack_status = 'streaming'
        except natnet.DiscoveryError:
            self.optitrack_status = 'Optitrack couldn\'t be started, make sure Motive is open!'
            client = optitrack.SimulatedClient()
        self.client = client

        # Create a source to buffer the motion tracking data
        from riglib import source
        self.motiondata = source.DataSource(optitrack.make(optitrack.System, self.client, self.optitrack_feature, 1))

        # Save to the sink
        from riglib import sink
        sink_manager = sink.SinkManager.get_instance()
        sink_manager.register(self.motiondata)
        super().init()
	def test_(self):
		# register the source with the sink manager
		sink_manager = sink.SinkManager.get_instance()

		n_channels = 4

		srcs = []
		for k in range(n_channels):
			src = source.DataSource(MockDataSourceSystem, send_data_to_sink_manager=True, name='counter%d' % k)
			sink_manager.register(src)
			srcs.append(src)

		# start an HDF sink
		sink_manager.start(HDFWriter, filename='test_high_rate_source_sink.hdf', mode='w')

		# start the source
		for src in srcs:
			src.start()

		# running for N seconds
		runtime = 60
		print("Letting the sources and sink run for %d sec..." % runtime)
		time.sleep(runtime)

		# stop source and sink
		for src in srcs:
			src.stop()

		time.sleep(1)
		sink_manager.stop()

		# sleep to allow HDF file to be closed
		time.sleep(2)

		hdf = tables.open_file('test_high_rate_source_sink.hdf', mode='r')
		for k in range(n_channels):
			data = getattr(hdf.root, 'counter%d' % k)[:]['value']
			self.assertTrue(check_counter_stream(data))
		# self.assertTrue(check_counter_stream(hdf.root.counter1[:]['value']))
		hdf.close()
Exemple #17
0
 def register_num_channels(self):
     from riglib import source, phidgets, sink
     System = phidgets.make(2, 1)
     self.joystick = source.DataSource(System)
Exemple #18
0
import time
from riglib import source
from riglib.plexon import Spikes
import pickle

ds = source.DataSource(Spikes)
ds.start()
time.sleep(0.1)

T = 1000
data = [None]*T
for k in range(T):
    data[k] = ds.get()
    data_k = data[k]
    print data_k[data_k['chan'] == 232]

    time.sleep(0.1)
ds.stop()

pickle.dump(data, open('plexstream_bmi_test.dat', 'wb'))
Exemple #19
0
 def register_num_channels(self):
     from riglib import arduino_joystick, source, sink
     System = arduino_joystick.make(2, 1)
     self.joystick = source.DataSource(System)
Exemple #20
0
import time
from riglib import source
from riglib.plexon import Spikes

ds = source.DataSource(Spikes, addr=('10.0.0.13', 6000), channels=[22])
ds.start()
time.sleep(10)
data = ds.get(True)
ds.stop()

print data
Exemple #21
0
import time
from riglib import source, blackrock

channels = [5, 6, 7, 8]
s = source.DataSource(blackrock.Spikes, channels=channels)
s.start()
import time
import numpy as np
np.set_printoptions(suppress=True)
from riglib.sink import sinks, PrintSink
from riglib import source
from riglib import motiontracker, hdfwriter, nidaq, calibrations

Motion = motiontracker.make(8, motiontracker.AligningSystem)

datasource = source.DataSource(Motion)
datasource.filter = calibrations.AutoAlign()
#sinks.start(nidaq.SendRowByte)
#sinks.register(Motion)

sinks.start(hdfwriter.HDFWriter, filename="/tmp/test.hdf")
#sinks.start(PrintSink)
sinks.register(Motion)

datasource.start()
print "reading for 10 seconds..."
try:
    while True:
        print datasource.get()
        time.sleep(0.01)
except KeyboardInterrupt:
    pass
datasource.stop()

sinks.stop()
print "complete!"
Exemple #23
0
 def register_num_channels(self):
     from riglib import source, arduino_imu
     System = arduino_imu.make(6, 1)
     self.arduino_imu = source.DataSource(System)
Exemple #24
0
import time
from riglib import source
from riglib.ecube import Broadband, make
import numpy as np

DURATION = 5

ecube = make(Broadband, headstages=[7], channels=[(1,1)])
ds = source.DataSource(ecube)
ds.start()
time.sleep(DURATION)
data = ds.get()
ds.stop()

print("Received {} packets in {} seconds ({} Hz)".format(data.shape[0], DURATION, data.shape[0]/DURATION))
ts = [d['timestamp'] for d in data]
print("First timestamp: {} ns ({:.5f} s)\tLast timestamp {} ns ({:.5f} s)".format(
    ts[0], ts[0]/1e9, ts[-1], ts[-1]/1e9
))
duration = (ts[-1]-ts[0])/1e9
samples = [d['data'].shape[0] for d in data]
print("Calculated duration: {:.5f} s, at {:.2f} Hz packet frequency and {} Hz sampling rate".format(
    duration, data.shape[0]/duration, np.sum(samples[:-1])/duration))
print("For reference, the ecube datasource is meant to have a sampling rate of {:.2f} Hz".format(ecube.update_freq))