def p3(noise, datadate, numhead, fsps, new_fsps, gain_noise, gain_factor_2,
       gain_factor_4, gain_factor_8, start_index, steps, scale_array):
    #establishing directory names
    if new_fsps == 1000000000:
        sample_rate = '1 Gsps'
    elif new_fsps == 500000000:
        sample_rate = '500 Msps'
    elif new_fsps == 250000000:
        sample_rate = '250 Msps'
    else:
        sample_rate = 'trash'
    filename = 'G:/data/watchman/' + datadate + '_watchman_spe/d2/d2_average.txt'
    writedir = 'G:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/averages/phase=' + str(
        start_index) + '/phase_raw_gained_analyzed/'
    #creating directories if they don't exist
    if not os.path.exists(writedir):
        os.makedirs(writedir)
    t, v, header = rw(filename, numhead)
    Nloops = len(scale_array)  #establishing how many files to cycle through
    for i in range(Nloops):
        scale_height = scale_array[i] / np.max(v)
        v_scaled = v * scale_height
        print('%s/%s, File: %05d' %
              (start_index + 1, steps,
               i))  #printing number of file currently being processed
        #establishing read and write names
        writename = writedir + 'Phase--waveforms--%05d.txt' % i
        #downsampling waveform values
        (t_down, v_down) = downsampling(t - start_index * 1 / 20000000000,
                                        v_scaled, fsps, new_fsps, start_index)
        #digitizing waveform values
        v_digit = digitize(v_down, noise)
        #saving downsampled and digitized waveforms
        write_waveform(t_down, v_digit, writename, header)
コード例 #2
0
def determine_average_shape(datadate, numhead):
    Nloops = len(
        os.listdir('G:/data/watchman/' + datadate +
                   '_watchman_spe/d2/d2_normalized'))
    writename = 'G:/data/watchman/' + datadate + '_watchman_spe/d2/d2_histograms/average_shape.txt'
    if not os.path.exists('G:/data/watchman/' + datadate +
                          '_watchman_spe/d2/d2_histograms/histogram_images'):
        os.makedirs('G:/data/watchman/' + datadate +
                    '_watchman_spe/d2/d2_histograms/histogram_images')
    for i in range(Nloops):
        print(i)
        filename = 'G:/data/watchman/' + datadate + '_watchman_spe/d2/d2_normalized/D2--waveforms--%05d.txt' % i
        (t, y, _) = rw(filename, numhead)
        #starting array if this is first file
        if i == 0:
            ysum = y
        #adding additional normalized files to the array index-wise
        else:
            ysum = np.add(ysum, y)
    yfinal = np.divide(
        ysum, Nloops)  #diving array index-wise by number of files added
    header_name = "Average Waveform Shape\n"
    write_waveform(t, yfinal, writename,
                   header_name)  #writing array to waveform file
    return (t, yfinal)
コード例 #3
0
def d2normalization(datadate, numhead):
    Nloops = len(
        os.listdir('G:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw'))
    if not os.path.exists('G:/data/watchman/' + datadate +
                          '_watchman_spe/d2/d2_normalized/'):
        os.makedirs('G:/data/watchman/' + datadate +
                    '_watchman_spe/d2/d2_normalized/')
    for i in range(Nloops):
        filename = 'G:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw/D2--waveforms--%05d.txt' % i
        writename = 'G:/data/watchman/' + datadate + '_watchman_spe/d2/d2_normalized/D2--waveforms--%05d.txt' % i
        (t, y, header) = rw(filename, numhead)
        y_norm = y / min(y)  #normalizing y to peak = 1
        write_waveform(t, y_norm, writename, header)
