예제 #1
0
    def __init__(self, source='', *args, **kwargs):

        dtype = np.dtype([
            ('swstx', np.uint16),
            ('swid', np.uint16),
            ('swdata_size', np.uint16),
            ('timestamp', np.uint64),
            ('points', np.uint32, 400),
            ('sncrc', np.int16),
            ('x', np.int32),
            ('y', np.int32),
            ('angle', np.int32),
            ('targets', np.int32, 50),
        ])

        time_accessor = accessor(dtype,
                                 'timestamp',
                                 label='time',
                                 record_shape=(),
                                 record_processor=NlxTimestamp2Seconds)
        x_accessor = accessor(dtype, 'y')
        y_accessor = accessor(dtype, 'x')

        accessors = dict(
            points=(accessor(dtype,
                             'points',
                             record_processor=self._convert_points), None),
            targets=(accessor(dtype,
                              'targets',
                              record_processor=lambda targets: self.
                              _convert_points(points=targets)), None),
            position=([time_accessor, x_accessor, y_accessor], None),
            default=([time_accessor, x_accessor, y_accessor], None))

        #call base class __init__
        NlxFileBase.__init__(self,
                             source,
                             dtype,
                             *args,
                             accessors=accessors,
                             **kwargs)

        #check if correct file type
        if self._header.filetype != "Video":
            raise NeuralynxIOError(self._header.file,
                                   'Not a valid Video Tracker file')

        # double check sampling frequency
        # based on first 1000 records
        if self.nrecords > 1:
            fs = 1. / np.mean(
                np.diff(self.data.time[0:min(self.nrecords, 1000)]))
            # more than 1% difference
            if np.abs(fs - self.header['SamplingFrequency']
                      ) / self.header['SamplingFrequency'] > 0.01:
                self._header._parameters['SamplingFrequency'] = fs
                warnings.warn(
                    'Sampling frequency in NVT file header does not match sampling frequency in file. Corrected to '
                    + str(fs) + ' Hz.')
예제 #2
0
    def __init__(self, source, dtype, accessors={}):
        #read file header
        if isinstance(source, NlxHeader):
            self._header = source
        else:
            self._header = NlxHeader(source)

        #get size of records in file
        self._recordsize = self._header.getvalue('RecordSize')

        self._record_dtype = dtype

        #define accessors
        self._accessors = dict(
            original_time=(accessor(dtype,
                                    'timestamp',
                                    label='time',
                                    record_shape=(),
                                    record_processor=NlxTimestamp2Seconds),
                           None),
            original_timestamp=(accessor(dtype, 'timestamp'), None),
            time=(accessor(dtype,
                           'timestamp',
                           label='time',
                           record_shape=(),
                           record_processor=NlxTimestamp2Seconds), None),
        )
        self._accessors['default_time'] = self._accessors['time']

        #merge in accessors specified as arguments
        self._accessors.update(accessors)

        self.data = BinaryFileReader(self.fullpath,
                                     self._record_dtype,
                                     offset=NLXHEADERSIZE,
                                     accessors=self._accessors)

        if self.nrecords > 0:
            self._starttimestamp = self.data.original_timestamp[0][0]
            self._endtimestamp = self.data.original_timestamp[self.nrecords -
                                                              1][0]
        else:
            self._starttimestamp = 0
            self._endtimestamp = 0
예제 #3
0
    def __init__(self, source='', *args, **kwargs):

        dtype = np.dtype([
            ('nstx', np.int16),
            ('npkt_id', np.int16),
            ('npkt_data_size', np.int16),
            ('timestamp', np.uint64),
            ('nevent_id', np.int16),
            ('nttl', np.int16),
            ('ncrc', np.int16),
            ('ndummy1', np.int16),
            ('ndummy2', np.int16),
            ('extra', np.int32, 8),
            ('eventstring', 'S128'),
        ])

        accessors = dict(default=([
            accessor(dtype,
                     'timestamp',
                     label='time',
                     record_shape=(),
                     record_processor=NlxTimestamp2Seconds),
            accessor(dtype, 'eventstring')
        ], None))

        #call base class __init__
        NlxFileBase.__init__(self,
                             source,
                             dtype,
                             *args,
                             accessors=accessors,
                             **kwargs)

        #check if correct file type
        if self._header.filetype != "Event":
            raise NeuralynxIOError(self._header.file, 'Not a valid Event file')
