Changeset 13442 for fact


Ignore:
Timestamp:
04/25/12 07:51:48 (13 years ago)
Author:
neise
Message:
...evolving...
File:
1 edited

Legend:

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

    r13439 r13442  
    2626thr = 3
    2727filter_delay = 3
     28search_window_size = 12
     29# shortcut
     30sws = search_window_size
    2831
    2932plt.ion()
    3033fig = plt.figure()
    3134fig.hold(True)
     35
    3236
    3337
     
    4145    filtered = smooth(filtered)
    4246
     47    # this is a loop over all pixel of this event
     48   
    4349    for dat, fil, orig in zip(data, filtered, data_orig):
    4450        plt.cla()
    4551        prod = fil[:-1] * fil[1:]
    4652        cand = np.where( prod <= 0)[0]
     53        if len(cand) == 0:
     54            continue
    4755        # zero crossing with rising edge
    4856        cross = cand[np.where(fil[cand] < 0)[0]]
    49        
     57        if len(cross) == 0:
     58            continue
    5059        over_thr = cross[np.where(dat[cross-4] > thr)[0]]
    5160
    52         # Now we have these values, we will throw away all those,
     61        # Now since we have these values, we will throw away all those,
    5362        # which are probably on a falling edge of its predecessor
    54        
    55        
    56         over = []
    5763        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        if len(dover) == 0:
     65            good = over_thr
     66        else:
     67            good = []
     68            good.append(over_thr[0])
     69            for i in range(len(dover)):
     70                if dover[-i-1] > 100:
     71                    good.append(over_thr[-i-1])
     72           
     73            good = np.array(sorted(good))
    6474        # these positions, we just found, do not exactly point to the maximum
    6575        # of a peak, but the peak will be on the left side of it.
     
    6878        # the smoothed data and the original data.
    6979       
    70         max_pos      = np.zeros( over_thr.shape )
    71         max_smoothed = np.zeros( over_thr.shape )
    72         max_orig     = np.zeros( over_thr.shape )
     80        max_pos      = np.zeros( good.shape )
     81        max_smoothed = np.zeros( good.shape )
     82        max_orig     = np.zeros( good.shape )
    7383   
    74         for i in range(len(over_thr)):
     84        for i in range(len(good)):
    7585            # We search for a local maximum in a window of size 12
    76             if len(dat[over_thr[i]-12:over_thr[i]]) > 0:
     86            if len(dat[good[i]-sws:good[i]]) > 0:
    7787           
    78                 max_pos[i]       = over_thr[i]-12 + np.argmax(dat[over_thr[i]-12:over_thr[i]])
     88                max_pos[i]       = good[i]-sws + np.argmax(dat[good[i]-sws:good[i]])
    7989                max_smoothed[i]  = dat[max_pos[i]]
    80                 max_orig[i]       = orig[max_pos[i]-filter_delay]
     90                max_orig[i]      = orig[max_pos[i]-filter_delay]
    8191
    8292        plt.plot(max_pos, max_smoothed, 'ro')
Note: See TracChangeset for help on using the changeset viewer.