コード例 #4
0
def d1normalization(datadate, numhead):
    Nloops = len(
        os.listdir(
            'G:/data/watchman/' + datadate +
            '_watchman_spe/d1/d1_50centered'))  #establishing size of directory
    if not os.path.exists('G:/data/watchman/' + datadate +
                          '_watchman_spe/d1/d1_normalized/'
                          ):  #creating write directory if nonexistant
        os.makedirs('G:/data/watchman/' + datadate +
                    '_watchman_spe/d1/d1_normalized/')
    for i in range(Nloops):
        filename = 'G:/data/watchman/' + datadate + '_watchman_spe/d1/d1_50centered/D1--waveforms--%05d.txt' % i  #setting file name for reading
        writename = 'G:/data/watchman/' + datadate + '_watchman_spe/d1/d1_normalized/D1--waveforms--%05d.txt' % i  #setting file name for writing
        (t, y, header) = rw(filename,
                            numhead)  #gathering waveform data into array
        y_norm = y / min(y)  #normalizing y to peak = 1
        write_waveform(t, y_norm, writename,
                       header)  #writing normalized waveform
コード例 #5
0
def baselineshift(datadate, numhead):
    Nloops = len(
        os.listdir(
            'G:/data/watchman/' + datadate +
            '_watchman_spe/d1/d1_renamed'))  #establish size of directory
    if not os.path.exists('G:/data/watchman/' + datadate +
                          '_watchman_spe/d1/d1_baseline_shifted/'
                          ):  #create write directory if nonexistant
        os.makedirs('G:/data/watchman/' + datadate +
                    '_watchman_spe/d1/d1_baseline_shifted/')
    for i in range(Nloops):
        filename = 'G:/data/watchman/' + datadate + '_watchman_spe/d1/d1_renamed/D1--waveforms--%05d.txt' % i  #establish file name to read
        writename = 'G:/data/watchman/' + datadate + '_watchman_spe/d1/d1_baseline_shifted/D1--waveforms--%05d.txt' % i  #establish file name to write
        (t, y, header) = rw(filename,
                            numhead)  #collect waveform data into array
        baseline = np.mean(
            y[0:200]
        )  #determining average value at beginning to establish baseline
        if abs(baseline) >= 0.0005:  #used to check baselines that are too big
            print(str(baseline) + ', ' + str(i))
        y_new = (y - baseline)  #reducing y to factor out baseline
        write_waveform(t, y_new, writename, header)  #writing waveforms
コード例 #6
0
def d1shift50(datadate, numhead):
    Nloops = len(
        os.listdir('G:/data/watchman/' + datadate +
                   '_watchman_spe/d1/d1_baseline_shifted')
    )  #establishing size of direcory
    (max_index, min_index, center_index, center_list) = center_check(
        Nloops, numhead,
        datadate)  #checking for average location of 50% rise point
    #printing calculated indices
    print(min_index)
    print(center_index)
    print(max_index)
    if not os.path.exists('G:/data/watchman/' + datadate +
                          '_watchman_spe/d1/d1_50centered/'
                          ):  #creating write directory if nonexistant
        os.makedirs('G:/data/watchman/' + datadate +
                    '_watchman_spe/d1/d1_50centered/')
    for i in range(Nloops):
        filename = 'G:/data/watchman/' + datadate + '_watchman_spe/d1/d1_baseline_shifted/D1--waveforms--%05d.txt' % i  #setting file name for reading
        writename = 'G:/data/watchman/' + datadate + '_watchman_spe/d1/d1_50centered/D1--waveforms--%05d.txt' % i  #setting file name for writing
        (t, y, header) = rw(filename, numhead)  #reading in waveform values
        index_50 = int(center_list[i] + 0.5)  #converting to int
        t_50 = t[
            index_50]  #converting index of 50% rising point to value at that point
        t_new = (t - t_50)  #shifting t_50 to t=0s
        #rolling so 50 rising point is at center index
        t_intermediate = np.roll(t_new, center_index - index_50)
        y_intermediate = np.roll(y, center_index - index_50)
        first_cutoff = (center_index - min_index
                        )  #determining latest first index
        last_cutoff = (len(y) - max_index + center_index
                       )  #determining earliest last index
        #slicing off 'problem indices'
        t_50centered = t_intermediate[first_cutoff:last_cutoff]
        y_50centered = y_intermediate[first_cutoff:last_cutoff]
        write_waveform(t_50centered, y_50centered, writename,
                       header)  #writing final waveform
