Changeset 13088


Ignore:
Timestamp:
03/13/12 19:19:33 (13 years ago)
Author:
neise
Message:
running version - produces area vs log(size) plot
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/tools/cleaning/begin.py

    r13081 r13088  
    1313from plotters import *
    1414import time as t
    15 confirm_next_step = True # this is for user interaction
     15from coor import Coordinator
     16confirm_next_step = False# this is for user interaction
    1617
    1718data_file_name = '/media/daten_platte/FACT/data/20120229_144.fits.gz'
     
    2930extract = GlobalMaxFinder(40,200)
    3031
    31 plotA = CamPlotter('amplitudes')
    32 plotT = CamPlotter('times')
    33 plotCA = CamPlotter('cleaned amplitudes')
     32#plotA = CamPlotter('amplitudes')
     33#plotT = CamPlotter('times')
     34#plotCA = CamPlotter('cleaned amplitudes')
    3435
    35 coreTHR = 50 # copied from F. Temme
    36 edgeTHR = 20 # copied from F. Temme
     36#plotArea = HistPlotter('area', 1440, (0,1440) )
     37#plotSize = HistPlotter('size', 1000, (0,10000) )
     38
     39#funnyPlot = Plotter('area vs log(size')
     40
     41
     42coreTHR = 45 # copied from F. Temme
     43edgeTHR = 18 # copied from F. Temme
    3744
    3845# get dictionary of next neighbors
    3946nn = Coordinator().nn
    4047
     48print 'Core threshold=', coreTHR
     49print 'Edge threshold=', edgeTHR
     50print '*'*70
     51
     52areas = []
     53sizes = []
     54
    4155for data,startcell,tt in run:
    42     data = despike(data)
    43     data = smooth(data)
    44     amplitude, time_of_max = extract(data)
    45    
    46     plotA.name='amplitudes EvtID:' + str(run.event_id.value) + ' TT:' + str(tt)
    47     plotA(amplitude)
    48     plotT(time_of_max)
    49    
    50     # Here we start the cleaning ... just like that...
    51     print 'cleaning away all pixel <' , coreTHR
    52     coor_chid_candidates = np.where( amplitude > coreTHR)[0]
    53     coor_chids = [] # coor chids, which survive Gauks step 1
    54     survivors = [] # coor & edge pixel
    55     print 'number of coor candidates:', len(coor_chid_candidates)
    56    
    57     print 'throwing away all pixel w/o any neighbor'
    58     # get rid of single coor pics
    59     for cand in coor_chid_candidates:
    60         neighbor_found = False
    61         # loop over all neigbors of cand'idate
    62         for n in nn[cand]:
    63             if n in coor_chid_candidates:
    64                 neighbor_found = True
    65         if neighbor_found:
    66             coor_chids.append(cand)
    67            
    68     print 'after deletion of single coor pixels'
    69     print 'number of coor pixel', len(coor_chids)
    70    
    71     #add edge pixel to the edge of the coors
    72     print 'resurrecting edge pixels ... i.e. all pixel >', edgeTHR
    73     survivors = coor_chids[:]
    74     for coor in coor_chids:
    75         for n in nn[coor]:
    76             # if neighbor is a core pixel, then do nothing
    77             if n in coor_chids:
    78                 pass
    79             elif amplitude[n] > edgeTHR:
    80                 survivors.append(n)
    81    
    82     print 'total number of pixel in cleaned event', len(survivors)
    83    
    84     plotCA(
    85    
    86     if confirm_next_step:
    87         user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
    88         if user_input.find('q') != -1:
    89             sys.exit(0)
    90         elif user_input.find('r') != -1:
    91             confirm_next_step = False
     56    if tt==4:
     57        data = despike(data)
     58        data = smooth(data)
     59        amplitude, time_of_max = extract(data)
     60       
     61        #plotA.name='amplitudes EvtID:' + str(run.event_id.value) + ' TT:' + str(tt)
     62        #plotA(amplitude)
     63        #plotT(time_of_max)
     64       
     65        # Here we start the cleaning ... just like that...
     66        #print 'cleaning away all pixel <' , coreTHR
     67        core_chid_candidates = np.where( amplitude > coreTHR)[0]
     68        core_chids = [] # coor chids, which survive Gauks step 1
     69        survivors = [] # coor & edge pixel
     70        #print 'number of core candidates:', len(core_chid_candidates)
     71       
     72        #print 'throwing away all pixel w/o any neighbor'
     73        # get rid of single coor pics
     74        for cand in core_chid_candidates:
     75            neighbor_found = False
     76            # loop over all neigbors of cand'idate
     77            for n in nn[cand]:
     78                if n in core_chid_candidates:
     79                    neighbor_found = True
     80            if neighbor_found:
     81                core_chids.append(cand)
     82               
     83        #print 'after deletion of single coor pixels'
     84       
     85       
     86        #add edge pixel to the edge of the coors
     87        #print 'resurrecting edge pixels ... i.e. all pixel >', edgeTHR
     88        survivors = core_chids[:]
     89        for coor in core_chids:
     90            for n in nn[coor]:
     91                # if neighbor is a core pixel, then do nothing
     92                if n in core_chids:
     93                    pass
     94                elif amplitude[n] > edgeTHR:
     95                    survivors.append(n)
     96        survivors = np.array(survivors, dtype=int)
     97        print '#survivors', len(survivors), 'evtID', run.event_id.value
     98       
     99        #plotCA(data=amplitude, mask=survivors)
     100       
     101        size = 0
     102        for pixel in survivors:
     103            size += amplitude[pixel]
     104       
     105        if len(survivors) > 0:
     106            areas.append( len(survivors) )
     107            sizes.append( size )
     108       
     109       
     110        #plotArea(areas, 'areas of ' + str(run.event_id.value) + 'events')
     111        #plotSize(sizes, 'sizes of ' + str(run.event_id.value) + 'events')
     112       
     113        if confirm_next_step:
     114            user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
     115            number=None
     116            try:
     117                number=int(user_input)
     118            except:
     119                number=None
     120            if user_input.find('q') != -1:
     121                sys.exit(0)
     122            elif user_input.find('r') != -1:
     123                confirm_next_step = False
     124            elif number!=None:
     125                run += number
     126               
     127        total_event_number = run.event_id.value
     128
     129plt.ion()
     130myfig = plt.figure()
     131myn = myfig.number
     132logsize = np.log10(np.array(sizes))
     133areas = np.array(areas)
     134
     135plt.figure(myn)
     136plt.title('area vs. log10(size) of '+ str(total_event_number) + 'events')
     137plt.xlabel('log10(size/1mV)')
     138plt.ylabel('area [#pixel]')
     139plt.plot( logsize,areas, '.')
Note: See TracChangeset for help on using the changeset viewer.