def __init__(self, file_path: PathType, smrx_ch_inds: list): assert HAVE_SONPY, self.installation_mesg file_path = Path(file_path) assert file_path.is_file() and file_path.suffix == '.smrx', 'file_path must lead to a .smrx file!' super().__init__() # Open smrx file self._recording_file_path = file_path self._recording_file = sp.SonFile(sName=str(file_path), bReadOnly=True) if self._recording_file.GetOpenError() != 0: raise ValueError(f'Error opening file:', sp.GetErrorString(self._recording_file.GetOpenError())) # Map Recording channel_id to smrx index / test for invalid indexes / # get channel info / set channel gains self._channelid_to_smrxind = dict() self._channel_smrxinfo = dict() for i, ind in enumerate(smrx_ch_inds): if self._recording_file.ChannelType(ind) == sp.DataType.Off: raise ValueError(f'Channel {ind} is type Off and cannot be used') self._channelid_to_smrxind[i] = ind self._channel_smrxinfo[i] = get_channel_info( f=self._recording_file, smrx_ch_ind=ind ) # Set channel gains: http://ced.co.uk/img/Spike10.pdf # from 16-bit encoded int / to ADC +-5V input / to measured Volts gains = self._channel_smrxinfo[i]['scale'] / 6553.6 self.set_channel_gains( channel_ids=[i], gains=gains ) self._kwargs = {'file_path': str(Path(file_path).absolute()), 'smrx_ch_inds': smrx_ch_inds}
def __init__(self, file_path: PathType, smrx_channel_ids: list): assert self.installed, self.installation_mesg file_path = Path(file_path) assert file_path.is_file( ) and file_path.suffix == '.smrx', 'file_path must lead to a .smrx file!' assert len(smrx_channel_ids ) > 0, "'smrx_channel_ids' cannot be an empty list!" super().__init__() # Open smrx file self._recording_file_path = file_path self._recording_file = sp.SonFile(sName=str(file_path), bReadOnly=True) if self._recording_file.GetOpenError() != 0: raise ValueError( f'Error opening file:', sp.GetErrorString(self._recording_file.GetOpenError())) # Map Recording channel_id to smrx index / test for invalid indexes / # get channel info / set channel gains self._channelid_to_smrxind = dict() self._channel_smrxinfo = dict() self._channel_names = [] gains = [] for i, ind in enumerate(smrx_channel_ids): if self._recording_file.ChannelType(ind) == sp.DataType.Off: raise ValueError( f'Channel {ind} is type Off and cannot be used') self._channelid_to_smrxind[i] = ind self._channel_smrxinfo[i] = get_channel_info( f=self._recording_file, smrx_ch_ind=ind) # Set channel gains: http://ced.co.uk/img/Spike10.pdf # from 16-bit encoded int / to ADC +-5V input / to measured Volts gain = self._channel_smrxinfo[i]['scale'] / 6553.6 gain *= 1000 # mV --> uV gains.append(gain) self._channel_names.append(self._channel_smrxinfo[i]['title']) # Set gains self.set_channel_gains(gains=gains) self.has_unscaled = True rate0 = self._channel_smrxinfo[0]['rate'] for chan, info in self._channel_smrxinfo.items(): assert info['rate'] == rate0, "Inconsistency between 'sampling_frequency' of different channels. The " \ "extractor only supports channels with the same 'rate'" # Set self._times times = (self._channel_smrxinfo[0]['frame_offset'] + np.arange( self.get_num_frames())) / self.get_sampling_frequency() self.set_times(times=times) self._kwargs = { 'file_path': str(Path(file_path).absolute()), 'smrx_channel_ids': smrx_channel_ids }
def get_all_channels_info(file_path): """ Extract info from all channels in the smrx file. Returns a dictionary with valid smrx channel indexes as keys and the respective channel information as value. Parameters: ----------- f: str Path to .smrx file """ f = sp.SonFile(sName=str(file_path), bReadOnly=True) n_channels = f.MaxChannels() return { i: get_channel_info(f, i) for i in range(n_channels) if f.ChannelType(i) != sp.DataType.Off }