コード例 #1
0
def jog_stepper(n, speed=10):
    current_pos = ipg.sm.get_current_position(unitful=False)
    new_pos = current_pos + n
    λ_current = ipg.get_lm()
    print(f"Initial position: {current_pos}")
    print(f"Initial λ: {λ_current}")
    print(f"Final position: {new_pos}")
    ipg.sm.go_and_wait(new_pos, speed=10)
    λ_final = ipg.get_lm()
    print(f"final λ: {λ_final}")
コード例 #2
0
def grab_and_save_trace_data(fpath, inds):
    arm_and_wait_for_triggers()
    trace_data_12_on = grab_traces(trace_dict=traces_12_on)
    OPA_to_SHG()
    sleep(2.5)
    arm_and_wait_for_triggers()
    trace_data_12_off = grab_traces(trace_dict=traces_12_off)
    SHG_to_OPA()
    with h5py.File(fpath, "r+") as f:
        grp_12_on = f['12_on']
        grp_12_off = f['12_off']
        for t_name, t in trace_data_12_on.items():
            grp_12_on[t_name][(slice(None, None), ) + inds] = t[1].m
        for t_name, t in trace_data_12_off.items():
            grp_12_off[t_name][(slice(None, None), ) + inds] = t[1].m
        f['lm'][inds] = ipg.get_lm().m
        f['T'][inds] = get_meas_temp()
        f.flush()
コード例 #3
0
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
コード例 #4
0
def collect_shg_wavelength_sweep(lm_set,
                                 name='',
                                 data_dir=default_data_dir,
                                 n_pts_per_setpoint=1,
                                 time_constant=sr850.TimeConstant.x3s,
                                 settle_time=10 * u.second,
                                 autogain=True,
                                 color='C3',
                                 P_24_trans_ch=1,
                                 P_24_ref_ch=3,
                                 return_fpath=True,
                                 live_plot=True,
                                 fig=None,
                                 ax=None):
    lia.set_time_constant(time_constant)
    timestamp_str = datetime.strftime(datetime.now(), '%Y_%m_%d_%H_%M_%S')
    fname = 'SHG_wavelength_sweep_' + name + '_' + timestamp_str + '.npz'
    fpath = path.normpath(path.join(data_dir, fname))
    print('saving to ' + fpath)
    V_R = np.zeros((len(lm_set), n_pts_per_setpoint)) * u.volt
    theta = np.zeros((len(lm_set), n_pts_per_setpoint)) * u.degree
    lm_meas = np.zeros((len(lm_set), n_pts_per_setpoint)) * u.nm
    V_P_24_trans = np.zeros((len(lm_set), n_pts_per_setpoint)) * u.volt
    V_P_24_ref = np.zeros((len(lm_set), 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=(12, 8))
        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)

    for lind, ll in enumerate(lm_set):
        ipg.set_wavelength(ll, tuning_SHG=False)
        if autogain:
            lia.auto_gain()
        for nn in range(n_pts_per_setpoint):
            lm_meas[lind, nn] = ipg.get_lm()
            sleep(settle_time.to(u.second).m)
            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)
            theta[lind, nn] = lia.read_output(sr850.OutputType.theta)
            np.savez(Path(fpath),
                     lm_set=lm_set.m,
                     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)
            if live_plot:
                ax.plot(lm_meas[lind, nn],
                        V_R[lind, nn] / V_P_24_trans[lind, nn]**2,
                        'o',
                        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
コード例 #5
0
def retune_SHG(wait=False):
    ipg.tune_SHG(ipg.get_lm(), wait=wait)
コード例 #6
0
def collect_shg_temperature_sweep(T_set,
                                  name='',
                                  data_dir=default_data_dir,
                                  settle_time=10 * u.second,
                                  autogain=True,
                                  P_24_trans_ch=1,
                                  P_24_ref_ch=3,
                                  return_fpath=True,
                                  live_plot=True,
                                  n_T_samples=4,
                                  dt_T_sample=0.5 * u.second,
                                  n_pts_per_setpoint=1):
    timestamp_str = datetime.strftime(datetime.now(), '%Y_%m_%d_%H_%M_%S')
    fname = 'SHG_temperature_sweep_' + name + '_' + timestamp_str + '.npz'
    fpath = path.normpath(path.join(data_dir, fname))
    print('saving to ' + fpath)
    V_R = np.zeros((len(T_set), n_pts_per_setpoint)) * u.volt
    theta = np.zeros((len(T_set), n_pts_per_setpoint)) * u.degree
    lm_meas = np.zeros((len(T_set), n_pts_per_setpoint)) * u.nm
    T_meas = np.zeros(
        (len(T_set), n_pts_per_setpoint))  # Celsius is too annoying with pint
    V_P_24_trans = np.zeros((len(T_set), n_pts_per_setpoint)) * u.volt
    V_P_24_ref = np.zeros((len(T_set), 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 = [T_set.min() - 1., T_set.max() + 1.]
        fig, ax = plt.subplots(1, 1)
        ax.set_xlabel('Temperature [C]')
        ax.set_ylabel('$P_{1.2} / P_{2.4}^2$')
        ax.set_xlim(xlimits)
        plt.show()

    for Tind, TT in enumerate(T_set):
        T_meas_temp = set_temp_and_wait(TT,
                                        n_samples=n_T_samples,
                                        dt_sample=dt_T_sample)
        if autogain:
            lia.auto_gain()
        for nn in range(n_pts_per_setpoint):
            lm_meas[Tind, nn] = ipg.get_lm()
            T_meas[Tind, nn] = get_meas_temp()
            sleep(settle_time.to(u.second).m)
            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[Tind, nn] = V_P_24_data[0]
            V_P_24_ref[Tind, nn] = V_P_24_data[1]
            V_R[Tind, nn] = lia.read_output(sr850.OutputType.R)
            theta[Tind, nn] = lia.read_output(sr850.OutputType.theta)
            np.savez(Path(fpath),
                     T_set=T_set,
                     T_meas=T_meas,
                     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)
            if live_plot:
                ax.plot(T_meas[Tind, nn],
                        V_R[Tind, nn] / V_P_24_trans[Tind, nn]**2, 'C0')
                fig.canvas.draw()
                plt.show()
    if return_fpath:
        return fpath