コード例 #7
0
def p3_average_cycling(datadate, numhead, fsps, new_fsps, noise):
    filedir = 'G:/Data/watchman/' + datadate + '_watchman_spe/d2/'
    writedir1 = 'G:/Data/watchman/' + datadate + '_watchman_spe/d3/d3_averages/raw/'
    writedir2 = 'G:/Data/watchman/' + datadate + '_watchman_spe/d3/d3_averages/rise_doubled/'
    writedir4 = 'G:/Data/watchman/' + datadate + '_watchman_spe/d3/d3_averages/rise_quadrupled/'
    writedir8 = 'G:/Data/watchman/' + datadate + '_watchman_spe/d3/d3_averages/rise_octupled/'
    if not os.path.exists(writedir1):
        os.makedirs(writedir1)
    if not os.path.exists(writedir2):
        os.makedirs(writedir2)
    if not os.path.exists(writedir4):
        os.makedirs(writedir4)
    if not os.path.exists(writedir8):
        os.makedirs(writedir8)
    filename1 = filedir + 'd2_average.txt'
    filename2 = filedir + 'd2_average_doubled.txt'
    filename4 = filedir + 'd2_average_quadrupled.txt'
    filename8 = filedir + 'd2_average_octupled.txt'
    (t, v, header) = rw(filename1, numhead)
    (t2, v2, header2) = rw(filename2, numhead)
    (t4, v4, header4) = rw(filename4, numhead)
    (t8, v8, header8) = rw(filename8, numhead)
    (v, v2, v4, v8) = gain(v, v2, v4, v8)
    Nloops = 10000
    for i in range(Nloops):
        print(i)
        writename1 = writedir1 + 'D3--waveforms--%05d.txt' % i
        writename2 = writedir2 + 'D3--waveforms--%05d.txt' % i
        writename4 = writedir4 + 'D3--waveforms--%05d.txt' % i
        writename8 = writedir8 + 'D3--waveforms--%05d.txt' % i
        #downsampling waveform values
        (t_down_1, v_down_1) = downsampling(t, v, fsps, new_fsps)
        (t_down_2, v_down_2) = downsampling(t2, v2, fsps, new_fsps)
        (t_down_4, v_down_4) = downsampling(t4, v4, fsps, new_fsps)
        (t_down_8, v_down_8) = downsampling(t8, v8, fsps, new_fsps)
        #digitizing waveform values
        v_digit_1 = digitize(v_down_1, noise)
        v_digit_2 = digitize(v_down_2, noise)
        v_digit_4 = digitize(v_down_4, noise)
        v_digit_8 = digitize(v_down_8, noise)
        #saving downsampled and digitized waveforms
        write_waveform(t_down_1, v_digit_1, writename1, header)
        write_waveform(t_down_2, v_digit_2, writename2, header2)
        write_waveform(t_down_4, v_digit_4, writename4, header4)
        write_waveform(t_down_8, v_digit_8, writename8, header8)
