コード例 #1
0
def ToA_cluster(shot):
    # Go to the @shot folder
    try:
        path = path_to_shot(shot)
    except:
        raise SystemExit
    
    # Get the data
    Data_tpx3_cent = np.genfromtxt('%s.csv' % shot, delimiter=',')
    # Read the first row in the .csv file and get index of the required signal
    with open('%s.csv' % shot, newline='') as f:
        reader = csv.reader(f)
        row1 = next(reader) 
    
    try:
        index = row1.index('#Trig-ToA[arb]')
        index2 = row1.index('#Centroid')
        time_new = np.array([row[index] for row in Data_tpx3_cent]) * 25/4096/1e6 + 912
        cent = np.array([row[index2] for row in Data_tpx3_cent])
        p=1
    except:
        print("No 'Trig-ToA' in the list")
        index = row1.index('#ToA')
        index2 = row1.index('#Centroid')
        time_new = np.array([row[index] for row in Data_tpx3_cent]) * 25/4096/1e6
        cent = np.array([row[index2] for row in Data_tpx3_cent])
    
    # try:
    #     index1 = row1.index('#ToA')
    #     index2 = row1.index('#Centroid')
    #     time_new = np.array([row[index1] for row in Data_tpx3_cent]) * 25/4096/1e6
    #     cent = np.array([row[index2] for row in Data_tpx3_cent])
    # except:
    #     print("No 'ToA' in the list")
    #     raise SystemExit
    
    # Define the bins with the step of 1.5625
    bins1 = np.arange(time_new[0], time_new[-1], 1.5625)
    
    # Compute a histogram
    a = np.histogram(time_new, bins = bins1)
    
    # Prepare empty arrays for the indices of particular clusters
    ones_full = np.zeros(len(cent))
    twos_full = np.zeros(len(cent))
    threes_full = np.zeros(len(cent))
    fours_full = np.zeros(len(cent))
    fives_full = np.zeros(len(cent))
    
    # Fill the arrays with indices
    for i in range (0, len(cent)):
        if cent[i] == 1:
            ones_full[i] = i
        elif cent[i] == 2:
            twos_full[i] = i
        elif cent[i] == 3:
            threes_full[i] = i
        elif cent[i] == 4:
            fours_full[i] = i
        else: fives_full[i] = i
    
    # Cut off the empty part, leaving an array of indices of clusters
    ones = ones_full[ones_full != 0]
    twos = twos_full[twos_full != 0]
    threes = threes_full[threes_full != 0]
    fours = fours_full[fours_full != 0]
    fives = fives_full[fives_full != 0]

    # Transform float to integer for further manipulation
    ones = ones.astype(int)
    twos = twos.astype(int)
    threes = threes.astype(int)
    fours = fours.astype(int)
    fives = fives.astype(int)
    
    # Prepair array for the data from time_new
    ones_toa = np.zeros(len(ones))
    twos_toa = np.zeros(len(twos))
    threes_toa = np.zeros(len(threes))
    fours_toa = np.zeros(len(fours))
    fives_toa = np.zeros(len(fives))
    
    # Fill the toa arrays with the corresponding data
    for j in range (0, len(ones)):
        a = ones[j]
        ones_toa[j] = time_new[a]
        
        a,j = 0,0
    for j in range (0, len(twos)):
        a = twos[j]
        twos_toa[j] = time_new[a]
    
    a,j = 0,0  
    for j in range (0, len(threes)):
        a = threes[j]
        threes_toa[j] = time_new[a]
    
    a,j = 0,0   
    for j in range (0, len(fours)):
        a = fours[j]
        fours_toa[j] = time_new[a]
        
    a,j = 0,0
    for j in range (0, len(fives)):
        a = fives[j]
        fives_toa[j] = time_new[a]
        
    # Prepair a tuple of arrays filled with toa clusters for stacked histogram
    toa_multi = [ones_toa, twos_toa, threes_toa, fours_toa, fives_toa]
    labels = ['1', '2', '3', '4', '5']
    
    bins = int((time_new[-1] - time_new[0]) / 1.5625*4)
    empty = np.zeros(len(time_new))
    
    # Define the range limits for the appropriate plot
    # left, right = int(np.nonzero(data)[0][0]), int(np.nonzero(data)[0][-1])
    
    fig = plt.figure()
    plt.rcParams.update({'font.size': 16})
    plt.title("Shot %s: ToA by clusters" % shot)
    plt.xlabel("Time, [ms]")
    plt.ylabel("Hits, [a.u.]")
    plt.plot(empty, color = 'white', label="Cluster size:")
    a = plt.hist(toa_multi, bins, (time_new[0], time_new[-1]), histtype='step', stacked=True, fill=False, label = labels)
    # Get rid off the noisy "ones" for an appropriate plot
    data = None
    for i in range (0,4):
        if max(a[0][i+1]) > max(a[0][i]):
            data = a[0][i+1]
    timee = a[1]
    
    ones = np.where(data < 10)[0]
    
    for i in range (0, len(ones)):
        data[ones[i]] = 0
    
    # Define limits of x axis for an appropriate plot
    try:
        left, right = int(timee[np.nonzero(data)[0][0]]-10), int(timee[np.nonzero(data)[0][-1]]+10)
        plt.xlim(left, right)
    except:
        print("Probably no data at all or just a weak signal")
        pass
    
    plt.legend(loc="upper left")
    