예제 #4
0
    def __init__(self, source='', *args, **kwargs):

        if not isinstance(source, NlxHeader):
            source = NlxHeader(source)
        nchan = 1
        nsamples = NLXCSCBUFFERSIZE

        dtype = np.dtype([('timestamp', np.uint64),
                          ('channelnumber', np.uint32),
                          ('samplefreq', np.uint32),
                          ('numvalidsamples', np.uint32),
                          ('signal', np.int16, nsamples)])

        #set default options
        kwargs.setdefault('correct_inversion', True)
        kwargs.setdefault('scale_data', True)
        kwargs.setdefault('units', 'uV')

        #call base class __init__
        NlxFileTimedBuffers.__init__(self,
                                     source,
                                     dtype,
                                     nchannels=nchan,
                                     nsamples=nsamples,
                                     **kwargs)

        #check if correct file type
        if self._header.filetype != "CSC":
            raise NeuralynxIOError(self._header.file, 'Not a valid CSC file')

        validsamples = self.data.numvalidsamples[:]
        invalid = np.flatnonzero(validsamples < NLXCSCBUFFERSIZE)

        self._ninvalid = len(invalid)
        self._invalid_samples = np.vstack([invalid, validsamples[invalid]]).T

        indexer = signal_indexer(NLXCSCBUFFERSIZE, self.nrecords,
                                 self._invalid_samples)
        time_by_sample_accessor = accessor(
            dtype,
            'timestamp',
            label='time',
            record_shape=(nsamples, ),
            sample_dim=0,
            record_processor=self._convert_timestamp)
        signal_by_sample_accessor = accessor(
            dtype,
            'signal',
            record_shape=(nsamples, ),
            sample_dim=0,
            record_processor=self._convert_data)
        accessors = dict(
            time_by_sample=(time_by_sample_accessor, indexer),
            timestamp_by_sample=(accessor(
                dtype,
                'timestamp',
                record_shape=(nsamples, ),
                sample_dim=0,
                record_processor=self._expand_timestamp), indexer),
            signal_by_sample=(signal_by_sample_accessor, indexer),
            signal=(accessor(dtype,
                             'signal',
                             record_processor=self._convert_data), None),
            default=([time_by_sample_accessor,
                      signal_by_sample_accessor], indexer))

        accessors['default_time'] = accessors['time_by_sample']

        self.data.add_accessors(accessors)
