2018/detector_count_movie.py
def counts_per_s(work_dir,obsid,doplot):
    """
    Output is a dictionary, which has as keys, the DET_ID, and correspondingly
    an array where each entry = counts per second at any given second.
    
    counts_dict = {'detector':[t=1,t=2,t=3,...], 'detector':[t=1,t=2,...]}
    """ 
    
    counts_dict = {}
    
    times,pi,counts,detid_data = get_data(work_dir,obsid)
    
    shifted_t = times-times[0]
    t_bins = np.linspace(0,int(shifted_t[-1]),int(shifted_t[-1])+1)
    detids = detid()
    
    for i in range(len(detids)): #for each FPM
        times,pi,counts,detid_data = get_data(work_dir,obsid)
        np.place(counts,detid_data!=np.int8(detids[i]),0) #replace not-detector by 0
        summed_data, bin_edges, binnumber = stats.binned_statistic(shifted_t,counts,statistic='sum',bins=t_bins)
        if detids[i] < 10:
            index = '0' + str(detids[i])
            counts_dict[index] = summed_data
        else:
            counts_dict[str(detids[i])] = summed_data

    if doplot==True:
        boundaries = get_subregion_indices(work_dir,obsid)
        
        from matplotlib.backends.backend_pdf import PdfPages
        count = 0
        for i in tqdm(range(0,len(boundaries),2)):
            xlim1 = boundaries[i]
            xlim2 = boundaries[i+1]
            count+=1
            subr_dir = work_dir+obsid+'/detectors/'
            ensure_dir(subr_dir)
            filename = subr_dir + 'SubR'+str(count)+'.pdf'
            with PdfPages(filename) as pdf:
                max_y = 0
                for i in range(len(detids)):
                    if detids[i] < 10:
                        index = '0' + str(detids[i])
                    else:
                        index = str(detids[i])
                    if max(counts_dict[index][xlim1:xlim2]) > max_y:
                        max_y = max(counts_dict[index][xlim1:xlim2])
               
                for i in range(len(detids)):    
                    if detids[i] < 10:
                        index = '0' + str(detids[i])
                    else:
                        index = str(detids[i])
                    plt.figure(figsize=(10,8))
                    plt.plot(t_bins[:-1][xlim1:xlim2],counts_dict[index][xlim1:xlim2],'-')
                    plt.title(obsname + ' ' + obsid + ': Counts/s vs time (s), DETID ' + index,fontsize=15)
                    plt.xlabel('Time (s)',fontsize=15)
                    plt.xlim([xlim1,xlim2])
                    plt.ylim([0,max_y])
                    plt.ylabel('Count/s',fontsize=15)
                    pdf.savefig()
                    plt.close()
            
    return counts_dict

    Output is a dictionary, which has as keys, the DET_ID, and correspondingly
    an array where each entry = counts per second at any given second.
    
    counts_dict = {'detector':[t=1,t=2,t=3,...], 'detector':[t=1,t=2,...]}
    
Output is a dictionary, which has as keys, the DET_ID, and correspondingly
an array where each entry = counts per second at any given second.


Output is a dictionary which has as keys the DET_ID and correspondingly an array where each entry = counts per second at any given second .
def counts_per_s(work_dir,obsid,doplot):
    counts_dict = {}
    times,pi,counts,detid_data = get_data(work_dir,obsid)
    shifted_t = times-times[0]
    t_bins = np.linspace(0,int(shifted_t[-1]),int(shifted_t[-1])+1)
    detids = detid()
    for i in range(len(detids)): 
        times,pi,counts,detid_data = get_data(work_dir,obsid)
        np.place(counts,detid_data!=np.int8(detids[i]),0) 
        summed_data, bin_edges, binnumber = stats.binned_statistic(shifted_t,counts,statistic='sum',bins=t_bins)
        if detids[i] < 10:
            index = '0' + str(detids[i])
            counts_dict[index] = summed_data
        else:
            counts_dict[str(detids[i])] = summed_data
    if doplot==True:
        boundaries = get_subregion_indices(work_dir,obsid)
        from matplotlib.backends.backend_pdf import PdfPages
        count = 0
        for i in tqdm(range(0,len(boundaries),2)):
            xlim1 = boundaries[i]
            xlim2 = boundaries[i+1]
            count+=1
            subr_dir = work_dir+obsid+'/detectors/'
            ensure_dir(subr_dir)
            filename = subr_dir + 'SubR'+str(count)+'.pdf'
            with PdfPages(filename) as pdf:
                max_y = 0
                for i in range(len(detids)):
                    if detids[i] < 10:
                        index = '0' + str(detids[i])
                    else:
                        index = str(detids[i])
                    if max(counts_dict[index][xlim1:xlim2]) > max_y:
                        max_y = max(counts_dict[index][xlim1:xlim2])
                for i in range(len(detids)):    
                    if detids[i] < 10:
                        index = '0' + str(detids[i])
                    else:
                        index = str(detids[i])
                    plt.figure(figsize=(10,8))
                    plt.plot(t_bins[:-1][xlim1:xlim2],counts_dict[index][xlim1:xlim2],'-')
                    plt.title(obsname + ' ' + obsid + ': Counts/s vs time (s), DETID ' + index,fontsize=15)
                    plt.xlabel('Time (s)',fontsize=15)
                    plt.xlim([xlim1,xlim2])
                    plt.ylim([0,max_y])
                    plt.ylabel('Count/s',fontsize=15)
                    pdf.savefig()
                    plt.close()
    return counts_dict
