Пример #1
0
def job_asymetry(T):
    s_array = np.array([91.225, 89.225, 93.225])
    sin_sq_array = np.array([0.21, 0.23, 0.25])
    q = -1
    i_3 = -1/2

    angle_array = np.arcsin(np.sqrt(sin_sq_array))
    #re_propagator = 1 / (s_array - (mass_z/1000)**2)
    re_propagator = s_array * (s_array - (mass_z/1000)**2) / \
            ((s_array - (mass_z/1000)**2)**2 + s_array * total_width / (mass_z/1000))

    a_e = i_3 / (2 * np.sin(angle_array) * np.cos(angle_array))
    a_f = a_e
    v_e = (i_3 - 2 * q * sin_sq_array) / (2 * np.sin(angle_array) * np.cos(angle_array))
    v_f = v_e

    asymmetry = np.outer(re_propagator, -3/2 * a_e * a_f * q / ((v_e**2 + a_e**2) * (a_f**2 + a_f**2)))

    print(asymmetry)

    T['asymmetry_table'] = list([[siunitx(s)] + siunitx(row, digits=5) for s, row in zip(s_array, asymmetry)])
    T['sin_sq_array'] = siunitx(sin_sq_array)
    T['s_array'] = siunitx(s_array)

    s_array = np.linspace(88.4, 93.8, 200)
    re_propagator = s_array * (s_array - (mass_z/1000)**2) / \
            ((s_array - (mass_z/1000)**2)**2 + s_array * total_width / (mass_z/1000))
    a_e = i_3 / (2 * np.sin(weak_mixing_angle) * np.cos(weak_mixing_angle))
    a_f = a_e
    v_e = (i_3 - 2 * q * sin_sq_weak_mixing) / (2 * np.sin(weak_mixing_angle) * np.cos(weak_mixing_angle))
    v_f = v_e
    asymmetry = re_propagator * (-3)/2 * a_e * a_f * q / ((v_e**2 + a_e**2) * (a_f**2 + a_f**2))

    np.savetxt('_build/xy/afb_theory.tsv', np.column_stack([s_array, asymmetry]))
Пример #2
0
def get_scattering_rate_MHz(T, intens_mw_cm2_val, intens_mw_cm2_err, detuning_MHz_val, detuning_MHz_err):
    intens_sat_mw_cm2 = 4.1
    natural_width_MHz = 6

    intens_ratio_val = intens_mw_cm2_val / intens_sat_mw_cm2
    intens_ratio_err = intens_mw_cm2_err / intens_sat_mw_cm2

    detuning_ratio_val = detuning_MHz_val / natural_width_MHz
    detuning_ratio_err = detuning_MHz_err / natural_width_MHz

    T["intens_ratio"] = siunitx(intens_ratio_val, intens_ratio_err)
    T["detuning_ratio"] = siunitx(detuning_ratio_val, detuning_ratio_err)

    val = intens_ratio_val * np.pi * natural_width_MHz / (1 + intens_ratio_val + 4 * detuning_ratio_val ** 2)
    derivative_intens = -intens_ratio_val * natural_width_MHz * np.pi / (
        1 + 4 * detuning_ratio_val ** 2 + intens_ratio_val
    ) ** 2 + natural_width_MHz * np.pi / (1 + 4 * detuning_ratio_val ** 2 + intens_ratio_val)
    derivative_detuning = (
        -8
        * detuning_ratio_val
        * intens_ratio_val
        * natural_width_MHz
        * np.pi
        / (1 + 4 * detuning_ratio_val ** 2 + intens_ratio_val) ** 2
    )
    err = np.sqrt((derivative_intens * intens_ratio_err) ** 2 + (derivative_detuning * detuning_ratio_err) ** 2)

    return val, err