# Go to the Figures folder
    try:
        os.chdir("%s/Figures" % path)
    except:
        print("No folder, creating one")
        os.mkdir("%s/Figures" % path)
        os.chdir("%s/Figures" % path)
    
    fig.set_size_inches(20., 12., forward=True)
    plt.savefig('%s:ToA_cluster.pdf' % shot)
    plt.close(fig)
コード例 #2
0
pyautogui.FAILSAFE = True

os.chdir("/home/sjing/Documents/daisuki/COMPASS/Codes/Functional")

### Automatic for all shots (add indent for all below) ###
shots = np.genfromtxt('shots:21215-21237.txt')

for i in range(0, len(shots)):
    shot = int(shots[i])

    ### For single shot (un-indent everything below)
    # shot = input("Shot number:")

    # Go to the @shot folder
    try:
        path = path_to_shot(shot)
        # path = "/home/sjing/Documents/daisuki/COMPASS/RE_18.11.2020/%s" % shot
    except:
        continue

    # Urls and datafiles: 1-current, 2-HXR, 3-SXR, 4-neutrons, 5-gas puff
    url1 = 'https://webcdb.tok.ipp.cas.cz/data_signals/728/%s/data?variant=&revision=1&downsample=100' % (
        shot)
    url2 = 'https://webcdb.tok.ipp.cas.cz/data_signals/1266/%s/data?variant=&revision=1&downsample=100' % (
        shot)
    url3 = 'https://webcdb.tok.ipp.cas.cz/data_signals/1195/%s/data?variant=&revision=1&downsample=100' % (
        shot)
    url4 = 'https://webcdb.tok.ipp.cas.cz/data_signals/2122/%s/data?variant=&revision=1&downsample=100' % (
        shot)
    url5 = 'https://webcdb.tok.ipp.cas.cz/data_signals/4789/%s/data?variant=&revision=1' % (
        shot)