def counts_per_s ( work_dir , obsid , doplot ) : counts_dict = { } times , pi , counts , detid_data = get_data ( work_dir , obsid ) shifted_t = times - times [ 0 ] t_bins = np . linspace ( 0 , int ( shifted_t [ - 1 ] ) , int ( shifted_t [ - 1 ] ) + 1 ) detids = detid ( ) for i in range ( len ( detids ) ) : times , pi , counts , detid_data = get_data ( work_dir , obsid ) np . place ( counts , detid_data != np . int8 ( detids [ i ] ) , 0 ) summed_data , bin_edges , binnumber = stats . binned_statistic ( shifted_t , counts , statistic = 'sum' , bins = t_bins ) if detids [ i ] < 10 : index = '0' + str ( detids [ i ] ) counts_dict [ index ] = summed_data else : counts_dict [ str ( detids [ i ] ) ] = summed_data if doplot == True : boundaries = get_subregion_indices ( work_dir , obsid ) from matplotlib . backends . backend_pdf import PdfPages count = 0 for i in tqdm ( range ( 0 , len ( boundaries ) , 2 ) ) : xlim1 = boundaries [ i ] xlim2 = boundaries [ i + 1 ] count += 1 subr_dir = work_dir + obsid + '/detectors/' ensure_dir ( subr_dir ) filename = subr_dir + 'SubR' + str ( count ) + '.pdf' with PdfPages ( filename ) as pdf : max_y = 0 for i in range ( len ( detids ) ) : if detids [ i ] < 10 : index = '0' + str ( detids [ i ] ) else : index = str ( detids [ i ] ) if max ( counts_dict [ index ] [ xlim1 : xlim2 ] ) > max_y : max_y = max ( counts_dict [ index ] [ xlim1 : xlim2 ] ) for i in range ( len ( detids ) ) : if detids [ i ] < 10 : index = '0' + str ( detids [ i ] ) else : index = str ( detids [ i ] ) plt . figure ( figsize = ( 10 , 8 ) ) plt . plot ( t_bins [ : - 1 ] [ xlim1 : xlim2 ] , counts_dict [ index ] [ xlim1 : xlim2 ] , '-' ) plt . title ( obsname + ' ' + obsid + ': Counts/s vs time (s), DETID ' + index , fontsize = 15 ) plt . xlabel ( 'Time (s)' , fontsize = 15 ) plt . xlim ( [ xlim1 , xlim2 ] ) plt . ylim ( [ 0 , max_y ] ) plt . ylabel ( 'Count/s' , fontsize = 15 ) pdf . savefig ( ) plt . close ( ) return counts_dict
Output is a dictionary, which has as keys, the DET_ID, and correspondingly
an array where each entry = counts per second at any given second.
Output is a dictionary which has as keys the DET_ID and correspondingly an array where each entry = counts per second at any given second .
"""
    Output is a dictionary, which has as keys, the DET_ID, and correspondingly
    an array where each entry = counts per second at any given second.
    
    counts_dict = {'detector':[t=1,t=2,t=3,...], 'detector':[t=1,t=2,...]}
    """ #for each FPM #replace not-detector by 0
work_dir
obsid
doplot