コード例 #8
0
def p1_sort(filenum, datadate, lowpass, numhead, numtaps, threshold, baseline):
    filename = 'g:/data/watchman/' + datadate + '_watchman_spe/C2--waveforms--%05d.txt' % filenum
    spe_wasname = 'g:/data/watchman/' + datadate + '_watchman_spe/d1/d1_raw/D1--waveforms--%05d.txt' % filenum
    spe_not_there = 'g:/data/watchman/' + datadate + '_watchman_spe/d1/not_spe/D1--waveforms--%05d.txt' % filenum
    spe_unsure = 'g:/data/watchman/' + datadate + '_watchman_spe/d1/unsure_if_spe/D1--waveforms--%05d.txt' % filenum
    if not os.path.exists('g:/data/watchman/' + datadate +
                          '_watchman_spe/d1/d1_raw/'):
        os.makedirs('g:/data/watchman/' + datadate +
                    '_watchman_spe/d1/d1_raw/')
    if not os.path.exists('g:/data/watchman/' + datadate +
                          '_watchman_spe/d1/not_spe/'):
        os.makedirs('g:/data/watchman/' + datadate +
                    '_watchman_spe/d1/not_spe/')
    if not os.path.exists('g:/data/watchman/' + datadate +
                          '_watchman_spe/d1/unsure_if_spe/'):
        os.makedirs('g:/data/watchman/' + datadate +
                    '_watchman_spe/d1/unsure_if_spe/')
    if os.path.isfile(spe_wasname):
        pass
    elif os.path.isfile(spe_not_there):
        pass
    elif os.path.isfile(spe_unsure):
        pass
    else:
        (t, v, header) = rw(filename, numhead)

        y = signal.filtfilt(lowpass, 1.0, v)
        y2 = y[numtaps:len(y) - 1]
        t2 = t[numtaps:len(y) - 1]

        y_flip = -1 * y2
        height = -1 * (baseline + threshold)
        peaks, _ = signal.find_peaks(y_flip, height, distance=370)
        y_peaks = y2[peaks]
        t_peaks = t2[peaks]

        if len(peaks) != 0:  #Making sure there is a peak
            if len(peaks) == 1 and peaks[
                    0] >= 450:  #Checking if only 1 peak exists, making sure it's in proper range
                if min(
                        y2[370:1370]
                ) < baseline + threshold:  #Checking if peak is below -.0015V in range 370 to 1370
                    write_waveform(t2, y2, spe_wasname, header)
                    print(
                        len(
                            os.listdir('g:/data/watchman/' + datadate +
                                       '_watchman_spe/d1/d1_raw/')))
            else:
                if min(
                        y2[370:1370]
                ) < baseline + threshold:  #Shows plot if min is less than -0.0015V in range 370 to 1370
                    plt.figure()
                    plt.plot(t, v, 'b')
                    plt.plot(t2, y2, 'r', linewidth=2.5)
                    plt.plot(t_peaks, y_peaks, 'x', color='cyan')
                    plt.grid(True)
                    print('Displaying file #%05d' % filenum)
                    plt.get_current_fig_manager().window.showMaximized(
                    )  #maximizes plot
                    plt.show()

                    spe_check = 'pre-loop initialization'
                    while spe_check != 'y' and spe_check != 'u' and spe_check != 'n':
                        spe_check = input(
                            'Is there a single visible SPE? "y" or "n" or "u"\n'
                        )
                    #writing data to proper folder
                    if spe_check == 'y':
                        write_waveform(t2, y2, spe_wasname, header)
                    elif spe_check == 'n':
                        write_waveform(t2, y2, spe_not_there, header)
                    elif spe_check == 'u':
                        write_waveform(t2, y2, spe_unsure, header)
                    print('File #%05d: Done' % filenum)
                    print(
                        len(
                            os.listdir('g:/data/watchman/' + datadate +
                                       '_watchman_spe/d1/d1_raw/')))
    return
