for shot in range(5): conductor_json_path = data_folder + '\\{}'.format(shot) + '.conductor.json' tcam_hdf5_path = data_folder + '\\{}'.format(shot) + '.ixon.hdf5' f = open(conductor_json_path, 'r') f1 = f.read() f2 = json.loads(f1) t = f2['sequencer.DO_parameters.red_mot_tof'] + t_delay images = {} with h5py.File(tcam_hdf5_path, 'r') as images_h5: for key in images_h5: images[key] = np.array(images_h5[key], dtype = 'float64') images_h5.close() n0 = process_images_g(images) n = n0 # yc, xc = np.unravel_index(n0.argmax(), n0.shape) # n = n0[yc - roi_width: yc + roi_width, xc - roi_width: xc + roi_width] n = np.flipud(n) # print(yc, xc) X = range(n.shape[1]) Y = range(n.shape[0]) x_trace = np.sum(n, axis = 0) y_trace = np.sum(n, axis = 1) p0x = (x_trace.argmax(), fit_width, np.max(x_trace), np.min(x_trace)) p0y = (y_trace.argmax(), fit_width, np.max(y_trace), np.min(y_trace))
def process_red_mot_tof_ccd(settings): shot = settings['shot'] roi_width = settings['kwargs']['roi_width'] fit_width = settings['kwargs']['fit_width'] x_key = settings['kwargs']['x_key'] y_key = settings['kwargs']['y_key'] method = settings['kwargs']['method'] if shot >= 0: data = [] data_folder = os.path.join(PROJECT_DATA_PATH, settings['data_path']) save_folder = os.path.join(PROJECT_DATA_PATH, settings['data_path'], 'processed_data') save_path = os.path.join(save_folder, str(shot)) if not os.path.isdir(save_folder): os.makedirs(save_folder) conductor_json_path = data_folder + '\\{}'.format( shot) + '.conductor.json' ccd_hdf5_path = data_folder + '\\{}'.format(shot) + '.{}.hdf5'.format( method) try: f = open(conductor_json_path, 'r') f1 = f.read() f2 = json.loads(f1) tof = f2['sequencer.DO_parameters.red_mot_tof'] + t_delay try: em_gain = f2['andor.record_path']['em_gain'] except: em_gain = 1 images = {} with h5py.File(ccd_hdf5_path, 'r') as images_h5: for key in images_h5: images[key] = np.array(images_h5[key], dtype='float64') images_h5.close() n0 = process_images_g(images, em_gain) x_trace0 = np.sum(n0, axis=0) y_trace0 = np.sum(n0, axis=1) xc = x_trace0.argmax() yc = y_trace0.argmax() n = n0 n = np.flipud(n) X = range(n.shape[1]) Y = range(n.shape[0]) x_trace = np.sum(n, axis=0) y_trace = np.sum(n, axis=1) p0x = (x_trace.argmax(), fit_width, np.max(x_trace), np.min(x_trace)) p0y = (y_trace.argmax(), fit_width, np.max(y_trace), np.min(y_trace)) try: poptx, pcovx = optimize.curve_fit(fit_Gaussian, X, x_trace, p0=p0x) popty, pcovy = optimize.curve_fit(fit_Gaussian, Y, y_trace, p0=p0y) except Exception as e1: print(e1) poptx = p0x popty = p0y xcen = poptx[0] ycen = popty[0] xwidth = poptx[1] ywidth = popty[1] count1 = np.sum(x_trace) - poptx[-1] * len(x_trace) # test count2 = np.sum(y_trace) - popty[-1] * len(y_trace) # test count = (count1 + count2) / 2 count = round(count, 1) data.append({ 'shot': shot, x_key: tof, 'fit': { 'xcen': xcen, 'ycen': ycen, 'xwidth': xwidth, 'ywidth': ywidth, 'count': count } }) fig, ax = plt.subplots(1, 1) fig.set_size_inches(20, 8) n1 = n0[yc - roi_width:yc + roi_width, xc - roi_width:xc + roi_width] X = range(n1.shape[1]) Y = range(n1.shape[0]) cmap = plt.get_cmap('jet') ax.set_aspect('equal') plt.pcolormesh(X, Y, n1, cmap=cmap, vmin=0) plt.colorbar() plt.title('Atom number: {:.2e}'.format(count)) plt.savefig(save_path + '.png', bbox_inches='tight') X = range(n.shape[1]) Y = range(n.shape[0]) plt.figure() t_plot = np.linspace(np.min(X), np.max(X), 100) plt.scatter(X, x_trace, c='blue') plt.plot( t_plot, fit_Gaussian(t_plot, poptx[0], poptx[1], poptx[2], poptx[3])) plt.savefig(save_path + '_traceX.png', bbox_inches='tight') plt.figure() t_plot = np.linspace(np.min(Y), np.max(Y), 100) plt.scatter(Y, y_trace, c='red') plt.plot( t_plot, fit_Gaussian(t_plot, popty[0], popty[1], popty[2], popty[3])) plt.savefig(save_path + '_traceY.png', bbox_inches='tight') plt.clf() plt.close('all') except Exception as e: print(e) data = [] xcen = 0 ycen = 0 xwidth = 0 ywidth = 0 count = 0 data.append({ 'shot': shot, x_key: tof, 'fit': { 'xcen': xcen, 'ycen': ycen, 'xwidth': xwidth, 'ywidth': ywidth, 'count': count } }) return data else: return data
def process_lattice_accelerate_image_ccd(settings): shot = settings['shot'] roi_center = settings['kwargs']['roi_center'] roi_width = settings['kwargs']['roi_width'] fit_width = settings['kwargs']['fit_width'] x_key = settings['kwargs']['x_key'] y_key = settings['kwargs']['y_key'] method = settings['kwargs']['method'] image = settings['kwargs']['image'] if shot >= 0: data = [] data_folder = os.path.join(PROJECT_DATA_PATH, settings['data_path']) save_folder = os.path.join(PROJECT_DATA_PATH, settings['data_path'], 'processed_data') save_path = os.path.join(save_folder, str(shot)) if not os.path.isdir(save_folder): os.makedirs(save_folder) conductor_json_path = data_folder + '\\{}'.format( shot) + '.conductor.json' ccd_hdf5_path = data_folder + '\\{}'.format(shot) + '.{}.hdf5'.format( method) with open(conductor_json_path, 'r') as file: f1 = file.read() f2 = json.loads(f1) try: em_gain = f2['andor.record_path']['em_gain'] except: em_gain = 1 try: images = {} with h5py.File(ccd_hdf5_path, 'r') as images_h5: for key in images_h5: images[key] = np.array(images_h5[key], dtype='float64') images_h5.close() if image == 'absorption': n0 = process_images_g(images, em_gain) xc = n0.shape[1] - roi_center[1] yc = roi_center[0] n = n0[:, xc - roi_width:xc + roi_width] x_trace0 = np.sum(n, axis=0) y_trace0 = np.sum(n, axis=1) X = range(n.shape[1]) Y = range(n.shape[0]) count = np.sum(n) count = round(float(count), 1) elif image == 'fluorescence': n0 = process_images_g_fluorescence(images) xc = n0.shape[1] - roi_center[1] yc = roi_center[0] n = n0[:, xc - roi_width:xc + roi_width] x_trace0 = np.sum(n, axis=0) y_trace0 = np.sum(n, axis=1) X = range(n.shape[1]) Y = range(n.shape[0]) count = np.sum(n) count = round(float(count), 1) fig, ax = plt.subplots(1, 1) fig.set_size_inches(20, 8) cmap = plt.get_cmap('jet') ax.set_aspect('equal') # X = range(n0.shape[1]) # Y = range(n0.shape[0]) plt.pcolormesh(X, Y, n, cmap=cmap, vmin=0) ax.set_xlim(0, n.shape[1]) ax.set_ylim(0, n.shape[0]) # plt.plot(X, x_trace0/max(x_trace0)*roi_width, c = 'yellow', label = 'x_trace') # plt.plot(y_trace0/max(y_trace0)*roi_width, Y, c = 'yellow', label = 'y_trace') # plt.legend() plt.colorbar() # plt.title('Atom number: {:.2e}'.format(count)) plt.savefig(save_path + '.png', bbox_inches='tight') plt.clf() plt.close('all') except Exception as e: print(e) count = 0 data.append({'shot': shot, 'fit': {y_key: count}}) return data else: return data
def process_red_mot_image_ccd(settings): shot = settings['shot'] roi_width = settings['kwargs']['roi_width'] fit_width = settings['kwargs']['fit_width'] x_key = settings['kwargs']['x_key'] y_key = settings['kwargs']['y_key'] method = settings['kwargs']['method'] image = settings['kwargs']['image'] if shot >= 0: data = [] data_folder = os.path.join(PROJECT_DATA_PATH, settings['data_path']) save_folder = os.path.join(PROJECT_DATA_PATH, settings['data_path'], 'processed_data') save_path = os.path.join(save_folder, str(shot)) if not os.path.isdir(save_folder): os.makedirs(save_folder) conductor_json_path = data_folder + '\\{}.conductor.json'.format(shot) ccd_hdf5_path = data_folder + '\\{}.{}.hdf5'.format(shot, method) with open(conductor_json_path, 'r') as file: f1 = file.read() f2 = json.loads(f1) try: em_gain = f2['andor.record_path']['em_gain'] except: em_gain = 1 try: images = {} with h5py.File(ccd_hdf5_path, "r") as images_h5: for key in images_h5: images[key] = np.array(images_h5[key], dtype='float64') images_h5.close() if image == 'absorption': n0 = process_images_g(images, em_gain) x_trace0 = np.sum(n0, axis=0) y_trace0 = np.sum(n0, axis=1) xc = x_trace0.argmax() yc = y_trace0.argmax() n = n0[yc - roi_width:yc + roi_width, xc - roi_width:xc + roi_width] n = np.flipud(n) X = range(n.shape[1]) Y = range(n.shape[0]) # x_trace = np.sum(n, axis = 0) # y_trace = np.sum(n, axis = 1) # p0x = (x_trace.argmax(), fit_width, np.max(x_trace), np.min(x_trace)) # p0y = (y_trace.argmax(), fit_width, np.max(y_trace), np.min(y_trace)) # try: # poptx, pcovx = optimize.curve_fit(fit_Gaussian, X, x_trace, p0 = p0x) # popty, pcovy = optimize.curve_fit(fit_Gaussian, Y, y_trace, p0 = p0y) # except Exception as e1: # print(e1) # poptx = p0x # popty = p0y # count1 = np.sum(x_trace) - poptx[-1]*len(x_trace) # test # count2 = np.sum(y_trace) - popty[-1]*len(y_trace) # test # count = (count1+count2)/2 # count = round(count, 1) count = np.sum(n) count = round(float(count), 1) elif image == 'fluorescence': n0 = process_images_g_fluorescence(images) (yc, xc) = np.unravel_index(np.argmax(n0, axis=None), n0.shape) n = n0[yc - roi_width:yc + roi_width, xc - roi_width:xc + roi_width] n = np.flipud(n) X = range(n.shape[1]) Y = range(n.shape[0]) count = float(np.sum(n)) count = round(count, 1) data.append({x_key: shot, 'fit': {y_key: count}}) fig, ax = plt.subplots(1, 1) fig.set_size_inches(20, 8) cmap = plt.get_cmap('jet') ax.set_aspect('equal') plt.pcolormesh(X, Y, n, cmap=cmap) plt.colorbar() plt.title('Atom number: {:.2e}'.format(count)) plt.savefig(save_path + '.png', bbox_inches='tight') plt.clf() plt.close('all') except Exception as e: print(e) count = 0 data.append({x_key: shot, 'fit': {y_key: count}}) return data else: return data