コード例 #3
0
def hitmap_double(shot):

    # Go to the @shot folder
    try:
        path = path_to_shot(shot)
    except:
        raise SystemExit

    # Get the data
    Data_tpx3_cent = np.genfromtxt('%s.csv' % shot, delimiter=',')
    # Read the first row in the .csv file and get index of the required signal
    with open('%s.csv' % shot, newline='') as f:
        reader = csv.reader(f)
        row1 = next(reader)

    try:
        index1 = row1.index('#Col')
        index2 = row1.index('#Row')
        index3 = row1.index('#Centroid')
        col_total = np.array([row[index1] for row in Data_tpx3_cent])
        row_total = np.array([row[index2] for row in Data_tpx3_cent])
        cent = np.array([row[index3] for row in Data_tpx3_cent])
    except:
        print("No 'ToA' in the list")
        raise SystemExit

    # Prepare arrays for the cluster separation
    col_ones = np.zeros(len(col_total))
    row_ones = np.zeros(len(row_total))
    col_noones = np.zeros(len(col_total))
    row_noones = np.zeros(len(row_total))

    # Fill the arrays with appropriate data defined by the cluster size
    for i in range(0, len(col_total)):
        if cent[i] == 1:
            col_ones[i] = col_total[i]
            row_ones[i] = row_total[i]
            col_noones[i] = 0
            row_noones[i] = 0
        else:
            col_ones[i] = 0
            row_ones[i] = 0
            col_noones[i] = col_total[i]
            row_noones[i] = row_total[i]

    # Compute histograms: H - all data, H1 - with particular cluster size
    H, xedges, yedges = np.histogram2d(row_total, col_total, 255,
                                       [[0, 255], [0, 255]])
    H1, xedges1, yedges1 = np.histogram2d(row_ones, col_ones, 255,
                                          [[0, 255], [0, 255]])
    H2, xedges2, xedges2 = np.histogram2d(row_noones, col_noones, 255,
                                          [[0, 255], [0, 255]])

    row_left = min(row_total)
    row_right = max(row_total)
    col_left = min(col_total)
    col_right = max(col_total)
    row_l = int(row_right - row_left)
    col_l = int(col_right - col_left)

    H_, xedges_, yedges_ = np.histogram2d(
        row_total, col_total, (row_l, col_l),
        [[row_left, row_right], [col_left, col_right]])
    H_1, xedges_1, yedges_1 = np.histogram2d(
        row_ones, col_ones, (row_l, col_l),
        [[row_left, row_right], [col_left, col_right]])
    H_2, xedges_2, ydeges_2 = np.histogram2d(
        row_noones, col_noones, (row_l, col_l),
        [[row_left, row_right], [col_left, col_right]])

    # Mask zeros to get a white color of the background
    H_masked = np.ma.masked_where(H == 0, H)
    H1_masked = np.ma.masked_where(H1 == 0, H1)
    H2_masked = np.ma.masked_where(H2 == 0, H2)
    H__masked = np.ma.masked_where(H_ == 0, H_)
    H_1_masked = np.ma.masked_where(H_1 == 0, H_1)
    H_2_masked = np.ma.masked_where(H_2 == 0, H_2)
    # Limits for the same colorbars
    vmin = 0
    vmax = np.max(H)
    # =============================================================================
    # Plot
    # =============================================================================

    fig, axes = plt.subplots(2, 3)
    fig.subplots_adjust(hspace=0.6, wspace=0.6)
    plt.rcParams.update({'font.size': 16})

    fig1 = axes[0, 0].imshow(H_masked,
                             interpolation='none',
                             origin='low',
                             vmin=vmin,
                             vmax=vmax)
    fig.colorbar(fig1, ax=axes[0, 0], label="Hits", fraction=0.046, pad=0.04)
    axes[0, 0].set_title("Shot %s: Hitmap" % shot)
    axes[0, 0].set_xlabel("Pixels, x axis")
    axes[0, 0].set_ylabel("Pixels, y axis")

    fig2 = axes[0, 1].imshow(H1_masked,
                             interpolation='none',
                             origin='low',
                             vmin=vmin,
                             vmax=vmax)
    fig.colorbar(fig2, ax=axes[0, 1], label="Hits", fraction=0.046, pad=0.04)
    axes[0, 1].set_title("Hitmap, cluster=1")
    axes[0, 1].set_xlabel("Pixels, x axis")
    axes[0, 1].set_ylabel("Pixels, y axis")

    fig3 = axes[0, 2].imshow(H2_masked,
                             interpolation='none',
                             origin='low',
                             vmin=vmin,
                             vmax=vmax)
    fig.colorbar(fig3, ax=axes[0, 2], label="Hits", fraction=0.046, pad=0.04)
    axes[0, 2].set_title("Hitmap, cluster>1")
    axes[0, 2].set_xlabel("Pixels, x axis")
    axes[0, 2].set_ylabel("Pixels, y axis")

    fig4 = axes[1, 0].imshow(H__masked,
                             interpolation='none',
                             origin='low',
                             vmin=vmin,
                             vmax=vmax)
    fig.colorbar(fig4, ax=axes[1, 0], label="Hits", fraction=0.046, pad=0.04)
    axes[1, 0].set_title("Hitmap")
    axes[1, 0].set_xlabel("Pixels, x axis")
    axes[1, 0].set_ylabel("Pixels, y axis")

    fig5 = axes[1, 1].imshow(H_1_masked,
                             interpolation='none',
                             origin='low',
                             vmin=vmin,
                             vmax=vmax)
    fig.colorbar(fig5, ax=axes[1, 1], label="Hits", fraction=0.046, pad=0.04)
    axes[1, 1].set_title("Hitmap, cluster=1")
    axes[1, 1].set_xlabel("Pixels, x axis")
    axes[1, 1].set_ylabel("Pixels, y axis")

    fig6 = axes[1, 2].imshow(H_2_masked,
                             interpolation='none',
                             origin='low',
                             vmin=vmin,
                             vmax=vmax)
    fig.colorbar(fig6, ax=axes[1, 2], label="Hits", fraction=0.046, pad=0.04)
    axes[1, 2].set_title("Hitmap, cluster>1")
    axes[1, 2].set_xlabel("Pixels, x axis")
    axes[1, 2].set_ylabel("Pixels, y axis")

    # Go to the Figures folder
    try:
        os.chdir("%s/Figures" % path)
    except:
        print("No folder, creating one")
        os.mkdir("%s/Figures" % path)
        os.chdir("%s/Figures" % path)

    fig.set_size_inches(20., 12., forward=True)
    plt.savefig('%s:Hitmap_double.pdf' % shot)
    plt.close(fig)
