Ejemplo n.º 1
0
def noise_a_chn(rmsdata,
                chnno,
                fft_en=True,
                fft_s=2000,
                fft_avg_cycle=50,
                wibno=0,
                fembno=0):
    asicchn = chnno % 16
    chnrmsdata = rmsdata[0][7][asicchn]
    feed_loc = rmsdata[0][8]
    len_chnrmsdata = len(chnrmsdata)
    if (len_chnrmsdata > 200000):
        len_chnrmsdata = 200000
    chnrmsdata = chnrmsdata[0:len_chnrmsdata]
    rms = np.std(chnrmsdata[0:10000])
    ped = np.mean(chnrmsdata[0:10000])
    if len(feed_loc) > 2:
        data_slice = chnrmsdata
        data_200ms_slice = chnrmsdata[0:200000:200]
    else:
        data_slice = chnrmsdata
        data_200ms_slice = chnrmsdata[0:200000:200]

    avg_cycle_l = 2
    if (len_chnrmsdata >= 200000):
        fft_s_l = 200000 // avg_cycle_l
    else:
        fft_s_l = len(chnrmsdata)

    if (fft_en):
        f, p = chn_rfft_psd(chnrmsdata, fft_s=fft_s, avg_cycle=fft_avg_cycle)
        f_l, p_l = chn_rfft_psd(chnrmsdata,
                                fft_s=fft_s_l,
                                avg_cycle=avg_cycle_l)
    else:
        f = None
        p = None
        f_l = None
        p_l = None


#   data after highpass filter
    flt_chn_data = hp_flt_applied(chnrmsdata,
                                  fs=2000000,
                                  passfreq=1000,
                                  flt_order=3)
    flt_chn_data = np.array(flt_chn_data) + ped
    hfped = ped
    hfrms = np.std(flt_chn_data)
    if (fft_en):
        hff, hfp = chn_rfft_psd(flt_chn_data,
                                fft_s=fft_s,
                                avg_cycle=fft_avg_cycle)
        hff_l, hfp_l = chn_rfft_psd(flt_chn_data,
                                    fft_s=fft_s_l,
                                    avg_cycle=avg_cycle_l)
    else:
        hff = None
        hfp = None
        hff_l = None
        hfp_l = None

    if len(feed_loc) > 2:
        #hfdata_slice = flt_chn_data[feed_loc[0]:feed_loc[0] + 5000]
        hfdata_slice = flt_chn_data
    else:
        hfdata_slice = flt_chn_data
    hfdata_100us_slice = flt_chn_data[0:100000:200]

    #   data after stuck code filter
    tmp_data = []
    lenonechn_data = len(chnrmsdata)
    for tmp in chnrmsdata:
        if (tmp % 64 == 63) or (tmp % 64 == 0) or (tmp % 64 == 1) or (
                tmp % 64 == 62) or (tmp % 64 == 2):
            pass
        else:
            tmp_data.append(tmp)
    len_tmp_data = len(tmp_data)
    unstk_ratio = 1.0 * len_tmp_data / lenonechn_data
    #    if ( unstk_ratio > 0.95 ):
    #        stuck_type = "Small"
    #    elif ( unstk_ratio > 0.8 ):
    #        stuck_type = "Middle"
    #    else:
    #        stuck_type = "Large"
    sfrms = np.std(tmp_data[0:10000])
    sfped = np.mean(tmp_data[0:10000])

    chn_noise_paras = [
        chnno, rms, ped, data_slice, data_200ms_slice, f, p, hfrms, hfped,
        hfdata_slice, hfdata_100us_slice, hff, hfp, sfrms, sfped, unstk_ratio,
        f_l, p_l, hff_l, hfp_l, wibno, fembno
    ]
    return chn_noise_paras
