def grab_traces(trace_dict=traces_12_on, verbose=True): trace_data = {} for t_name, t in trace_dict.items(): if t[0] is lia: if verbose: print_statusline(f'grabbing ' + t_name + f' trace from channel {t[1].value} on ' + t[0].model + '...') trace_data[t_name] = t[0].get_trace(t[1], units=u.ampere) else: # otherwise data is being grabbed from a scope if verbose: print_statusline(f'grabbing ' + t_name + f' trace from channel {t[1]} on ' + t[0].model + '...') trace_data[t_name] = t[0].get_data(channel=t[1]) return trace_data
def load_SHG_V_wavelength_sweep(name='', data_dir=default_data_dir, verbose=False, set_dir=None, metadata=False, exact_name=False): if set_dir: if verbose: print_statusline('Loading data from dir: ' + path.basename(path.normpath(set_dir))) else: file_list = glob( path.normpath(data_dir) + path.normpath('/' + 'SHG_V_wavelength_sweep_' + name + '*')) set_dir = path.normpath(max(file_list, key=path.getctime)) if verbose: print_statusline('Loading data from dir: ' + path.basename(set_dir)) sweep_file_list = glob( path.normpath(set_dir) + path.normpath('/' + 'sweep_data' + '*')) latest_sweep_file = path.normpath(max(sweep_file_list, key=path.getctime)) with open(latest_sweep_file, "rb") as f: ds = pickle.load(f) for Vind, VV in enumerate(ds['V']): V_dir = path.normpath(path.join(set_dir, f'{VV.m:3.2f}V')) V_ds = load_shg_wavelength_sweep( fpath=path.join(V_dir, f'{VV.m:3.2f}V.npz')) if Vind == 0: n_lm = V_ds['lm_meas'].shape[0] n_pts_per_setpoint = V_ds['lm_meas'].shape[1] lm_meas = np.zeros((n_lm, n_pts_per_setpoint, len(ds['V']))) * u.nm V_R = np.zeros((n_lm, n_pts_per_setpoint, len(ds['V']))) * u.volt theta = np.zeros( (n_lm, n_pts_per_setpoint, len(ds['V']))) * u.degree lm_meas[:, :, Vind] = V_ds['lm_meas'] V_R[:, :, Vind] = V_ds['V_R'] theta[:, :, Vind] = V_ds['theta'] ds['lm_meas'] = lm_meas ds['V_R'] = V_R ds['theta'] = theta return ds
def load_shg_temperature_sweep(name='', data_dir=default_data_dir, verbose=False, fpath=None, metadata=False, exact_name=False): if fpath: if verbose: print_statusline('Loading data from file: ' + path.basename(path.normpath(fpath))) data_npz = np.load(Path(fpath)) else: file_list = glob( path.normpath(data_dir) + path.normpath('/' + 'SHG_temperature_sweep_' + name + '*')) latest_file = max(file_list, key=path.getctime) if verbose: print_statusline('Loading ' + name + ' data from file: ' + path.basename(path.normpath(latest_file))) data_npz = np.load(latest_file) T_set = Q_(data_npz['T_set'], u.degC) T_meas = Q_(data_npz['T_meas'], u.degC) lm_meas = data_npz['lm_meas'] * u.nm V_P_24_trans = data_npz['V_P_24_trans'] * u.volt V_P_24_ref = data_npz['V_P_24_ref'] * u.volt V_R = data_npz['V_R'] * u.volt theta = data_npz['theta'] * u.volt ds = { 'T_set': T_set, 'T_meas': T_meas, 'lm_meas': lm_meas, 'V_P_24_trans': V_P_24_trans, 'V_P_24_ref': V_P_24_ref, 'V_R': V_R, 'theta': theta } return ds
def set_temp_and_wait(T_set, settling_threshold=0.015, t_settle_max=15 * u.minute, n_samples=10, dt_sample=10 * u.second, verbose=False): print_statusline(f'setting sample temp to {T_set:2.4f}C...') set_set_temp(T_set) t0 = time.time() samples = np.zeros(10) n_samples_taken = 0 sample_deviation = 100 # random high number, shouldn't matter while ((((time.time() - t0) < t_settle_max.to(u.second).m) and (n_samples_taken < (n_samples - 1))) or (sample_deviation > settling_threshold)): time.sleep(dt_sample.to(u.second).m) new_sample = get_meas_temp() if n_samples_taken < n_samples: samples[n_samples_taken] = new_sample else: samples[:-1] = samples[1:] samples[-1] = new_sample sample_deviation = samples.max() - samples.min() n_samples_taken += 1 if verbose: print(f'n_samples_taken: {n_samples_taken}') print(f'time elapsed: {(time.time()-t0):4.1f} sec') print(f'samples: {samples} C') print(f'sample_deviation: {sample_deviation:3.4f} C') print('#########################') new_temp = samples.mean() time_spent = (time.time() - t0) * u.second if time_spent.m > 60.0: time_spent = time_spent.to(u.minute) print_statusline( f'settled at {new_temp:2.3f}C after {time_spent.m:2.2f} minutes') else: print_statusline( f'settled at {new_temp:2.3f}C after {time_spent.m:2.1f} seconds') return new_temp
def collect_shg_open_loop_wavelength_sweep(lm_start, steps_per_point, n_pts, name='', data_dir=default_data_dir, n_pts_per_setpoint=1, norm_with_P_trans=True, settle_time=10 * u.second, autogain=True, color='C3', short_name=False, n_line=0, P_24_trans_ch=1, P_24_ref_ch=3, return_fpath=True, live_plot=True, fig=None, ax=None): timestamp_str = datetime.strftime(datetime.now(), '%Y_%m_%d_%H_%M_%S') if short_name: fname = name + '.npz' else: fname = 'SHG_wavelength_sweep_' + name + '_' + timestamp_str + '.npz' fpath = path.normpath(path.join(data_dir, fname)) #print('saving to '+fpath) V_R = np.zeros((n_pts, n_pts_per_setpoint)) * u.volt theta = np.zeros((n_pts, n_pts_per_setpoint)) * u.degree lm_meas = np.zeros((n_pts, n_pts_per_setpoint)) * u.nm V_P_24_trans = np.zeros((n_pts, n_pts_per_setpoint)) * u.volt V_P_24_ref = np.zeros((n_pts, n_pts_per_setpoint)) * u.volt # V_P_24_data_init = P_24_measurements(set_up_measurements=True, # wait=True, # P_24_trans_ch=P_24_trans_ch, # P_24_ref_ch=P_24_ref_ch) if live_plot: #xlimits = [lm_set.to(u.nm).min().m-2., lm_set.to(u.nm).max().m+2.] if not ax: fig, ax = plt.subplots(1, 1, figsize=(11, 6)) ax.set_xlabel('Wavelength [nm]') ax.set_ylabel('$P_{1.2} / P_{2.4}^2$') #ax.set_xlim(xlimits) plt.subplots_adjust(right=0.7, bottom=0.3) ipg.set_wavelength(lm_start, tuning_SHG=False) sm = ipg.sm for lind in range(n_pts): curr_pos_steps = sm.get_current_position(unitful=False) relative_move = steps_per_point target_pos_steps = curr_pos_steps + relative_move if not (sm.limit_switch_1_pos < target_pos_steps < sm.limit_switch_2_pos): print('Warning: bad target_pos_steps: {:2.1g}, lm_meas:{:7.3f}\n'. format(target_pos_steps, float(lm_meas.magnitude))) target_pos_steps = 0 sm.go_and_wait(target_pos_steps, unitful=False, polling_period=100 * u.ms) # if autogain: # lia.auto_gain() for nn in range(n_pts_per_setpoint): sleep(settle_time.to(u.second).m) pct_complete = 100. * float(lind * n_pts_per_setpoint + nn) / float(n_pts_per_setpoint * n_pts) print_statusline( f'step {lind+1} of {n_pts}, point {nn+1} of {n_pts_per_setpoint}, {pct_complete:3.2f}% complete' ) lm_meas[lind, nn] = ipg.get_lm() if norm_with_P_trans: V_P_24_data = P_24_measurements(set_up_measurements=False, P_24_trans_ch=P_24_trans_ch, P_24_ref_ch=P_24_ref_ch) V_P_24_trans[lind, nn] = V_P_24_data[0] V_P_24_ref[lind, nn] = V_P_24_data[1] V_R[lind, nn] = lia.read_output( sr850.OutputType.R ) # changed to X now that I figured out the right phase (currently 10.7 degree). keeping 'V_R' name for backwards compatibility #theta[lind,nn] = lia.read_output(sr850.OutputType.theta) # no need for theta any more, just save zeros also for backwards compatibility if norm_with_P_trans: np.savez(Path(fpath), lm_meas=lm_meas.m, V_R=V_R.m, theta=theta.m, V_P_24_trans=V_P_24_trans.m, V_P_24_ref=V_P_24_ref.m) else: np.savez(Path(fpath), lm_meas=lm_meas.m, V_R=V_R.m, theta=theta.m) if live_plot: x = lm_meas[np.nonzero(V_R)][lm_meas[np.nonzero(V_R)] > ( lm_start - 2 * u.nm)] if norm_with_P_trans: V_P_24_ref_rel = V_P_24_ref / V_P_24_ref.max() y = V_R[np.nonzero(V_R)] / V_P_24_ref_rel[np.nonzero( V_R)]**2 else: # V_P_24_ref_rel = V_P_24_ref / V_P_24_ref.max() # y = V_R[np.nonzero(V_R)]/V_P_24_ref_rel[np.nonzero(V_R)]**2 y = np.abs(V_R[np.nonzero(V_R)][lm_meas[np.nonzero(V_R)] > (lm_start - 2 * u.nm)]) if not ((nn == 0) and (lind == 0)): line = ax.lines[n_line] line.set_xdata(x) line.set_ydata(y) ax.relim() ax.autoscale_view(True, True, True) # y_lim = ax.get_ylim() # ax.set_ylim([min(4e-14,ax.get_ylim()[1]]) else: ax.semilogy(x, y, '.', color=color) fig.canvas.draw() plt.subplots_adjust(right=0.9, bottom=0.1) if return_fpath: return fpath, fig, ax else: return fig, ax
def collect_OPO_data(lm_start, n_V_pzt, stepper_incr, n_stepper_pts, Vrb=8.5 * u.volt, config=True, f_ring=0.5 * u.Hz, name='', data_dir=default_data_dir, settle_time=1 * u.second, color='C3', short_name=False, return_fpath=True, live_plot=True, pzt=ipg.pzt1, V_pzt_min=0 * u.volt, V_pzt_max=60 * u.volt, wait_for_SHG=False, fig=None, ax=None): set_Vrb(Vrb) SHG_to_OPA( ) # set control signals to send 1.2um light to microscope and measure transmission directly ### initialize scopes and configure AFGs and scopes if config=True # pause current scope acquisition scope3.stop_acquire() scope2.stop_acquire() sleep(0.1) if config: configure_measurement(f_ring=f_ring) # set oscilloscopes to single-sequence acquisition scope3.acquire_single() scope2.acquire_single() ## collect prototype trace data for initializing dataset file prototype_trace_data_12_on, prototype_trace_data_12_off = grab_prototype_trace_data( ) # note, triggers are now in single sequence mode and *not* armed ## create sweep parameter arrays V_pzt = np.linspace(V_pzt_min.m, V_pzt_max.m, n_V_pzt) * u.volt ## create dataset file fpath = create_dataset_file(prototype_trace_data_12_on, prototype_trace_data_12_off, (len(V_pzt), n_stepper_pts), attrs={ 'stepper_incr': stepper_incr, }, name=name, short_name=short_name, data_dir=data_dir) ## if plotting, initialize plot # if live_plot: # #xlimits = [lm_set.to(u.nm).min().m-2., lm_set.to(u.nm).max().m+2.] # if not ax: # fig,ax=plt.subplots(1,1,figsize=(11,6)) # ax.set_xlabel('Wavelength [nm]') # ax.set_ylabel('$P_{1.2} / P_{2.4}^2$') # #ax.set_xlim(xlimits) # plt.subplots_adjust(right=0.7,bottom=0.3) ipg.set_wavelength(lm_start, tuning_SHG=True) for sind in range(n_stepper_pts): curr_pos_steps = ipg.sm.get_current_position(unitful=False) relative_move = stepper_incr target_pos_steps = curr_pos_steps + relative_move if not (ipg.sm.limit_switch_1_pos < target_pos_steps < ipg.sm.limit_switch_2_pos): print('Warning: bad target_pos_steps: {:2.1g}, lm_meas:{:7.3f}\n'. format(target_pos_steps, float(lm_meas.magnitude))) target_pos_steps = 0 ipg.sm.go_and_wait(target_pos_steps, unitful=False, polling_period=100 * u.ms) retune_SHG(wait=wait_for_SHG) for Vind, VV in enumerate(V_pzt): pzt.set_V(VV) sleep(settle_time.to(u.second).m) pct_complete = 100. * float(sind * n_V_pzt + Vind + 1) / float( n_V_pzt * n_stepper_pts) print_statusline( f'step {sind+1} of {n_stepper_pts}, point {Vind+1} of {n_V_pzt}, {pct_complete:3.2f}% complete' ) grab_and_save_trace_data(fpath, (Vind, sind)) reset_scopes() reset_laser(lm_start) SHG_to_OPA() if return_fpath: return fpath else: return