def generate_signals(a_timer: PipelineTimer, arb_id_dict: dict, signal_pickle_filename: str, normalize_strategy, force=False): if path.isfile(signal_pickle_filename): if force: # Remove any existing pickled Signal dictionary and create one. remove(signal_pickle_filename) else: print( "\nSignal generation already completed and forcing is turned off. Using pickled data..." ) return load(open(signal_pickle_filename, "rb")) a_timer.start_function_time() signal_dict = {} for k, arb_id in arb_id_dict.items(): if not arb_id.static: for token in arb_id.tokenization: a_timer.start_iteration_time() signal = Signal(k, token[0], token[1]) # Convert the binary ndarray to a list of string representations of each row temp1 = [ ''.join(str(x) for x in row) for row in arb_id.boolean_matrix[:, token[0]:token[1] + 1] ] temp2 = zeros((temp1.__len__(), 1), dtype=uint64) # convert each string representation to int for i, row in enumerate(temp1): temp2[i] = int(row, 2) # create an unsigned integer pandas.Series using the time index from this Arb ID's original data. signal.time_series = Series(temp2[:, 0], index=arb_id.original_data.index, dtype=float64) # Normalize the signal and update its meta-data signal.normalize_and_set_metadata(normalize_strategy) # add this signal to the signal dictionary which is keyed by Arbitration ID if k in signal_dict: signal_dict[k][(arb_id.id, signal.start_index, signal.stop_index)] = signal else: signal_dict[k] = { (arb_id.id, signal.start_index, signal.stop_index): signal } a_timer.set_token_to_signal() a_timer.set_signal_generation() return signal_dict