def do_jackknife(T, prefix, x, y, y_err):
    fit_x = np.linspace(np.min(x), np.max(x), 100)
    y_dist = []
    popt_dist = []
    for i in range(len(x)):
        jack_x = np.delete(x, i)
        jack_y = np.delete(y, i)

        popt, pconv = op.curve_fit(linear, jack_x, jack_y)
        boot_fit_y = linear(fit_x, *popt)

        y_dist.append(boot_fit_y)
        popt_dist.append(popt)

        np.savetxt(
            '_build/xy/bootstrap-{}-{:d}-resampled.tsv'.format(prefix, i),
            np.column_stack([jack_x, jack_y]))
        np.savetxt('_build/xy/bootstrap-{}-{:d}-fit.tsv'.format(prefix, i),
                   np.column_stack([fit_x, boot_fit_y]))

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(y_dist)
    np.savetxt('_build/xy/bootstrap-{}-band.tsv'.format(prefix),
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    np.savetxt('_build/xy/bootstrap-{}-final-fit.tsv'.format(prefix),
               np.column_stack([fit_x, fit_y_val]))

    popt_val, popt_err = bootstrap.average_and_std_arrays(popt_dist)
    popt_val, pconv = op.curve_fit(linear, x, y, sigma=y_err)
    T['bootstrap_{}_popt'.format(prefix)] = siunitx(popt_val,
                                                    popt_err,
                                                    error_digits=2)
    T['bootstrap_{}_err'.format(prefix)] = siunitx(popt_err)
Пример #4
0
def main():
    T = {}

    T['sin_sq_weak_mixing'] = siunitx(sin_sq_weak_mixing)

    # We use bootstrap and obtain different results every single time. This is
    # bad, therefore we fix the seed here.
    random.seed(0)

    parser = argparse.ArgumentParser()
    parser.add_argument('--show', action='store_true')
    options = parser.parse_args()

    job_br_theory(T)
    bootstrap_driver(T)
    job_decay_widths(T)
    job_colors()
    job_afb_analysis(T)
    job_grope(T, options.show)
    job_angular_dependence(T)
    job_asymetry(T)

    T['mass_z_lit'] = siunitx(mass_z / 1e3, digits=5)

    test_keys(T)
    with open('_build/template.js', 'w') as f:
        json.dump(dict(T), f, indent=4, sort_keys=True)
def do_jackknife(T, prefix, x, y, y_err):
    fit_x = np.linspace(np.min(x), np.max(x), 100)
    y_dist = []
    popt_dist = []
    for i in range(len(x)):
        jack_x = np.delete(x, i)
        jack_y = np.delete(y, i)

        popt, pconv = op.curve_fit(linear, jack_x, jack_y)
        boot_fit_y = linear(fit_x, *popt)

        y_dist.append(boot_fit_y)
        popt_dist.append(popt)

        np.savetxt('_build/xy/bootstrap-{}-{:d}-resampled.tsv'.format(prefix, i),
                   np.column_stack([jack_x, jack_y]))
        np.savetxt('_build/xy/bootstrap-{}-{:d}-fit.tsv'.format(prefix, i),
                   np.column_stack([fit_x, boot_fit_y]))

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(y_dist)
    np.savetxt('_build/xy/bootstrap-{}-band.tsv'.format(prefix),
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    np.savetxt('_build/xy/bootstrap-{}-final-fit.tsv'.format(prefix),
               np.column_stack([fit_x, fit_y_val]))


    popt_val, popt_err = bootstrap.average_and_std_arrays(popt_dist)
    popt_val, pconv = op.curve_fit(linear, x, y, sigma=y_err)
    T['bootstrap_{}_popt'.format(prefix)] = siunitx(popt_val, popt_err, error_digits=2)
    T['bootstrap_{}_err'.format(prefix)] = siunitx(popt_err)
def do_choice(T, prefix, x, y, y_err):
    fit_x = np.linspace(np.min(x), np.max(x), 100)
    y_dist = []
    popt_dist = []
    for i in range(len(x)):
        choice_x = bootstrap.generate_sample(x)
        choice_y = bootstrap.generate_sample(y)
        choice_y_err = bootstrap.generate_sample(y_err)

        popt, pconv = op.curve_fit(linear, choice_x, choice_y, sigma=choice_y_err)
        boot_fit_y = linear(fit_x, *popt)

        y_dist.append(boot_fit_y)
        popt_dist.append(popt)

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(y_dist)
    np.savetxt('_build/xy/bootstrap-{}-band.tsv'.format(prefix),
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    np.savetxt('_build/xy/bootstrap-{}-final-fit.tsv'.format(prefix),
               np.column_stack([fit_x, fit_y_val]))

    popt_val, popt_err = bootstrap.average_and_std_arrays(popt_dist)
    popt_val, pconv = op.curve_fit(linear, x, y, sigma=y_err)
    T['bootstrap_{}_popt'.format(prefix)] = siunitx(popt_val, popt_err, error_digits=2)
    T['bootstrap_{}_err'.format(prefix)] = siunitx(popt_err)
def do_choice(T, prefix, x, y, y_err):
    fit_x = np.linspace(np.min(x), np.max(x), 100)
    y_dist = []
    popt_dist = []
    for i in range(len(x)):
        choice_x = bootstrap.generate_sample(x)
        choice_y = bootstrap.generate_sample(y)
        choice_y_err = bootstrap.generate_sample(y_err)

        popt, pconv = op.curve_fit(linear,
                                   choice_x,
                                   choice_y,
                                   sigma=choice_y_err)
        boot_fit_y = linear(fit_x, *popt)

        y_dist.append(boot_fit_y)
        popt_dist.append(popt)

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(y_dist)
    np.savetxt('_build/xy/bootstrap-{}-band.tsv'.format(prefix),
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    np.savetxt('_build/xy/bootstrap-{}-final-fit.tsv'.format(prefix),
               np.column_stack([fit_x, fit_y_val]))

    popt_val, popt_err = bootstrap.average_and_std_arrays(popt_dist)
    popt_val, pconv = op.curve_fit(linear, x, y, sigma=y_err)
    T['bootstrap_{}_popt'.format(prefix)] = siunitx(popt_val,
                                                    popt_err,
                                                    error_digits=2)
    T['bootstrap_{}_err'.format(prefix)] = siunitx(popt_err)
Пример #8
0
def job_diameter(T):
    data = np.loadtxt('Data/diameter.tsv')
    position = data[:, 0]
    power = data[:, 1]

    x = np.linspace(np.min(position), np.max(position), 100)
    popt, pconv = op.curve_fit(errorfunction,
                               position,
                               power,
                               p0=[3.4, .4, 29.5])
    perr = np.sqrt(pconv.diagonal())

    y = errorfunction(x, *popt)
    # pl.plot(position, power, linestyle="none", marker="+")
    # pl.plot(x, y)
    # pl.show()
    # pl.clf()

    np.savetxt('_build/xy/diameter-data.tsv',
               np.column_stack([position, power]))
    np.savetxt('_build/xy/diameter-fit.tsv', np.column_stack([x, y]))

    T['beam_diameter_table'] = list(zip(siunitx(position), siunitx(power)))

    T['beam_diameter'] = siunitx(popt[1], perr[1])
    T['beam_power'] = siunitx(popt[0], perr[0])

    return popt[1], perr[1]
Пример #9
0
def main():
    T = {}

    T['sin_sq_weak_mixing'] = siunitx(sin_sq_weak_mixing)

    # We use bootstrap and obtain different results every single time. This is
    # bad, therefore we fix the seed here.
    random.seed(0)

    parser = argparse.ArgumentParser()
    parser.add_argument('--show', action='store_true')
    options = parser.parse_args()

    job_br_theory(T)
    bootstrap_driver(T)
    job_decay_widths(T)
    job_colors()
    job_afb_analysis(T)
    job_grope(T, options.show)
    job_angular_dependence(T)
    job_asymetry(T)

    T['mass_z_lit'] = siunitx(mass_z / 1e3, digits=5)

    test_keys(T)
    with open('_build/template.js', 'w') as f:
        json.dump(dict(T), f, indent=4, sort_keys=True)
Пример #10
0
def get_scattering_rate_MHz(T, intens_mw_cm2_val, intens_mw_cm2_err,
                            detuning_MHz_val, detuning_MHz_err):
    intens_sat_mw_cm2 = 4.1
    natural_width_MHz = 6

    intens_ratio_val = intens_mw_cm2_val / intens_sat_mw_cm2
    intens_ratio_err = intens_mw_cm2_err / intens_sat_mw_cm2

    detuning_ratio_val = detuning_MHz_val / natural_width_MHz
    detuning_ratio_err = detuning_MHz_err / natural_width_MHz

    T['intens_ratio'] = siunitx(intens_ratio_val, intens_ratio_err)
    T['detuning_ratio'] = siunitx(detuning_ratio_val, detuning_ratio_err)

    val = intens_ratio_val * np.pi * natural_width_MHz / (
        1 + intens_ratio_val + 4 * detuning_ratio_val**2)
    derivative_intens = -intens_ratio_val * natural_width_MHz * np.pi / (
        1 + 4 * detuning_ratio_val**2 +
        intens_ratio_val)**2 + natural_width_MHz * np.pi / (
            1 + 4 * detuning_ratio_val**2 + intens_ratio_val)
    derivative_detuning = -8 * detuning_ratio_val * intens_ratio_val * natural_width_MHz * np.pi / (
        1 + 4 * detuning_ratio_val**2 + intens_ratio_val)**2
    err = np.sqrt((derivative_intens * intens_ratio_err)**2 +
                  (derivative_detuning * detuning_ratio_err)**2)

    return val, err
Пример #11
0
def get_mot_power_nw(T):
    data = np.loadtxt("Data/mot-intensity.tsv")
    mot_with = data[:, 0]
    und = data[:, 1]
    # err = data[:,2]
    mot_w_o = mot_with - und

    power_mean = np.mean(mot_w_o)
    power_err = np.std(mot_w_o)

    T["power_mot"] = siunitx(power_mean, power_err)
    T["power_mot_table"] = list(zip(siunitx(mot_with), siunitx(und), siunitx(mot_w_o)))

    return power_mean, power_err
def do_pconv(T, prefix, x, y, y_err):
    popt, pconv = op.curve_fit(linear, x, y, sigma=y_err)

    fit_x = np.linspace(np.min(x), np.max(x), 100)
    fit_y = linear(fit_x, *popt)

    np.savetxt('_build/xy/bootstrap-{}-normal-data.tsv'.format(prefix),
               np.column_stack([x, y, y_err]))
    np.savetxt('_build/xy/bootstrap-{}-normal-fit.tsv'.format(prefix),
               np.column_stack([fit_x, fit_y]))

    T['bootstrap_{}_popt'.format(prefix)] = siunitx(popt, np.sqrt(pconv.diagonal()), error_digits=2)
    T['bootstrap_{}_val'.format(prefix)] = siunitx(popt)
    T['bootstrap_{}_err'.format(prefix)] = siunitx(np.sqrt(pconv.diagonal()))
Пример #13
0
def job_decay_widths(T):
    # T_3, Q, N_color
    quantum_numbers = {
        'electron': [-1/2, -1, 1],
        'neutrino': [+1/2, 0, 1],
        'up_type': [+1/2, 2/3, 3],
        'down_type': [-1/2, -1/3, 3],
    }

    T['fermi_coupling'] = siunitx(fermi_coupling)

    widths = {}

    for particle, (i_3, q, n_c) in quantum_numbers.items():
        g_v = i_3 - 2 * q * sin_sq_weak_mixing
        g_a = i_3

        decay_width = n_c / (12 * np.pi) * fermi_coupling \
                * mass_z**3 * (g_a**2 + g_v**2)

        T['gamma_'+particle] = siunitx(decay_width)

        widths[particle] = decay_width

        if False:
            print()
            print('Particle:', particle)
            print('I_3:', i_3)
            print('Q:', q)
            print('N_color:', n_c)
            print('g_v:', g_v)
            print('g_a:', g_a)
            print('Decay width Γ:', decay_width, 'MeV')

    groups = ['hadronic', 'charged_leptonic', 'neutral_leptonic']

    widths['hadronic'] = 2 * widths['up_type'] + 3 * widths['down_type']
    widths['charged_leptonic'] = 3 * widths['electron']
    widths['neutral_leptonic'] = 3 * widths['neutrino']

    global total_width
    total_width = widths['hadronic'] + widths['charged_leptonic'] + widths['neutral_leptonic']

    ratios = {}

    for group in groups:
        T[group+'_width'] = siunitx(widths[group])
        T['total_width'] = siunitx(total_width)

        ratios[group] = widths[group] / total_width
        T[group+'_ratio'] = siunitx(ratios[group])

        partial_cross_section = 12 * np.pi / mass_z**2 * widths['electron'] * widths[group] / total_width**2
        T[group+'_partial_cross_section'] = siunitx(partial_cross_section / 1e-11)

    total_cross_section = 12 * np.pi / mass_z**2 * widths['electron'] / total_width
    T['total_cross_section'] = siunitx(total_cross_section / 1e-11)

    extra_width = 1 + (widths['up_type'] + widths['down_type'] + widths['charged_leptonic'] + widths['neutral_leptonic']) / total_width
    T['extra_width'] = siunitx(extra_width)
Пример #14
0
def job_grating_resolution(T):
    lines_per_m = 600e3
    diameter_val = 3.5e-3 / 2
    diameter_err = 0.5e-3 / 2
    diameter_dist = bootstrap.make_dist(diameter_val, diameter_err)

    illuminated_dist = [diameter * lines_per_m for diameter in diameter_dist]
    illuminated_val, illuminated_err = bootstrap.average_and_std_arrays(
        illuminated_dist)
    T['illuminated'] = siunitx(illuminated_val, illuminated_err)

    rel_error_dist = [1 / illuminated for illuminated in illuminated_dist]
    rel_error_val, rel_error_err = bootstrap.average_and_std_arrays(
        rel_error_dist)
    T['rel_error'] = siunitx(rel_error_val, rel_error_err)
Пример #15
0
def get_mot_power_nw(T):
    data = np.loadtxt('Data/mot-intensity.tsv')
    mot_with = data[:, 0]
    und = data[:, 1]
    # err = data[:,2]
    mot_w_o = mot_with - und

    power_mean = np.mean(mot_w_o)
    power_err = np.std(mot_w_o)

    T['power_mot'] = siunitx(power_mean, power_err)
    T['power_mot_table'] = list(
        zip(siunitx(mot_with), siunitx(und), siunitx(mot_w_o)))

    return power_mean, power_err
def do_pconv(T, prefix, x, y, y_err):
    popt, pconv = op.curve_fit(linear, x, y, sigma=y_err)

    fit_x = np.linspace(np.min(x), np.max(x), 100)
    fit_y = linear(fit_x, *popt)

    np.savetxt('_build/xy/bootstrap-{}-normal-data.tsv'.format(prefix),
               np.column_stack([x, y, y_err]))
    np.savetxt('_build/xy/bootstrap-{}-normal-fit.tsv'.format(prefix),
               np.column_stack([fit_x, fit_y]))

    T['bootstrap_{}_popt'.format(prefix)] = siunitx(popt,
                                                    np.sqrt(pconv.diagonal()),
                                                    error_digits=2)
    T['bootstrap_{}_val'.format(prefix)] = siunitx(popt)
    T['bootstrap_{}_err'.format(prefix)] = siunitx(np.sqrt(pconv.diagonal()))
Пример #17
0
def job_input_polarization(T):
    data = np.loadtxt('Data/harmonic_bare.tsv')
    angle = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = data[:, 2] * 1e-6
    power_dist = bootstrap.make_dist(power_val, power_err)

    T['harmonic_bare_table'] = list(
        zip(
            siunitx(angle),
            siunitx(power_val * 1e6, power_err * 1e6),
        ))

    fit_x = np.linspace(np.min(angle), np.max(angle), 200)
    fit_y_dist = []
    angle_offset_dist = []
    a_dist = []
    b_dist = []
    popt_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(cos_quartic,
                                   angle,
                                   power,
                                   p0=[1.5e-5, 0, 0])
        fit_y_dist.append(cos_quartic(fit_x, *popt))
        angle_offset_dist.append(popt[1])
        a = popt[0]
        b = popt[2]
        a_dist.append(a)
        b_dist.append(b)
        popt_dist.append(popt)
    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)
    angle_offset_val, angle_offset_err = bootstrap.average_and_std_arrays(
        angle_offset_dist)
    a_val, a_err = bootstrap.average_and_std_arrays(a_dist)
    b_val, b_err = bootstrap.average_and_std_arrays(b_dist)

    np.savetxt('_build/xy/harmonic-bare-data.tsv',
               np.column_stack([angle, power_val, power_err]))
    np.savetxt('_build/xy/harmonic-bare-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/harmonic-bare-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    T['bare_angle_offset'] = siunitx(angle_offset_val, angle_offset_err)
    T['bare_a'] = siunitx(a_val, a_err)
    T['bare_b'] = siunitx(b_val, b_err)
Пример #18
0
def job_loading(T):
    res_max = []
    res_slope = []
    for i, directory in zip(itertools.count(), ["0002", "0003", "0004", "0005", "0006", "0007"]):
        data_x, data_y = trek.load_dir(directory)
        data_x, data_y = data_x[120:-500], data_y[120:-500]

        lower = np.where(data_y > 0.095)[0][0]

        fit_x = np.linspace(data_x[lower - 20], data_x[-1], 100)
        popt, pconv = op.curve_fit(loading, data_x[lower:], data_y[lower:])
        res_max.append(popt[0])
        res_slope.append(1 / popt[1])
        fit_y = loading(fit_x, *popt)
        # pl.plot(data_x, data_y)
        # pl.plot(fit_x, fit_y)
        # pl.show()
        # pl.clf()

        avg_before = np.mean(data_y[:lower])

        stretched_data = stretch(data_y, avg_before, 0, popt[0], 1)
        stretched_fit = stretch(fit_y, avg_before, 0, popt[0], 1)

        np.savetxt("_build/xy/loading-{}-data.tsv".format(i), np.column_stack([data_x - data_x[lower], stretched_data]))
        np.savetxt("_build/xy/loading-{}-fit.tsv".format(i), np.column_stack([fit_x - data_x[lower], stretched_fit]))

    maximum_val, maximum_err = np.mean(res_max), np.std(res_max)
    slope_val, slope_err = np.mean(res_slope), np.std(res_slope)

    T["loading_maximum"] = siunitx(maximum_val, maximum_err)
    T["loading_lifetime"] = siunitx(slope_val, slope_err)

    mass = 85 * 1.66e-27

    pressure_dist = [1.1e-5, 1.5e-5]
    pressure_val = np.mean(pressure_dist)
    pressure_err = np.std(pressure_dist)

    temperature = 24 + 273

    k_boltzmann = 1.3806e-23

    velocity = np.sqrt(temperature * k_boltzmann / mass)

    density_val = pressure_val / (k_boltzmann * temperature)
    density_err = pressure_err / (k_boltzmann * temperature)

    cross_section_val = 1 / (slope_val * density_val * velocity)
    cross_section_err = np.sqrt(
        (slope_err / (slope_val ** 2 * density_val * velocity)) ** 2
        + (density_err / (slope_val * density_val ** 2 * velocity)) ** 2
    )

    T["cross_section"] = siunitx(cross_section_val, cross_section_err)
    T["density"] = siunitx(density_val, density_err)
    T["pressure"] = siunitx(pressure_val, pressure_err)
    T["rubidium_mass"] = siunitx(mass)
    T["velocity"] = siunitx(velocity)
Пример #19
0
def job_grating_resolution(T):
    lines_per_m = 600e3
    diameter_val = 3.5e-3 / 2
    diameter_err = 0.5e-3 / 2
    diameter_dist = bootstrap.make_dist(diameter_val, diameter_err)

    illuminated_dist = [
        diameter * lines_per_m
        for diameter in diameter_dist
    ]
    illuminated_val, illuminated_err = bootstrap.average_and_std_arrays(illuminated_dist)
    T['illuminated'] = siunitx(illuminated_val, illuminated_err)

    rel_error_dist = [
        1 / illuminated
        for illuminated in illuminated_dist
    ]
    rel_error_val, rel_error_err = bootstrap.average_and_std_arrays(rel_error_dist)
    T['rel_error'] = siunitx(rel_error_val, rel_error_err)
Пример #20
0
def job_theory(T):
    prefactor_val = speed_of_light * B_val * mu_n / hbar_omega0_joule
    prefactor_err = speed_of_light * B_err * mu_n / hbar_omega0_joule

    debye_1 = 3 * hbar_omega0_joule**2 / (4 * iron_mass * speed_of_light**2 * k_boltzmann * debye_temp)
    debye_2 = 1 + 2 * np.pi**2/3 * (room_temp / debye_temp)**2
    debye_3 = np.exp(- debye_1 * debye_2)

    T['debye_1'] = siunitx(debye_1)
    T['debye_2'] = siunitx(debye_2)
    T['debye_3'] = siunitx(debye_3)
    T['iron_mass'] = siunitx(iron_mass)
    T['room_temp'] = siunitx(room_temp)

    T['length_mm'] = siunitx(length_val / 1e-3, length_err / 1e-3)

    T['v_prefactor'] = siunitx(prefactor_val, prefactor_err)
    T['B'] = siunitx(B_val, B_err)
    T['hbar_omega0_joule'] = siunitx(hbar_omega0_joule)
    T['hbar_omega0_ev'] = siunitx(hbar_omega0_ev)
Пример #21
0
def job_rayleigh_length(T):
    beam_diameter_val = 3.5e-3
    beam_diameter_err = 0.5e-3
    refractive_index = 2.2
    wavelength = 987e-9
    length = 5e-3
    distance = 60e-3

    beam_radius_val = beam_diameter_val / 2
    beam_radius_err = beam_diameter_err / 2

    T['beam_radius'] = siunitx(beam_radius_val, beam_radius_err)

    beam_radius_dist = bootstrap.make_dist(beam_radius_val, beam_diameter_err)

    theta_dist = [
        np.arctan(beam_radius / distance)
        for beam_radius in beam_radius_dist
    ]
    theta_val, theta_err = bootstrap.average_and_std_arrays(theta_dist)
    T['theta'] = siunitx(theta_val, theta_err)
    bootstrap.save_hist(theta_dist, '_build/dist-theta.pdf')

    waist_dist = [
        wavelength / (np.pi * theta)
        for theta in theta_dist
    ]
    waist_val, waist_err = bootstrap.average_and_std_arrays(waist_dist)
    T['waist_mum'] = siunitx(waist_val / 1e-6, waist_err / 1e-6)
    bootstrap.save_hist(waist_dist, '_build/dist-waist.pdf')

    rayleigh_length_dist = list(itertools.filterfalse(np.isnan, [
        refractive_index * np.pi * waist**2 / wavelength
        for waist in waist_dist
    ]))
    rayleigh_length_val, rayleigh_length_err = bootstrap.average_and_std_arrays(rayleigh_length_dist)
    T['rayleigh_length_mm'] = siunitx(rayleigh_length_val / 1e-3, rayleigh_length_err / 1e-3, error_digits=2)
    bootstrap.save_hist(rayleigh_length_dist, '_build/dist-rayleigh_length.pdf')

    normalized_length_dist = list([
        length / (2 * rayleigh_length)
        for rayleigh_length in rayleigh_length_dist
    ])
    normalized_length_val, normalized_length_err = bootstrap.average_and_std_arrays(normalized_length_dist)
    T['normalized_length'] = siunitx(normalized_length_val, normalized_length_err, error_digits=2)
    bootstrap.save_hist(normalized_length_dist, '_build/dist-normalized_length.pdf')

    t = (normalized_length_val - 2.84) / normalized_length_err
    T['boyd_kleinman_ttest_t'] = siunitx(t)

    optimal_focal_length_dist = list([
        get_optimal_focal_length(beam_radius, refractive_index, wavelength, length)
        for beam_radius in beam_radius_dist
    ])
    optimal_focal_length_val, optimal_focal_length_err = bootstrap.average_and_std_arrays(optimal_focal_length_dist)
    T['optimal_focal_length_mm'] = siunitx(optimal_focal_length_val / 1e-3, optimal_focal_length_err / 1e-3, error_digits=2)
Пример #22
0
def job_asymetry(T):
    s_array = np.array([91.225, 89.225, 93.225])
    sin_sq_array = np.array([0.21, 0.23, 0.25])
    q = -1
    i_3 = -1 / 2

    angle_array = np.arcsin(np.sqrt(sin_sq_array))
    #re_propagator = 1 / (s_array - (mass_z/1000)**2)
    re_propagator = s_array * (s_array - (mass_z/1000)**2) / \
            ((s_array - (mass_z/1000)**2)**2 + s_array * total_width / (mass_z/1000))

    a_e = i_3 / (2 * np.sin(angle_array) * np.cos(angle_array))
    a_f = a_e
    v_e = (i_3 - 2 * q * sin_sq_array) / (2 * np.sin(angle_array) *
                                          np.cos(angle_array))
    v_f = v_e

    asymmetry = np.outer(
        re_propagator,
        -3 / 2 * a_e * a_f * q / ((v_e**2 + a_e**2) * (a_f**2 + a_f**2)))

    print(asymmetry)

    T['asymmetry_table'] = list([[siunitx(s)] + siunitx(row, digits=5)
                                 for s, row in zip(s_array, asymmetry)])
    T['sin_sq_array'] = siunitx(sin_sq_array)
    T['s_array'] = siunitx(s_array)

    s_array = np.linspace(88.4, 93.8, 200)
    re_propagator = s_array * (s_array - (mass_z/1000)**2) / \
            ((s_array - (mass_z/1000)**2)**2 + s_array * total_width / (mass_z/1000))
    a_e = i_3 / (2 * np.sin(weak_mixing_angle) * np.cos(weak_mixing_angle))
    a_f = a_e
    v_e = (i_3 - 2 * q * sin_sq_weak_mixing) / (2 * np.sin(weak_mixing_angle) *
                                                np.cos(weak_mixing_angle))
    v_f = v_e
    asymmetry = re_propagator * (-3) / 2 * a_e * a_f * q / ((v_e**2 + a_e**2) *
                                                            (a_f**2 + a_f**2))

    np.savetxt('_build/xy/afb_theory.tsv',
               np.column_stack([s_array, asymmetry]))
Пример #23
0
def job_input_polarization(T):
    data = np.loadtxt('Data/harmonic_bare.tsv')
    angle = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = data[:, 2] * 1e-6
    power_dist = bootstrap.make_dist(power_val, power_err)

    T['harmonic_bare_table'] = list(zip(
        siunitx(angle),
        siunitx(power_val*1e6, power_err*1e6),
    ))

    fit_x = np.linspace(np.min(angle), np.max(angle), 200)
    fit_y_dist = []
    angle_offset_dist = []
    a_dist = []
    b_dist = []
    popt_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(cos_quartic, angle, power, p0=[1.5e-5, 0, 0])
        fit_y_dist.append(cos_quartic(fit_x, *popt))
        angle_offset_dist.append(popt[1])
        a = popt[0]
        b = popt[2]
        a_dist.append(a)
        b_dist.append(b)
        popt_dist.append(popt)
    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)
    angle_offset_val, angle_offset_err = bootstrap.average_and_std_arrays(angle_offset_dist)
    a_val, a_err = bootstrap.average_and_std_arrays(a_dist)
    b_val, b_err = bootstrap.average_and_std_arrays(b_dist)

    np.savetxt('_build/xy/harmonic-bare-data.tsv',
               np.column_stack([angle, power_val, power_err]))
    np.savetxt('_build/xy/harmonic-bare-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/harmonic-bare-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    T['bare_angle_offset'] = siunitx(angle_offset_val, angle_offset_err)
    T['bare_a'] = siunitx(a_val, a_err)
    T['bare_b'] = siunitx(b_val, b_err)
Пример #24
0
def job_theory(T):
    prefactor_val = speed_of_light * B_val * mu_n / hbar_omega0_joule
    prefactor_err = speed_of_light * B_err * mu_n / hbar_omega0_joule

    debye_1 = 3 * hbar_omega0_joule**2 / (4 * iron_mass * speed_of_light**2 *
                                          k_boltzmann * debye_temp)
    debye_2 = 1 + 2 * np.pi**2 / 3 * (room_temp / debye_temp)**2
    debye_3 = np.exp(-debye_1 * debye_2)

    T['debye_1'] = siunitx(debye_1)
    T['debye_2'] = siunitx(debye_2)
    T['debye_3'] = siunitx(debye_3)
    T['iron_mass'] = siunitx(iron_mass)
    T['room_temp'] = siunitx(room_temp)

    T['length_mm'] = siunitx(length_val / 1e-3, length_err / 1e-3)

    T['v_prefactor'] = siunitx(prefactor_val, prefactor_err)
    T['B'] = siunitx(B_val, B_err)
    T['hbar_omega0_joule'] = siunitx(hbar_omega0_joule)
    T['hbar_omega0_ev'] = siunitx(hbar_omega0_ev)
Пример #25
0
def job_mot_size(T):
    diff3 = subtract_images("03")
    scipy.misc.imsave("_build/difference-3.png", diff3)
    scipy.misc.imsave("_build/difference-3-inv.png", invert_image(diff3))
    diff4 = subtract_images("04")
    scipy.misc.imsave("_build/difference-4.png", diff4)

    superposition = add_images("Figures/scale.bmp", "_build/difference-3-inv.png")
    scipy.misc.imsave("_build/motsize.png", superposition[147 : 147 + 308, 402 : 402 + 329])

    mm_per_pixel = get_mm_per_pixel()

    selection = diff3[221 : 221 + 167, 513 : 513 + 150]

    scipy.misc.imsave("_build/mot-crop.png", selection)

    s = selection.shape
    total_pixels = s[0] * s[1]

    white_pixels = np.sum(selection - np.min(selection)) / (np.max(selection) - np.min(selection))

    radius_px = np.sqrt(white_pixels / np.pi)
    radius_mm = radius_px * mm_per_pixel
    volume_mm3 = 4 / 3 * np.pi * radius_mm ** 3

    T["mot_mm_per_pixel"] = siunitx(mm_per_pixel)
    T["mot_total_pixels"] = siunitx(total_pixels)
    T["mot_white_pixels"] = siunitx(white_pixels)
    T["mot_radius_px"] = siunitx(radius_px)
    T["mot_radius_mm"] = siunitx(radius_mm)
    T["mot_volume_mm3"] = siunitx(volume_mm3)
Пример #26
0
def job_mot_size(T):
    diff3 = subtract_images('03')
    scipy.misc.imsave('_build/difference-3.png', diff3)
    scipy.misc.imsave('_build/difference-3-inv.png', invert_image(diff3))
    diff4 = subtract_images('04')
    scipy.misc.imsave('_build/difference-4.png', diff4)

    superposition = add_images('Figures/scale.bmp',
                               '_build/difference-3-inv.png')
    scipy.misc.imsave('_build/motsize.png', superposition[147:147 + 308,
                                                          402:402 + 329])

    mm_per_pixel = get_mm_per_pixel()

    selection = diff3[221:221 + 167, 513:513 + 150]

    scipy.misc.imsave('_build/mot-crop.png', selection)

    s = selection.shape
    total_pixels = s[0] * s[1]

    white_pixels = np.sum(selection - np.min(selection)) / (np.max(selection) -
                                                            np.min(selection))

    radius_px = np.sqrt(white_pixels / np.pi)
    radius_mm = radius_px * mm_per_pixel
    volume_mm3 = 4 / 3 * np.pi * radius_mm**3

    T['mot_mm_per_pixel'] = siunitx(mm_per_pixel)
    T['mot_total_pixels'] = siunitx(total_pixels)
    T['mot_white_pixels'] = siunitx(white_pixels)
    T['mot_radius_px'] = siunitx(radius_px)
    T['mot_radius_mm'] = siunitx(radius_mm)
    T['mot_volume_mm3'] = siunitx(volume_mm3)
Пример #27
0
def job_scan_cooling(T):
    osci19_x1, osci19_y1, osci19_x2, osci19_y2 = trek.load_dir("0019")
    osci20_x1, osci20_y1, osci20_x2, osci20_y2 = trek.load_dir("0020")

    np.savetxt("_build/xy/scan-cooling-mot-input.tsv", np.column_stack([osci20_x1, osci20_y1]))
    np.savetxt("_build/xy/scan-cooling-mot-output.tsv", np.column_stack([osci20_x2, osci20_y2]))
    np.savetxt("_build/xy/scan-cooling-no_mot-input.tsv", np.column_stack([osci19_x1, osci19_y1]))
    np.savetxt("_build/xy/scan-cooling-no_mot-output.tsv", np.column_stack([osci19_x2, osci19_y2]))
    np.savetxt("_build/xy/scan-cooling-difference-output.tsv", np.column_stack([osci19_x2, osci19_y2 - osci20_y2]))

    peaks_val = []
    peaks_err = []

    peak_val, peak_err = fit_osci_peak(osci20_x1, osci20_y1, -1.00, -0.65, "scan-cooling-mot-input-fit1.tsv")
    peaks_val.append(peak_val)
    peaks_err.append(peak_err)
    peak_val, peak_err = fit_osci_peak(osci20_x1, osci20_y1, -0.40, -0.10, "scan-cooling-mot-input-fit2.tsv")
    peaks_val.append(peak_val)
    peaks_err.append(peak_err)
    peak_val, peak_err = fit_osci_peak(osci20_x1, osci20_y1, 0.80, 1.07, "scan-cooling-mot-input-fit3.tsv")
    peaks_val.append(peak_val)
    peaks_err.append(peak_err)

    spacings = np.array([0, 31.7, 31.7 + 60.3])
    spacings -= spacings[2]
    popt, pconv = op.curve_fit(linear, spacings, peaks_val, sigma=peaks_err)

    np.savetxt("_build/xy/scan-cooling-spacing-data.tsv", np.column_stack([spacings, peaks_val, peaks_err]))

    fit_x = np.linspace(min(spacings), max(spacings), 10)
    fit_y = linear(fit_x, *popt)

    np.savetxt("_build/xy/scan-cooling-spacing-data.tsv", np.column_stack([spacings, peaks_val, peaks_err]))
    np.savetxt("_build/xy/scan-cooling-spacing-fit.tsv", np.column_stack([fit_x, fit_y]))

    detuning_x = (osci19_x2 - popt[1]) / popt[0]
    detuning_y = osci19_y2 - osci20_y2

    np.savetxt("_build/xy/scan-cooling-detuning.tsv", np.column_stack([detuning_x, detuning_y]))

    sel = (-18 < detuning_x) & (detuning_x < -9)
    p0 = [-15, 3, 1]
    popt, pconv = op.curve_fit(gauss, detuning_x[sel], detuning_y[sel], p0=p0)
    fit_x = np.linspace(-18, -9, 100)
    fit_y = gauss(fit_x, *popt)
    np.savetxt("_build/xy/scan-cooling-detuning-fit.tsv", np.column_stack([fit_x, fit_y]))

    perr = np.sqrt(pconv.diagonal())

    T["detuning"] = siunitx(popt[0], perr[0])

    return popt[0], perr[0]
Пример #28
0
def job_harmonic_power(T, extinction_dist, input_popt_dist):
    data = np.loadtxt('Data/harmonic_splitter.tsv')
    angle = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = data[:, 2] * 1e-6

    T['harmonic_splitter_table'] = list(zip(
        siunitx(angle),
        siunitx(power_val*1e6, power_err*1e6),
    ))

    power_dist = bootstrap.make_dist(power_val, power_err)

    fit_x = np.linspace(np.min(angle), np.max(angle), 200)
    fit_y_dist = []
    angle_offset_dist = []
    a_dist = []
    b_dist = []
    popt_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(cos_quartic, angle, power, p0=[1.5e-5, 0, 0])
        fit_y_dist.append(cos_quartic(fit_x, *popt))
        angle_offset_dist.append(popt[1])
        a = popt[0]
        b = popt[2]
        a_dist.append(a)
        b_dist.append(b)
        popt_dist.append(popt)
    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)
    angle_offset_val, angle_offset_err = bootstrap.average_and_std_arrays(angle_offset_dist)
    a_val, a_err = bootstrap.average_and_std_arrays(a_dist)
    b_val, b_err = bootstrap.average_and_std_arrays(b_dist)

    np.savetxt('_build/xy/harmonic-splitter-data.tsv',
               np.column_stack([angle, power_val, power_err]))
    np.savetxt('_build/xy/harmonic-splitter-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/harmonic-splitter-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    T['splitter_angle_offset'] = siunitx(angle_offset_val, angle_offset_err)
    T['splitter_a'] = siunitx(a_val, a_err)
    T['splitter_b'] = siunitx(b_val, b_err)

    efficiency_dist = []
    efficiency_sq_dist = []
    for extinction, input_popt, popt in zip(extinction_dist, input_popt_dist, popt_dist):
        efficiency = popt[0] / (input_popt[0] * extinction)
        efficiency_dist.append(efficiency)
        efficiency_sq = popt[0] / (input_popt[0] * extinction)**2
        efficiency_sq_dist.append(efficiency_sq)
    efficiency_val, efficiency_err = bootstrap.average_and_std_arrays(efficiency_dist)
    efficiency_sq_val, efficiency_sq_err = bootstrap.average_and_std_arrays(efficiency_sq_dist)
    T['efficiency'] = siunitx(efficiency_val, efficiency_err)
    T['efficiency_sq'] = siunitx(efficiency_sq_val, efficiency_sq_err)
Пример #29
0
def job_diameter(T):
    data = np.loadtxt("Data/diameter.tsv")
    position = data[:, 0]
    power = data[:, 1]

    x = np.linspace(np.min(position), np.max(position), 100)
    popt, pconv = op.curve_fit(errorfunction, position, power, p0=[3.4, 0.4, 29.5])
    perr = np.sqrt(pconv.diagonal())

    y = errorfunction(x, *popt)
    # pl.plot(position, power, linestyle="none", marker="+")
    # pl.plot(x, y)
    # pl.show()
    # pl.clf()

    np.savetxt("_build/xy/diameter-data.tsv", np.column_stack([position, power]))
    np.savetxt("_build/xy/diameter-fit.tsv", np.column_stack([x, y]))

    T["beam_diameter_table"] = list(zip(siunitx(position), siunitx(power)))

    T["beam_diameter"] = siunitx(popt[1], perr[1])
    T["beam_power"] = siunitx(popt[0], perr[0])

    return popt[1], perr[1]
Пример #30
0
def job_variable_attenuator(T, extinction_dist):
    data = np.loadtxt('Data/variable.tsv')
    angle = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = np.ones(power_val.shape) * 1e-6

    T['variable_attenuator_table'] = list(
        zip(
            siunitx(angle),
            siunitx(power_val * 1e6, power_err * 1e6),
        ))

    power_dist = bootstrap.make_dist(power_val,
                                     power_err,
                                     n=len(extinction_dist))

    fit_x = np.linspace(np.min(angle), np.max(angle), 200)
    fit_y_dist = []
    angle_offset_dist = []
    a_dist = []
    b_dist = []
    popt_dist = []
    extinction_ratio_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(cos_squared, angle, power, p0=[1.5, 0, 0])
        fit_y_dist.append(cos_squared(fit_x, *popt))
        angle_offset_dist.append(popt[1])
        a = popt[0]
        b = popt[2]
        a_dist.append(a)
        b_dist.append(b)
        popt_dist.append(popt)
        extinction_ratio_dist.append((a + b) / b)
    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)
    angle_offset_val, angle_offset_err = bootstrap.average_and_std_arrays(
        angle_offset_dist)
    a_val, a_err = bootstrap.average_and_std_arrays(a_dist)
    b_val, b_err = bootstrap.average_and_std_arrays(b_dist)
    extinction_ratio_val, extinction_ratio_err = bootstrap.average_and_std_arrays(
        extinction_ratio_dist)

    np.savetxt('_build/xy/variable-data.tsv',
               np.column_stack([angle, power_val, power_err]))
    np.savetxt('_build/xy/variable-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/variable-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))

    T['variable_angle_offset'] = siunitx(angle_offset_val, angle_offset_err)
    T['variable_a'] = siunitx(a_val, a_err)
    T['variable_b'] = siunitx(b_val, b_err)
    T['extinction_ratio'] = siunitx(extinction_ratio_val, extinction_ratio_err)

    return popt_dist
Пример #31
0
def job_variable_attenuator(T, extinction_dist):
    data = np.loadtxt('Data/variable.tsv')
    angle = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = np.ones(power_val.shape) * 1e-6

    T['variable_attenuator_table'] = list(zip(
        siunitx(angle),
        siunitx(power_val*1e6, power_err*1e6),
    ))

    power_dist = bootstrap.make_dist(power_val, power_err, n=len(extinction_dist))

    fit_x = np.linspace(np.min(angle), np.max(angle), 200)
    fit_y_dist = []
    angle_offset_dist = []
    a_dist = []
    b_dist = []
    popt_dist = []
    extinction_ratio_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(cos_squared, angle, power, p0=[1.5, 0, 0])
        fit_y_dist.append(cos_squared(fit_x, *popt))
        angle_offset_dist.append(popt[1])
        a = popt[0]
        b = popt[2]
        a_dist.append(a)
        b_dist.append(b)
        popt_dist.append(popt)
        extinction_ratio_dist.append((a + b) / b)
    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)
    angle_offset_val, angle_offset_err = bootstrap.average_and_std_arrays(angle_offset_dist)
    a_val, a_err = bootstrap.average_and_std_arrays(a_dist)
    b_val, b_err = bootstrap.average_and_std_arrays(b_dist)
    extinction_ratio_val, extinction_ratio_err = bootstrap.average_and_std_arrays(extinction_ratio_dist)

    np.savetxt('_build/xy/variable-data.tsv',
               np.column_stack([angle, power_val, power_err]))
    np.savetxt('_build/xy/variable-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/variable-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))

    T['variable_angle_offset'] = siunitx(angle_offset_val, angle_offset_err)
    T['variable_a'] = siunitx(a_val, a_err)
    T['variable_b'] = siunitx(b_val, b_err)
    T['extinction_ratio'] = siunitx(extinction_ratio_val, extinction_ratio_err)

    return popt_dist
Пример #32
0
def job_temperature_dependence(T):
    data = np.loadtxt('Data/temperature.tsv')
    temp = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = np.ones(power_val.shape) * 1e-6
    power_dist = bootstrap.make_dist(power_val, power_err)

    T['temperature_table'] = list(
        zip(
            siunitx(temp),
            siunitx(power_val * 1e6, power_err * 1e6),
        ))

    p0 = [36.5, 1, 36 - 6, 2e-6]
    fit_x = np.linspace(np.min(temp), np.max(temp), 300)
    popt_dist = []
    fit_y_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(sinc, temp, power, p0=p0)
        fit_y_dist.append(sinc(fit_x, *popt))
        popt_dist.append(popt)

    center_dist, width_dist, amplitude_dist, offset_dist = zip(*popt_dist)

    center_val, center_err = bootstrap.average_and_std_arrays(center_dist)
    width_val, width_err = bootstrap.average_and_std_arrays(width_dist)
    amplitude_val, amplitude_err = bootstrap.average_and_std_arrays(
        amplitude_dist)
    offset_val, offset_err = bootstrap.average_and_std_arrays(offset_dist)

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)

    np.savetxt('_build/xy/temperature-data.tsv',
               np.column_stack([temp, power_val, power_err]))
    np.savetxt('_build/xy/temperature-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/temperature-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))

    T['temp_center'] = siunitx(center_val, center_err)
    T['temp_width'] = siunitx(width_val, width_err)
    T['temp_amplitude'] = siunitx(amplitude_val, amplitude_err)
    T['temp_offset'] = siunitx(offset_val, offset_err)
Пример #33
0
def job_temperature_dependence(T):
    data = np.loadtxt('Data/temperature.tsv')
    temp = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = np.ones(power_val.shape) * 1e-6
    power_dist = bootstrap.make_dist(power_val, power_err)

    T['temperature_table'] = list(zip(
        siunitx(temp),
        siunitx(power_val*1e6, power_err*1e6),
    ))

    p0 = [36.5, 1, 36-6, 2e-6]
    fit_x = np.linspace(np.min(temp), np.max(temp), 300)
    popt_dist = []
    fit_y_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(sinc, temp, power, p0=p0)
        fit_y_dist.append(sinc(fit_x, *popt))
        popt_dist.append(popt)

    center_dist, width_dist, amplitude_dist, offset_dist = zip(*popt_dist)

    center_val, center_err = bootstrap.average_and_std_arrays(center_dist)
    width_val, width_err = bootstrap.average_and_std_arrays(width_dist)
    amplitude_val, amplitude_err = bootstrap.average_and_std_arrays(amplitude_dist)
    offset_val, offset_err = bootstrap.average_and_std_arrays(offset_dist)

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)

    np.savetxt('_build/xy/temperature-data.tsv',
               np.column_stack([temp, power_val, power_err]))
    np.savetxt('_build/xy/temperature-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/temperature-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))

    T['temp_center'] = siunitx(center_val, center_err)
    T['temp_width'] = siunitx(width_val, width_err)
    T['temp_amplitude'] = siunitx(amplitude_val, amplitude_err)
    T['temp_offset'] = siunitx(offset_val, offset_err)
Пример #34
0
def get_indium_data(T, slope_val, width):
    files = glob.glob('Data/in-*.txt')

    temps_val = []
    temps_err = []

    all_counts = []

    all_tau_0_dist = []
    all_tau_bar_dist = []
    all_tau_f_dist = []
    all_tau_t_dist = []

    all_intens_0_dist = []
    all_intens_t_dist = []

    all_lifetime_y_dist = []
    all_lifetime_popt_dist = []

    all_sigma_c_dist = []

    # Process lifetime curves with bootstrap.
    for sample_id in range(BOOTSTRAP_SAMPLES):
        print('Bootstrap sample', sample_id, 'running …')

        results = []

        for file_ in sorted(files):
            print('Working on lifetime spectrum', file_)

            if sample_id == 0:
                temp_lower, temp_upper = get_temp(file_)
                temp_mean = (temp_lower + temp_upper) / 2
                temp_err = temp_upper - temp_mean
                temps_val.append(temp_mean)
                temps_err.append(temp_err)
                print('Mean temperature:', temp_mean)

            data = np.loadtxt(file_)
            channel = data[:, 0]
            time = slope_val * channel
            counts = data[:, 1]
            boot_counts = bootstrap.redraw_count(counts)

            if sample_id == 0:
                all_counts.append(counts)

            x = np.linspace(np.min(time), np.max(time), 2000)

            sel = (9 < time) & (time < 15)

            fit_func = lambda t, mean, A_0, A_t, tau_0, tau_t, BG: \
                    models.lifetime_spectrum(t, mean, width, A_0, A_t, tau_0, tau_t, BG)
            p0 = [10.5, 210, 190, 0.07, 0.8, 0]
            popt, pconv = op.curve_fit(fit_func,
                                       time[sel],
                                       boot_counts[sel],
                                       p0=p0)
            mean, A_0, A_t, tau_0, tau_t, BG = popt

            intens_0 = A_0 / (A_0 + A_t)
            intens_t = A_t / (A_0 + A_t)
            tau_bar = intens_0 * tau_0 + intens_t * tau_t
            y = fit_func(x, *popt)
            tau_f = 1 / (intens_0 / tau_0 - intens_t / tau_t)
            sigma_c = 1 / tau_0 - 1 / tau_f

            results.append([
                tau_0,
                tau_bar,
                tau_f,
                tau_t,
                intens_0,
                intens_t,
                y,
                popt,
                sigma_c,
            ])


        tau_0_list, tau_bar_list, tau_f_list, tau_t_list, intens_0_list, \
                intens_t_list, lifetime_y_list, lifetime_popt_list, sigma_c_list \
                = zip(*results)

        all_tau_0_dist.append(tau_0_list)
        all_tau_bar_dist.append(tau_bar_list)
        all_tau_f_dist.append(tau_f_list)
        all_tau_t_dist.append(tau_t_list)
        all_intens_0_dist.append(intens_0_list)
        all_intens_t_dist.append(intens_t_list)
        all_lifetime_y_dist.append(lifetime_y_list)
        all_lifetime_popt_dist.append(lifetime_popt_list)
        all_sigma_c_dist.append(sigma_c_list)

    T['temps_int'] = []

    # Generate plots with lifetime curves and fits.
    for temp, counts, lifetime_y_dist in zip(temps_val, all_counts,
                                             zip(*all_lifetime_y_dist)):
        print('Creating lifetime plot with temp', temp)
        y_val, y_err = bootstrap.average_and_std_arrays(lifetime_y_dist)

        np.savetxt(
            '_build/xy/lifetime-{}K-data.tsv'.format(int(temp)),
            bootstrap.pgfplots_error_band(time[0:4000], counts[0:4000],
                                          np.sqrt(counts[0:4000])))
        np.savetxt('_build/xy/lifetime-{}K-fit.tsv'.format(int(temp)),
                   np.column_stack([x, y_val]))
        np.savetxt('_build/xy/lifetime-{}K-band.tsv'.format(int(temp)),
                   bootstrap.pgfplots_error_band(x, y_val, y_err))

        T['temps_int'].append(int(temp))

        if False:
            pl.fill_between(x,
                            y_val - y_err,
                            y_val + y_err,
                            alpha=0.5,
                            color='red')
            pl.plot(time, counts, color='black')
            counts_smooth = scipy.ndimage.filters.gaussian_filter1d(counts, 8)
            pl.plot(time, counts_smooth, color='green')
            pl.plot(x, y_val, color='red')
            pl.xlabel('Time / ns')
            pl.ylabel('Counts')
            dandify_plot()
            pl.xlim((8, 20))
            pl.savefig('_build/mpl-lifetime-{:04d}K.pdf'.format(int(temp)))
            pl.savefig('_build/mpl-lifetime-{:04d}K.png'.format(int(temp)))
            pl.yscale('log')
            pl.savefig('_build/mpl-lifetime-{:04d}K-log.pdf'.format(int(temp)))
            pl.savefig('_build/mpl-lifetime-{:04d}K-log.png'.format(int(temp)))
            pl.clf()

    T['temps_int'].sort()

    # Plot the lifetimes.
    taus_0_val, taus_0_err = bootstrap.average_and_std_arrays(all_tau_0_dist)
    taus_t_val, taus_t_err = bootstrap.average_and_std_arrays(all_tau_t_dist)
    taus_f_val, taus_f_err = bootstrap.average_and_std_arrays(all_tau_f_dist)
    taus_bar_val, taus_bar_err = bootstrap.average_and_std_arrays(
        all_tau_bar_dist)
    pl.errorbar(temps_val,
                taus_0_val,
                xerr=temps_err,
                yerr=taus_0_err,
                label=r'$\tau_0$',
                linestyle='none',
                marker='+')
    pl.errorbar(temps_val,
                taus_bar_val,
                xerr=temps_err,
                yerr=taus_bar_err,
                label=r'$\bar\tau$',
                linestyle='none',
                marker='+')
    pl.errorbar(temps_val,
                taus_t_val,
                xerr=temps_err,
                yerr=taus_t_err,
                label=r'$\tau_\mathrm{t}$',
                linestyle='none',
                marker='+')
    pl.errorbar(temps_val,
                taus_f_val,
                xerr=temps_err,
                yerr=taus_f_err,
                label=r'$\tau_\mathrm{f}$',
                linestyle='none',
                marker='+')
    pl.xlabel('T / K')
    pl.ylabel(r'$\tau$ / ns')
    dandify_plot()
    pl.savefig('_build/mpl-tau_0-tau_t.pdf')
    pl.savefig('_build/mpl-tau_0-tau_t.png')
    pl.clf()
    np.savetxt('_build/xy/tau_0.tsv',
               np.column_stack([temps_val, taus_0_val, taus_0_err]))
    np.savetxt('_build/xy/tau_t.tsv',
               np.column_stack([temps_val, taus_t_val, taus_t_err]))
    np.savetxt('_build/xy/tau_f.tsv',
               np.column_stack([temps_val, taus_f_val, taus_f_err]))
    np.savetxt('_build/xy/tau_bar.tsv',
               np.column_stack([temps_val, taus_bar_val, taus_bar_err]))

    T['taus_table'] = list(
        zip(
            siunitx(temps_val, temps_err),
            siunitx(taus_0_val, taus_0_err),
            siunitx(taus_t_val, taus_t_err),
            siunitx(taus_f_val, taus_f_err),
            siunitx(taus_bar_val, taus_bar_err),
        ))

    # Plot relative intensities.
    all_intens_0_val, all_intens_0_err = bootstrap.average_and_std_arrays(
        all_intens_0_dist)
    all_intens_t_val, all_intens_t_err = bootstrap.average_and_std_arrays(
        all_intens_t_dist)
    pl.errorbar(temps_val,
                all_intens_0_val,
                xerr=temps_err,
                yerr=all_intens_0_err,
                label=r'$A_0$',
                linestyle='none',
                marker='+')
    pl.errorbar(temps_val,
                all_intens_t_val,
                xerr=temps_err,
                yerr=all_intens_t_err,
                label=r'$A_\mathrm{t}$',
                linestyle='none',
                marker='+')
    pl.xlabel('T / K')
    pl.ylabel(r'Relative Intensity')
    dandify_plot()
    pl.savefig('_build/mpl-intensities.pdf')
    pl.savefig('_build/mpl-intensities.png')
    pl.clf()

    np.savetxt(
        '_build/xy/intensities-0.tsv',
        np.column_stack([temps_val, all_intens_0_val, all_intens_0_err]))
    np.savetxt(
        '_build/xy/intensities-t.tsv',
        np.column_stack([temps_val, all_intens_t_val, all_intens_t_err]))

    T['intensities_table'] = list(
        zip(
            siunitx(temps_val, temps_err),
            siunitx(all_intens_0_val, all_intens_0_err),
            siunitx(all_intens_t_val, all_intens_t_err),
        ))

    inv_temps = 1 / np.array(temps_val)
    results = []
    x = np.linspace(np.min(inv_temps), np.max(inv_temps), 1000)
    kelvin_to_eV = 8.621738e-5
    for all_sigma_c in all_sigma_c_dist:
        p0 = [11, 240]
        print('inv_temps:', inv_temps)
        print('all_sigma_c:', all_sigma_c)
        for leave_out in range(len(all_sigma_c)):
            inv_temps_jack = np.delete(inv_temps, leave_out)
            all_sigma_c_jack = np.delete(all_sigma_c, leave_out)
            popt, pconv = op.curve_fit(exp_decay,
                                       inv_temps_jack,
                                       all_sigma_c_jack,
                                       p0=p0)
            y = exp_decay(x, *popt)
            results.append([
                popt,
                popt[1] * kelvin_to_eV,
                y,
            ])

    popt_dist, Ht_eV_dist, arr_y_dist = zip(*results)

    popt_val, popt_err = bootstrap.average_and_std_arrays(popt_dist)
    print('popt:', siunitx(popt_val, popt_err))
    Ht_eV_val, Ht_eV_err = bootstrap.average_and_std_arrays(Ht_eV_dist)
    arr_y_val, arr_y_err = bootstrap.average_and_std_arrays(arr_y_dist)
    sigma_c_val, sigma_c_err = bootstrap.average_and_std_arrays(
        all_sigma_c_dist)

    pl.fill_between(x,
                    arr_y_val - arr_y_err,
                    arr_y_val + arr_y_err,
                    alpha=0.5,
                    color='red')
    pl.plot(x, arr_y_val, color='red')
    pl.errorbar(inv_temps,
                sigma_c_val,
                yerr=sigma_c_err,
                marker='+',
                linestyle='none',
                color='black')
    pl.xlabel(r'$1 / T$')
    pl.ylabel(r'$\sigma C_t(T)$')
    pl.savefig('_build/mpl-arrhenius.pdf')
    pl.savefig('_build/mpl-arrhenius.png')
    pl.clf()

    np.savetxt('_build/xy/arrhenius-data.tsv',
               np.column_stack([inv_temps, sigma_c_val, sigma_c_err]))
    np.savetxt('_build/xy/arrhenius-fit.tsv', np.column_stack([x, arr_y_val]))
    np.savetxt('_build/xy/arrhenius-band.tsv',
               bootstrap.pgfplots_error_band(x, arr_y_val, arr_y_err))

    T['arrhenius_table'] = list(
        zip(
            siunitx(inv_temps),
            siunitx(sigma_c_val, sigma_c_err),
        ))

    print('Ht_eV:', siunitx(Ht_eV_val, Ht_eV_err))

    T['Ht_eV'] = siunitx(Ht_eV_val, Ht_eV_err)

    pl.errorbar(temps_val,
                taus_bar_val,
                xerr=temps_err,
                yerr=taus_bar_err,
                label=r'$\bar\tau$',
                linestyle='none',
                marker='+')
    dandify_plot()
    pl.xlabel('T / K')
    pl.ylabel(r'$\bar\tau$ / ns')
    pl.savefig('_build/mpl-s_curve.pdf')
    pl.savefig('_build/mpl-s_curve.png')
    pl.clf()
    np.savetxt('_build/xy/s_curve.tsv',
               np.column_stack([temps_val, taus_bar_val, taus_bar_err]))
Пример #35
0
def job_scan_cooling(T):
    osci19_x1, osci19_y1, osci19_x2, osci19_y2 = trek.load_dir('0019')
    osci20_x1, osci20_y1, osci20_x2, osci20_y2 = trek.load_dir('0020')

    np.savetxt('_build/xy/scan-cooling-mot-input.tsv',
               np.column_stack([osci20_x1, osci20_y1]))
    np.savetxt('_build/xy/scan-cooling-mot-output.tsv',
               np.column_stack([osci20_x2, osci20_y2]))
    np.savetxt('_build/xy/scan-cooling-no_mot-input.tsv',
               np.column_stack([osci19_x1, osci19_y1]))
    np.savetxt('_build/xy/scan-cooling-no_mot-output.tsv',
               np.column_stack([osci19_x2, osci19_y2]))
    np.savetxt('_build/xy/scan-cooling-difference-output.tsv',
               np.column_stack([osci19_x2, osci19_y2 - osci20_y2]))

    peaks_val = []
    peaks_err = []

    peak_val, peak_err = fit_osci_peak(osci20_x1, osci20_y1, -1.00, -0.65,
                                       'scan-cooling-mot-input-fit1.tsv')
    peaks_val.append(peak_val)
    peaks_err.append(peak_err)
    peak_val, peak_err = fit_osci_peak(osci20_x1, osci20_y1, -0.40, -0.10,
                                       'scan-cooling-mot-input-fit2.tsv')
    peaks_val.append(peak_val)
    peaks_err.append(peak_err)
    peak_val, peak_err = fit_osci_peak(osci20_x1, osci20_y1, 0.80, 1.07,
                                       'scan-cooling-mot-input-fit3.tsv')
    peaks_val.append(peak_val)
    peaks_err.append(peak_err)

    spacings = np.array([0, 31.7, 31.7 + 60.3])
    spacings -= spacings[2]
    popt, pconv = op.curve_fit(linear, spacings, peaks_val, sigma=peaks_err)

    np.savetxt('_build/xy/scan-cooling-spacing-data.tsv',
               np.column_stack([spacings, peaks_val, peaks_err]))

    fit_x = np.linspace(min(spacings), max(spacings), 10)
    fit_y = linear(fit_x, *popt)

    np.savetxt('_build/xy/scan-cooling-spacing-data.tsv',
               np.column_stack([spacings, peaks_val, peaks_err]))
    np.savetxt('_build/xy/scan-cooling-spacing-fit.tsv',
               np.column_stack([fit_x, fit_y]))

    detuning_x = (osci19_x2 - popt[1]) / popt[0]
    detuning_y = osci19_y2 - osci20_y2

    np.savetxt('_build/xy/scan-cooling-detuning.tsv',
               np.column_stack([detuning_x, detuning_y]))

    sel = (-18 < detuning_x) & (detuning_x < -9)
    p0 = [-15, 3, 1]
    popt, pconv = op.curve_fit(gauss, detuning_x[sel], detuning_y[sel], p0=p0)
    fit_x = np.linspace(-18, -9, 100)
    fit_y = gauss(fit_x, *popt)
    np.savetxt('_build/xy/scan-cooling-detuning-fit.tsv',
               np.column_stack([fit_x, fit_y]))

    perr = np.sqrt(pconv.diagonal())

    T['detuning'] = siunitx(popt[0], perr[0])

    return popt[0], perr[0]
Пример #36
0
def job_spectrum(T):
    data = np.loadtxt('Data/runs.tsv')


    T['raw_table'] = list([[str(int(x)) for x in row] for row in data])

    runs = data[:, 0]
    motor = data[:, 1]
    T_LR = data[:, 2]
    N_LR = data[:, 3]
    T_RL = data[:, 4]
    N_RL = data[:, 5]

    time_lr = T_LR * 10e-3
    time_rl = T_RL * 10e-3

    velocity_lr_val = - length_val * runs / time_lr
    velocity_rl_val = length_val * runs / time_rl
    velocity_lr_err = - length_err * runs / time_lr
    velocity_rl_err = length_err * runs / time_rl

    rate_lr_val = N_LR / time_lr
    rate_rl_val = N_RL / time_rl
    rate_lr_err = np.sqrt(N_LR) / time_lr
    rate_rl_err = np.sqrt(N_RL) / time_rl

    rate_val = np.concatenate((rate_lr_val, rate_rl_val))
    rate_err = np.concatenate((rate_lr_err, rate_rl_err))
    velocity_val = np.concatenate((velocity_lr_val, velocity_rl_val))
    velocity_err = np.concatenate((velocity_lr_err, velocity_rl_err))

    fit_val, fit_err = fit_dip(velocity_val, rate_val, rate_err)
    x = np.linspace(np.min(velocity_val), np.max(velocity_val), 1000)
    y = lorentz6(x, *fit_val)
    pl.plot(x, y)

    widths_val = fit_val[1::3]
    widths_err = fit_err[1::3]

    delta_e_val = hbar_omega0_ev * widths_val / speed_of_light
    delta_e_err = hbar_omega0_ev * widths_err / speed_of_light

    relative_width_val = widths_val / speed_of_light
    relative_width_err = widths_err / speed_of_light

    T['widths_table'] = list(zip(*[
        siunitx(widths_val / 1e-6, widths_err / 1e-6),
        siunitx(delta_e_val / 1e-9, delta_e_err / 1e-9),
        siunitx(relative_width_val / 1e-13, relative_width_err / 1e-13),
    ]))

    formatted = siunitx(fit_val / 1e-6, fit_err / 1e-6)
    offset = siunitx(fit_val[-1], fit_err[-1])

    T['fit_param'] = list(zip(*[iter(formatted[:-1])]*3))
    T['fit_offset'] = offset

    np.savetxt('_build/xy/rate_fit.csv', np.column_stack([
        x / 1e-3, y
    ]))

    np.savetxt('_build/xy/rate_lr.csv', np.column_stack([
        velocity_lr_val / 1e-3, rate_lr_val, rate_lr_err,
    ]))
    np.savetxt('_build/xy/rate_rl.csv', np.column_stack([
        velocity_rl_val / 1e-3, rate_rl_val, rate_rl_err,
    ]))

    np.savetxt('_build/xy/motor_lr.csv', np.column_stack([
        motor, -velocity_lr_val / 1e-3, velocity_lr_err / 1e-3,
    ]))
    np.savetxt('_build/xy/motor_rl.csv', np.column_stack([
        motor, velocity_rl_val / 1e-3, velocity_rl_err / 1e-3,
    ]))

    pl.errorbar(velocity_lr_val, rate_lr_val, rate_lr_err, xerr=velocity_lr_err, marker='o', linestyle='none')
    pl.errorbar(velocity_rl_val, rate_rl_val, rate_lr_err,  xerr=velocity_rl_err, marker='o', linestyle='none')
    pl.grid(True)
    pl.margins(0.05)
    pl.tight_layout()
    pl.savefig('_build/mpl-rate.pdf')
    pl.clf()

    #pl.errorbar(motor, -velocity_lr_val, velocity_lr_err, marker='o')
    #pl.errorbar(motor,  velocity_rl_val, velocity_rl_err, marker='o')
    #pl.grid(True)
    #pl.margins(0.05)
    #pl.tight_layout()
    #pl.savefig('_build/mpl-motor.pdf')
    #pl.clf()

    means_val = fit_val[:-1][0::3]
    means_err = fit_err[:-1][0::3]

    lande_factors(T, means_val, means_err)
Пример #37
0
def get_indium_data(T, slope_val, width):
    files = glob.glob('Data/in-*.txt')

    temps_val = []
    temps_err = []

    all_counts = []

    all_tau_0_dist = []
    all_tau_bar_dist = []
    all_tau_f_dist = []
    all_tau_t_dist = []

    all_intens_0_dist = []
    all_intens_t_dist = []

    all_lifetime_y_dist = []
    all_lifetime_popt_dist = []

    all_sigma_c_dist = []

    # Process lifetime curves with bootstrap.
    for sample_id in range(BOOTSTRAP_SAMPLES):
        print('Bootstrap sample', sample_id, 'running …')

        results = []

        for file_ in sorted(files):
            print('Working on lifetime spectrum', file_)

            if sample_id == 0:
                temp_lower, temp_upper = get_temp(file_)
                temp_mean = (temp_lower + temp_upper)/2
                temp_err = temp_upper - temp_mean
                temps_val.append(temp_mean)
                temps_err.append(temp_err)
                print('Mean temperature:', temp_mean)

            data = np.loadtxt(file_)
            channel = data[:, 0]
            time = slope_val * channel
            counts = data[:, 1]
            boot_counts = bootstrap.redraw_count(counts)

            if sample_id == 0:
                all_counts.append(counts)

            x = np.linspace(np.min(time), np.max(time), 2000)

            sel = (9 < time) & (time < 15)

            fit_func = lambda t, mean, A_0, A_t, tau_0, tau_t, BG: \
                    models.lifetime_spectrum(t, mean, width, A_0, A_t, tau_0, tau_t, BG)
            p0 = [10.5, 210, 190, 0.07, 0.8, 0]
            popt, pconv = op.curve_fit(fit_func, time[sel], boot_counts[sel], p0=p0)
            mean, A_0, A_t, tau_0, tau_t, BG = popt

            intens_0 = A_0 / (A_0 + A_t)
            intens_t = A_t / (A_0 + A_t)
            tau_bar = intens_0 * tau_0 + intens_t * tau_t
            y = fit_func(x, *popt)
            tau_f = 1 / (intens_0 / tau_0 - intens_t / tau_t)
            sigma_c = 1 / tau_0 - 1 / tau_f

            results.append([
                tau_0,
                tau_bar,
                tau_f,
                tau_t,
                intens_0,
                intens_t,
                y,
                popt,
                sigma_c,
            ])


        tau_0_list, tau_bar_list, tau_f_list, tau_t_list, intens_0_list, \
                intens_t_list, lifetime_y_list, lifetime_popt_list, sigma_c_list \
                = zip(*results)

        all_tau_0_dist.append(tau_0_list)
        all_tau_bar_dist.append(tau_bar_list)
        all_tau_f_dist.append(tau_f_list)
        all_tau_t_dist.append(tau_t_list)
        all_intens_0_dist.append(intens_0_list)
        all_intens_t_dist.append(intens_t_list)
        all_lifetime_y_dist.append(lifetime_y_list)
        all_lifetime_popt_dist.append(lifetime_popt_list)
        all_sigma_c_dist.append(sigma_c_list)

    T['temps_int'] = []

    # Generate plots with lifetime curves and fits.
    for temp, counts, lifetime_y_dist in zip(temps_val, all_counts, zip(*all_lifetime_y_dist)):
        print('Creating lifetime plot with temp', temp)
        y_val, y_err = bootstrap.average_and_std_arrays(lifetime_y_dist)

        np.savetxt('_build/xy/lifetime-{}K-data.tsv'.format(int(temp)),
                   bootstrap.pgfplots_error_band(time[0:4000], counts[0:4000], np.sqrt(counts[0:4000])))
        np.savetxt('_build/xy/lifetime-{}K-fit.tsv'.format(int(temp)),
                   np.column_stack([x, y_val]))
        np.savetxt('_build/xy/lifetime-{}K-band.tsv'.format(int(temp)),
                   bootstrap.pgfplots_error_band(x, y_val, y_err))

        T['temps_int'].append(int(temp))

        if False:
            pl.fill_between(x, y_val - y_err, y_val + y_err, alpha=0.5, color='red')
            pl.plot(time, counts, color='black')
            counts_smooth = scipy.ndimage.filters.gaussian_filter1d(counts, 8)
            pl.plot(time, counts_smooth, color='green')
            pl.plot(x, y_val, color='red')
            pl.xlabel('Time / ns')
            pl.ylabel('Counts')
            dandify_plot()
            pl.xlim((8, 20))
            pl.savefig('_build/mpl-lifetime-{:04d}K.pdf'.format(int(temp)))
            pl.savefig('_build/mpl-lifetime-{:04d}K.png'.format(int(temp)))
            pl.yscale('log')
            pl.savefig('_build/mpl-lifetime-{:04d}K-log.pdf'.format(int(temp)))
            pl.savefig('_build/mpl-lifetime-{:04d}K-log.png'.format(int(temp)))
            pl.clf()

    T['temps_int'].sort()

    # Plot the lifetimes.
    taus_0_val, taus_0_err = bootstrap.average_and_std_arrays(all_tau_0_dist)
    taus_t_val, taus_t_err = bootstrap.average_and_std_arrays(all_tau_t_dist)
    taus_f_val, taus_f_err = bootstrap.average_and_std_arrays(all_tau_f_dist)
    taus_bar_val, taus_bar_err = bootstrap.average_and_std_arrays(all_tau_bar_dist)
    pl.errorbar(temps_val, taus_0_val, xerr=temps_err, yerr=taus_0_err,
                label=r'$\tau_0$', linestyle='none', marker='+')
    pl.errorbar(temps_val, taus_bar_val, xerr=temps_err, yerr=taus_bar_err,
                label=r'$\bar\tau$', linestyle='none', marker='+')
    pl.errorbar(temps_val, taus_t_val, xerr=temps_err, yerr=taus_t_err,
                label=r'$\tau_\mathrm{t}$', linestyle='none', marker='+')
    pl.errorbar(temps_val, taus_f_val, xerr=temps_err, yerr=taus_f_err,
                label=r'$\tau_\mathrm{f}$', linestyle='none', marker='+')
    pl.xlabel('T / K')
    pl.ylabel(r'$\tau$ / ns')
    dandify_plot()
    pl.savefig('_build/mpl-tau_0-tau_t.pdf')
    pl.savefig('_build/mpl-tau_0-tau_t.png')
    pl.clf()
    np.savetxt('_build/xy/tau_0.tsv',
               np.column_stack([temps_val, taus_0_val, taus_0_err]))
    np.savetxt('_build/xy/tau_t.tsv',
               np.column_stack([temps_val, taus_t_val, taus_t_err]))
    np.savetxt('_build/xy/tau_f.tsv',
               np.column_stack([temps_val, taus_f_val, taus_f_err]))
    np.savetxt('_build/xy/tau_bar.tsv',
               np.column_stack([temps_val, taus_bar_val, taus_bar_err]))

    T['taus_table'] = list(zip(
        siunitx(temps_val, temps_err),
        siunitx(taus_0_val, taus_0_err),
        siunitx(taus_t_val, taus_t_err),
        siunitx(taus_f_val, taus_f_err),
        siunitx(taus_bar_val, taus_bar_err),
    ))

    # Plot relative intensities.
    all_intens_0_val, all_intens_0_err = bootstrap.average_and_std_arrays(all_intens_0_dist)
    all_intens_t_val, all_intens_t_err = bootstrap.average_and_std_arrays(all_intens_t_dist)
    pl.errorbar(temps_val, all_intens_0_val, xerr=temps_err, yerr=all_intens_0_err,
                label=r'$A_0$', linestyle='none', marker='+')
    pl.errorbar(temps_val, all_intens_t_val, xerr=temps_err, yerr=all_intens_t_err,
                label=r'$A_\mathrm{t}$', linestyle='none', marker='+')
    pl.xlabel('T / K')
    pl.ylabel(r'Relative Intensity')
    dandify_plot()
    pl.savefig('_build/mpl-intensities.pdf')
    pl.savefig('_build/mpl-intensities.png')
    pl.clf()

    np.savetxt('_build/xy/intensities-0.tsv',
               np.column_stack([temps_val, all_intens_0_val, all_intens_0_err]))
    np.savetxt('_build/xy/intensities-t.tsv',
               np.column_stack([temps_val, all_intens_t_val, all_intens_t_err]))

    T['intensities_table'] = list(zip(
        siunitx(temps_val, temps_err),
        siunitx(all_intens_0_val, all_intens_0_err),
        siunitx(all_intens_t_val, all_intens_t_err),
    ))

    inv_temps = 1 / np.array(temps_val)
    results = []
    x = np.linspace(np.min(inv_temps), np.max(inv_temps), 1000)
    kelvin_to_eV = 8.621738e-5
    for all_sigma_c in all_sigma_c_dist:
        p0 = [11, 240]
        print('inv_temps:', inv_temps)
        print('all_sigma_c:', all_sigma_c)
        for leave_out in range(len(all_sigma_c)):
            inv_temps_jack = np.delete(inv_temps, leave_out)
            all_sigma_c_jack = np.delete(all_sigma_c, leave_out)
            popt, pconv = op.curve_fit(exp_decay, inv_temps_jack, all_sigma_c_jack, p0=p0)
            y = exp_decay(x, *popt)
            results.append([
                popt,
                popt[1] * kelvin_to_eV,
                y,
            ])

    popt_dist, Ht_eV_dist, arr_y_dist = zip(*results)

    popt_val, popt_err = bootstrap.average_and_std_arrays(popt_dist)
    print('popt:', siunitx(popt_val, popt_err))
    Ht_eV_val, Ht_eV_err = bootstrap.average_and_std_arrays(Ht_eV_dist)
    arr_y_val, arr_y_err = bootstrap.average_and_std_arrays(arr_y_dist)
    sigma_c_val, sigma_c_err = bootstrap.average_and_std_arrays(all_sigma_c_dist)

    pl.fill_between(x, arr_y_val - arr_y_err, arr_y_val + arr_y_err, alpha=0.5, color='red')
    pl.plot(x, arr_y_val, color='red')
    pl.errorbar(inv_temps, sigma_c_val, yerr=sigma_c_err, marker='+', linestyle='none', color='black')
    pl.xlabel(r'$1 / T$')
    pl.ylabel(r'$\sigma C_t(T)$')
    pl.savefig('_build/mpl-arrhenius.pdf')
    pl.savefig('_build/mpl-arrhenius.png')
    pl.clf()

    np.savetxt('_build/xy/arrhenius-data.tsv',
               np.column_stack([inv_temps, sigma_c_val, sigma_c_err]))
    np.savetxt('_build/xy/arrhenius-fit.tsv',
               np.column_stack([x, arr_y_val]))
    np.savetxt('_build/xy/arrhenius-band.tsv',
               bootstrap.pgfplots_error_band(x, arr_y_val, arr_y_err))

    T['arrhenius_table'] = list(zip(
        siunitx(inv_temps),
        siunitx(sigma_c_val, sigma_c_err),
    ))

    print('Ht_eV:', siunitx(Ht_eV_val, Ht_eV_err))

    T['Ht_eV'] = siunitx(Ht_eV_val, Ht_eV_err)

    pl.errorbar(temps_val, taus_bar_val, xerr=temps_err, yerr=taus_bar_err,
                label=r'$\bar\tau$', linestyle='none', marker='+')
    dandify_plot()
    pl.xlabel('T / K')
    pl.ylabel(r'$\bar\tau$ / ns')
    pl.savefig('_build/mpl-s_curve.pdf')
    pl.savefig('_build/mpl-s_curve.png')
    pl.clf()
    np.savetxt('_build/xy/s_curve.tsv',
               np.column_stack([temps_val, taus_bar_val, taus_bar_err]))
Пример #38
0
def job_br_theory(T):
    width_hadron = 2 * 299 + 3 * 378
    width_lepton = 83.8

    T['br_theory'] = siunitx(width_hadron / width_lepton)
Пример #39
0
def bootstrap_driver(T):
    # Load all the input data from the files.
    lum_data = np.loadtxt('Data/luminosity.txt')
    lum_val = lum_data[:, 0]
    lum_err = lum_data[:, 3]
    radiative_hadrons = np.loadtxt('Data/radiative-hadrons.tsv')
    radiative_leptons = np.loadtxt('Data/radiative-leptons.tsv')
    raw_matrix = np.loadtxt('Data/matrix.txt').T
    mc_sizes = np.loadtxt('Data/monte-carlo-sizes.txt')
    filtered = np.loadtxt('Data/filtered.txt')

    # Some output into the template.
    T['luminosities_table'] = list(zip(siunitx(energies), siunitx(lum_val, lum_err)))
    T['radiative_cs_table'] = list(zip(
        siunitx(energies),
        siunitx(radiative_hadrons),
        siunitx(radiative_leptons),
    ))

    # Container for the results of each bootstrap run.
    results = []

    for r in range(SAMPLES):
        # Draw new numbers for the matrix.
        boot_matrix = bootstrap.redraw_count(raw_matrix)

        # Draw new luminosities.
        boot_lum_val = np.array([
            random.gauss(val, err)
            for val, err
            in zip(lum_val, lum_err)])

        # Draw new filtered readings.
        boot_readings = bootstrap.redraw_count(filtered)

        # Run the analysis on the resampled data and save the results.
        results.append(bootstrap_kernel(mc_sizes, boot_matrix, boot_readings,
                                        boot_lum_val, radiative_hadrons,
                                        radiative_leptons))

    # The `results` is a list which contains one entry per bootstrap run. This
    # is not particularly helpful as the different interesting quantities are
    # only on the second index on the list. The first index of the `results`
    # list is the bootstrap run index. Therefore we use the `zip(*x)` trick to
    # exchange the two indices. The result will be a list of quantities which
    # are themselves lists of the bootstrap samples. Then using Python tuple
    # assignments, we can split that (now) outer list into different
    # quantities. Each of the new variables created here is a list of R
    # bootstrap samples.
    x_dist, masses_dist, widths_dist, cross_sections_dist, y_dist, corr_dist, \
            matrix_dist, inverted_dist, readings_dist, peaks_dist, brs_dist, \
            width_electron_dist, width_flavors_dist, missing_width_dist, \
            width_lepton_dist, neutrino_families_dist, popts_dist, \
            mean_mass_dist, mean_width_dist \
            = zip(*results)

    # We only need one of the lists of the x-values as they are all the same.
    # So take the first and throw the others out.
    x = x_dist[0]

    # The masses and the widths that are given back from the `bootstrap_kernel`
    # are a list of four elements (electrons, muons, tauons, hadrons) each. The
    # variable `masses_dist` contains R copies of this four-list, one copy for
    # each bootstrap sample. We now average along the bootstrap dimension, that
    # is the outermost dimension. For each of the four masses, we take the
    # average along the R copies. This will give us four masses and four
    # masses-errors.
    masses_val, masses_err = bootstrap.average_and_std_arrays(masses_dist)
    widths_val, widths_err = bootstrap.average_and_std_arrays(widths_dist)
    peaks_val, peaks_err = bootstrap.average_and_std_arrays(peaks_dist)
    brs_val, brs_err = bootstrap.average_and_std_arrays(brs_dist)

    T['brs'] = siunitx(brs_val[0:3], brs_err[0:3])

    # Format masses and widths for the template.
    T['lorentz_fits_table'] = list(zip(
        display_names,
        siunitx(masses_val, masses_err),
        siunitx(widths_val, widths_err),
        siunitx(peaks_val, peaks_err),
    ))

    width_electron_val, width_electron_err = bootstrap.average_and_std_arrays(width_electron_dist)
    width_flavors_val, width_flavors_err = bootstrap.average_and_std_arrays(width_flavors_dist)

    T['width_electron_mev'] = siunitx(width_electron_val*1000, width_electron_err*1000)
    T['width_flavors_mev'] = siunitx(width_flavors_val*1000, width_flavors_err*1000)

    missing_width_val, missing_width_err = bootstrap.average_and_std_arrays(missing_width_dist)
    width_lepton_val, width_lepton_err = bootstrap.average_and_std_arrays(width_lepton_dist)
    neutrino_families_val, neutrino_families_err = bootstrap.average_and_std_arrays(neutrino_families_dist)

    T['missing_width_mev'] = siunitx(missing_width_val*1000, missing_width_err*1000)
    T['width_lepton_mev'] = siunitx(width_lepton_val*1000, width_lepton_err*1000)
    T['neutrino_families'] = siunitx(neutrino_families_val, neutrino_families_err)

    # Format original counts for the template.
    val, err = bootstrap.average_and_std_arrays(readings_dist)
    T['counts_table'] = []
    for i in range(7):
        T['counts_table'].append([siunitx(energies[i])] + siunitx(val[i, :], err[i, :], allowed_hang=10))

    # Format corrected counts for the template.
    val, err = bootstrap.average_and_std_arrays(corr_dist)
    T['corrected_counts_table'] = []
    for i in range(7):
        T['corrected_counts_table'].append([siunitx(energies[i])] + siunitx(val[i, :], err[i, :], allowed_hang=10))

    # Format matrix for the template.
    matrix_val, matrix_err = bootstrap.average_and_std_arrays(matrix_dist)
    T['matrix'] = []
    for i in range(4):
        T['matrix'].append([display_names[i]] + siunitx(matrix_val[i, :]*100, matrix_err[i, :]*100, allowed_hang=10))

    # Format inverted matrix for the template.
    inverted_val, inverted_err = bootstrap.average_and_std_arrays(inverted_dist)
    T['inverted'] = []
    for i in range(4):
        T['inverted'].append([display_names[i]] +
                             list(map(number_padding,
                             siunitx(inverted_val[i, :], inverted_err[i, :], allowed_hang=10))))

    # Format cross sections for the template.
    cs_val, cs_err = bootstrap.average_and_std_arrays(cross_sections_dist)
    T['cross_sections_table'] = []
    for i in range(7):
        T['cross_sections_table'].append([siunitx(energies[i])] + siunitx(cs_val[:, i], cs_err[:, i]))

    # Build error band for pgfplots.
    y_list_val, y_list_err = bootstrap.average_and_std_arrays(y_dist)
    for i, name in zip(itertools.count(), names):
        # Extract the y-values for the given decay type.
        y_val = y_list_val[i, :]
        y_err = y_list_err[i, :]

        # Store the data for pgfplots.
        np.savetxt('_build/xy/cross_section-{}s.tsv'.format(name),
                   np.column_stack([energies, cs_val[i, :], cs_err[i, :]]))
        np.savetxt('_build/xy/cross_section-{}s-band.tsv'.format(name),
                   bootstrap.pgfplots_error_band(x, y_val, y_err))
        np.savetxt('_build/xy/cross_section-{}s-fit.tsv'.format(name),
                   np.column_stack((x, y_val)))

    popts_val, popts_err = bootstrap.average_and_std_arrays(popts_dist)
    T['chi_sq'] = []
    T['chi_sq_red'] = []
    T['p'] = []
    for i in range(4):
        residuals = cs_val[i, :] - propagator(energies, *popts_val[i, :])
        chi_sq = np.sum((residuals / cs_err[i, :])**2)
        dof = len(residuals) - 1 - len(popts_val[i, :])
        p = 1 - scipy.stats.chi2.cdf(chi_sq, dof)

        print('chi_sq', chi_sq, chi_sq/dof, p)
        T['chi_sq'].append(siunitx(chi_sq))
        T['chi_sq_red'].append(siunitx(chi_sq/dof))
        T['p'].append(siunitx(p))

    T['confidence_table'] = list(zip(
        display_names,
        T['chi_sq'],
        T['chi_sq_red'],
        T['p'],
    ))

    mean_mass_val, mean_mass_err = bootstrap.average_and_std_arrays(mean_mass_dist)
    mean_width_val, mean_width_err = bootstrap.average_and_std_arrays(mean_width_dist)

    T['mean_mass'] = siunitx(mean_mass_val, mean_mass_err)
    T['mean_width'] = siunitx(mean_width_val, mean_width_err)
Пример #40
0
def lande_factors(T, centers_val, centers_err):
    isomeric_val = np.mean(centers_val)
    isomeric_err = np.sqrt(np.mean(centers_err**2))

    factor_val = speed_of_light * B_val * magneton / hbar_omega0_joule
    factor_err = speed_of_light * B_err * magneton / hbar_omega0_joule

    T['isomeric_mm_s'] = siunitx(isomeric_val / 1e-3, isomeric_err / 1e-3)
    T['isomeric_nev'] = siunitx(
        hbar_omega0_ev * isomeric_val / speed_of_light / 1e-9,
        hbar_omega0_ev * isomeric_err / speed_of_light / 1e-9)

    if True:
        v_shift_e_val = -np.mean([
            #centers_val[2] - centers_val[0],
            centers_val[3] - centers_val[1],
            centers_val[4] - centers_val[2],
            #centers_val[5] - centers_val[3],
        ])
        v_shift_e_err = np.std([
            #centers_val[2] - centers_val[0],
            centers_val[3] - centers_val[1],
            centers_val[4] - centers_val[2],
            #centers_val[5] - centers_val[3],
        ])
        v_shift_e_err = np.sqrt(
            np.mean([
                centers_err[1]**2,
                centers_err[2]**2,
                centers_err[3]**2,
                centers_err[4]**2,
            ]))

        v_shift_q_val = ((centers_val[5] - centers_val[4]) -
                         (centers_val[1] - centers_val[0])) / 2
        v_shift_q_err = np.sqrt(centers_err[0]**2 + centers_err[2]**2 +
                                centers_err[3]**2 + centers_err[5]**2) / 2

        v_shift_g_val = np.mean([
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
        ])
        v_shift_g_err = np.std([
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
        ])
    else:
        v_shift_e_val = -np.mean([
            centers_val[1] - centers_val[0],
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
            centers_val[5] - centers_val[4],
        ])
        v_shift_e_err = np.std([
            centers_val[1] - centers_val[0],
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
            centers_val[5] - centers_val[4],
        ])
        #v_shift_e_err = np.sqrt(np.mean(centers_err**2))

        v_shift_g_val = np.mean([
            centers_val[4] - centers_val[0],
            centers_val[5] - centers_val[1],
        ])
        v_shift_g_err = np.std([
            centers_val[4] - centers_val[0],
            centers_val[5] - centers_val[1],
        ])

    lande_e_val = v_shift_e_val / factor_val
    lande_g_val = v_shift_g_val / factor_val
    lande_e_err = np.sqrt((v_shift_e_err / factor_val)**2 +
                          (v_shift_e_val / factor_val**2 * factor_err)**2)
    lande_g_err = np.sqrt((v_shift_g_err / factor_val)**2 +
                          (v_shift_g_val / factor_val**2 * factor_err)**2)

    T['v_shift_g'] = siunitx(v_shift_g_val / 1e-3, v_shift_g_err / 1e-3)
    T['v_shift_e'] = siunitx(v_shift_e_val / 1e-3, v_shift_e_err / 1e-3)
    T['v_shift_q'] = siunitx(v_shift_q_val / 1e-3,
                             v_shift_q_err / 1e-3,
                             error_digits=2)
    T['lande_g'] = siunitx(lande_g_val, lande_g_err)
    T['lande_e'] = siunitx(lande_e_val, lande_e_err)
Пример #41
0
def get_acryl_data(T, slope_val, width):
    data = np.loadtxt('Data/longlong.txt')
    channel = data[:, 0]
    time = slope_val * channel
    counts = data[:, 1]

    x = np.linspace(np.min(time), np.max(time), 500)

    fit_func = lambda t, mean, A_0, A_t, tau_0, tau_t, BG: \
            np.log(models.lifetime_spectrum(t, mean, width, A_0, A_t, tau_0, tau_t, BG))

    results = []

    sel1 = (10.92 < time) & (time < 11.58)
    sel2 = (13.11 < time) & (time < 22)
    sels = [sel1, sel2]

    x1 = np.linspace(np.min(time[sel1]), np.max(time[sel1]), 10)
    x2 = np.linspace(np.min(time[sel2]), np.max(time[sel2]), 10)

    for sample_id in range(BOOTSTRAP_SAMPLES):
        print('Bootstrap sample', sample_id, 'running …')

        boot_counts = bootstrap.redraw_count(counts)

        lin_lifetimes = []
        lin_results = []
        for sel_lin, x_lin in zip(sels, [x1, x2]):
            popt_lin, pconv_lin = op.curve_fit(exp_decay, time[sel_lin], boot_counts[sel_lin], p0=[1e5, 0.3])
            y_lin = exp_decay(x_lin, *popt_lin)

            lin_results.append(y_lin)
            lin_results.append(popt_lin)
            lin_results.append(1/popt_lin[1])
            lin_lifetimes.append(1/popt_lin[1])

        sel = (10 < time) & (time < 50) & (boot_counts > 0)

        p0 = [10.5, 13e3, 34e2] + lin_lifetimes + [2]
        popt, pconv = op.curve_fit(fit_func, time[sel], np.log(boot_counts[sel]), p0=p0)
        mean, A_0, A_t, tau_0, tau_t, BG = popt

        intens_0 = A_0 / (A_0 + A_t)
        intens_t = A_t / (A_0 + A_t)
        tau_bar = intens_0 * tau_0 + intens_t * tau_t
        y = np.exp(fit_func(x, *popt))
        tau_f = 1 / (intens_0 / tau_0 - intens_t / tau_t)
        sigma_c = 1 / tau_0 - 1 / tau_f

        results.append([
            tau_0,
            tau_bar,
            tau_f,
            tau_t,
            intens_0,
            intens_t,
            y,
            popt,
            sigma_c,
        ] + lin_results)
        
    tau_0_dist, tau_bar_dist, tau_f_dist, tau_t_dist, intens_0_dist, \
            intens_t_dist, lifetime_y_dist, lifetime_popt_dist, sigma_c_dist, \
            y_lin1_dist, popt_lin1_dist, tau_lin1_dist, \
            y_lin2_dist, popt_lin2_dist, tau_lin2_dist, \
            = zip(*results)

    tau_0_val, tau_0_err = bootstrap.average_and_std_arrays(tau_0_dist)
    tau_t_val, tau_t_err = bootstrap.average_and_std_arrays(tau_t_dist)
    tau_f_val, tau_f_err = bootstrap.average_and_std_arrays(tau_f_dist)
    tau_bar_val, tau_bar_err = bootstrap.average_and_std_arrays(tau_bar_dist)

    popt_val, popt_err = bootstrap.average_and_std_arrays(lifetime_popt_dist)
    y_val, y_err = bootstrap.average_and_std_arrays(lifetime_y_dist)

    popt_lin1_val, popt_lin1_err = bootstrap.average_and_std_arrays(popt_lin1_dist)
    y_lin1_val, y_lin1_err = bootstrap.average_and_std_arrays(y_lin1_dist)
    tau_lin1_val, tau_lin1_err = bootstrap.average_and_std_arrays(tau_lin1_dist)
    popt_lin2_val, popt_lin2_err = bootstrap.average_and_std_arrays(popt_lin2_dist)
    y_lin2_val, y_lin2_err = bootstrap.average_and_std_arrays(y_lin2_dist)
    tau_lin2_val, tau_lin2_err = bootstrap.average_and_std_arrays(tau_lin2_dist)

    print('tau_0', siunitx(tau_0_val, tau_0_err))
    print('tau_t', siunitx(tau_t_val, tau_t_err))
    print('tau_f', siunitx(tau_f_val, tau_f_err))
    print('tau_bar', siunitx(tau_bar_val, tau_bar_err))

    T['acryl_tau_0'] = siunitx(tau_0_val, tau_0_err)
    T['acryl_tau_t'] = siunitx(tau_t_val, tau_t_err)
    T['acryl_tau_f'] = siunitx(tau_f_val, tau_f_err)
    T['acryl_tau_bar'] = siunitx(tau_bar_val, tau_bar_err)

    print('popt', siunitx(popt_val, popt_err))
    print('popt_lin1', siunitx(popt_lin1_val, popt_lin1_err))
    print('popt_lin2', siunitx(popt_lin2_val, popt_lin2_err))
    print('tau_lin1', siunitx(tau_lin1_val, tau_lin1_err))
    print('tau_lin2', siunitx(tau_lin2_val, tau_lin2_err))

    T['acryl_tau_0_lin'] = siunitx(tau_lin1_val, tau_lin1_err)
    T['acryl_tau_t_lin'] = siunitx(tau_lin2_val, tau_lin2_err)

    print(x.shape)
    print(y_lin1_val.shape)

    pl.plot(time, counts, color='black', alpha=0.3)
    counts_smooth = scipy.ndimage.filters.gaussian_filter1d(counts, 8)
    pl.plot(time, counts_smooth, color='green')
    pl.fill_between(x, y_val - y_err, y_val + y_err, alpha=0.5, color='red')
    pl.plot(x, y_val, color='red')
    pl.xlabel('Time / ns')
    pl.ylabel('Counts')
    dandify_plot()
    #pl.xlim((8, 20))
    pl.ylim((0.1, np.max(counts)*1.1))
    pl.savefig('_build/mpl-lifetime-acryl.pdf')
    pl.savefig('_build/mpl-lifetime-acryl.png')
    pl.yscale('log')
    pl.fill_between(x1, y_lin1_val - y_lin1_err, y_lin1_val + y_lin1_err, alpha=0.5, color='blue')
    pl.fill_between(x2, y_lin2_val - y_lin2_err, y_lin2_val + y_lin2_err, alpha=0.5, color='blue')
    pl.plot(x1, y_lin1_val, color='blue', alpha=0.5)
    pl.plot(x2, y_lin2_val, color='blue', alpha=0.5)
    dandify_plot()
    pl.savefig('_build/mpl-lifetime-acryl-log.pdf')
    pl.savefig('_build/mpl-lifetime-acryl-log.png')
    #pl.show()
    pl.clf()

    np.savetxt('_build/xy/acryl-lifetime-data.tsv',
               np.column_stack([time, counts]))

    np.savetxt('_build/xy/acryl-lifetime-smoothed.tsv',
               np.column_stack([time, counts_smooth]))

    np.savetxt('_build/xy/acryl-lifetime-fit.tsv',
               np.column_stack([x, y_val]))
    np.savetxt('_build/xy/acryl-lifetime-band.tsv',
               bootstrap.pgfplots_error_band(x, y_val, y_err))

    np.savetxt('_build/xy/acryl-lifetime-fit-lin1.tsv',
               np.column_stack([x1, y_lin1_val]))
    np.savetxt('_build/xy/acryl-lifetime-band-lin1.tsv',
               bootstrap.pgfplots_error_band(x1, y_lin1_val, y_lin1_err))

    np.savetxt('_build/xy/acryl-lifetime-fit-lin2.tsv',
               np.column_stack([x2, y_lin2_val]))
    np.savetxt('_build/xy/acryl-lifetime-band-lin2.tsv',
               bootstrap.pgfplots_error_band(x2, y_lin2_val, y_lin2_err))
Пример #42
0
def job_br_theory(T):
    width_hadron = 2*299 + 3*378
    width_lepton = 83.8

    T['br_theory'] = siunitx(width_hadron / width_lepton)
Пример #43
0
def michelson_resolution(T):

    d_cm = np.sort(np.loadtxt('Data/lissajous_X.tsv'))
    order = np.arange(0, len(d_cm))

    wavelength = 987e-9

    # get theoretical values
    n_ground_theor = 1 + 1e-8 * (8342.13 + 2406030 /
                                 (130 - 1 / (wavelength * 1e6)**2) + 15997 /
                                 (38.9 - 1 / (wavelength * 1e6)**2))
    T['n_ground_theor'] = siunitx(n_ground_theor - 1)

    n_harm_theor = 1 + 1e-8 * (8342.13 + 2406030 /
                               (130 - 1 / (wavelength * .5e6)**2) + 15997 /
                               (38.9 - 1 / (wavelength * .5e6)**2))
    T['n_harm_theor'] = siunitx(n_harm_theor - 1)

    delta_n_theor = n_harm_theor - n_ground_theor
    T['delta_n_theor'] = siunitx(delta_n_theor)

    # prepare arrays
    slope_dist_cm = []
    offset_dist_cm = []
    delta_n_dist = []
    dev_ratio_dist = []
    res_michelson_dist = []

    fit_y_dist = []

    # perform Jackknife
    for i in range(len(d_cm)):
        x = np.delete(order, i)
        y = np.delete(d_cm, i)

        popt, pconv = op.curve_fit(linear, x, y)

        slope_dist_cm.append(popt[0])
        offset_dist_cm.append(popt[1])

        fit_y_dist.append(linear(order, *popt))

        # experimental value for difference in refractive index
        delta_n = wavelength / (8 * popt[0] * 1e-2)
        delta_n_dist.append(delta_n)

        # deviation from optimal 1/2 ratio
        dev_ratio_dist.append(.5 * delta_n / n_harm_theor)

        # resolution of michelson interferometer
        delta_wavelength = wavelength * (delta_n / n_ground_theor**2)
        res_michelson_dist.append(wavelength / delta_wavelength)

    # get averages and std
    slope_val_cm, slope_err_cm = bootstrap.average_and_std_arrays(
        slope_dist_cm)
    offset_val_cm, offset_err_cm = bootstrap.average_and_std_arrays(
        offset_dist_cm)

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)

    delta_n_val, delta_n_err = bootstrap.average_and_std_arrays(delta_n_dist)

    dev_ratio_val, dev_ratio_err = bootstrap.average_and_std_arrays(
        dev_ratio_dist)
    dev_ratio_theor = .5 * (delta_n_theor / n_harm_theor)

    res_michelson_val, res_michelson_err = bootstrap.average_and_std_arrays(
        res_michelson_dist)

    # write into T
    T['distance_lissajous_X'] = siunitx(slope_val_cm, slope_err_cm)
    T['delta_n'] = siunitx(delta_n_val, delta_n_err)
    T['dev_ratio'] = siunitx(dev_ratio_val, dev_ratio_err)
    T['dev_ratio_theor'] = siunitx(dev_ratio_theor)
    T['res_michelson'] = siunitx(res_michelson_val, res_michelson_err)

    # write data for plot

    np.savetxt('_build/xy/michelson-line.tsv', np.column_stack([order, d_cm]))
    np.savetxt('_build/xy/michelson-band.tsv',
               bootstrap.pgfplots_error_band(order, fit_y_val, fit_y_err))

    T['mirror_position_table'] = list(zip(siunitx(d_cm)))
    print(siunitx(dev_ratio_val, dev_ratio_err))
    print(siunitx(dev_ratio_theor))
    print(siunitx(res_michelson_val, res_michelson_err))
Пример #44
0
def job_power(T):
    data = np.loadtxt('Data/diode.tsv')
    norm_current = data[:, 0] * 1e-3
    norm_power_val = data[:, 1] * 1e-3
    norm_power_err = np.ones(norm_power_val.shape) * 1e-6
    norm_power_dist = bootstrap.make_dist(norm_power_val, norm_power_err)

    data = np.loadtxt('Data/diode_damped.tsv')
    damp_current = data[:, 0] * 1e-3
    damp_power_val = data[:, 1] * 1e-3
    damp_power_err = data[:, 2] * 1e-3
    damp_power_dist = bootstrap.make_dist(damp_power_val, damp_power_err)

    np.savetxt('_build/xy/diode_normal-data.tsv',
               np.column_stack([norm_current, norm_power_val, norm_power_err]))
    np.savetxt('_build/xy/diode_damped-data.tsv',
               np.column_stack([damp_current, damp_power_val, damp_power_err]))

    T['diode_normal_table'] = list(
        zip(
            siunitx(norm_current * 1e3),
            siunitx(norm_power_val * 1e6, norm_power_err * 1e6,
                    allowed_hang=6),
        ))
    T['diode_damped_table'] = list(
        zip(
            siunitx(damp_current * 1e3),
            siunitx(damp_power_val * 1e6, damp_power_err * 1e6),
        ))

    hbar_omega = 6.626e-34 * 3e8 / 987e-9
    electron_charge = 1.609e-19

    # Find the threshold current.
    sel = norm_power_val > 1e-3
    slope_dist = []
    quantum_efficiency_dist = []
    threshold_dist = []
    threshold_fit_x = np.linspace(0.05, 0.09, 100)
    threshold_fit_y_dist = []
    # Jackknife fit to find root.
    for i in range(len(norm_power_val[sel])):
        x = np.delete(norm_current[sel], i)
        y_val = np.delete(norm_power_val[sel], i)
        y_err = np.delete(norm_power_err[sel], i)
        popt, pconv = op.curve_fit(linear, x, y_val, sigma=y_err)
        a, b = popt
        root = -b / a
        threshold_dist.append(root)
        threshold_fit_y_dist.append(linear(threshold_fit_x, *popt))
        slope_dist.append(a)
        quantum_efficiency_dist.append(a * electron_charge / hbar_omega)
    threshold_val, threshold_err = bootstrap.average_and_std_arrays(
        threshold_dist)
    threshold_fit_y_val, threshold_fit_y_err = bootstrap.average_and_std_arrays(
        threshold_fit_y_dist)
    differential_efficiency_val, differential_efficiency_err = bootstrap.average_and_std_arrays(
        slope_dist)
    quantum_efficiency_val, quantum_efficiency_err = bootstrap.average_and_std_arrays(
        quantum_efficiency_dist)

    T['threshold'] = siunitx(threshold_val, threshold_err)
    T['differential_efficiency'] = siunitx(differential_efficiency_val,
                                           differential_efficiency_err)
    T['quantum_efficiency'] = siunitx(quantum_efficiency_val,
                                      quantum_efficiency_err)

    np.savetxt(
        '_build/xy/diode_normal-band.tsv',
        bootstrap.pgfplots_error_band(threshold_fit_x, threshold_fit_y_val,
                                      threshold_fit_y_err))

    # Compare ratios of damped and normal power in the overlap range.
    ratio_dist = []
    x = np.linspace(70.1e-3, 86.9e-3, 20)
    for norm_power, damp_power in zip(norm_power_dist, damp_power_dist):
        norm_inter = scipy.interpolate.interp1d(norm_current, norm_power)
        damp_inter = scipy.interpolate.interp1d(damp_current, damp_power)
        a = norm_inter(x)
        b = damp_inter(x)
        ratio = a / b
        ratio_dist.append(ratio)

    ratio_val, ratio_err = bootstrap.average_and_std_arrays(ratio_dist)

    extinction_dist = np.array(ratio_dist).flatten()
    extinction_val, extinction_err = np.mean(ratio_dist), np.std(ratio_dist)
    T['extinction'] = siunitx(extinction_val, extinction_err)

    np.savetxt('_build/xy/diode-ratio-line.tsv',
               np.column_stack([x, ratio_val]))
    np.savetxt('_build/xy/diode-ratio-band.tsv',
               bootstrap.pgfplots_error_band(x, ratio_val, ratio_err))

    return extinction_dist
Пример #45
0
def job_afb_analysis(T):
    data = np.loadtxt('Data/radiative_corrections.tsv')
    corrections = data[:, 1]

    energies = np.loadtxt('Data/energies.txt')
    data = np.loadtxt('Data/afb.txt')
    negative = data[:, 0]
    positive = data[:, 1]

    results = []
    for i in range(SAMPLES):
        positive_boot = bootstrap.redraw_count(positive)
        negative_boot = bootstrap.redraw_count(negative)

        result = afb_kernel(positive_boot, negative_boot, corrections)
        if result is not None:
            results.append(result)

    afb_corr_dist, sin_sq_dist = zip(*results)

    afb_filt, sin_sq_filt = zip(*[(x[3], y)
                                  for x, y in zip(afb_corr_dist, sin_sq_dist)
                                  if not np.isnan(y)])

    print('afb:', len(afb_corr_dist), len(afb_filt))

    T['sin_sq_bootstrap_acceptance'] = siunitx(
        (1 - len(sin_sq_filt) / len(sin_sq_dist)) * 100)

    afb_val, afb_err = bootstrap.average_and_std_arrays(afb_corr_dist)
    sin_sq_val, sin_sq_err = bootstrap.average_and_std_arrays(sin_sq_filt)

    afb_val, sin_sq_val = afb_kernel(positive, negative, corrections)

    sin_sq_up, sin_sq_down = bootstrap.percentile_arrays(
        sin_sq_filt, sin_sq_val)

    print('sin_sq:', sin_sq_val, sin_sq_err, sin_sq_up, sin_sq_down)

    np.savetxt('_build/xy/afb.tsv',
               np.column_stack([energies, afb_val, afb_err]))

    T['afb_table'] = list(zip(
        siunitx(energies),
        siunitx(afb_val, afb_err),
    ))

    T['sin_sq_afb'] = siunitx(sin_sq_val, sin_sq_err)

    T['sin_sq_afb_asym'] = '{:.3f}^{{+{:.3f}}}_{{-{:.3f}}}'.format(
        sin_sq_val, sin_sq_up, sin_sq_down)

    counts, bins = np.histogram(sin_sq_filt)
    counts = np.array(list(counts) + [counts[-1]])
    print(bins.shape, counts.shape)
    np.savetxt('_build/xy/sin_sq_hist.tsv', np.column_stack([bins, counts]))

    counts, bins = np.histogram([x[3] for x in afb_corr_dist])
    counts = np.array(list(counts) + [counts[-1]])
    print(bins.shape, counts.shape)
    np.savetxt('_build/xy/afb_hist.tsv', np.column_stack([bins, counts]))

    counts, bins = np.histogram(afb_filt, bins=bins)
    counts = np.array(list(counts) + [counts[-1]])
    print(bins.shape, counts.shape)
    np.savetxt('_build/xy/afb_filt_hist.tsv', np.column_stack([bins, counts]))
Пример #46
0
def job_atom_number(T):
    wavelength_nm = 780
    beam_power_mW = 2 * (3.57 + 3.36 + 4.45)
    mot_power_nW_val, mot_power_nW_err = get_mot_power_nw(T)
    lens_distance_cm_val = 10
    lens_distance_cm_err = 1
    lens_radius_cm_val = 2.54 / 2

    omega_val = np.pi * lens_radius_cm_val ** 2 / (lens_distance_cm_val ** 2)
    omega_err = 2 * np.pi * lens_radius_cm_val ** 2 / (lens_distance_cm_val ** 3) * lens_distance_cm_err

    mot_power_tot_nW_val = mot_power_nW_val * 4 * np.pi / omega_val
    mot_power_tot_nW_err = np.sqrt(
        (mot_power_nW_err * 4 * np.pi / omega_val) ** 2
        + (mot_power_nW_val * 4 * np.pi / omega_val ** 2 * omega_err) ** 2
    )

    diameter_cm_val, diameter_cm_err = job_diameter(T)

    beam_area_cm_val = np.pi * diameter_cm_val ** 2 / 4
    beam_area_cm_err = np.pi * diameter_cm_val / 2 * diameter_cm_err

    intens_mW_cm2_val = beam_power_mW / beam_area_cm_val
    intens_mW_cm2_err = beam_power_mW / beam_area_cm_val ** 2 * beam_area_cm_err

    hbar = 1.054571800e-34
    hbar_omega_nW_MHz = hbar * 1e15 * 2 * np.pi * 3e8 / (wavelength_nm * 1e-9)

    detuning_MHz_val, detuning_MHz_err = map(abs, job_scan_cooling(T))
    scattering_rate_MHz_val, scattering_rate_MHz_err = get_scattering_rate_MHz(
        T, intens_mW_cm2_val, intens_mW_cm2_err, detuning_MHz_val, detuning_MHz_err
    )

    atom_number_val = mot_power_tot_nW_val / hbar_omega_nW_MHz / scattering_rate_MHz_val
    atom_number_err = np.sqrt(
        (mot_power_tot_nW_err / hbar_omega_nW_MHz / scattering_rate_MHz_val) ** 2
        + (mot_power_tot_nW_val / hbar_omega_nW_MHz / scattering_rate_MHz_val ** 2 * scattering_rate_MHz_err) ** 2
    )

    T["atom_number"] = siunitx(atom_number_val, atom_number_err)
    T["beam_area_cm"] = siunitx(beam_area_cm_val, beam_area_cm_err)
    T["hbar_omega_nW_MHz"] = siunitx(hbar_omega_nW_MHz)
    T["intens_mW_cm2"] = siunitx(intens_mW_cm2_val, intens_mW_cm2_err)
    T["lens_distance_cm"] = siunitx(lens_distance_cm_val, lens_distance_cm_err)
    T["lens_radius_cm"] = siunitx(lens_radius_cm_val)
    T["mot_omega"] = siunitx(omega_val, omega_err)
    T["mot_power_nW"] = siunitx(mot_power_nW_val, mot_power_nW_err)
    T["mot_power_tot_nW"] = siunitx(mot_power_tot_nW_val, mot_power_tot_nW_err)
    T["scattering_rate_MHz"] = siunitx(scattering_rate_MHz_val, scattering_rate_MHz_err)
    T["total_beam_power_mW"] = siunitx(beam_power_mW)
    T["wavelength_nm"] = siunitx(wavelength_nm)
Пример #47
0
def job_loading(T):
    res_max = []
    res_slope = []
    for i, directory in zip(itertools.count(),
                            ['0002', '0003', '0004', '0005', '0006', '0007']):
        data_x, data_y = trek.load_dir(directory)
        data_x, data_y = data_x[120:-500], data_y[120:-500]

        lower = np.where(data_y > .095)[0][0]

        fit_x = np.linspace(data_x[lower - 20], data_x[-1], 100)
        popt, pconv = op.curve_fit(loading, data_x[lower:], data_y[lower:])
        res_max.append(popt[0])
        res_slope.append(1 / popt[1])
        fit_y = loading(fit_x, *popt)
        # pl.plot(data_x, data_y)
        # pl.plot(fit_x, fit_y)
        # pl.show()
        # pl.clf()

        avg_before = np.mean(data_y[:lower])

        stretched_data = stretch(data_y, avg_before, 0, popt[0], 1)
        stretched_fit = stretch(fit_y, avg_before, 0, popt[0], 1)

        np.savetxt('_build/xy/loading-{}-data.tsv'.format(i),
                   np.column_stack([data_x - data_x[lower], stretched_data]))
        np.savetxt('_build/xy/loading-{}-fit.tsv'.format(i),
                   np.column_stack([fit_x - data_x[lower], stretched_fit]))

    maximum_val, maximum_err = np.mean(res_max), np.std(res_max)
    slope_val, slope_err = np.mean(res_slope), np.std(res_slope)

    T['loading_maximum'] = siunitx(maximum_val, maximum_err)
    T['loading_lifetime'] = siunitx(slope_val, slope_err)

    mass = 85 * 1.66e-27

    pressure_dist = [1.1e-5, 1.5e-5]
    pressure_val = np.mean(pressure_dist)
    pressure_err = np.std(pressure_dist)

    temperature = 24 + 273

    k_boltzmann = 1.3806e-23

    velocity = np.sqrt(temperature * k_boltzmann / mass)

    density_val = pressure_val / (k_boltzmann * temperature)
    density_err = pressure_err / (k_boltzmann * temperature)

    cross_section_val = 1 / (slope_val * density_val * velocity)
    cross_section_err = np.sqrt((slope_err /
                                 (slope_val**2 * density_val * velocity))**2 +
                                (density_err /
                                 (slope_val * density_val**2 * velocity))**2)

    T['cross_section'] = siunitx(cross_section_val, cross_section_err)
    T['density'] = siunitx(density_val, density_err)
    T['pressure'] = siunitx(pressure_val, pressure_err)
    T['rubidium_mass'] = siunitx(mass)
    T['velocity'] = siunitx(velocity)
Пример #48
0
def job_harmonic_power(T, extinction_dist, input_popt_dist):
    data = np.loadtxt('Data/harmonic_splitter.tsv')
    angle = data[:, 0]
    power_val = data[:, 1] * 1e-6
    power_err = data[:, 2] * 1e-6

    T['harmonic_splitter_table'] = list(
        zip(
            siunitx(angle),
            siunitx(power_val * 1e6, power_err * 1e6),
        ))

    power_dist = bootstrap.make_dist(power_val, power_err)

    fit_x = np.linspace(np.min(angle), np.max(angle), 200)
    fit_y_dist = []
    angle_offset_dist = []
    a_dist = []
    b_dist = []
    popt_dist = []
    for power in power_dist:
        popt, pconv = op.curve_fit(cos_quartic,
                                   angle,
                                   power,
                                   p0=[1.5e-5, 0, 0])
        fit_y_dist.append(cos_quartic(fit_x, *popt))
        angle_offset_dist.append(popt[1])
        a = popt[0]
        b = popt[2]
        a_dist.append(a)
        b_dist.append(b)
        popt_dist.append(popt)
    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)
    angle_offset_val, angle_offset_err = bootstrap.average_and_std_arrays(
        angle_offset_dist)
    a_val, a_err = bootstrap.average_and_std_arrays(a_dist)
    b_val, b_err = bootstrap.average_and_std_arrays(b_dist)

    np.savetxt('_build/xy/harmonic-splitter-data.tsv',
               np.column_stack([angle, power_val, power_err]))
    np.savetxt('_build/xy/harmonic-splitter-fit.tsv',
               np.column_stack([fit_x, fit_y_val]))
    np.savetxt('_build/xy/harmonic-splitter-band.tsv',
               bootstrap.pgfplots_error_band(fit_x, fit_y_val, fit_y_err))
    T['splitter_angle_offset'] = siunitx(angle_offset_val, angle_offset_err)
    T['splitter_a'] = siunitx(a_val, a_err)
    T['splitter_b'] = siunitx(b_val, b_err)

    efficiency_dist = []
    efficiency_sq_dist = []
    for extinction, input_popt, popt in zip(extinction_dist, input_popt_dist,
                                            popt_dist):
        efficiency = popt[0] / (input_popt[0] * extinction)
        efficiency_dist.append(efficiency)
        efficiency_sq = popt[0] / (input_popt[0] * extinction)**2
        efficiency_sq_dist.append(efficiency_sq)
    efficiency_val, efficiency_err = bootstrap.average_and_std_arrays(
        efficiency_dist)
    efficiency_sq_val, efficiency_sq_err = bootstrap.average_and_std_arrays(
        efficiency_sq_dist)
    T['efficiency'] = siunitx(efficiency_val, efficiency_err)
    T['efficiency_sq'] = siunitx(efficiency_sq_val, efficiency_sq_err)
Пример #49
0
def time_gauge(T, show_gauss=False, show_lin=False):
    time = []
    channel_val = []
    channel_err = []

    # go through all six prompt-files
    for i in range(1,7):
        time_raw = np.loadtxt('Data/prompt-{}.txt'.format(i))
        channel = time_raw[:,0]
        counts = time_raw[:,1]
        if i==1:
            counts_tot = counts
        elif i<6:
            counts_tot += counts
        
         # bootstrap:
         # - draw new counts from gaussian distribution with width of 'sqrt(N)'
         # - fit gaussian distribution to drawn data
         # - add mean to array
        mean = []
        width = []
        amplitude = []
        for a in range(BOOTSTRAP_SAMPLES):
            boot_counts = redraw_count(counts)
            popt, pconv = op.curve_fit(gauss, channel, boot_counts, p0=[400+i*600, 200, 100])
            mean.append(popt[0])
            width.append(popt[1])
            amplitude.append(popt[2])

        # find average and standard deviation in arrays
        mean_val, mean_err = bootstrap.average_and_std_arrays(mean)
        width_val, width_err = bootstrap.average_and_std_arrays(width)
        amplitude_val, amplitude_err = bootstrap.average_and_std_arrays(amplitude)

        # create files for prompt curve fits
        x = np.linspace(mean_val-200, mean_val+200, 100)
        y = gauss(x, mean_val, width_val, amplitude_val)

        np.savetxt('_build/xy/prompt-{}-fit.txt'.format(i), np.column_stack([x, y]))

        # write result into new channel arrays
        channel_val.append(mean_val)
        channel_err.append(mean_err)

        # write real time for gauging
        time.append((i-1)*4)

    # write files for prompt curve plotting
    np.savetxt('_build/xy/prompts-short.txt',
               bootstrap.pgfplots_error_band(channel[500:3500], counts_tot[500:3500], np.sqrt(counts_tot[500:3500])))
    np.savetxt('_build/xy/prompts-long.txt',
               bootstrap.pgfplots_error_band(channel[3600:4200], counts[3600:4200], np.sqrt(counts[3600:4200])))

    # convert lists to arrays
    channel_val = np.array(channel_val)
    channel_err = np.array(channel_err)
    time = np.array(time)

    T['time_gauge_param'] = list(zip(
        map(str, time),
        siunitx(channel_val, channel_err)
    ))

    # linear fit with delete-1-jackknife
    slope = []
    intercept = []
    y_dist = []
    x = np.linspace(750, 4000, 100)
    for i in range(len(channel_val)):
        channel_jackknife = np.delete(channel_val, i)
        time_jackknife = np.delete(time, i)
        
        popt, pconv = op.curve_fit(linear, channel_jackknife, time_jackknife)
        
        slope.append(popt[0])
        intercept.append(popt[1])

        y = linear(x, *popt)

        y_dist.append(y)

        if show_lin:
            x = np.linspace(0, 4000, 1000)
            y = linear(x, *popt)
            pl.plot(channel_val, time, linestyle="none", marker="o")
            pl.plot(x, y)
            pl.show()
            pl.clf()

    slope_val, slope_err = bootstrap.average_and_std_arrays(slope)
    intercept_val, intercept_err = bootstrap.average_and_std_arrays(intercept)
    y_val, y_err = bootstrap.average_and_std_arrays(y_dist)

    # files for fit and plot of time gauge 

    np.savetxt('_build/xy/time_gauge_plot.txt',
               np.column_stack([channel_val,time, channel_err]))
    np.savetxt('_build/xy/time_gauge_fit.txt',
               np.column_stack([x, y_val]))
    np.savetxt('_build/xy/time_gauge_band.txt',
               bootstrap.pgfplots_error_band(x, y_val, y_err))
        
    T['time_gauge_slope'] = siunitx(slope_val*1e3, slope_err*1e3)
    T['time_gauge_intercept'] = siunitx(intercept_val, intercept_err)

    # time resolution

    T['width_6'] = siunitx(width_val , width_err)
    FWHM_val = 2*np.sqrt(2*np.log(2)) * width_val 
    FWHM_err = 2*np.sqrt(2*np.log(2)) * width_err 
    T['FWHM_6'] = siunitx(FWHM_val , FWHM_err)
    
    time_res = FWHM_val * slope_val
    time_res_err = np.sqrt((FWHM_val * slope_err)**2 + (FWHM_err * slope_val)**2)
    T['time_resolution'] = siunitx(time_res , time_res_err)
    return slope_val, width_val*slope_val
Пример #50
0
def michelson_resolution(T):

    d_cm = np.sort(np.loadtxt('Data/lissajous_X.tsv'))
    order = np.arange(0,len(d_cm))

    wavelength = 987e-9

    # get theoretical values
    n_ground_theor = 1 + 1e-8 * (8342.13 + 2406030/(130-1/(wavelength*1e6)**2) + 15997/(38.9-1/(wavelength*1e6)**2))
    T['n_ground_theor'] = siunitx(n_ground_theor - 1)

    n_harm_theor = 1 + 1e-8 * (8342.13 + 2406030/(130-1/(wavelength*.5e6)**2) + 15997/(38.9-1/(wavelength*.5e6)**2)) 
    T['n_harm_theor'] = siunitx(n_harm_theor - 1)

    delta_n_theor = n_harm_theor - n_ground_theor
    T['delta_n_theor'] = siunitx(delta_n_theor)

    # prepare arrays
    slope_dist_cm = []
    offset_dist_cm = []
    delta_n_dist = []
    dev_ratio_dist = []
    res_michelson_dist = []

    fit_y_dist = []

    # perform Jackknife
    for i in range(len(d_cm)):
        x = np.delete(order, i)
        y = np.delete(d_cm, i)

        popt, pconv = op.curve_fit(linear, x, y)

        slope_dist_cm.append(popt[0])
        offset_dist_cm.append(popt[1])

        fit_y_dist.append(linear(order, *popt))

        # experimental value for difference in refractive index
        delta_n = wavelength/(8*popt[0]*1e-2)
        delta_n_dist.append(delta_n)

        # deviation from optimal 1/2 ratio
        dev_ratio_dist.append(.5*delta_n/n_harm_theor)

        # resolution of michelson interferometer
        delta_wavelength = wavelength * (delta_n/n_ground_theor**2)
        res_michelson_dist.append(wavelength/delta_wavelength)

    # get averages and std
    slope_val_cm, slope_err_cm = bootstrap.average_and_std_arrays(slope_dist_cm)
    offset_val_cm, offset_err_cm = bootstrap.average_and_std_arrays(offset_dist_cm)

    fit_y_val, fit_y_err = bootstrap.average_and_std_arrays(fit_y_dist)

    delta_n_val, delta_n_err = bootstrap.average_and_std_arrays(delta_n_dist)

    dev_ratio_val, dev_ratio_err = bootstrap.average_and_std_arrays(dev_ratio_dist)
    dev_ratio_theor = .5*(delta_n_theor/n_harm_theor)

    res_michelson_val, res_michelson_err = bootstrap.average_and_std_arrays(res_michelson_dist)

    # write into T
    T['distance_lissajous_X'] = siunitx(slope_val_cm, slope_err_cm)
    T['delta_n'] = siunitx(delta_n_val, delta_n_err)
    T['dev_ratio'] = siunitx(dev_ratio_val, dev_ratio_err)
    T['dev_ratio_theor'] = siunitx(dev_ratio_theor)
    T['res_michelson'] = siunitx(res_michelson_val, res_michelson_err)

    # write data for plot

    np.savetxt('_build/xy/michelson-line.tsv', np.column_stack([order, d_cm])) 
    np.savetxt('_build/xy/michelson-band.tsv', bootstrap.pgfplots_error_band(order, fit_y_val, fit_y_err))

    T['mirror_position_table'] = list(zip(
        siunitx(d_cm)
    ))
    print(siunitx(dev_ratio_val, dev_ratio_err))
    print(siunitx(dev_ratio_theor))
    print(siunitx(res_michelson_val, res_michelson_err))
Пример #51
0
def job_rayleigh_length(T):
    beam_diameter_val = 3.5e-3
    beam_diameter_err = 0.5e-3
    refractive_index = 2.2
    wavelength = 987e-9
    length = 5e-3
    distance = 60e-3

    beam_radius_val = beam_diameter_val / 2
    beam_radius_err = beam_diameter_err / 2

    T['beam_radius'] = siunitx(beam_radius_val, beam_radius_err)

    beam_radius_dist = bootstrap.make_dist(beam_radius_val, beam_diameter_err)

    theta_dist = [
        np.arctan(beam_radius / distance) for beam_radius in beam_radius_dist
    ]
    theta_val, theta_err = bootstrap.average_and_std_arrays(theta_dist)
    T['theta'] = siunitx(theta_val, theta_err)
    bootstrap.save_hist(theta_dist, '_build/dist-theta.pdf')

    waist_dist = [wavelength / (np.pi * theta) for theta in theta_dist]
    waist_val, waist_err = bootstrap.average_and_std_arrays(waist_dist)
    T['waist_mum'] = siunitx(waist_val / 1e-6, waist_err / 1e-6)
    bootstrap.save_hist(waist_dist, '_build/dist-waist.pdf')

    rayleigh_length_dist = list(
        itertools.filterfalse(np.isnan, [
            refractive_index * np.pi * waist**2 / wavelength
            for waist in waist_dist
        ]))
    rayleigh_length_val, rayleigh_length_err = bootstrap.average_and_std_arrays(
        rayleigh_length_dist)
    T['rayleigh_length_mm'] = siunitx(rayleigh_length_val / 1e-3,
                                      rayleigh_length_err / 1e-3,
                                      error_digits=2)
    bootstrap.save_hist(rayleigh_length_dist,
                        '_build/dist-rayleigh_length.pdf')

    normalized_length_dist = list([
        length / (2 * rayleigh_length)
        for rayleigh_length in rayleigh_length_dist
    ])
    normalized_length_val, normalized_length_err = bootstrap.average_and_std_arrays(
        normalized_length_dist)
    T['normalized_length'] = siunitx(normalized_length_val,
                                     normalized_length_err,
                                     error_digits=2)
    bootstrap.save_hist(normalized_length_dist,
                        '_build/dist-normalized_length.pdf')

    t = (normalized_length_val - 2.84) / normalized_length_err
    T['boyd_kleinman_ttest_t'] = siunitx(t)

    optimal_focal_length_dist = list([
        get_optimal_focal_length(beam_radius, refractive_index, wavelength,
                                 length) for beam_radius in beam_radius_dist
    ])
    optimal_focal_length_val, optimal_focal_length_err = bootstrap.average_and_std_arrays(
        optimal_focal_length_dist)
    T['optimal_focal_length_mm'] = siunitx(optimal_focal_length_val / 1e-3,
                                           optimal_focal_length_err / 1e-3,
                                           error_digits=2)
Пример #52
0
def job_power(T):
    data = np.loadtxt('Data/diode.tsv')
    norm_current = data[:, 0] * 1e-3
    norm_power_val = data[:, 1] * 1e-3
    norm_power_err = np.ones(norm_power_val.shape) * 1e-6
    norm_power_dist = bootstrap.make_dist(norm_power_val, norm_power_err)

    data = np.loadtxt('Data/diode_damped.tsv')
    damp_current = data[:, 0] * 1e-3
    damp_power_val = data[:, 1] * 1e-3
    damp_power_err = data[:, 2] * 1e-3
    damp_power_dist = bootstrap.make_dist(damp_power_val, damp_power_err)

    np.savetxt('_build/xy/diode_normal-data.tsv',
               np.column_stack([norm_current, norm_power_val, norm_power_err]))
    np.savetxt('_build/xy/diode_damped-data.tsv',
               np.column_stack([damp_current, damp_power_val, damp_power_err]))
    
    T['diode_normal_table'] = list(zip(
        siunitx(norm_current*1e3),
        siunitx(norm_power_val*1e6, norm_power_err*1e6, allowed_hang=6),
    ))
    T['diode_damped_table'] = list(zip(
        siunitx(damp_current*1e3),
        siunitx(damp_power_val*1e6, damp_power_err*1e6),
    ))

    hbar_omega = 6.626e-34 * 3e8 / 987e-9
    electron_charge = 1.609e-19

    # Find the threshold current.
    sel = norm_power_val > 1e-3
    slope_dist = []
    quantum_efficiency_dist = []
    threshold_dist = []
    threshold_fit_x = np.linspace(0.05, 0.09, 100)
    threshold_fit_y_dist = []
    # Jackknife fit to find root.
    for i in range(len(norm_power_val[sel])):
        x = np.delete(norm_current[sel], i)
        y_val = np.delete(norm_power_val[sel], i)
        y_err = np.delete(norm_power_err[sel], i)
        popt, pconv = op.curve_fit(linear, x, y_val, sigma=y_err)
        a, b = popt
        root = -b / a
        threshold_dist.append(root)
        threshold_fit_y_dist.append(linear(threshold_fit_x, *popt))
        slope_dist.append(a)
        quantum_efficiency_dist.append(a * electron_charge / hbar_omega)
    threshold_val, threshold_err = bootstrap.average_and_std_arrays(threshold_dist)
    threshold_fit_y_val, threshold_fit_y_err = bootstrap.average_and_std_arrays(threshold_fit_y_dist)
    differential_efficiency_val, differential_efficiency_err = bootstrap.average_and_std_arrays(slope_dist)
    quantum_efficiency_val, quantum_efficiency_err = bootstrap.average_and_std_arrays(quantum_efficiency_dist)

    T['threshold'] = siunitx(threshold_val, threshold_err)
    T['differential_efficiency'] = siunitx(differential_efficiency_val, differential_efficiency_err)
    T['quantum_efficiency'] = siunitx(quantum_efficiency_val, quantum_efficiency_err)

    np.savetxt('_build/xy/diode_normal-band.tsv',
               bootstrap.pgfplots_error_band(threshold_fit_x, threshold_fit_y_val, threshold_fit_y_err))

    # Compare ratios of damped and normal power in the overlap range.
    ratio_dist = []
    x = np.linspace(70.1e-3, 86.9e-3, 20)
    for norm_power, damp_power in zip(norm_power_dist, damp_power_dist):
        norm_inter = scipy.interpolate.interp1d(norm_current, norm_power)
        damp_inter = scipy.interpolate.interp1d(damp_current, damp_power)
        a = norm_inter(x)
        b = damp_inter(x)
        ratio = a / b
        ratio_dist.append(ratio)

    ratio_val, ratio_err = bootstrap.average_and_std_arrays(ratio_dist)

    extinction_dist = np.array(ratio_dist).flatten()
    extinction_val, extinction_err = np.mean(ratio_dist), np.std(ratio_dist)
    T['extinction'] = siunitx(extinction_val, extinction_err)

    np.savetxt('_build/xy/diode-ratio-line.tsv',
               np.column_stack([x, ratio_val]))
    np.savetxt('_build/xy/diode-ratio-band.tsv',
               bootstrap.pgfplots_error_band(x, ratio_val, ratio_err))

    return extinction_dist
Пример #53
0
def job_atom_number(T):
    wavelength_nm = 780
    beam_power_mW = 2 * (3.57 + 3.36 + 4.45)
    mot_power_nW_val, mot_power_nW_err = get_mot_power_nw(T)
    lens_distance_cm_val = 10
    lens_distance_cm_err = 1
    lens_radius_cm_val = 2.54 / 2

    omega_val = np.pi * lens_radius_cm_val**2 / (lens_distance_cm_val**2)
    omega_err = 2 * np.pi * lens_radius_cm_val**2 / (lens_distance_cm_val**
                                                     3) * lens_distance_cm_err

    mot_power_tot_nW_val = mot_power_nW_val * 4 * np.pi / omega_val
    mot_power_tot_nW_err = np.sqrt(
        (mot_power_nW_err * 4 * np.pi / omega_val)**2 +
        (mot_power_nW_val * 4 * np.pi / omega_val**2 * omega_err)**2)

    diameter_cm_val, diameter_cm_err = job_diameter(T)

    beam_area_cm_val = np.pi * diameter_cm_val**2 / 4
    beam_area_cm_err = np.pi * diameter_cm_val / 2 * diameter_cm_err

    intens_mW_cm2_val = beam_power_mW / beam_area_cm_val
    intens_mW_cm2_err = beam_power_mW / beam_area_cm_val**2 * beam_area_cm_err

    hbar = 1.054571800e-34
    hbar_omega_nW_MHz = hbar * 1e15 * 2 * np.pi * 3e8 / (wavelength_nm * 1e-9)

    detuning_MHz_val, detuning_MHz_err = map(abs, job_scan_cooling(T))
    scattering_rate_MHz_val, scattering_rate_MHz_err = get_scattering_rate_MHz(
        T, intens_mW_cm2_val, intens_mW_cm2_err, detuning_MHz_val,
        detuning_MHz_err)

    atom_number_val = mot_power_tot_nW_val / hbar_omega_nW_MHz / scattering_rate_MHz_val
    atom_number_err = np.sqrt((mot_power_tot_nW_err / hbar_omega_nW_MHz /
                               scattering_rate_MHz_val)**2 +
                              (mot_power_tot_nW_val / hbar_omega_nW_MHz /
                               scattering_rate_MHz_val**2 *
                               scattering_rate_MHz_err)**2)

    T['atom_number'] = siunitx(atom_number_val, atom_number_err)
    T['beam_area_cm'] = siunitx(beam_area_cm_val, beam_area_cm_err)
    T['hbar_omega_nW_MHz'] = siunitx(hbar_omega_nW_MHz)
    T['intens_mW_cm2'] = siunitx(intens_mW_cm2_val, intens_mW_cm2_err)
    T['lens_distance_cm'] = siunitx(lens_distance_cm_val, lens_distance_cm_err)
    T['lens_radius_cm'] = siunitx(lens_radius_cm_val)
    T['mot_omega'] = siunitx(omega_val, omega_err)
    T['mot_power_nW'] = siunitx(mot_power_nW_val, mot_power_nW_err)
    T['mot_power_tot_nW'] = siunitx(mot_power_tot_nW_val, mot_power_tot_nW_err)
    T['scattering_rate_MHz'] = siunitx(scattering_rate_MHz_val,
                                       scattering_rate_MHz_err)
    T['total_beam_power_mW'] = siunitx(beam_power_mW)
    T['wavelength_nm'] = siunitx(wavelength_nm)
Пример #54
0
def get_acryl_data(T, slope_val, width):
    data = np.loadtxt('Data/longlong.txt')
    channel = data[:, 0]
    time = slope_val * channel
    counts = data[:, 1]

    x = np.linspace(np.min(time), np.max(time), 500)

    fit_func = lambda t, mean, A_0, A_t, tau_0, tau_t, BG: \
            np.log(models.lifetime_spectrum(t, mean, width, A_0, A_t, tau_0, tau_t, BG))

    results = []

    sel1 = (10.92 < time) & (time < 11.58)
    sel2 = (13.11 < time) & (time < 22)
    sels = [sel1, sel2]

    x1 = np.linspace(np.min(time[sel1]), np.max(time[sel1]), 10)
    x2 = np.linspace(np.min(time[sel2]), np.max(time[sel2]), 10)

    for sample_id in range(BOOTSTRAP_SAMPLES):
        print('Bootstrap sample', sample_id, 'running …')

        boot_counts = bootstrap.redraw_count(counts)

        lin_lifetimes = []
        lin_results = []
        for sel_lin, x_lin in zip(sels, [x1, x2]):
            popt_lin, pconv_lin = op.curve_fit(exp_decay,
                                               time[sel_lin],
                                               boot_counts[sel_lin],
                                               p0=[1e5, 0.3])
            y_lin = exp_decay(x_lin, *popt_lin)

            lin_results.append(y_lin)
            lin_results.append(popt_lin)
            lin_results.append(1 / popt_lin[1])
            lin_lifetimes.append(1 / popt_lin[1])

        sel = (10 < time) & (time < 50) & (boot_counts > 0)

        p0 = [10.5, 13e3, 34e2] + lin_lifetimes + [2]
        popt, pconv = op.curve_fit(fit_func,
                                   time[sel],
                                   np.log(boot_counts[sel]),
                                   p0=p0)
        mean, A_0, A_t, tau_0, tau_t, BG = popt

        intens_0 = A_0 / (A_0 + A_t)
        intens_t = A_t / (A_0 + A_t)
        tau_bar = intens_0 * tau_0 + intens_t * tau_t
        y = np.exp(fit_func(x, *popt))
        tau_f = 1 / (intens_0 / tau_0 - intens_t / tau_t)
        sigma_c = 1 / tau_0 - 1 / tau_f

        results.append([
            tau_0,
            tau_bar,
            tau_f,
            tau_t,
            intens_0,
            intens_t,
            y,
            popt,
            sigma_c,
        ] + lin_results)

    tau_0_dist, tau_bar_dist, tau_f_dist, tau_t_dist, intens_0_dist, \
            intens_t_dist, lifetime_y_dist, lifetime_popt_dist, sigma_c_dist, \
            y_lin1_dist, popt_lin1_dist, tau_lin1_dist, \
            y_lin2_dist, popt_lin2_dist, tau_lin2_dist, \
            = zip(*results)

    tau_0_val, tau_0_err = bootstrap.average_and_std_arrays(tau_0_dist)
    tau_t_val, tau_t_err = bootstrap.average_and_std_arrays(tau_t_dist)
    tau_f_val, tau_f_err = bootstrap.average_and_std_arrays(tau_f_dist)
    tau_bar_val, tau_bar_err = bootstrap.average_and_std_arrays(tau_bar_dist)

    popt_val, popt_err = bootstrap.average_and_std_arrays(lifetime_popt_dist)
    y_val, y_err = bootstrap.average_and_std_arrays(lifetime_y_dist)

    popt_lin1_val, popt_lin1_err = bootstrap.average_and_std_arrays(
        popt_lin1_dist)
    y_lin1_val, y_lin1_err = bootstrap.average_and_std_arrays(y_lin1_dist)
    tau_lin1_val, tau_lin1_err = bootstrap.average_and_std_arrays(
        tau_lin1_dist)
    popt_lin2_val, popt_lin2_err = bootstrap.average_and_std_arrays(
        popt_lin2_dist)
    y_lin2_val, y_lin2_err = bootstrap.average_and_std_arrays(y_lin2_dist)
    tau_lin2_val, tau_lin2_err = bootstrap.average_and_std_arrays(
        tau_lin2_dist)

    print('tau_0', siunitx(tau_0_val, tau_0_err))
    print('tau_t', siunitx(tau_t_val, tau_t_err))
    print('tau_f', siunitx(tau_f_val, tau_f_err))
    print('tau_bar', siunitx(tau_bar_val, tau_bar_err))

    T['acryl_tau_0'] = siunitx(tau_0_val, tau_0_err)
    T['acryl_tau_t'] = siunitx(tau_t_val, tau_t_err)
    T['acryl_tau_f'] = siunitx(tau_f_val, tau_f_err)
    T['acryl_tau_bar'] = siunitx(tau_bar_val, tau_bar_err)

    print('popt', siunitx(popt_val, popt_err))
    print('popt_lin1', siunitx(popt_lin1_val, popt_lin1_err))
    print('popt_lin2', siunitx(popt_lin2_val, popt_lin2_err))
    print('tau_lin1', siunitx(tau_lin1_val, tau_lin1_err))
    print('tau_lin2', siunitx(tau_lin2_val, tau_lin2_err))

    T['acryl_tau_0_lin'] = siunitx(tau_lin1_val, tau_lin1_err)
    T['acryl_tau_t_lin'] = siunitx(tau_lin2_val, tau_lin2_err)

    print(x.shape)
    print(y_lin1_val.shape)

    pl.plot(time, counts, color='black', alpha=0.3)
    counts_smooth = scipy.ndimage.filters.gaussian_filter1d(counts, 8)
    pl.plot(time, counts_smooth, color='green')
    pl.fill_between(x, y_val - y_err, y_val + y_err, alpha=0.5, color='red')
    pl.plot(x, y_val, color='red')
    pl.xlabel('Time / ns')
    pl.ylabel('Counts')
    dandify_plot()
    #pl.xlim((8, 20))
    pl.ylim((0.1, np.max(counts) * 1.1))
    pl.savefig('_build/mpl-lifetime-acryl.pdf')
    pl.savefig('_build/mpl-lifetime-acryl.png')
    pl.yscale('log')
    pl.fill_between(x1,
                    y_lin1_val - y_lin1_err,
                    y_lin1_val + y_lin1_err,
                    alpha=0.5,
                    color='blue')
    pl.fill_between(x2,
                    y_lin2_val - y_lin2_err,
                    y_lin2_val + y_lin2_err,
                    alpha=0.5,
                    color='blue')
    pl.plot(x1, y_lin1_val, color='blue', alpha=0.5)
    pl.plot(x2, y_lin2_val, color='blue', alpha=0.5)
    dandify_plot()
    pl.savefig('_build/mpl-lifetime-acryl-log.pdf')
    pl.savefig('_build/mpl-lifetime-acryl-log.png')
    #pl.show()
    pl.clf()

    np.savetxt('_build/xy/acryl-lifetime-data.tsv',
               np.column_stack([time, counts]))

    np.savetxt('_build/xy/acryl-lifetime-smoothed.tsv',
               np.column_stack([time, counts_smooth]))

    np.savetxt('_build/xy/acryl-lifetime-fit.tsv', np.column_stack([x, y_val]))
    np.savetxt('_build/xy/acryl-lifetime-band.tsv',
               bootstrap.pgfplots_error_band(x, y_val, y_err))

    np.savetxt('_build/xy/acryl-lifetime-fit-lin1.tsv',
               np.column_stack([x1, y_lin1_val]))
    np.savetxt('_build/xy/acryl-lifetime-band-lin1.tsv',
               bootstrap.pgfplots_error_band(x1, y_lin1_val, y_lin1_err))

    np.savetxt('_build/xy/acryl-lifetime-fit-lin2.tsv',
               np.column_stack([x2, y_lin2_val]))
    np.savetxt('_build/xy/acryl-lifetime-band-lin2.tsv',
               bootstrap.pgfplots_error_band(x2, y_lin2_val, y_lin2_err))
Пример #55
0
def job_afb_analysis(T):
    data = np.loadtxt('Data/radiative_corrections.tsv')
    corrections = data[:, 1]

    energies = np.loadtxt('Data/energies.txt')
    data = np.loadtxt('Data/afb.txt')
    negative = data[:, 0]
    positive = data[:, 1]

    results = []
    for i in range(SAMPLES):
        positive_boot = bootstrap.redraw_count(positive)
        negative_boot = bootstrap.redraw_count(negative)

        result = afb_kernel(positive_boot, negative_boot, corrections)
        if result is not None:
            results.append(result)

    afb_corr_dist, sin_sq_dist = zip(*results)

    afb_filt, sin_sq_filt = zip(*[
        (x[3], y)
        for x, y in zip(afb_corr_dist, sin_sq_dist)
        if not np.isnan(y)
    ])

    print('afb:', len(afb_corr_dist), len(afb_filt))

    T['sin_sq_bootstrap_acceptance'] = siunitx((1 - len(sin_sq_filt) / len(sin_sq_dist)) * 100)

    afb_val, afb_err = bootstrap.average_and_std_arrays(afb_corr_dist)
    sin_sq_val, sin_sq_err = bootstrap.average_and_std_arrays(sin_sq_filt)

    afb_val, sin_sq_val = afb_kernel(positive, negative, corrections)

    sin_sq_up, sin_sq_down = bootstrap.percentile_arrays(sin_sq_filt, sin_sq_val)

    print('sin_sq:', sin_sq_val, sin_sq_err, sin_sq_up, sin_sq_down)

    np.savetxt('_build/xy/afb.tsv', np.column_stack([energies, afb_val, afb_err]))

    T['afb_table'] = list(zip(
        siunitx(energies),
        siunitx(afb_val, afb_err),
    ))

    T['sin_sq_afb'] = siunitx(sin_sq_val, sin_sq_err)

    T['sin_sq_afb_asym'] = '{:.3f}^{{+{:.3f}}}_{{-{:.3f}}}'.format(sin_sq_val, sin_sq_up, sin_sq_down)

    counts, bins = np.histogram(sin_sq_filt)
    counts = np.array(list(counts) + [counts[-1]])
    print(bins.shape, counts.shape)
    np.savetxt('_build/xy/sin_sq_hist.tsv', np.column_stack([bins, counts]))

    counts, bins = np.histogram([x[3] for x in afb_corr_dist])
    counts = np.array(list(counts) + [counts[-1]])
    print(bins.shape, counts.shape)
    np.savetxt('_build/xy/afb_hist.tsv', np.column_stack([bins, counts]))

    counts, bins = np.histogram(afb_filt, bins=bins)
    counts = np.array(list(counts) + [counts[-1]])
    print(bins.shape, counts.shape)
    np.savetxt('_build/xy/afb_filt_hist.tsv', np.column_stack([bins, counts]))
Пример #56
0
def time_gauge(T, show_gauss=False, show_lin=False):
    time = []
    channel_val = []
    channel_err = []

    # go through all six prompt-files
    for i in range(1, 7):
        time_raw = np.loadtxt('Data/prompt-{}.txt'.format(i))
        channel = time_raw[:, 0]
        counts = time_raw[:, 1]
        if i == 1:
            counts_tot = counts
        elif i < 6:
            counts_tot += counts

        # bootstrap:
        # - draw new counts from gaussian distribution with width of 'sqrt(N)'
        # - fit gaussian distribution to drawn data
        # - add mean to array
        mean = []
        width = []
        amplitude = []
        for a in range(BOOTSTRAP_SAMPLES):
            boot_counts = redraw_count(counts)
            popt, pconv = op.curve_fit(gauss,
                                       channel,
                                       boot_counts,
                                       p0=[400 + i * 600, 200, 100])
            mean.append(popt[0])
            width.append(popt[1])
            amplitude.append(popt[2])

        # find average and standard deviation in arrays
        mean_val, mean_err = bootstrap.average_and_std_arrays(mean)
        width_val, width_err = bootstrap.average_and_std_arrays(width)
        amplitude_val, amplitude_err = bootstrap.average_and_std_arrays(
            amplitude)

        # create files for prompt curve fits
        x = np.linspace(mean_val - 200, mean_val + 200, 100)
        y = gauss(x, mean_val, width_val, amplitude_val)

        np.savetxt('_build/xy/prompt-{}-fit.txt'.format(i),
                   np.column_stack([x, y]))

        # write result into new channel arrays
        channel_val.append(mean_val)
        channel_err.append(mean_err)

        # write real time for gauging
        time.append((i - 1) * 4)

    # write files for prompt curve plotting
    np.savetxt(
        '_build/xy/prompts-short.txt',
        bootstrap.pgfplots_error_band(channel[500:3500], counts_tot[500:3500],
                                      np.sqrt(counts_tot[500:3500])))
    np.savetxt(
        '_build/xy/prompts-long.txt',
        bootstrap.pgfplots_error_band(channel[3600:4200], counts[3600:4200],
                                      np.sqrt(counts[3600:4200])))

    # convert lists to arrays
    channel_val = np.array(channel_val)
    channel_err = np.array(channel_err)
    time = np.array(time)

    T['time_gauge_param'] = list(
        zip(map(str, time), siunitx(channel_val, channel_err)))

    # linear fit with delete-1-jackknife
    slope = []
    intercept = []
    y_dist = []
    x = np.linspace(750, 4000, 100)
    for i in range(len(channel_val)):
        channel_jackknife = np.delete(channel_val, i)
        time_jackknife = np.delete(time, i)

        popt, pconv = op.curve_fit(linear, channel_jackknife, time_jackknife)

        slope.append(popt[0])
        intercept.append(popt[1])

        y = linear(x, *popt)

        y_dist.append(y)

        if show_lin:
            x = np.linspace(0, 4000, 1000)
            y = linear(x, *popt)
            pl.plot(channel_val, time, linestyle="none", marker="o")
            pl.plot(x, y)
            pl.show()
            pl.clf()

    slope_val, slope_err = bootstrap.average_and_std_arrays(slope)
    intercept_val, intercept_err = bootstrap.average_and_std_arrays(intercept)
    y_val, y_err = bootstrap.average_and_std_arrays(y_dist)

    # files for fit and plot of time gauge

    np.savetxt('_build/xy/time_gauge_plot.txt',
               np.column_stack([channel_val, time, channel_err]))
    np.savetxt('_build/xy/time_gauge_fit.txt', np.column_stack([x, y_val]))
    np.savetxt('_build/xy/time_gauge_band.txt',
               bootstrap.pgfplots_error_band(x, y_val, y_err))

    T['time_gauge_slope'] = siunitx(slope_val * 1e3, slope_err * 1e3)
    T['time_gauge_intercept'] = siunitx(intercept_val, intercept_err)

    # time resolution

    T['width_6'] = siunitx(width_val, width_err)
    FWHM_val = 2 * np.sqrt(2 * np.log(2)) * width_val
    FWHM_err = 2 * np.sqrt(2 * np.log(2)) * width_err
    T['FWHM_6'] = siunitx(FWHM_val, FWHM_err)

    time_res = FWHM_val * slope_val
    time_res_err = np.sqrt((FWHM_val * slope_err)**2 +
                           (FWHM_err * slope_val)**2)
    T['time_resolution'] = siunitx(time_res, time_res_err)
    return slope_val, width_val * slope_val
Пример #57
0
def job_decay_widths(T):
    # T_3, Q, N_color
    quantum_numbers = {
        'electron': [-1 / 2, -1, 1],
        'neutrino': [+1 / 2, 0, 1],
        'up_type': [+1 / 2, 2 / 3, 3],
        'down_type': [-1 / 2, -1 / 3, 3],
    }

    T['fermi_coupling'] = siunitx(fermi_coupling)

    widths = {}

    for particle, (i_3, q, n_c) in quantum_numbers.items():
        g_v = i_3 - 2 * q * sin_sq_weak_mixing
        g_a = i_3

        decay_width = n_c / (12 * np.pi) * fermi_coupling \
                * mass_z**3 * (g_a**2 + g_v**2)

        T['gamma_' + particle] = siunitx(decay_width)

        widths[particle] = decay_width

        if False:
            print()
            print('Particle:', particle)
            print('I_3:', i_3)
            print('Q:', q)
            print('N_color:', n_c)
            print('g_v:', g_v)
            print('g_a:', g_a)
            print('Decay width Γ:', decay_width, 'MeV')

    groups = ['hadronic', 'charged_leptonic', 'neutral_leptonic']

    widths['hadronic'] = 2 * widths['up_type'] + 3 * widths['down_type']
    widths['charged_leptonic'] = 3 * widths['electron']
    widths['neutral_leptonic'] = 3 * widths['neutrino']

    global total_width
    total_width = widths['hadronic'] + widths['charged_leptonic'] + widths[
        'neutral_leptonic']

    ratios = {}

    for group in groups:
        T[group + '_width'] = siunitx(widths[group])
        T['total_width'] = siunitx(total_width)

        ratios[group] = widths[group] / total_width
        T[group + '_ratio'] = siunitx(ratios[group])

        partial_cross_section = 12 * np.pi / mass_z**2 * widths[
            'electron'] * widths[group] / total_width**2
        T[group + '_partial_cross_section'] = siunitx(partial_cross_section /
                                                      1e-11)

    total_cross_section = 12 * np.pi / mass_z**2 * widths[
        'electron'] / total_width
    T['total_cross_section'] = siunitx(total_cross_section / 1e-11)

    extra_width = 1 + (widths['up_type'] + widths['down_type'] +
                       widths['charged_leptonic'] +
                       widths['neutral_leptonic']) / total_width
    T['extra_width'] = siunitx(extra_width)
Пример #58
0
def job_spectrum(T):
    data = np.loadtxt('Data/runs.tsv')

    T['raw_table'] = list([[str(int(x)) for x in row] for row in data])

    runs = data[:, 0]
    motor = data[:, 1]
    T_LR = data[:, 2]
    N_LR = data[:, 3]
    T_RL = data[:, 4]
    N_RL = data[:, 5]

    time_lr = T_LR * 10e-3
    time_rl = T_RL * 10e-3

    velocity_lr_val = -length_val * runs / time_lr
    velocity_rl_val = length_val * runs / time_rl
    velocity_lr_err = -length_err * runs / time_lr
    velocity_rl_err = length_err * runs / time_rl

    rate_lr_val = N_LR / time_lr
    rate_rl_val = N_RL / time_rl
    rate_lr_err = np.sqrt(N_LR) / time_lr
    rate_rl_err = np.sqrt(N_RL) / time_rl

    rate_val = np.concatenate((rate_lr_val, rate_rl_val))
    rate_err = np.concatenate((rate_lr_err, rate_rl_err))
    velocity_val = np.concatenate((velocity_lr_val, velocity_rl_val))
    velocity_err = np.concatenate((velocity_lr_err, velocity_rl_err))

    fit_val, fit_err = fit_dip(velocity_val, rate_val, rate_err)
    x = np.linspace(np.min(velocity_val), np.max(velocity_val), 1000)
    y = lorentz6(x, *fit_val)
    pl.plot(x, y)

    widths_val = fit_val[1::3]
    widths_err = fit_err[1::3]

    delta_e_val = hbar_omega0_ev * widths_val / speed_of_light
    delta_e_err = hbar_omega0_ev * widths_err / speed_of_light

    relative_width_val = widths_val / speed_of_light
    relative_width_err = widths_err / speed_of_light

    T['widths_table'] = list(
        zip(*[
            siunitx(widths_val / 1e-6, widths_err / 1e-6),
            siunitx(delta_e_val / 1e-9, delta_e_err / 1e-9),
            siunitx(relative_width_val / 1e-13, relative_width_err / 1e-13),
        ]))

    formatted = siunitx(fit_val / 1e-6, fit_err / 1e-6)
    offset = siunitx(fit_val[-1], fit_err[-1])

    T['fit_param'] = list(zip(*[iter(formatted[:-1])] * 3))
    T['fit_offset'] = offset

    np.savetxt('_build/xy/rate_fit.csv', np.column_stack([x / 1e-3, y]))

    np.savetxt(
        '_build/xy/rate_lr.csv',
        np.column_stack([
            velocity_lr_val / 1e-3,
            rate_lr_val,
            rate_lr_err,
        ]))
    np.savetxt(
        '_build/xy/rate_rl.csv',
        np.column_stack([
            velocity_rl_val / 1e-3,
            rate_rl_val,
            rate_rl_err,
        ]))

    np.savetxt(
        '_build/xy/motor_lr.csv',
        np.column_stack([
            motor,
            -velocity_lr_val / 1e-3,
            velocity_lr_err / 1e-3,
        ]))
    np.savetxt(
        '_build/xy/motor_rl.csv',
        np.column_stack([
            motor,
            velocity_rl_val / 1e-3,
            velocity_rl_err / 1e-3,
        ]))

    pl.errorbar(velocity_lr_val,
                rate_lr_val,
                rate_lr_err,
                xerr=velocity_lr_err,
                marker='o',
                linestyle='none')
    pl.errorbar(velocity_rl_val,
                rate_rl_val,
                rate_lr_err,
                xerr=velocity_rl_err,
                marker='o',
                linestyle='none')
    pl.grid(True)
    pl.margins(0.05)
    pl.tight_layout()
    pl.savefig('_build/mpl-rate.pdf')
    pl.clf()

    #pl.errorbar(motor, -velocity_lr_val, velocity_lr_err, marker='o')
    #pl.errorbar(motor,  velocity_rl_val, velocity_rl_err, marker='o')
    #pl.grid(True)
    #pl.margins(0.05)
    #pl.tight_layout()
    #pl.savefig('_build/mpl-motor.pdf')
    #pl.clf()

    means_val = fit_val[:-1][0::3]
    means_err = fit_err[:-1][0::3]

    lande_factors(T, means_val, means_err)
Пример #59
0
def bootstrap_driver(T):
    # Load all the input data from the files.
    lum_data = np.loadtxt('Data/luminosity.txt')
    lum_val = lum_data[:, 0]
    lum_err = lum_data[:, 3]
    radiative_hadrons = np.loadtxt('Data/radiative-hadrons.tsv')
    radiative_leptons = np.loadtxt('Data/radiative-leptons.tsv')
    raw_matrix = np.loadtxt('Data/matrix.txt').T
    mc_sizes = np.loadtxt('Data/monte-carlo-sizes.txt')
    filtered = np.loadtxt('Data/filtered.txt')

    # Some output into the template.
    T['luminosities_table'] = list(
        zip(siunitx(energies), siunitx(lum_val, lum_err)))
    T['radiative_cs_table'] = list(
        zip(
            siunitx(energies),
            siunitx(radiative_hadrons),
            siunitx(radiative_leptons),
        ))

    # Container for the results of each bootstrap run.
    results = []

    for r in range(SAMPLES):
        # Draw new numbers for the matrix.
        boot_matrix = bootstrap.redraw_count(raw_matrix)

        # Draw new luminosities.
        boot_lum_val = np.array(
            [random.gauss(val, err) for val, err in zip(lum_val, lum_err)])

        # Draw new filtered readings.
        boot_readings = bootstrap.redraw_count(filtered)

        # Run the analysis on the resampled data and save the results.
        results.append(
            bootstrap_kernel(mc_sizes, boot_matrix, boot_readings,
                             boot_lum_val, radiative_hadrons,
                             radiative_leptons))

    # The `results` is a list which contains one entry per bootstrap run. This
    # is not particularly helpful as the different interesting quantities are
    # only on the second index on the list. The first index of the `results`
    # list is the bootstrap run index. Therefore we use the `zip(*x)` trick to
    # exchange the two indices. The result will be a list of quantities which
    # are themselves lists of the bootstrap samples. Then using Python tuple
    # assignments, we can split that (now) outer list into different
    # quantities. Each of the new variables created here is a list of R
    # bootstrap samples.
    x_dist, masses_dist, widths_dist, cross_sections_dist, y_dist, corr_dist, \
            matrix_dist, inverted_dist, readings_dist, peaks_dist, brs_dist, \
            width_electron_dist, width_flavors_dist, missing_width_dist, \
            width_lepton_dist, neutrino_families_dist, popts_dist, \
            mean_mass_dist, mean_width_dist \
            = zip(*results)

    # We only need one of the lists of the x-values as they are all the same.
    # So take the first and throw the others out.
    x = x_dist[0]

    # The masses and the widths that are given back from the `bootstrap_kernel`
    # are a list of four elements (electrons, muons, tauons, hadrons) each. The
    # variable `masses_dist` contains R copies of this four-list, one copy for
    # each bootstrap sample. We now average along the bootstrap dimension, that
    # is the outermost dimension. For each of the four masses, we take the
    # average along the R copies. This will give us four masses and four
    # masses-errors.
    masses_val, masses_err = bootstrap.average_and_std_arrays(masses_dist)
    widths_val, widths_err = bootstrap.average_and_std_arrays(widths_dist)
    peaks_val, peaks_err = bootstrap.average_and_std_arrays(peaks_dist)
    brs_val, brs_err = bootstrap.average_and_std_arrays(brs_dist)

    T['brs'] = siunitx(brs_val[0:3], brs_err[0:3])

    # Format masses and widths for the template.
    T['lorentz_fits_table'] = list(
        zip(
            display_names,
            siunitx(masses_val, masses_err),
            siunitx(widths_val, widths_err),
            siunitx(peaks_val, peaks_err),
        ))

    width_electron_val, width_electron_err = bootstrap.average_and_std_arrays(
        width_electron_dist)
    width_flavors_val, width_flavors_err = bootstrap.average_and_std_arrays(
        width_flavors_dist)

    T['width_electron_mev'] = siunitx(width_electron_val * 1000,
                                      width_electron_err * 1000)
    T['width_flavors_mev'] = siunitx(width_flavors_val * 1000,
                                     width_flavors_err * 1000)

    missing_width_val, missing_width_err = bootstrap.average_and_std_arrays(
        missing_width_dist)
    width_lepton_val, width_lepton_err = bootstrap.average_and_std_arrays(
        width_lepton_dist)
    neutrino_families_val, neutrino_families_err = bootstrap.average_and_std_arrays(
        neutrino_families_dist)

    T['missing_width_mev'] = siunitx(missing_width_val * 1000,
                                     missing_width_err * 1000)
    T['width_lepton_mev'] = siunitx(width_lepton_val * 1000,
                                    width_lepton_err * 1000)
    T['neutrino_families'] = siunitx(neutrino_families_val,
                                     neutrino_families_err)

    # Format original counts for the template.
    val, err = bootstrap.average_and_std_arrays(readings_dist)
    T['counts_table'] = []
    for i in range(7):
        T['counts_table'].append(
            [siunitx(energies[i])] +
            siunitx(val[i, :], err[i, :], allowed_hang=10))

    # Format corrected counts for the template.
    val, err = bootstrap.average_and_std_arrays(corr_dist)
    T['corrected_counts_table'] = []
    for i in range(7):
        T['corrected_counts_table'].append(
            [siunitx(energies[i])] +
            siunitx(val[i, :], err[i, :], allowed_hang=10))

    # Format matrix for the template.
    matrix_val, matrix_err = bootstrap.average_and_std_arrays(matrix_dist)
    T['matrix'] = []
    for i in range(4):
        T['matrix'].append([display_names[i]] + siunitx(
            matrix_val[i, :] * 100, matrix_err[i, :] * 100, allowed_hang=10))

    # Format inverted matrix for the template.
    inverted_val, inverted_err = bootstrap.average_and_std_arrays(
        inverted_dist)
    T['inverted'] = []
    for i in range(4):
        T['inverted'].append([display_names[i]] + list(
            map(
                number_padding,
                siunitx(
                    inverted_val[i, :], inverted_err[i, :], allowed_hang=10))))

    # Format cross sections for the template.
    cs_val, cs_err = bootstrap.average_and_std_arrays(cross_sections_dist)
    T['cross_sections_table'] = []
    for i in range(7):
        T['cross_sections_table'].append([siunitx(energies[i])] +
                                         siunitx(cs_val[:, i], cs_err[:, i]))

    # Build error band for pgfplots.
    y_list_val, y_list_err = bootstrap.average_and_std_arrays(y_dist)
    for i, name in zip(itertools.count(), names):
        # Extract the y-values for the given decay type.
        y_val = y_list_val[i, :]
        y_err = y_list_err[i, :]

        # Store the data for pgfplots.
        np.savetxt('_build/xy/cross_section-{}s.tsv'.format(name),
                   np.column_stack([energies, cs_val[i, :], cs_err[i, :]]))
        np.savetxt('_build/xy/cross_section-{}s-band.tsv'.format(name),
                   bootstrap.pgfplots_error_band(x, y_val, y_err))
        np.savetxt('_build/xy/cross_section-{}s-fit.tsv'.format(name),
                   np.column_stack((x, y_val)))

    popts_val, popts_err = bootstrap.average_and_std_arrays(popts_dist)
    T['chi_sq'] = []
    T['chi_sq_red'] = []
    T['p'] = []
    for i in range(4):
        residuals = cs_val[i, :] - propagator(energies, *popts_val[i, :])
        chi_sq = np.sum((residuals / cs_err[i, :])**2)
        dof = len(residuals) - 1 - len(popts_val[i, :])
        p = 1 - scipy.stats.chi2.cdf(chi_sq, dof)

        print('chi_sq', chi_sq, chi_sq / dof, p)
        T['chi_sq'].append(siunitx(chi_sq))
        T['chi_sq_red'].append(siunitx(chi_sq / dof))
        T['p'].append(siunitx(p))

    T['confidence_table'] = list(
        zip(
            display_names,
            T['chi_sq'],
            T['chi_sq_red'],
            T['p'],
        ))

    mean_mass_val, mean_mass_err = bootstrap.average_and_std_arrays(
        mean_mass_dist)
    mean_width_val, mean_width_err = bootstrap.average_and_std_arrays(
        mean_width_dist)

    T['mean_mass'] = siunitx(mean_mass_val, mean_mass_err)
    T['mean_width'] = siunitx(mean_width_val, mean_width_err)
Пример #60
0
def lande_factors(T, centers_val, centers_err):
    isomeric_val = np.mean(centers_val)
    isomeric_err = np.sqrt(np.mean(centers_err**2))

    factor_val = speed_of_light * B_val * magneton / hbar_omega0_joule
    factor_err = speed_of_light * B_err * magneton / hbar_omega0_joule

    T['isomeric_mm_s'] = siunitx(isomeric_val / 1e-3, isomeric_err / 1e-3)
    T['isomeric_nev'] = siunitx(hbar_omega0_ev * isomeric_val / speed_of_light / 1e-9, hbar_omega0_ev * isomeric_err / speed_of_light / 1e-9)

    if True:
        v_shift_e_val = - np.mean([
            #centers_val[2] - centers_val[0],
            centers_val[3] - centers_val[1],
            centers_val[4] - centers_val[2],
            #centers_val[5] - centers_val[3],
        ])
        v_shift_e_err = np.std([
            #centers_val[2] - centers_val[0],
            centers_val[3] - centers_val[1],
            centers_val[4] - centers_val[2],
            #centers_val[5] - centers_val[3],
        ])
        v_shift_e_err = np.sqrt(np.mean([
            centers_err[1]**2,
            centers_err[2]**2,
            centers_err[3]**2,
            centers_err[4]**2,
        ]))

        v_shift_q_val = ((centers_val[5] - centers_val[4]) - (centers_val[1] - centers_val[0]))/2
        v_shift_q_err = np.sqrt(
            centers_err[0]**2 + centers_err[2]**2 + centers_err[3]**2 + centers_err[5]**2
        ) / 2

        v_shift_g_val = np.mean([
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
        ])
        v_shift_g_err = np.std([
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
        ])
    else:
        v_shift_e_val = - np.mean([
            centers_val[1] - centers_val[0],
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
            centers_val[5] - centers_val[4],
        ])
        v_shift_e_err = np.std([
            centers_val[1] - centers_val[0],
            centers_val[2] - centers_val[1],
            centers_val[4] - centers_val[3],
            centers_val[5] - centers_val[4],
        ])
        #v_shift_e_err = np.sqrt(np.mean(centers_err**2))

        v_shift_g_val = np.mean([
            centers_val[4] - centers_val[0],
            centers_val[5] - centers_val[1],
        ])
        v_shift_g_err = np.std([
            centers_val[4] - centers_val[0],
            centers_val[5] - centers_val[1],
        ])

    lande_e_val = v_shift_e_val / factor_val
    lande_g_val = v_shift_g_val / factor_val
    lande_e_err = np.sqrt((v_shift_e_err / factor_val)**2 + (v_shift_e_val / factor_val**2 * factor_err)**2)
    lande_g_err = np.sqrt((v_shift_g_err / factor_val)**2 + (v_shift_g_val / factor_val**2 * factor_err)**2)

    T['v_shift_g'] = siunitx(v_shift_g_val / 1e-3, v_shift_g_err / 1e-3)
    T['v_shift_e'] = siunitx(v_shift_e_val / 1e-3, v_shift_e_err / 1e-3)
    T['v_shift_q'] = siunitx(v_shift_q_val / 1e-3, v_shift_q_err / 1e-3, error_digits=2)
    T['lande_g'] = siunitx(lande_g_val, lande_g_err)
    T['lande_e'] = siunitx(lande_e_val, lande_e_err)