コード例 #4
0
ファイル: ToA_func.py プロジェクト: rngKomorebi/Tpx3_old
def ToA(shot):
    # Go to the @shot folder
    try:
        path = path_to_shot(shot)
    except:
        raise SystemExit
    
    # Get the data
    Data_tpx3_cent = np.genfromtxt('%s.csv' % shot, delimiter=',')
    # Read the first row in the .csv file and get index of the required signal
    with open('%s.csv' % shot, newline='') as f:
        reader = csv.reader(f)
        row1 = next(reader) 
    
    try:
        index = row1.index('#Trig-ToA[arb]')
        time_new = np.array([row[index] for row in Data_tpx3_cent]) * 25/4096/1e6 + 912
        p=1
    except: 
        print("No 'Trig-ToA' in the list")
        index = row1.index('#ToA')
        time_new = np.array([row[index] for row in Data_tpx3_cent]) * 25/4096/1e6
    
    # try:
    #     index = row1.index('#ToA')
    #     time_new = np.array([row[index] for row in Data_tpx3_cent]) * 25/4096/1e6
    # except:
    #     print("No 'ToA' in the list")
    
    # Define the bins with the step of 1.5625
    bins1 = int((time_new[-1] - time_new[0]) / 1.5625*4)
    
    # Prepare figure and compute the histogram
    fig = plt.figure()
    plt.rcParams.update({'font.size': 16})
    plt.title("Shot %s: ToA" % shot)
    plt.xlabel("Time, [ms]")
    plt.ylabel("Hits, [a.u.]")
    a = plt.hist(time_new, bins1, (time_new[0], time_new[-1]), histtype='step', fill=False)
    # Get rid off the noisy "ones" for an appropriate plot
    data = a[0]
    timee = a[1]
    
    ones = np.where(data < 10)[0]
    
    for i in range (0, len(ones)):
        data[ones[i]] = 0
    
    # Define limits of x axis for an appropriate plot
    try:
        left, right = int(timee[np.nonzero(data)[0][0]]-10), int(timee[np.nonzero(data)[0][-1]]+10)
        plt.xlim(left, right)
    except:
        print("Probably no data at all or just a weak signal")
        pass
    
    # Show the result within the limits
    plt.show()
    
    # Go to the Figures folder
    try:
        os.chdir("%s/Figures" % path)
    except:
        print("No folder, creating one")
        os.mkdir("%s/Figures" % path)
        os.chdir("%s/Figures" % path)

    fig.set_size_inches(20., 12., forward=True)
    fig.savefig('%s:ToA_plt.pdf' % shot)
    plt.close(fig)