コード例 #9
0
def p1b_sort(datadate,charge_mean,peak_mean,FWHM_mean,numhead):
    #set file locations for charge and peak histograms
    charge_name = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_histograms/charge.txt'
    peak_name = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_histograms/peak_amplitude.txt'
    FWHM_name = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_histograms/FWHM.txt'
    ten_jitter_name = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_histograms/10_jitter.txt'
    twenty_jitter_name = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_histograms/20_jitter.txt'
    #initialize histogram arrays
    charge_histo = np.array([])
    peak_histo = np.array([])
    FWHM_histo = np.array([])
    ten_jitter_histo = np.array([])
    twenty_jitter_histo = np.array([])
    #read histogram txt files int othe arrays
    charge_fin = open(charge_name,'r')
    for line in charge_fin:
        charge_histo = np.append(charge_histo, float(line.split(',')[0]))
    charge_fin.close
    peak_fin = open(peak_name,'r')
    for line in peak_fin:
        peak_histo = np.append(peak_histo, float(line.split(',')[0]))
    peak_fin.close
    FWHM_fin = open(FWHM_name,'r')
    for line in FWHM_fin:
        FWHM_histo = np.append(FWHM_histo, float(line.split(',')[0]))
    FWHM_fin.close
    ten_jitter_fin = open(ten_jitter_name,'r')
    for line in ten_jitter_fin:
        ten_jitter_histo = np.append(ten_jitter_histo, float(line.split(',')[0]))
    ten_jitter_fin.close
    twenty_jitter_fin = open(twenty_jitter_name,'r')
    for line in twenty_jitter_fin:
        twenty_jitter_histo = np.append(twenty_jitter_histo, float(line.split(',')[0]))
    twenty_jitter_fin.close
    #setting up arrays listing indices of where the value is twice the mean or greater
    charge_doubles = np.asarray(charge_histo >= 2*charge_mean).nonzero()
    charge_doubles = charge_doubles[0]
    peak_doubles = np.asarray(peak_histo >= 2*peak_mean).nonzero()
    peak_doubles = peak_doubles[0]
    FWHM_doubles = np.asarray(FWHM_histo >= 2*FWHM_mean).nonzero()
    FWHM_doubles = FWHM_doubles[0]
    ten_jitter_positive = np.asarray(ten_jitter_histo > 0).nonzero()
    ten_jitter_positive = ten_jitter_positive[0]
    twenty_jitter_positive = np.asarray(twenty_jitter_histo > 0).nonzero()
    twenty_jitter_positive = twenty_jitter_positive[0]
    for i in range(len(charge_histo)):
        print(i)
        #setting location of files to read
        filename = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_50centered/D1--waveforms--%05d.txt' % i
        #setting up locations to write each file to
        writename_double = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_final_doubles/D1--waveforms--%05d.txt' % i
        writename_single = 'G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_final_spes/D1--waveforms--%05d.txt' % i
        if not os.path.exists('G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_final_doubles/'):
            os.makedirs('G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_final_doubles/')
        if not os.path.exists('G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_final_spes/'):
            os.makedirs('G:/data/watchman/'+datadate+'_watchman_spe/d1/d1_final_spes/')
        t,v,header = rw(filename,numhead)                                   #reading data from waveform file
        #checking if both charge and peak or charge and FWHM are greater than twice the mean
        if (np.any(charge_doubles == i) and np.any(peak_doubles == i)) or (np.any(FWHM_doubles == i) and np.any(charge_doubles == i)):
            print("Was double!")
            write_waveform(t,v,writename_double,header)
        #checking if any charge, peak, or FWHM are greater than twice the mean or if 10% or 20% rise times are positive
        elif any([np.any(charge_doubles == i), np.any(peak_doubles == i), np.any(FWHM_doubles == i), np.any(ten_jitter_positive == i), np.any(twenty_jitter_positive == i)]):
            #printing off what caused the graph to display for manual selection
            if np.any(charge_doubles == i):
                print("Charge")
            if np.any(peak_doubles == i):
                print("Peak")
            if np.any(FWHM_doubles == i):
                print("FWHM")
            if np.any(ten_jitter_positive == i):
                print("10% Jitter")
            if np.any(twenty_jitter_positive == i):
                print("20% Jitter")
            plt.title(filename)
            plt.plot(t,v)                   #plotting waveform in question
            plt.get_current_fig_manager().window.showMaximized()        #maximizes plot
            plt.show()
            double_check = 'Initialization.'
            while double_check != 's' and double_check != 'd':
                double_check = input('Is there a single or double? "s" or "d"\n')
            if double_check == 's':
                write_waveform(t,v,writename_single,header)
            if double_check == 'd':
                print("Was double!")
                write_waveform(t,v,writename_double,header)
        else:
            write_waveform(t,v,writename_single,header)
    return
