def write_xlsx_list(file_name, data_list, column_headers, column_indices): file_name = func.ChangeExtension(file_name, '.xlsx') data = pd.DataFrame(data_list) num_stacks = len(data) num_param = np.shape(data[0][0])[1] try: book = load_workbook(file_name) writer = pd.ExcelWriter(file_name, engine='openpyxl') writer.book = book writer.sheets = dict((ws.title, ws) for ws in book.worksheets) except FileNotFoundError: print('No .xlsx file found') writer = pd.ExcelWriter(file_name, engine='openpyxl') for stack_nr in range(0, num_stacks): for column_nr in range(0, num_param): column_index = column_indices[column_nr] header = column_headers[column_nr] data_param = pd.DataFrame( {header: data[0][stack_nr][:, column_nr]}) data_param.to_excel(writer, sheet_name='Sheet' + str(stack_nr), startcol=column_index, index=False) writer.save()
def read_logfile(path_logfile): path_logfile = func.ChangeExtension(path_logfile, '.log') f = open(path_logfile, 'r') log = f.readlines()[:] f.close() for n, line in enumerate(log): log[n] = line.rstrip() return log
def read_bin(path_binfile, slice_nr): path_binfile = func.ChangeExtension(path_binfile, '.bin') path_logfile = func.ChangeExtension(path_binfile, '.log') data_log = file_io.read_logfile(path_logfile) # Get 2D dimensions image from log file ypix = np.uint(str.split(data_log[8], ' ')[3]) xpix = np.uint(str.split(data_log[9], ' ')[3]) pix_slice = ypix * xpix # Open file and read data of 1 slice f = open(path_binfile, mode='rb') if slice_nr != 0: f.seek(slice_nr * pix_slice * 2, 0) im_slice = np.fromfile(f, dtype=np.uint16, count=pix_slice) else: im_slice = np.fromfile(f, dtype=np.uint16, count=pix_slice) f.close() im_slice = np.reshape(im_slice, [ypix, xpix], 'F') return im_slice
f.seek(slice_nr * pix_slice * 2, 0) im_slice = np.fromfile(f, dtype=np.uint16, count=pix_slice) else: im_slice = np.fromfile(f, dtype=np.uint16, count=pix_slice) f.close() im_slice = np.reshape(im_slice, [ypix, xpix], 'F') return im_slice aap2 = read_bin(filepath, 0) #%% path_binfile = func.ChangeExtension(filepath, '.bin') path_logfile = func.ChangeExtension(filepath, '.log') data_log = file_io.read_logfile(path_logfile) # Get 2D dimensions image from log file ypix = np.uint(str.split(data_log[8], ' ')[3]) xpix = np.uint(str.split(data_log[9], ' ')[3]) pix_slice = ypix * xpix # Open file and read data of 1 slice f = open(path_binfile, 'rb') slice_nr = 1 if slice_nr != 0: f.seek(slice_nr * pix_slice * 2, 0) im_slice = np.fromfile(f, count=pix_slice, dtype='>i2')