コード例 #5
0
def ToT_vs_ToA(shot):
    # Go to the @shot folder
    try:
        path = path_to_shot(shot)
    except:
        raise SystemExit
    
    # Get the data
    Data_tpx3_cent = np.genfromtxt('%s.csv' % shot, delimiter=',')
    # Read the first row in the .csv file and get index of the required signal
    with open('%s.csv' % shot, newline='') as f:
        reader = csv.reader(f)
        row1 = next(reader) 
    
    try:
        index1 = row1.index('#ToA')
        index2 = row1.index('#ToTtotal[arb]')
        time_new = np.array([row[index1] for row in Data_tpx3_cent]) * 25/4096/1e6
        tot = np.array([row[index2] for row in Data_tpx3_cent])
    except:
        print("No 'ToA' or 'ToT' in the list")
        raise SystemExit
    
    bins1 = np.arange(time_new[0], time_new[-1], 1.5625)
    bins2 = np.arange(0, 25000, 25)
    
    H, xedges, yedges = np.histogram2d(time_new, tot, [bins1,bins2])
    a = np.histogram(time_new, bins = bins1)
    
    # Time and data from the histogram
    timee = a[1]
    data = a[0]
    
    # Get rid off the noisy "ones" for an appropriate plot
    ones = np.where(data == 1)[0]
    
    for i in range (0, len(ones)):
        data[ones[i]] = 0
    
    # Define the range limits for the appropriate plot
    try:
        l_lim, r_lim = int(np.nonzero(data)[0][0]), int(np.nonzero(data)[0][-1])
        left, right = timee[l_lim]-10, timee[r_lim]+10
    except:
        print("Could not compute 'left' and 'right'")
    y, x = np.meshgrid(yedges,xedges)
    
    data_masked = np.ma.masked_where(H == 0, H)
    
    fig = plt.figure()
    fig1 = plt.gca()
    plt.rcParams.update({'font.size': 16})
    try:
        plt.xlim(left, right)
    except:
        pass
    yticks = fig1.yaxis.get_major_ticks() 
    yticks[0].label1.set_visible(False)
    # plt.pcolormesh(x, y, H)
    plt.pcolormesh(x, y, data_masked)
    plt.colorbar(label="Hits")
    plt.title("Shot %s: ToT vs ToA" % shot)
    plt.xlabel("ToA, [ms]")
    plt.ylabel("ToT, [a.u.]")
    
# Go to the Figures folder
    try:
        os.chdir("%s/Figures" % path)
    except:
        print("No folder, creating one")
        os.mkdir("%s/Figures" % path)
        os.chdir("%s/Figures" % path)
    
    fig.set_size_inches(20., 12., forward=True)
    fig.savefig('%s:ToTvsToA.png' % shot)
    plt.close(fig)
コード例 #6
0
ファイル: window_size.py プロジェクト: rngKomorebi/Tpx3_old
import numpy as np
import matplotlib.pyplot as plt
import os
import csv
from path_to_shot import *
# Plot figures in external window:
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'qt')

shot1 = int(input("Shot number:"))
shot2 = int(input("Shot number:"))
shot3 = int(input("Shot number:"))

# Go to the @shot folder
try:
    path = path_to_shot(shot1)
except:
    raise SystemExit

# Get the data
Data_tpx3_cent1 = np.genfromtxt('%s.csv' % shot1, delimiter=',')
# Read the first row in the .csv file and get index of the required signal
with open('%s.csv' % shot1, newline='') as f1:
    reader1 = csv.reader(f1)
    row1 = next(reader1)

# Go to the @shot folder
try:
    path = path_to_shot(shot2)
except:
    raise SystemExit
