Пример #1
0
def histogram_spike_duration(file):
    fills = fills_from_file(file, "OML")
    outliers = []
    durations = []
    for nbr in fills:
        fill = Fill(nbr)

        start, end = fill.OML_period()
        d = fill.blm_ir7().x[end] - fill.blm_ir7().x[start]
        if d < 70 or d > 300:
            outliers.append(nbr)
        durations.append(d)

    draw_histogram('Spike duration for {}'.format(file), durations, 10,
                   'Seconds', 'Count')
    return outliers
Пример #2
0
def plot_aggregate_fill_overlayed(beam, fill_list):
    """ 'beam' must be iterable: (1,), (2,), or (1, 2) """
    fig, axes = plt.subplots(2, sharex=True, sharey=True)
    for b in beam:
        ls = '--' if b == 2 and len(beam) == 2 else '-'
        for nbr in fill_list:
            fill = Fill(nbr, beam=b)
            c = np.random.rand(3)
            axes[0].plot(*fill.blm_ir3(), color=c, alpha=0.3, linestyle=ls)
            axes[1].plot(*fill.blm_ir7(), color=c, alpha=0.3, linestyle=ls)

        aggr = aggregate_fill(b, fill_list)
        axes[0].plot(*aggr.blm_ir3(),
                     color='black',
                     label='IR3 Aggregate B{}'.format(b),
                     zorder=5,
                     linestyle=ls)
        axes[1].plot(*aggr.blm_ir7(),
                     color='black',
                     label='IR7 Aggregate B{}'.format(b),
                     zorder=4,
                     linestyle=ls)

    axes[0].set_xlim(aggr.blm_ir3().x[aggr.OML_period()] +
                     np.array([-5, +120]))
    axes[0].set_ylabel("Losses (Gy/s)")
    axes[1].set_ylabel("Losses (Gy/s)")
    for ax in axes:
        ax.set_yscale("log")
        ax.set_xlabel("t (s)")
        ax.legend(loc="upper right")
    fig.suptitle("Overlay plot (beam {})".format(",".join(map(str, beam))))
    # plt.title("Overlay plot (beam {})".format(beam))
    plt.show()
Пример #3
0
def comp_blm_ir3_vs_ir7(file):
    fills = fills_from_file(file, "OML")
    ok = 0
    notok = 0
    sdata = {
        'max': [],
        'mean': [],
    }
    bdata = {'max': [], 'mean': []}
    for nbr in fills:
        fill = Fill(nbr)
        fill.beta_coll_merge()

        smin, smax = fill.OML_period()
        tmin, tmax = fill.blm_ir3().x[[smin, smax]]
        bmin = fill.blm_ir7().index_for_time(tmin)
        bmax = fill.blm_ir7().index_for_time(tmax)

        bsubset = fill.blm_ir7().y[bmin:bmax]
        ssubset = fill.blm_ir3().y[smin:smax]

        sdata['max'].append(max(ssubset))
        sdata['mean'].append(np.mean(ssubset))
        bdata['max'].append(max(bsubset))
        bdata['mean'].append(np.mean(bsubset))

    fig, ax = plt.subplots()
    ax.set_xlabel("Synchrotron (IR3) TCP")
    ax.set_ylabel("Betatron (IR7) TCPs")

    ax.scatter(sdata['max'], bdata['max'], color='r')
    slope, intercept, r_value, p_value, std_err = stats.linregress(
        sdata['max'], bdata['max'])
    # print(slope, intercept, r_value, p_value, std_err)
    xval = [0, 1]
    max_yval = [slope * x + intercept for x in xval]
    ax.plot(xval, max_yval, color='r', label='max')

    ax.scatter(sdata['mean'], bdata['mean'], color='b')
    slope, intercept, r_value, p_value, std_err = stats.linregress(
        sdata['mean'], bdata['mean'])
    # print(slope, intercept, r_value, p_value, std_err)
    mean_yval = [slope * x + intercept for x in xval]
    ax.plot(xval, mean_yval, color='b', label='mean')

    ax.plot([0, 1], [0, 1], color='black', label='delimiter')

    for v in ['max', 'mean']:
        count = 0
        for i, sd in enumerate(sdata[v]):
            if bdata[v][i] > sd:
                count += 1
        print(v, "over: ", count,
              "({}%)".format(int(float(count) / len(sdata[v]) * 100)))

    plt.title(
        'Losses due to synchrotron vs betatron oscillations\n for {}'.format(
            file))
    ax.legend(loc='upper right')
    ax.set_ylim([0, 0.5])
    ax.set_xlim([0, 0.5])
    plt.show()