def setup(self): ModuleAbstract.setup(self) self.filename = None if 'file' in self.module_conf['outputs']['data']: self.save_integers = True # get the filename to write to self.filename = self.module_conf['outputs']['data']['file'] file_extension = os.path.splitext(self.filename)[1] # include timestamp in the filename if requested if self.module_settings['include_timestamp_in_filename']: timestamp = strftime("%m-%d-%Y_%H-%M-%S", localtime()) self.filename = self.filename.replace(file_extension,"-"+timestamp+file_extension) # touch the file if overwriting is set to true, this will also set the timestamp overwrite_existing = self.module_conf['outputs']['data']['overwrite_existing'] if 'overwrite_existing' in self.module_conf['outputs']['data'] else False if overwrite_existing: with open(self.filename, 'a'): os.utime(self.filename,None) # if we don't want the timestamp, pop it off the beginning of the headers if not self.module_settings['include_timestamp']: self.headers.pop(0) if self.debug: print self.LOGNAME + "setup"
def setup(self): ModuleAbstract.setup(self) if self.debug: print self.LOGNAME + "setup" # sampling_frequency self.sampling_rate = self.module_settings["sampling_rate"] if "sampling_rate" in self.module_settings and self.module_settings["sampling_rate"] is not False else 250.0 # notch self.notch_filter = self.module_settings["notch_filter"] if "notch_filter" in self.module_settings and self.module_settings["notch_filter"] is not False else None # bandpass self.bandpass_filter = self.module_settings["bandpass_filter"] if "bandpass_filter" in self.module_settings and self.module_settings["bandpass_filter"] is not False else None # create the notch filter coefficients (60 Hz) """ For more info, see http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.butter.html#scipy.signal.butter Or http://www.mathworks.com/help/signal/ref/butter.html?s_tid=gn_loc_drop#buct3_m """ if self.notch_filter: self.notch_filter_b, self.notch_filter_a = FilterCoefficients('bandstop',self.sampling_rate,np.array(self.notch_filter)) # create the bandpass filter (7-13Hz) if self.bandpass_filter: self.bandpass_filter_b, self.bandpass_filter_a = FilterCoefficients('bandpass',self.sampling_rate,np.array(self.bandpass_filter))
def setup(self): ModuleAbstract.setup(self) self.file_to_write = None if 'file' in self.module_conf['outputs']['data']: # set file write mode ('a', or append, by default) file_write_mode = self.module_conf['outputs']['data']['file_write_mode'] if 'file_write_mode' in self.module_conf['outputs']['data'] else 'a' # get the filename to write to filename = self.module_conf['outputs']['data']['file'] # include timestamp in the filename if requested if self.module_settings['include_timestamp_in_filename']: timestamp = strftime("_%H-%M-%S", localtime()) filename = filename.replace('.data',timestamp+'.data') # open the file self.file_to_write = open(filename,file_write_mode) # if we don't want the timestamp, pop it off the beginning of the headers if not self.module_settings['include_timestamp']: self.headers.pop(0) if self.debug: print self.LOGNAME + "setup"
def setup(self): ModuleAbstract.setup(self) if self.debug: print self.LOGNAME + "setup" self.extractSettings( self.module_settings, { 'bandpass_filter_range': [7.0, 13.0], 'calculation_threshold': 30, 'class_label_channel': None, 'class_labels': None, 'epoch_size': 250, 'notch_filter': None, 'num_spatial_filters': 8, 'optimization_trace': False, 'sampling_rate': 250, 'separator': '\t', 'test_file': None, 'plot': False, 'include_electrodes': None }) # sampling_rate (Hz) self.sampling_rate = float(self.sampling_rate) # class labels if self.class_labels: self.class1, self.class2 = self.class_labels if self.notch_filter: # create the notch filter coefficients (60 Hz) self.notch_filter_b, self.notch_filter_a = FilterCoefficients( 'bandstop', self.sampling_rate, np.array(self.notch_filter)) if self.bandpass_filter_range: # create the bandpass filter (7-13Hz) self.bandpass_filter_b, self.bandpass_filter_a = FilterCoefficients( 'bandpass', self.sampling_rate, np.array(self.bandpass_filter_range)) # X and y for classification self.X = np.array([]) self.y = np.array([]) # holds epochs segregated into separate bins for each class (each dict key is a class) self.epochs_by_class = dict() # hold covariances self.covariances_by_class = dict() """ initialize a standard 3-dim array just to have a data structure that is standard with other libs In most other libraries, CSP uses a 3 dimensional epoch input: (n_epochs, n_channels, n_times) """ self.epochs = np.zeros((0, self.num_channels, self.epoch_size)) self.covariances = np.zeros((0, self.num_channels, self.num_channels)) self.all_spatial_filters = None self.spatial_filters = None # counter for epochs self.epochsCounter = Counter()
def setup(self): ModuleAbstract.setup(self) """ device_name="muse", mock_data_enabled=True, device_id=MOCK_DEVICE_ID, cloudbrain_address=RABBITMQ_ADDRESS, buffer_size=10, step_size=10, device_port=None, pipe_name=None, publisher_type="pika", device_mac=None """ if 'mock_data_enabled' not in self.module_settings: self.module_settings['mock_data_enabled'] = False if self.debug is None: self.debug = False if 'device_buffer' not in self.module_settings: self.module_settings['device_buffer'] = 10 if 'publisher_type' not in self.module_settings: self.module_settings['publisher_type'] = "pika" if self.debug: print self.LOGNAME + "setup" print self.module_settings
def setup(self): ModuleAbstract.setup(self) if self.debug: print self.LOGNAME + "setup" self.extractSettings(self.module_settings, { 'bandpass_filter_range': [7.0,13.0], 'calculation_threshold': 30, 'class_label_channel': None, 'class_labels': None, 'epoch_size': 250, 'notch_filter': None, 'num_spatial_filters': 8, 'optimization_trace': False, 'sampling_rate': 250, 'separator': '\t', 'test_file': None, 'plot': False, 'include_electrodes': None }) # sampling_rate (Hz) self.sampling_rate = float(self.sampling_rate) # class labels if self.class_labels: self.class1, self.class2 = self.class_labels if self.notch_filter: # create the notch filter coefficients (60 Hz) self.notch_filter_b, self.notch_filter_a = FilterCoefficients('bandstop',self.sampling_rate,np.array(self.notch_filter)) if self.bandpass_filter_range: # create the bandpass filter (7-13Hz) self.bandpass_filter_b, self.bandpass_filter_a = FilterCoefficients('bandpass',self.sampling_rate,np.array(self.bandpass_filter_range)) # X and y for classification self.X = np.array([]) self.y = np.array([]) # holds epochs segregated into separate bins for each class (each dict key is a class) self.epochs_by_class = dict() # hold covariances self.covariances_by_class = dict() """ initialize a standard 3-dim array just to have a data structure that is standard with other libs In most other libraries, CSP uses a 3 dimensional epoch input: (n_epochs, n_channels, n_times) """ self.epochs = np.zeros((0,self.num_channels,self.epoch_size)) self.covariances = np.zeros((0,self.num_channels,self.num_channels)) self.all_spatial_filters = None self.spatial_filters = None # counter for epochs self.epochsCounter = Counter()
def setup(self): ModuleAbstract.setup(self) if self.debug: print self.LOGNAME + "setup" # sampling_rate (Hz) self.sampling_rate = float(self.module_settings["sampling_rate"]) if "sampling_rate" in self.module_settings else 100. self.samples_per_window = self.module_settings["samples_per_window"] if "samples_per_window" in self.module_settings else 500 if len(self.inputs) and "data" in self.inputs and len(self.outputs) and "data" in self.outputs: # check if conversion is supported input_message_type = self.inputs["data"]["message_type"] input_data_type = self.inputs["data"]["data_type"] output_message_type = self.outputs["data"]["message_type"] output_data_type = self.outputs["data"]["data_type"]
def setup(self): ModuleAbstract.setup(self) if self.debug: print self.LOGNAME + "setup" if len(self.inputs) and "data" in self.inputs and len(self.outputs) and "data" in self.outputs: # check if conversion is supported input_message_type = self.inputs["data"]["message_type"] input_data_type = self.inputs["data"]["data_type"] output_message_type = self.outputs["data"]["message_type"] output_data_type = self.outputs["data"]["data_type"] # check that requested conversion is supported if input_message_type == MESSAGE_TYPE_MATRIX: if input_data_type not in self.SUPPORTED_CONVERSIONS.keys(): raise ValueError(self.LOGNAME + "Conversion from type " + input_data_type + " is not supported.") elif output_data_type not in self.SUPPORTED_CONVERSIONS[input_data_type]: raise ValueError(self.LOGNAME + "Conversion from type " + input_data_type + " to " + output_data_type + " is not supported.") else: raise ValueError(self.LOGNAME + "Input and output 'data' must be of type " + MESSAGE_TYPE_MATRIX + ". Only matrix conversions are supported so far.")
def setup(self): ModuleAbstract.setup(self) self.countTotal = 0 # Deprecated (leaving this in just in case we decide someday that we need to support # multiple EEG inputs with different numbers of channels) ## override num_channels if our input is coming from a signal generator, which could have any number of channels ##if 'num_channels' in self.module_conf['inputs']['data']: ## self.num_channels = self.module_conf['inputs']['data']['num_channels'] ##self.headers = ['timestamp'] + ['channel_%s' % i for i in xrange(self.num_channels)] self.window = np.matrix(np.zeros((self.num_channels, 0))) self.nextWindowSegment = np.matrix(np.zeros((self.num_channels, 0))) self.timestamps = [] self.lastClassLabel = 0 self.currentClassLabel = 0 self.currentClassLabelTimepointIndex = 0 self.classLabels = [] if self.debug: print self.LOGNAME + "setup"
def setup(self): ModuleAbstract.setup(self) self.countTotal = 0 # Deprecated (leaving this in just in case we decide someday that we need to support # multiple EEG inputs with different numbers of channels) ## override num_channels if our input is coming from a signal generator, which could have any number of channels ##if 'num_channels' in self.module_conf['inputs']['data']: ## self.num_channels = self.module_conf['inputs']['data']['num_channels'] ##self.headers = ['timestamp'] + ['channel_%s' % i for i in xrange(self.num_channels)] self.window = np.matrix(np.zeros((self.num_channels,0))) self.nextWindowSegment = np.matrix(np.zeros((self.num_channels,0))) self.timestamps = [] self.lastClassLabel = 0 self.currentClassLabel = 0 self.currentClassLabelTimepointIndex = 0 self.classLabels = [] if self.debug: print self.LOGNAME + "setup"
def setup(self): ModuleAbstract.setup(self) if self.debug: print self.LOGNAME + "setup" # notch self.notch_filter = self.module_settings["notch_filter"] if "notch_filter" in self.module_settings and self.module_settings["notch_filter"] is not False else None # bandpass self.bandpass_filter = self.module_settings["bandpass_filter"] if "bandpass_filter" in self.module_settings and self.module_settings["bandpass_filter"] is not False else None # create the notch filter coefficients (60 Hz) """ For more info, see http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.butter.html#scipy.signal.butter Or http://www.mathworks.com/help/signal/ref/butter.html?s_tid=gn_loc_drop#buct3_m """ if self.notch_filter: self.notch_filter_b, self.notch_filter_a = FilterCoefficients('bandstop',250.0,np.array(self.notch_filter)) # create the bandpass filter (7-13Hz) if self.bandpass_filter: self.bandpass_filter_b, self.bandpass_filter_a = FilterCoefficients('bandpass',250.0,np.array(self.bandpass_filter))
def setup(self): ModuleAbstract.setup(self) if self.debug: print self.LOGNAME + "setup"
def setup(self): ModuleAbstract.setup(self) # time counter, counts number of ticks in current period self.period_counter = 0; self.lines_counter = 0; self.total_counter = 0; # params # sampling_rate (Hz) self.sampling_rate = float(self.module_settings["sampling_rate"]) if "sampling_rate" in self.module_settings else 100. # frequency (Hz) self.frequency = float(self.module_settings["sine_frequency"]) if "sine_frequency" in self.module_settings else 10. # range self.range = self.module_settings["range"] if "range" in self.module_settings else [0,1] # separator self.separator = self.module_settings["separator"] if "separator" in self.module_settings else '\t' # skip_lines_prefix self.skip_lines_prefix = self.module_settings["skip_lines_prefix"] if "skip_lines_prefix" in self.module_settings else None # skip_lines_num self.skip_lines = self.module_settings["skip_lines"] if "skip_lines" in self.module_settings else None # skip_columns self.skip_columns = self.module_settings["skip_columns"] if "skip_columns" in self.module_settings else None # include_columns self.include_columns = self.module_settings["include_columns"] if "include_columns" in self.module_settings else None # data contains timestamp flag self.data_already_contains_timestamp = self.module_settings["data_already_contains_timestamp"] if "data_already_contains_timestamp" in self.module_settings else False # timestamp_column self.timestamp_column = self.module_settings["timestamp_column"] if "timestamp_column" in self.module_settings else 0 # class_label_column self.class_label_column = self.module_settings["class_label_column"] if "class_label_column" in self.module_settings else None # flag: whether to playback at the samplig_rate. if false, generate as fast as possible self.generate_at_sampling_rate = self.module_settings["generate_at_sampling_rate"] if "generate_at_sampling_rate" in self.module_settings else True # pattern self.pattern = "rand" if self.module_settings["pattern"]: self.pattern = self.module_settings["pattern"] # what pattern to generate if self.pattern == "sine": # SINE WAVE PATTERN # formula for sine wave is: # sine_wave = amp.*sin(2*pi*freq.*time); # amplitude = half the distance between the min and max amp = abs(float(self.range[1]) - float(self.range[0])) / 2 # zero will be halfway between the min and max offset = float(self.range[1]) - amp # np.linspace(-np.pi, np.pi, sampling_rate) --> make a range of x values, as many as sampling rate # this is equivalent to 2*pi*time sine_x = np.linspace(-np.pi, np.pi, self.sampling_rate) self.sine_waves = [] # sine wave 1 sine1 = [(amp * np.sin(t * self.sampling_rate/self.frequency)) + offset for t in sine_x] self.sine_waves.append(np.tile(sine1,self.frequency)) # sine wave 2 (double amp, triple freq) sine2 = [((2*amp) * np.sin(3 * t * self.sampling_rate/self.frequency)) + offset for t in sine_x] self.sine_waves.append(np.tile(sine2,self.frequency)) # default to the first sine wave (only used if sine) self.sine_wave_to_use = 0 self.generate_pattern_func = "generateSine" elif self.pattern == "files": # get file list from settings self.file_list = self.module_settings["files"] # force file list to be list if not already if type(self.file_list) != list: self.file_list = [self.file_list] self.current_file_index = -1 self.current_file = None self.generate_pattern_func = "generateFromFiles" else: # RANDOM PATTERN self.generate_pattern_func = "generateRandom" if self.class_label_column: self.lastClassLabel = None
def setup(self): ModuleAbstract.setup(self) # time counter, counts number of ticks in current period self.period_counter = 0; self.lines_counter = 0; self.total_counter = 0; # params # sampling_rate (Hz) self.sampling_rate = float(self.module_settings["sampling_rate"]) if "sampling_rate" in self.module_settings else 100. # frequency (Hz) self.frequency = float(self.module_settings["sine_frequency"]) if "sine_frequency" in self.module_settings else 10. # range self.range = self.module_settings["range"] if "range" in self.module_settings else [0,1] # separator self.separator = self.module_settings["separator"] if "separator" in self.module_settings else '\t' # skip_lines_prefix self.skip_lines_prefix = self.module_settings["skip_lines_prefix"] if "skip_lines_prefix" in self.module_settings else None # skip_lines_num self.skip_lines = self.module_settings["skip_lines"] if "skip_lines" in self.module_settings else None # skip_columns self.skip_columns = self.module_settings["skip_columns"] if "skip_columns" in self.module_settings else None # include_columns self.include_columns = self.module_settings["include_columns"] if "include_columns" in self.module_settings else None # data contains timestamp flag self.data_already_contains_timestamp = self.module_settings["data_already_contains_timestamp"] if "data_already_contains_timestamp" in self.module_settings else False # timestamp_column self.timestamp_column = self.module_settings["timestamp_column"] if "timestamp_column" in self.module_settings else 0 # class_label_column self.class_label_column = self.module_settings["class_label_column"] if "class_label_column" in self.module_settings else None # flag: whether to playback at the samplig_rate. if false, generate as fast as possible self.generate_at_sampling_rate = self.module_settings["generate_at_sampling_rate"] if "generate_at_sampling_rate" in self.module_settings else True # pattern self.pattern = "rand" if self.module_settings["pattern"]: self.pattern = self.module_settings["pattern"] # what pattern to generate if self.pattern == "sine": # SINE WAVE PATTERN # formula for sine wave is: # sine_wave = amp.*sin(2*pi*freq.*time); # amplitude = half the distance between the min and max amp = abs(float(self.range[1]) - float(self.range[0])) / 2 # zero will be halfway between the min and max offset = float(self.range[1]) - amp # np.linspace(-np.pi, np.pi, sampling_rate) --> make a range of x values, as many as sampling rate # this is equivalent to 2*pi*time sine_x = np.linspace(-np.pi, np.pi, self.sampling_rate) self.sine_waves = [] # sine wave 1 sine1 = [(amp * np.sin(t * self.sampling_rate/self.frequency)) + offset for t in sine_x] self.sine_waves.append(np.tile(sine1,self.frequency)) # sine wave 2 (double amp, triple freq) sine2 = [((2*amp) * np.sin(3 * t * self.sampling_rate/self.frequency)) + offset for t in sine_x] self.sine_waves.append(np.tile(sine2,self.frequency)) # default to the first sine wave (only used if sine) self.sine_wave_to_use = 0 self.generate_pattern_func = "generateSine" elif self.pattern == "files": # get file list from settings self.file_list = self.module_settings["files"] # force file list to be list if not already if type(self.file_list) != list: self.file_list = [self.file_list] self.current_file_index = -1 self.current_file = None self.generate_pattern_func = "generateFromFiles" elif self.pattern == "class_labels": self.first_class_sent = False self.inactive_class = 0 self.class_length_sec = self.module_settings["class_sec"] if "class_sec" in self.module_settings else 3 self.inactive_length_sec = self.module_settings["between_class_sec"] if "between_class_sec" in self.module_settings else 6 self.class_samples_per_trial = self.class_length_sec * self.sampling_rate self.inactive_samples_per_trial = self.inactive_length_sec * self.sampling_rate self.current_class = self.inactive_class self.initial_countdown = self.module_settings["start_delay_sec"] if "start_delay_sec" in self.module_settings else 10 self.countdown = (self.initial_countdown+1) * self.sampling_rate self.generate_pattern_func = "generateClassLabel" else: # RANDOM PATTERN self.generate_pattern_func = "generateRandom" if self.class_label_column: self.lastClassLabel = None