Changeset 13439 for fact/tools/pyscripts


Ignore:
Timestamp:
04/24/12 16:52:43 (13 years ago)
Author:
neise
Message:
further steps
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/sandbox/dneise/gain/gain.py

    r13421 r13439  
    66from drs_spikes import DRSSpikes       
    77from fir_filter import CFD
    8 from extractor import ZeroXing
    98from fir_filter import SlidingAverage
    109
     
    1615import numpy as np
    1716
    18 data_filename = 'data/20111017_010.fits.gz'
    19 calib_filename = 'data/20111017_007.drs.fits.gz'
     17data_filename = 'data/20111017_009.fits.gz'
     18calib_filename = 'data/20111017_006.drs.fits.gz'
    2019out_filename = 'test.pkl'
    2120
    2221run = RawData(data_filename, calib_filename, return_dict = True, do_calibration=True)
    2322despike = DRSSpikes()
    24 smooth = SlidingAverage(8)
     23smooth = SlidingAverage(7)
    2524cfd = CFD()
    26 find = ZeroXing()
    2725
    28 #plt.ion()
     26thr = 3
     27filter_delay = 3
    2928
    30 peak_list = []
    31        
    32 p = Plotter('data[0]')
     29plt.ion()
     30fig = plt.figure()
     31fig.hold(True)
    3332
    34 
    35 #fig = plt.figure()
    36 #plt.grid(True)
    37 
    38 stupid_list = []
    3933
    4034for event in run:
     
    4236    data = event['acal_data']
    4337    data = despike(data)
     38    data_orig = data.copy()
    4439    data = smooth(data)
    4540    filtered = cfd(data)
    4641    filtered = smooth(filtered)
    47     peak_positions = find(data)
     42
     43    for dat, fil, orig in zip(data, filtered, data_orig):
     44        plt.cla()
     45        prod = fil[:-1] * fil[1:]
     46        cand = np.where( prod <= 0)[0]
     47        # zero crossing with rising edge
     48        cross = cand[np.where(fil[cand] < 0)[0]]
     49       
     50        over_thr = cross[np.where(dat[cross-4] > thr)[0]]
     51
     52        # Now we have these values, we will throw away all those,
     53        # which are probably on a falling edge of its predecessor
     54       
     55       
     56        over = []
     57        dover = np.diff(over_thr)
     58       
     59        for i in range(len(over_thr)):
     60            if dover[i] > 100:
     61               
     62               
     63        over_thr = np.array(over)
     64        # these positions, we just found, do not exactly point to the maximum
     65        # of a peak, but the peak will be on the left side of it.
     66        # we use the smoothed data to find the position of the local maximum
     67        # and then stopre this position and the value of both
     68        # the smoothed data and the original data.
     69       
     70        max_pos      = np.zeros( over_thr.shape )
     71        max_smoothed = np.zeros( over_thr.shape )
     72        max_orig     = np.zeros( over_thr.shape )
    4873   
    49     # find peak heights
    50     # and get rid of too small peaks
    51 #    good_peaks = []
    52 #    for idx,pixel in enumerate(peak_positions):
    53 #        good_peaks.append([])
    54 #        for peak_pos in pixel:
    55 #            peak_height = data[idx][int(peak_pos)]
    56 #            stupid_list.append(peak_height)
    57 #            if peak_height > 4.0:
    58 #                good_peaks[-1].append((peak_pos,peak_height))
    59 #
    60 #    plt.hist(np.array(stupid_list))
     74        for i in range(len(over_thr)):
     75            # We search for a local maximum in a window of size 12
     76            if len(dat[over_thr[i]-12:over_thr[i]]) > 0:
     77           
     78                max_pos[i]       = over_thr[i]-12 + np.argmax(dat[over_thr[i]-12:over_thr[i]])
     79                max_smoothed[i]  = dat[max_pos[i]]
     80                max_orig[i]       = orig[max_pos[i]-filter_delay]
    6181
    62     p((data[0],filtered[0]))
    63     print 'peak_positions:', map(int, peak_positions[0])
    64    
    65     peak_pussies = map(int, peak_positions[0])
    66     peak_h = []
    67     for i in peak_pussies:
    68         peak_h.append(data[0][i-8])
    69 
    70 
    71     pp = Plotter('peaks', x=peak_pussies)
    72     pp(peak_h)
    73    
    74 
    75     ret = raw_input('quit?')
    76     if ret=='q':
    77         break
    78 
    79 #    peak_list.append( good_peaks )
     82        plt.plot(max_pos, max_smoothed, 'ro')
     83        plt.plot(max_pos, max_orig, 'bo')
     84        plt.plot(np.arange(len(dat)), dat, 'k:')
     85       
     86        raw_input('bla')
    8087
    8188
Note: See TracChangeset for help on using the changeset viewer.