Ejemplo n.º 2
0
def noise_a_chn_fast(rmsdata,
                     chnno,
                     fft_en=True,
                     fft_s=2000,
                     fft_avg_cycle=50,
                     wibno=0,
                     fembno=0):
    asicchn = chnno % 16
    chnrmsdata = rmsdata[0][7][asicchn][0:20000]
    feed_loc = rmsdata[0][8]
    len_chnrmsdata = len(chnrmsdata)
    if (len_chnrmsdata > 200000):
        len_chnrmsdata = 200000
    rms = np.std(chnrmsdata[0:10000])
    ped = np.mean(chnrmsdata[0:10000])
    data_slice = chnrmsdata[feed_loc[0]:feed_loc[1]]
    data_200ms_slice = chnrmsdata[0:20000:20]

    avg_cycle_l = 1
    if (len(chnrmsdata) >= 400000):
        fft_s_l = 400000 // avg_cycle_l

    if (False):
        f, p = chn_rfft_psd(chnrmsdata, fft_s=fft_s, avg_cycle=fft_avg_cycle)
        f_l, p_l = chn_rfft_psd(chnrmsdata,
                                fft_s=fft_s_l,
                                avg_cycle=avg_cycle_l)
    else:
        f = None
        p = None
        f_l = None
        p_l = None

    if (False):
        flt_chn_data = hp_flt_applied(chnrmsdata,
                                      fs=2000000,
                                      passfreq=1000,
                                      flt_order=3)
        flt_chn_data = np.array(flt_chn_data) + ped
        hfped = ped
        hfrms = np.std(flt_chn_data)
        if (fft_en):
            hff, hfp = chn_rfft_psd(flt_chn_data,
                                    fft_s=fft_s,
                                    avg_cycle=fft_avg_cycle)
            hff_l, hfp_l = chn_rfft_psd(flt_chn_data,
                                        fft_s=fft_s_l,
                                        avg_cycle=avg_cycle_l)
        else:
            hff = None
            hfp = None
            hff_l = None
            hfp_l = None

        hfdata_slice = flt_chn_data[feed_loc[0]:feed_loc[1]]
        hfdata_100us_slice = flt_chn_data[0:100000:200]
    else:
        hfped = ped
        hfrms = rms
        hff = None
        hfp = None
        hff_l = None
        hfp_l = None
        hfdata_slice = data_slice
        hfdata_100us_slice = chnrmsdata[0:10000:10]

    tmp_data = []
    lenonechn_data = len(chnrmsdata)
    for tmp in chnrmsdata:
        if (tmp % 64 == 63) or (tmp % 64 == 0) or (tmp % 64 == 1) or (
                tmp % 64 == 62) or (tmp % 64 == 2):
            pass
        else:
            tmp_data.append(tmp)
    len_tmp_data = len(tmp_data)
    unstk_ratio = 1.0 * len_tmp_data / lenonechn_data
    sfrms = np.std(tmp_data[0:10000])
    sfped = np.mean(tmp_data[0:10000])

    chn_noise_paras = [
        chnno, rms, ped, data_slice, data_200ms_slice, f, p, hfrms, hfped,
        hfdata_slice, hfdata_100us_slice, hff, hfp, sfrms, sfped, unstk_ratio,
        f_l, p_l, hff_l, hfp_l, wibno, fembno
    ]
    return chn_noise_paras
