Index: /fact/tools/pyscripts/tools/cleaning/begin.py
===================================================================
--- /fact/tools/pyscripts/tools/cleaning/begin.py	(revision 13081)
+++ /fact/tools/pyscripts/tools/cleaning/begin.py	(revision 13081)
@@ -0,0 +1,91 @@
+#!/usr/bin/python -i
+#
+# Dominik Neise
+#
+# cleaning a small step towards the truth
+from pyfact_rename import *
+import os.path
+import matplotlib.pyplot as plt
+import numpy as np
+from fir_filter import *
+from extractor import *
+from drs_spikes import *
+from plotters import *
+import time as t
+confirm_next_step = True # this is for user interaction
+
+data_file_name = '/media/daten_platte/FACT/data/20120229_144.fits.gz'
+calib_file_name = '/media/daten_platte/FACT/data/20120229_132.drs.fits.gz'
+if not os.path.isfile(data_file_name):
+    print 'not able to find file:', data_file_name
+    sys.exit(-1)
+if not os.path.isfile(calib_file_name ):
+    print 'not able to find file:', calib_file_name 
+    sys.exit(-1)
+
+run = RawData(data_file_name, calib_file_name)
+despike = DRSSpikes()
+smooth = SlidingAverage(8)
+extract = GlobalMaxFinder(40,200)
+
+plotA = CamPlotter('amplitudes')
+plotT = CamPlotter('times')
+plotCA = CamPlotter('cleaned amplitudes')
+
+coreTHR = 50 # copied from F. Temme
+edgeTHR = 20 # copied from F. Temme
+
+# get dictionary of next neighbors
+nn = Coordinator().nn
+
+for data,startcell,tt in run:
+    data = despike(data)
+    data = smooth(data)
+    amplitude, time_of_max = extract(data)
+    
+    plotA.name='amplitudes EvtID:' + str(run.event_id.value) + ' TT:' + str(tt)
+    plotA(amplitude)
+    plotT(time_of_max)
+    
+    # Here we start the cleaning ... just like that...
+    print 'cleaning away all pixel <' , coreTHR
+    coor_chid_candidates = np.where( amplitude > coreTHR)[0]
+    coor_chids = [] # coor chids, which survive Gauks step 1
+    survivors = [] # coor & edge pixel 
+    print 'number of coor candidates:', len(coor_chid_candidates)
+    
+    print 'throwing away all pixel w/o any neighbor' 
+    # get rid of single coor pics
+    for cand in coor_chid_candidates:
+        neighbor_found = False
+        # loop over all neigbors of cand'idate
+        for n in nn[cand]:
+            if n in coor_chid_candidates:
+                neighbor_found = True
+        if neighbor_found:
+            coor_chids.append(cand)
+            
+    print 'after deletion of single coor pixels'
+    print 'number of coor pixel', len(coor_chids)
+    
+    #add edge pixel to the edge of the coors
+    print 'resurrecting edge pixels ... i.e. all pixel >', edgeTHR
+    survivors = coor_chids[:]
+    for coor in coor_chids:
+        for n in nn[coor]:
+            # if neighbor is a core pixel, then do nothing
+            if n in coor_chids:
+                pass
+            elif amplitude[n] > edgeTHR:
+                survivors.append(n)
+    
+    print 'total number of pixel in cleaned event', len(survivors)
+    
+    plotCA( 
+    
+    if confirm_next_step:
+        user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
+        if user_input.find('q') != -1:
+            sys.exit(0)
+        elif user_input.find('r') != -1:
+            confirm_next_step = False