예제 #5
0
    def __init__(self, source='', *args, **kwargs):

        #we need to figure out the number of channels and samples first
        #read header
        if not isinstance(source, NlxHeader):
            source = NlxHeader(source)
        nchan = source.getvalue('NumADChannels')
        nsamples = source.getvalue('SamplesPerRecord')

        dtype = np.dtype([('seconds', np.int32), ('nanoseconds', np.int32),
                          ('dt', np.int32),
                          ('data', np.int16, (nsamples, nchan))])

        #set default options
        kwargs.setdefault('correct_inversion', True)
        kwargs.setdefault('scale_data', True)
        kwargs.setdefault('units', 'uV')

        #call base class __init__
        NlxFileTimedBuffers.__init__(self,
                                     source,
                                     dtype,
                                     nchannels=nchan,
                                     nsamples=nsamples,
                                     accessors={},
                                     **kwargs)

        #check if correct file type
        if self._header.filetype != "MOZ":
            raise NeuralynxIOError(self._header.file,
                                   'Not a valid Tahiti MOZ file')

        indexer = signal_indexer(nsamples, self.nrecords, None)
        time_by_sample_accessor = accessor(
            dtype, ['seconds', 'nanoseconds'],
            label='time',
            record_shape=(nsamples, ),
            sample_dim=0,
            record_processor=self._convert_and_expand_timestamp)
        data_by_sample_accessor = accessor(dtype,
                                           'data',
                                           sample_dim=0,
                                           record_processor=self._convert_data)

        accessors = dict(
            original_time=(accessor(dtype, ['seconds', 'nanoseconds'],
                                    label='time',
                                    record_shape=(),
                                    record_processor=self._convert_timestamp),
                           None),
            original_timestamp=(accessor(
                dtype, ['seconds', 'nanoseconds'],
                label='timestamp',
                record_shape=(),
                record_processor=self._convert_timestamp), None),
            time=(accessor(dtype, ['seconds', 'nanoseconds'],
                           label='time',
                           record_shape=(),
                           record_processor=self._convert_timestamp), None),
            time_by_sample=(time_by_sample_accessor, indexer),
            data=(accessor(dtype, 'data',
                           record_processor=self._convert_data), None),
            data_by_sample=(data_by_sample_accessor, indexer),
            default=([time_by_sample_accessor,
                      data_by_sample_accessor], indexer))

        accessors['default_time'] = accessors['time_by_sample']

        self.data.add_accessors(accessors)
예제 #6
0
    def __init__(self, source, *args, **kwargs):

        #we need to figure out the number of channels first
        #read header
        if not isinstance(source, NlxHeader):
            source = NlxHeader(source)
        nchan = source.getvalue('NumADChannels')
        nsamples = source.getvalue('WaveformLength')

        dtype = np.dtype([('timestamp', np.uint64), ('scnumber', np.uint32),
                          ('cellnumber', np.uint32), ('params', np.uint32, 8),
                          ('waveform', np.int16, (nsamples, nchan))])

        spike_time_accessor = accessor(
            dtype,
            'timestamp',
            label='time',
            record_shape=(),
            record_processor=self._convert_timestamp_to_time)
        waveform_accessor = accessor(dtype,
                                     'waveform',
                                     record_processor=self._convert_data)

        accessors = dict(sample_time=(accessor(
            dtype,
            'timestamp',
            label='time',
            record_shape=(),
            record_processor=self._convert_timestamp), None),
                         sample_timestamp=(accessor(
                             dtype,
                             'timestamp',
                             record_processor=self._expand_timestamp), None),
                         waveform=(waveform_accessor, None),
                         spike_time=(spike_time_accessor, None),
                         spikes=([spike_time_accessor,
                                  waveform_accessor], None),
                         default=([spike_time_accessor,
                                   waveform_accessor], None))

        accessors['default_time'] = accessors['spike_time']

        #set default options
        kwargs.setdefault('correct_inversion', True)
        kwargs.setdefault('scale_data', True)
        kwargs.setdefault('units', 'uV')

        #call base class __init__
        NlxFileTimedBuffers.__init__(self,
                                     source,
                                     dtype,
                                     nchannels=nchan,
                                     nsamples=nsamples,
                                     accessors=accessors,
                                     **kwargs)

        #check if correct file type
        if self._header.filetype != "Spike":
            raise NeuralynxIOError(
                self._header.file,
                'Not a valid Spike file [tetrode/stereotrode/electrode]')

        indexer = signal_indexer(nsamples, self.nrecords)

        time_by_sample_accessor = accessor(
            dtype,
            'timestamp',
            label='time',
            record_shape=(nsamples, ),
            sample_dim=0,
            record_processor=self._convert_timestamp)
        waveform_by_sample_accessor = accessor(
            dtype,
            'waveform',
            record_shape=(nsamples, nchan),
            sample_dim=0,
            record_processor=self._convert_data)

        self.data.add_accessors(
            dict(time_by_sample=(time_by_sample_accessor, indexer),
                 waveform_by_sample=(waveform_by_sample_accessor, indexer)))