コード例 #10
0
def p3(noise_filter, noise, datadate, numhead, fsps, new_fsps, gain_noise,
       gain_factor_2, gain_factor_4, gain_factor_8, start_index, steps):
    #establishing directory names
    if new_fsps == 1000000000:
        sample_rate = '1 Gsps'
    elif new_fsps == 500000000:
        sample_rate = '500 Msps'
    elif new_fsps == 250000000:
        sample_rate = '250 Msps'
    else:
        sample_rate = 'trash'
    if noise_filter == 0 and gain_noise == 0:
        filedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw'
        filedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled'
        filedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled'
        filedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled'
        writedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_raw'
        writedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_doubled'
        writedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_quadrupled'
        writedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_octupled'
    elif gain_noise == 0:
        filedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw_noise=' + str(
            noise) + 'V'
        filedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled_noise=' + str(
            noise) + 'V'
        filedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled_noise=' + str(
            noise) + 'V'
        filedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled_noise=' + str(
            noise) + 'V'
        writedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_raw_noise=' + str(noise_filter) + 'V'
        writedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_doubled_noise=' + str(
                noise_filter) + 'V'
        writedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_quadrupled_noise=' + str(
                noise_filter) + 'V'
        writedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_octupled_noise=' + str(
                noise_filter) + 'V'
    elif noise_filter == 0:
        filedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw_gain_noise=' + str(
            gain_noise) + 'V'
        filedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled_gain_noise=' + str(
            gain_noise) + 'V'
        filedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled_gain_noise=' + str(
            gain_noise) + 'V'
        filedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled_gain_noise=' + str(
            gain_noise) + 'V'
        writedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_raw_gain_noise=' + str(gain_noise) + 'V'
        writedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_doubled_gain_noise=' + str(
                gain_noise) + 'V'
        writedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_quadrupled_gain_noise=' + str(
                gain_noise) + 'V'
        writedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_octupled_gain_noise=' + str(
                gain_noise) + 'V'
    else:
        filedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
        filedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
        filedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
        filedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
        writedir1 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_raw_gain_noise=' + str(
                gain_noise) + 'V_noise=' + str(noise_filter) + 'V'
        writedir2 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_doubled_gain_noise=' + str(
                gain_noise) + 'V_noise=' + str(noise_filter) + 'V'
        writedir4 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_quadrupled_gain_noise=' + str(
                gain_noise) + 'V_noise=' + str(noise_filter) + 'V'
        writedir8 = 'g:/data/watchman/' + datadate + '_watchman_spe/studies/phase/' + sample_rate + '/phase=' + str(
            start_index) + '/phase_rise_octupled_gain_noise=' + str(
                gain_noise) + 'V_noise=' + str(noise_filter) + 'V'
    if gain_factor_2 != 1 or gain_factor_4 != 1 or gain_factor_8:
        filedir1 = filedir1 + '_gained/'
        filedir2 = filedir2 + '_gained/'
        filedir4 = filedir4 + '_gained/'
        filedir8 = filedir8 + '_gained/'
        writedir1 = writedir1 + '_gained_analyzed/'
        writedir2 = writedir2 + '_gained_analyzed/'
        writedir4 = writedir4 + '_gained_analyzed/'
        writedir8 = writedir8 + '_gained_analyzed/'
    else:
        filedir1 = filedir1 + '/'
        filedir2 = filedir2 + '/'
        filedir4 = filedir4 + '/'
        filedir8 = filedir8 + '/'
        writedir1 = writedir1 + '_analyzed/'
        writedir2 = writedir2 + '_analyzed/'
        writedir4 = writedir4 + '_analyzed/'
        writedir8 = writedir8 + '_analyzed/'
    #creating directories if they don't exist
    if not os.path.exists(writedir1):
        os.makedirs(writedir1)
    if not os.path.exists(writedir2):
        os.makedirs(writedir2)
    if not os.path.exists(writedir4):
        os.makedirs(writedir4)
    if not os.path.exists(writedir8):
        os.makedirs(writedir8)
    Nloops = len(
        os.listdir(filedir2))  #establishing how many files to cycle through
    for i in range(Nloops):
        print('%s/%s, File: %05d' %
              (start_index + 1, steps,
               i))  #printing number of file currently being processed
        #establishing read and write names
        filename1 = filedir1 + 'D2--waveforms--%05d.txt' % i
        filename2 = filedir2 + 'D2--waveforms--%05d.txt' % i
        filename4 = filedir4 + 'D2--waveforms--%05d.txt' % i
        filename8 = filedir8 + 'D2--waveforms--%05d.txt' % i
        writename1 = writedir1 + 'Phase--waveforms--%05d.txt' % i
        writename2 = writedir2 + 'Phase--waveforms--%05d.txt' % i
        writename4 = writedir4 + 'Phase--waveforms--%05d.txt' % i
        writename8 = writedir8 + 'Phase--waveforms--%05d.txt' % i
        #reading in waveform values
        (t1, v1, header1) = rw(filename1, numhead)
        (t2, v2, header2) = rw(filename2, numhead)
        (t4, v4, header4) = rw(filename4, numhead)
        (t8, v8, header8) = rw(filename8, numhead)
        #downsampling waveform values
        (t_down_1, v_down_1) = downsampling(t1 - start_index * 1 / 20000000000,
                                            v1, fsps, new_fsps, start_index)
        (t_down_2, v_down_2) = downsampling(t2 - start_index * 1 / 20000000000,
                                            v2, fsps, new_fsps, start_index)
        (t_down_4, v_down_4) = downsampling(t4 - start_index * 1 / 20000000000,
                                            v4, fsps, new_fsps, start_index)
        (t_down_8, v_down_8) = downsampling(t8 - start_index * 1 / 20000000000,
                                            v8, fsps, new_fsps, start_index)
        #digitizing waveform values
        v_digit_1 = digitize(v_down_1, noise)
        v_digit_2 = digitize(v_down_2, noise)
        v_digit_4 = digitize(v_down_4, noise)
        v_digit_8 = digitize(v_down_8, noise)
        #saving downsampled and digitized waveforms
        write_waveform(t_down_1, v_digit_1, writename1, header1)
        write_waveform(t_down_2, v_digit_2, writename2, header2)
        write_waveform(t_down_4, v_digit_4, writename4, header4)
        write_waveform(t_down_8, v_digit_8, writename8, header8)
