def save_notes(notes, simID, path): """ Save the notes about the current simulation Parameters ---------- notes : string text specifing what is special about the simulation simID : string simulation ID path : string directory to save """ from utils.utils import check_directory import csv folder = path + '/Log/' check_directory(path + '/Log/') fields = [simID, notes] try: with open(folder + 'notes.csv', 'a') as file: writer = csv.writer(file) writer.writerow(fields) except IOError: with open(folder + 'notes.csv', 'w') as file: writer = csv.writer(file) writer.writerow(fields)
def save_data(data, filename, file_format, folder='/Data'): """ Saves the data for later use Parameters ---------- data: array_like data to be stored filename: stringor filename to store to file_format: sting file format folder: folder to store to """ from utils.utils import check_directory check_directory(folder) if file_format == 'pkl' and type(data) == pd.core.frame.DataFrame: data.to_pickle(folder + '/' + filename + '.pkl') elif file_format == 'pkl' and isinstance(data, object): with open(folder + '/' + filename + '.pkl', 'wb') as output: pickle.dump(data, output, pickle.HIGHEST_PROTOCOL)
def __init__(self, params, nn=2, cond='30'): self.cond = cond self.input_dir = f'{params.path}/Data/{params.simID}/{cond}/' self.params = params self.output_dir = params.path + '/Figures/' check_directory(self.output_dir) self.fig_format = 'pdf' self.save = params.save_figs self.nn = nn self.o = -1 self.fit = 'Rn:0' self.title = f'o={params.offset[self.o]}, {omega}={params.noise[self.nn]}, cond={cond}'
def __init__(self, params, data): self.params = params self.N = params.list_length self.input_dir = params.data_dir self.output_dir = params.path + '/Figures/' check_directory(self.output_dir) self.data = data self.fig_format = '.pdf' filenames = sorted([ item for item in os.listdir(self.input_dir) if item[-3:] == 'pkl' ]) self.data_observed = [ pd.read_pickle(self.input_dir + file) for file in filenames ]
def __init__(self, params): self.params = params self.N = params.list_length self.input_dir = params.data_dir self.output_dir = params.path + '/Figures' self.fig_format = 'pdf' check_directory(self.output_dir) filenames = sorted([ item for item in os.listdir(self.input_dir) if item[-3:] == 'pkl' and 'std' not in item ]) self.data = [ pd.read_pickle(self.input_dir + file) for file in filenames ] self.save = params.save_figs
def prepare_data(self): """ Select the positive responses for targets and lures and save them in csv-files sorted by condition """ params = self.params from utils.data import select_data input_dir = params.data_dir filenames = sorted([ item for item in os.listdir(input_dir) if item[-3:] == 'pkl' and 'std' not in item ]) data = [pd.read_pickle(input_dir + file) for file in filenames] print(filenames) self.target, self.lure = np.ones((len(filenames))).tolist(), np.ones( (len(filenames))).tolist() for i, dat in enumerate(data): self.target[i] = [ select_data(dat, ['target'], o, params.noise)['target'] for o in params.offset ] self.lure[i] = [ select_data(dat, ['lure'], o, params.noise)['lure'] for o in params.offset ] self.filenames = [item.strip('.pkl') for item in filenames] path = params.data_dir + '/Matlab/Model_input/' path1 = params.data_dir + '/Matlab/Model_output/' # needed for later check_directory(path) check_directory(path1) for i in range(len(self.target)): for ii in range(len(self.target[i])): name = path + self.filenames[i] + "_" + str( params.offset[ii]) + ".csv" self.save_csv(self.target[i][ii], self.lure[i][ii], name, ii + 1)
def __init__(self,simID): self.simID=simID self.params=load_params(simID,os.path.abspath('..')) self.data=pd.read_pickle(self.params.data_dir+'data.pkl') self.output_dir=self.params.path+'/Figures/' check_directory(self.output_dir)