def restore_online_signal(h5_dataset, signal_name, band=None, spatial_filter=None, smoothing_factor=0.999): df, fs, channels, p_names = load_data(h5_dataset) n_channels = len(channels) with h5py.File(h5_dataset) as f: last_block = len(df.block_number.unique()) if spatial_filter is None: spatial_filter = f['protocol{}/signals_stats/Signal/spatial_filter' .format(last_block)][:] if band is None: band = f['protocol{}/signals_stats/Signal/bandpass'.format( last_block)][:] xml_settings = load_xml_str_from_hdf5_dataset(h5_dataset, 'settings.xml') params = xml_file_to_params(xml_settings) signals_params_list = params['vSignals']['DerivedSignal'] signals_names = [s['sSignalName'] for s in signals_params_list] signal = signals_params_list[signals_names.index(signal_name)] signal['fBandpassLowHz'], signal['fBandpassHighHz'] = band signal['sTemporalFilterType'] = 'butter' signal['fSmoothingFactor'] = smoothing_factor signal = DerivedSignal.from_params(0, fs, n_channels, channels, signal, spatial_filter) time_series = signal.update(df[channels].values) return signal, time_series
def load_signal(filename, channels_labels): signal = xml_file_to_odict(filename) default = vectors_defaults['vSignals']['DerivedSignal'][0].copy() for key, value in default.items(): default[key] = signal.get(key, value) signal = default if isinstance(signal['SpatialFilterMatrix'], str): if signal['SpatialFilterMatrix'] == '': spatial_filter = None else: spatial_filter = read_spatial_filter(signal['SpatialFilterMatrix'], channels_labels) elif isinstance(signal['SpatialFilterMatrix'], list): spatial_filter = array(signal['SpatialFilterMatrix']).astype(float) else: raise TypeError( '\'SpatialFilterMatrix\' must be string or list (vector)') s = DerivedSignal( bandpass_high=signal['fBandpassHighHz'], bandpass_low=signal['fBandpassLowHz'], name=signal['sSignalName'], n_channels=len(channels_labels), spatial_filter=spatial_filter, disable_spectrum_evaluation=signal['bDisableSpectrumEvaluation'], n_samples=signal['fFFTWindowSize'], smoothing_factor=signal['fSmoothingFactor']) return s
def restore_online_signal(h5_dataset, signal_name, band=None, spatial_filter=None, smoothing_factor=0.999): df, fs, channels, p_names = load_data(h5_dataset) n_channels = len(channels) with h5py.File(h5_dataset) as f: last_block = len(df.block_number.unique()) if spatial_filter is None: spatial_filter = f['protocol{}/signals_stats/Signal/spatial_filter'.format(last_block)][:] if band is None: band = f['protocol{}/signals_stats/Signal/bandpass'.format(last_block)][:] xml_settings = load_xml_str_from_hdf5_dataset(h5_dataset, 'settings.xml') params = xml_file_to_params(xml_settings) signals_params_list = params['vSignals']['DerivedSignal'] signals_names = [s['sSignalName'] for s in signals_params_list] signal = signals_params_list[signals_names.index(signal_name)] signal['fBandpassLowHz'], signal['fBandpassHighHz'] = band signal['sTemporalFilterType'] = 'butter' signal['fSmoothingFactor'] = smoothing_factor signal = DerivedSignal.from_params(0, fs, n_channels, channels, signal, spatial_filter) time_series = signal.update(df[channels].values) return signal, time_series
labels_, fs_ = get_lsl_info_from_xml(f['stream_info.xml'][0]) print(labels_) channels = [ label for label in labels_ if label not in ['A1', 'A2', 'AUX'] ] print(labels_) pz_index = channels.index('Pz') raw = raw - np.dot(raw[:, [pz_index]], np.ones((1, raw.shape[1]))) del channels[pz_index] raw = raw[:, np.arange(raw.shape[1]) != pz_index] signal = DerivedSignal(ind=0, name='Signal', bandpass_low=9, bandpass_high=14, spatial_filter=np.array([0]), n_channels=raw.shape[1]) w = SignalsSSDManager([signal], raw, ch_names_to_2d_pos(channels), channels, None, None, [], sampling_freq=fs_) w.exec_() rejections = signal.rejections.get_list() new_rejections[experiment] = rejections with open(new_rejections_file, 'wb') as pkl: pickle.dump(new_rejections, pkl)
#channels = [b[0] for b in mat_file['EEGchanslabels'][0]] #print(np.shape(channels)) #print(np.shape(x)) #print(np.shape(marks)) channels = [ 'Fc1', 'Fc3', 'Fc5', 'C1', 'C3', 'C5', 'Cp1', 'Cp3', 'Cp5', 'Cz', 'Pz', 'Cp2', 'Cp4', 'Cp6', 'C2', 'C4', 'C6', 'Fc2', 'Fc4', 'Fc6' ] n_ch = len(channels) from pynfb.signals import CompositeSignal signals = [ DerivedSignal(ind=k, source_freq=500, name='Signal' + str(k), bandpass_low=0 + k, bandpass_high=1 + 10 * k, spatial_filter=np.array([k]), n_channels=n_ch) for k in range(3) ] signals += [CompositeSignal(signals, '', 'Composite', 3, fs=500)] signals += [BCISignal(500, channels, 'bci', n_ch)] app = QtGui.QApplication([]) x = np.random.randn(5000, n_ch) from pynfb.widgets.helpers import ch_names_to_2d_pos #x[2500:3000, channels.index('Cz')] /= 50 x = x[:50000] #marks = marks[:50000]
from pynfb.signals import DerivedSignal, CompositeSignal from pynfb.io.hdf5 import save_signals signals = [DerivedSignal(name='One'), DerivedSignal(name='Two')] signals += [CompositeSignal(signals, 'One+Two', name='Three')] save_signals('signals_info.hdf5', signals, group_name='protocol1')