コード例 #11
0
from readwaveform import read_waveform as rw
from writewaveform import write_waveform

#low pass filter
def lpfFirstOrder(v,tau,fsps):
    alpha = 1-np.exp(-1/(fsps*tau))                     #calcuating alpha variable for later use
    y = np.zeros(len(v))                                #initializing y array
    for i in range(len(v)):
        if i == 0:
            y[i] = v[i]                                 #setting first index to be the same
        else:
            y[i] = v[i]*alpha + (1-alpha)*y[i-1]        #calculating new values for subsequent indices
    baseline = np.mean(y[0:100])
    y = (y - baseline)
    return y

#for testing purposes
if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser(prog="p2 lowpass",description="applies lowpass filter to waveform.")
    parser.add_argument("--numhead",type=int,help='number of header lines to skip in the raw file',default=5)
    parser.add_argument("--filename",type=str,help="filename",default='g:/data/watchman/20190724_watchman_spe/d2/d2_histograms/average_quadrupled.txt')
    parser.add_argument("--writename",type=str,help="filename",default='g:/data/watchman/20190724_watchman_spe/d2/d2_histograms/average_octupled.txt')
    parser.add_argument("--tau",type=float,help="tau value",default=3.690110404416177e-08)
    parser.add_argument("--fsps",type=float,help="hz, samples/s",default=20e9)
    args = parser.parse_args()

    t,v,header = rw(args.filename,args.numhead)         #reading in information
    v_taued = lpfFirstOrder(v,args.tau,args.fsps)       #appling lpf
    write_waveform(t,v_taued,args.writename,header)     #saving new average waveform txt file