コード例 #7
0
def ToT_cluster(shot):
    # Go to the @shot folder
    try:
        path = path_to_shot(shot)
    except:
        raise SystemExit

    # Get the data
    Data_tpx3_cent = np.genfromtxt('%s.csv' % shot, delimiter=',')
    # Read the first row in the .csv file and get index of the required signal
    with open('%s.csv' % shot, newline='') as f:
        reader = csv.reader(f)
        row1 = next(reader)

    try:
        index1 = row1.index('#ToTtotal[arb]')
        index2 = row1.index('#Centroid')
        tot_total = np.array([row[index1]
                              for row in Data_tpx3_cent])  # Total ToT
        cent = np.array([row[index2] for row in Data_tpx3_cent])
    except:
        print("No 'ToA' in the list")
        raise SystemExit

    # Prepare empty arrays for the indices of particular clusters
    ones_full = np.zeros(len(cent))
    twos_full = np.zeros(len(cent))
    threes_full = np.zeros(len(cent))
    fours_full = np.zeros(len(cent))
    fives_full = np.zeros(len(cent))

    # Fill the arrays with indices
    for i in range(0, len(cent)):
        if cent[i] == 1:
            ones_full[i] = i
        elif cent[i] == 2:
            twos_full[i] = i
        elif cent[i] == 3:
            threes_full[i] = i
        elif cent[i] == 4:
            fours_full[i] = i
        else:
            fives_full[i] = i

    # Cut off the empty part, leaving an array of indices of clusters
    ones = ones_full[ones_full != 0]
    twos = twos_full[twos_full != 0]
    threes = threes_full[threes_full != 0]
    fours = fours_full[fours_full != 0]
    fives = fives_full[fives_full != 0]

    # Transform float to integer for further manipulation
    ones = ones.astype(int)
    twos = twos.astype(int)
    threes = threes.astype(int)
    fours = fours.astype(int)
    fives = fives.astype(int)

    # Prepair array for the data from ToT_total
    ones_tot = np.zeros(len(ones))
    twos_tot = np.zeros(len(twos))
    threes_tot = np.zeros(len(threes))
    fours_tot = np.zeros(len(fours))
    fives_tot = np.zeros(len(fives))

    # Fill the ToT arrays with the corresponding data
    for j in range(0, len(ones)):
        a = ones[j]
        ones_tot[j] = tot_total[a]

    a, j = 0, 0
    for j in range(0, len(twos)):
        a = twos[j]
        twos_tot[j] = tot_total[a]

    a, j = 0, 0
    for j in range(0, len(threes)):
        a = threes[j]
        threes_tot[j] = tot_total[a]

    a, j = 0, 0
    for j in range(0, len(fours)):
        a = fours[j]
        fours_tot[j] = tot_total[a]

    a, j = 0, 0
    for j in range(0, len(fives)):
        a = fives[j]
        fives_tot[j] = tot_total[a]

    # Prepair a tuple of arrays filled with ToT clusters for stacked histogram
    tot_multi = [ones_tot, twos_tot, threes_tot, fours_tot, fives_tot]
    labels = ['1', '2', '3', '4', '5']

    # To add some text to the legend
    empty = np.zeros(len(tot_multi))
    # Bin value==25
    # bins1 = np.arange(0,25000,1000)
    # Comptute a histogram
    # hist = np.histogram(tot_multi, bins=bins1)
    # timee = hist[0]
    # data = hist[1]
    # =============================================================================
    # Plot
    # =============================================================================

    fig = plt.figure()
    plt.rcParams.update({'font.size': 16})
    plt.title("Shot %s: ToT by clusters" % shot)
    plt.xlabel("ToT, [a.u.]")
    plt.ylabel("Hits, [a.u.]")
    plt.plot(empty, color='white', label="Cluster size:")
    plt.hist(tot_multi,
             1000, (0, 25000),
             histtype='step',
             stacked=True,
             fill=False,
             label=labels)
    # plt.plot(timee, data)
    plt.legend()

    # Go to the Figures folder
    try:
        os.chdir("%s/Figures" % path)
    except:
        print("No folder, creating one")
        os.mkdir("%s/Figures" % path)
        os.chdir("%s/Figures" % path)

    fig.set_size_inches(20., 12., forward=True)
    plt.savefig('%s:ToT_cluster.pdf' % shot)
    plt.close(fig)