Ejemplo n.º 3
0
def all_chn_results_coherent(all_chn_results,
                             apa40_yuv_f,
                             coherent_chn_np,
                             coh_mode=1):
    ##coh_mode = 1 --> middle value of chns
    ##coh_mode = 2 --> mean value of chns
    ##coh_mode = 3 --> histogram peak value of chns
    ##coh_mode = 4 --> sum value of chns
    coh_tp_chn_data = []
    for tp_fe in [1, 0, 3, 2]:
        coh_chn_data = []
        for chn in range(128):
            coh_chn = np.where(chn == np.array(coherent_chn_np))
            bad_chn = np.where(chn == np.array(apa40_yuv_f))
            if (len(coh_chn[0]) > 0) and (len(bad_chn[0]) <= 0):
                if (all_chn_results[chn][tp_fe][0][8] != "Large"):
                    ped_mean = all_chn_results[chn][tp_fe][0][5]
                    raw_sub_ped = np.array(
                        all_chn_results[chn][tp_fe][0][1]) - ped_mean
                    coh_chn_data.append([chn, tp_fe, raw_sub_ped])
        coh_num = len(coh_chn_data)
        smps = len(coh_chn_data[0][2])
        coh_noise = []
        coh_noise_raw = []
        for smpsi in range(smps):
            tmpa = []
            coh_sum = 0
            for i in range(coh_num):
                tmpa.append(coh_chn_data[i][2][smpsi])
                coh_sum = coh_sum + coh_chn_data[i][2][smpsi]
            tmpa.sort()
            mid_tmpa = tmpa[len(tmpa) // 2 + len(tmpa) % 2]
            mean_tmpa = np.mean(tmpa)
            std_tmpa = np.std(tmpa)
            mintmp = int(np.min(tmpa))
            maxtmp = int(np.max(tmpa))

            yhist, xhist = np.histogram(tmpa, bins='sturges')
            xh_pos = np.where(yhist > 0)[0]
            if (len(xh_pos) > 0):
                xh = xhist[xh_pos]
                yh = yhist[xh_pos]
                yhmax = np.max(yh)
                yhmax_pos = np.where(yh == yhmax)[0]
                max_hist_v_all = xh[yhmax_pos]
                max_hist_v = np.max(max_hist_v_all)
                try:
                    popt, pcov = curve_fit(gaussian, xh, yh)
                    mean_from_fit = popt[1]
                except RuntimeError:
                    mean_from_fit = mean_tmpa
            else:
                max_hist_v = mean_tmpa
                mean_from_fit = mean_tmpa

            if (coh_mode == 1):
                coh_noise.append(mid_tmpa)
            elif (coh_mode == 2):
                coh_noise.append(mean_tmpa)
            elif (coh_mode == 3):
                coh_noise.append(max_hist_v)
            elif (coh_mode == 4):
                coh_noise.append(coh_sum)
            elif (coh_mode == 5):
                coh_noise.append(coh_sum / (coh_num))
            elif (coh_mode == 6):  #no use
                coh_noise.append(mean_from_fit)
            else:
                coh_noise.append(mid_tmpa)

            coh_noise_raw.append(tmpa)

        coh_noise = np.array(coh_noise)

        for i in range(coh_num):
            raw_sub_coh = coh_chn_data[i][2] - coh_noise

            psd = True
            if (psd == True):
                f1, p1 = chn_rfft_psd(coh_chn_data[i][2],
                                      fft_s=2000,
                                      avg_cycle=50)
                f2, p2 = chn_rfft_psd(raw_sub_coh, fft_s=2000, avg_cycle=50)
                f3, p3 = chn_rfft_psd(coh_noise, fft_s=2000, avg_cycle=50)
            else:
                f1, p1 = chn_rfft(coh_chn_data[i][2], fft_s=2000, avg_cycle=50)
                f2, p2 = chn_rfft(raw_sub_coh, fft_s=2000, avg_cycle=50)
                f3, p3 = chn_rfft(coh_noise, fft_s=2000, avg_cycle=50)
            rms1 = np.std(coh_chn_data[i][2])
            rms2 = np.std(raw_sub_coh)
            rms3 = np.std(coh_noise)
            print "before %.3f, after %.3f, coherent %.3f" % (rms1, rms2, rms3)

            coh_tp_chn_data.append([coh_chn_data[i][0], coh_chn_data[i][1], coh_chn_data[i][2], raw_sub_coh, coh_noise, \
                                    rms1, rms2, rms3, f1, p1, f2, p2, f3, p3])

    tmp = []
    for chn in range(128):
        tmp_2 = []
        for tp_fe in [1, 0, 3, 2]:
            tmp_2.append([])
        tmp.append(tmp_2)

    for tp_fe in [1, 0, 3, 2]:
        for chn in range(128):
            one_chn_tp = all_chn_results[chn][tp_fe]
            coh_chn = np.where(chn == np.array(coherent_chn_np))
            bad_chn = np.where(chn == np.array(apa40_yuv_f))
            if (len(coh_chn[0]) > 0) and (len(bad_chn[0]) <= 0):
                for tmpi in coh_tp_chn_data:
                    if (tmpi[0] == chn) and (tmpi[1] == tp_fe):
                        one_chn_tp.append(tmpi)
                        tmp[chn][tp_fe] = one_chn_tp
#                        print "coherent for %d, %d"%(tmpi[0], tmpi[1])
            else:
                tmp[chn][tp_fe] = one_chn_tp

    all_chn_results = tmp
    return all_chn_results
Ejemplo n.º 4
0
def asic_coh_plot_wire(out_path, asic_results, wiretype="U"):
    w_results = []
    wi = 0
    for chni in range(16):
        chn_noise_paras = asic_results[chni]
        wireinfo = chn_noise_paras[19]
        APAno = chn_noise_paras[1]
        unstk_ratio = chn_noise_paras[12]
        if (wireinfo[0][0] in wiretype) and (unstk_ratio > 0.9):
            data_slice = chn_noise_paras[13]
            if (wi == 0):
                avg_data = np.array(data_slice)
            else:
                avg_data = avg_data + np.array(data_slice)
            wi = wi + 1
            w_results.append(asic_results[chni])

    coh_data = (avg_data * 1.0 / wi)
    coh_data = coh_data - np.mean(coh_data)

    for chni in range(len(w_results)):
        fig = plt.figure(figsize=(32, 18))
        axu = []
        axm = []
        axd = []
        for i in range(3):
            axu.append(plt.subplot2grid((3, 3), (0, i), colspan=1, rowspan=1))
            axm.append(plt.subplot2grid((3, 3), (1, i), colspan=1, rowspan=1))
            axd.append(plt.subplot2grid((3, 3), (2, i), colspan=1, rowspan=1))

        chn_noise_paras = w_results[chni]
        wireinfo = chn_noise_paras[19]
        APAno = chn_noise_paras[1]
        rms = chn_noise_paras[6]
        ped = chn_noise_paras[7]
        rawdata = chn_noise_paras[13]
        unstk_ratio = chn_noise_paras[12]
        pos_data = np.array(rawdata) - coh_data
        pos_ped = np.mean(pos_data[0:100000])
        pos_rms = np.std(pos_data[0:100000])
        apainfo = chn_noise_paras[0]
        label = wireinfo[0] + "_ASIC" + str(wireinfo[2]) + "_CHN" + wireinfo[3]
        ped_wf_subplot(axu[0],
                       rawdata[0:1000],
                       ped,
                       rms,
                       t_rate=0.5,
                       title="Waveforms of raw data (2MSPS)",
                       label=label)
        ped_wf_subplot(axm[0],
                       coh_data[0:1000],
                       np.mean(coh_data),
                       np.std(coh_data),
                       t_rate=0.5,
                       title="Waveforms of coherent noise (2MSPS)",
                       label=label)
        ped_wf_subplot(axd[0],
                       pos_data[0:1000],
                       pos_ped,
                       pos_rms,
                       t_rate=0.5,
                       title="Waveforms of post-filter data (2MSPS)",
                       label=label)

        rf_l, rp_l = chn_rfft_psd(rawdata, fft_s=len(rawdata), avg_cycle=1)
        cf_l, cp_l = chn_rfft_psd(coh_data, fft_s=len(coh_data), avg_cycle=1)
        pf_l, pp_l = chn_rfft_psd(pos_data, fft_s=len(pos_data), avg_cycle=1)

        #        ped_wf_subplot(axu[1], rawdata[::200],    ped,   rms,    t_rate=100, title="Waveforms of raw data (10kSPS)", label=label )
        #        ped_wf_subplot(axm[1], coh_data[::200],   np.mean(coh_data), np.std(coh_data)  ,    t_rate=100, title="Waveforms of coherent noise (10kSPS)", label=label )
        #        ped_wf_subplot(axd[1], pos_data[::200],   pos_ped,   pos_rms,    t_rate=100, title="Waveforms of post-filter data (10kSPS)", label=label )

        ped_fft_subplot(axu[1],
                        rf_l,
                        rp_l,
                        maxx=1000000,
                        title="FFT specturm",
                        label=label,
                        peaks_note=False)
        ped_fft_subplot(axm[1],
                        cf_l,
                        cp_l,
                        maxx=1000000,
                        title="FFT specturm",
                        label=label,
                        peaks_note=False)
        ped_fft_subplot(axd[1],
                        pf_l,
                        pp_l,
                        maxx=1000000,
                        title="FFT specturm",
                        label=label,
                        peaks_note=False)

        ped_fft_subplot(axu[2],
                        rf_l,
                        rp_l,
                        maxx=100000,
                        title="FFT specturm",
                        label=label,
                        peaks_note=False)
        ped_fft_subplot(axm[2],
                        cf_l,
                        cp_l,
                        maxx=100000,
                        title="FFT specturm",
                        label=label,
                        peaks_note=False)
        ped_fft_subplot(axd[2],
                        pf_l,
                        pp_l,
                        maxx=100000,
                        title="FFT specturm",
                        label=label,
                        peaks_note=False)

        fig_title = apainfo[0] + "_" + apainfo[1] + "_FE%d_%s" % (wireinfo[2],
                                                                  wiretype)
        plt.tight_layout(rect=[0, 0.05, 1, 0.95])
        fig.suptitle(fig_title, fontsize=20)
        plt.savefig(out_path + fig_title + "_coh_%s.png" % label, format='png')
        plt.close()
Ejemplo n.º 5
0
def one_chn_result(yuv_data_in,
                   chn,
                   apa="ProtoDUNE",
                   femb=0,
                   tp=1,
                   psd=True,
                   step="step001",
                   stuck_filter=True,
                   env="RT"):
    [yuv_chndata, y_chndata, v_chndata, u_chndata] = yuv_data_in
    APAMAP.APA = apa
    apa_yuv, apa_y, apa_v, apa_u = apamap.apa_mapping()

    wire_type = "B"
    y_wire = np.where(chn == np.array(apa_y))
    if (len(y_wire[0]) > 0):
        if (apa_y[y_wire[0][0]] == chn):
            wire_type = "Y"
    u_wire = np.where(chn == np.array(apa_u))
    if (len(u_wire[0]) > 0):
        if (apa_u[u_wire[0][0]] == chn):
            wire_type = "U"
    v_wire = np.where(chn == np.array(apa_v))
    if (len(v_wire[0]) > 0):
        if (apa_v[v_wire[0][0]] == chn):
            wire_type = "V"

    onechn_data = yuv_chndata[chn]

    stuck_type = "Small"
    if (stuck_filter == True):
        tmp_data = []
        lenonechn_data = len(onechn_data)
        for tmp in onechn_data:

            if (tmp % 64 == 63) or (tmp % 64 == 0) or (tmp % 64 == 1) or (
                    tmp % 64 == 62) or (tmp % 64 == 2):
                pass
            else:
                tmp_data.append(tmp)
        len_tmp_data = len(tmp_data)
        #if (len_tmp_data > (lenonechn_data//100)):
        if (len_tmp_data >= 100000):
            if (len_tmp_data > lenonechn_data * 0.95):
                stuck_type = "Small"
            else:
                if (env == "RT"):
                    stuck_type = "Small"
                else:
                    stuck_type = "Middle"
            rms = np.std(tmp_data[0:100000])
            ped_mean = np.mean(tmp_data[0:100000])
#            co_onechn_data = tmp_data[0:100000]
        else:
            rms = np.std(onechn_data)
            ped_mean = np.mean(onechn_data)
            stuck_type = "Large"
#            co_onechn_data = onechn_data[0:100000]

    else:
        rms = np.std(onechn_data)
        ped_mean = np.mean(onechn_data)
#        co_onechn_data = onechn_data[0:100000]

    if (psd == True):
        f, p = chn_rfft_psd(onechn_data, fft_s=100000, avg_cycle=10)
    else:
        f, p = chn_rfft(onechn_data, fft_s=100000, avg_cycle=10)

    return step, onechn_data[
        0:
        100000], wire_type, f, p, ped_mean, rms, chn, stuck_type  #, co_onechn_data