コード例 #12
0
def p2(datadate, numhead, fsps, noise, gain_noise, gain_factor_2,
       gain_factor_4, gain_factor_8):
    #establish tau values from average waveform
    tau_double = 1.4900444017760711e-08
    tau_quadruple = 1.05003120124805e-08
    tau_octuple = 3.690110404416177e-08
    #establish directories for reading and writing waveforms
    filedir = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw/'
    if noise == 0 and gain_noise == 0:
        writedir_1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw'
        writedir_2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled'
        writedir_4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled'
        writedir_8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled'
    elif gain_noise == 0:
        writedir_1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw_doubled_noise=' + str(
            noise) + 'V'
        writedir_2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled_noise=' + str(
            noise) + 'V'
        writedir_4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled_noise=' + str(
            noise) + 'V'
        writedir_8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled_noise=' + str(
            noise) + 'V'
    elif noise == 0:
        writedir_1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw_gain_noise=' + str(
            gain_noise) + 'V'
        writedir_2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled_gain_noise=' + str(
            gain_noise) + 'V'
        writedir_4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled_gain_noise=' + str(
            gain_noise) + 'V'
        writedir_8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled_gain_noise=' + str(
            gain_noise) + 'V'
    else:
        writedir_1 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_raw_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
        writedir_2 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_doubled_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
        writedir_4 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_quadrupled_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
        writedir_8 = 'g:/data/watchman/' + datadate + '_watchman_spe/d2/d2_rise_octupled_gain_noise=' + str(
            gain_noise) + 'V_noise=' + str(noise) + 'V'
    if gain_factor_2 != 1 or gain_factor_4 != 1 or gain_factor_8:
        writedir_1 = writedir_1 + '_gained/'
        writedir_2 = writedir_2 + '_gained/'
        writedir_4 = writedir_4 + '_gained/'
        writedir_8 = writedir_8 + '_gained/'
    else:
        writedir_1 = writedir_1 + '/'
        writedir_2 = writedir_2 + '/'
        writedir_4 = writedir_4 + '/'
        writedir_8 = writedir_8 + '/'
    #creating write directories if they're not there
    if not os.path.exists(writedir_1):
        os.makedirs(writedir_1)
    if not os.path.exists(writedir_2):
        os.makedirs(writedir_2)
    if not os.path.exists(writedir_4):
        os.makedirs(writedir_4)
    if not os.path.exists(writedir_8):
        os.makedirs(writedir_8)
    #establishing length of raw directory and subtracting one due to info file
    Nloops = len(
        os.listdir('G:/data/watchman/' + datadate +
                   '_watchman_spe/d2/d2_raw')) - 1
    #cycling through all waveform files in directory
    for i in range(Nloops):
        print("File: %05d" % i)
        #establishing file names for reading and writing
        filename = filedir + 'D2--waveforms--%05d.txt' % i
        writename_1 = writedir_1 + 'D2--waveforms--%05d.txt' % i
        writename_2 = writedir_2 + 'D2--waveforms--%05d.txt' % i
        writename_4 = writedir_4 + 'D2--waveforms--%05d.txt' % i
        writename_8 = writedir_8 + 'D2--waveforms--%05d.txt' % i
        #calculating and writing double files
        (t, v_2, header) = rw(filename, numhead)
        v_taued_2 = lpf(v_2, tau_double, fsps)
        if noise != 0:
            v_taued_2 = noise_add(v_taued_2, noise)
        #calculating and writing quadruple files
        v_taued_4 = lpf(v_taued_2, tau_quadruple, fsps)
        if noise != 0:
            v_taued_4 = noise_add(v_taued_4, noise)
        #calculating and writing octuple files
        v_taued_8 = lpf(v_taued_4, tau_octuple, fsps)
        if noise != 0:
            v_taued_8 = noise_add(v_taued_8, noise)
        #adding gain to waveforms
        if gain_factor_2 != 1:
            v_taued_2 = gain(v_taued_2, gain_noise, gain_factor_2)
        if gain_factor_4 != 1:
            v_taued_4 = gain(v_taued_4, gain_noise, gain_factor_4)
        if gain_factor_8 != 1:
            v_taued_8 = gain(v_taued_8, gain_noise, gain_factor_8)
        #writing waveforms
        shutil.copy2(filedir + 'd1_info.txt', writename_1)
        shutil.copy2(filename, writename_1)
        write_waveform(t, v_taued_2, writename_2, header)
        write_waveform(t, v_taued_4, writename_4, header)
        write_waveform(t, v_taued_8, writename_8, header)