title: Assigning events to pre-defined shapes
body: <p>My questions comes following what has been discussed <a href="https://stackoverflow.com/questions/61428166/extracting-specific-text-between-strings">here</a> and the advice I've been given there. </p>
  
  <p>I get data from seven devices (each, an XY matrix of responsive pixel sensors; think of a CCD camera). The dimensions of each device is X:1024 pixels, Y:512 pixels. The data is structured into separate events (i.e., timestamped), where a number of such pixels are active per event. The XY position of each pixel is represented by the two numbers following the <code>Pix</code> keyword in each device.</p>
  
  <p>An example of such an event, where only 6 of the 7 devices have active pixels:</p>
  
  <pre><code>=== 169139 ===
  Start: 4.80374e+19
  End:   4.80374e+19
  --- 1 ---
  Pix 9, 66
  --- 2 ---
  Pix 11, 31
  Pix 12, 31
  --- 3 ---
  Pix 17, 53
  Pix 16, 53
  Pix 16, 54
  --- 4 ---
  Pix 44, 64
  --- 5 ---
  Pix 49, 133
  Pix 48, 133
  --- 6 ---
  Pix 109, 143
  Pix 108, 143
  Pix 108, 144 
  Pix 109, 144 
  </code></pre>
  
  <p>I am now able to separate and plot for each of the 6 devices a 2D histogram showing where and which pixels were active thanks to the previous mentioned question in the forum.</p>
  
  <p>I do not know beforehand how many planes will be active in each event, which pixels will be active and how many in a device.</p>
  
  <p>What I would like to do next, would be to make a "<strong>frequency of occurrence</strong>" of different shapes of these pixels per plane. If a bunch of neighboring pixels are active, they are called a cluster. An example of such a classification:</p>
  
  <p><a href="https://i.stack.imgur.com/sUZy5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sUZy5.png" alt="Different active pixel shapes"></a></p>
  
  <p>As such, for the event example given above, one will find:</p>
  
  <ul>
  <li>2 occurrences of shape ID 0 (devices 1 and 4)</li>
  <li>2 occurrences of shape ID 1 (devices 2 and 5)</li>
  <li>1 occurrence of shape ID 6 (device 3)</li>
  <li>1 occurrence of shape ID 12 (device 6)</li>
  </ul>
  
  <p>A first classification would be based on the number of lines each device has. This would be a good indication of the number of active pixels per device (case not taken into account: if two regions of the same device have a active pixels firing at the same event).</p>
  
  <p>For one line in an event (meaning one pixel active), I could directly classify it into the number 0 category.
  For two lines, I could look to the left/right (or top/bottom) neighboring pixel and check if it is active and classify it as event 1 (or 2).</p>
  
  <p>For the case of 3 pixels, I am a bit unsure how to check. Basically, I would take the first value of the <code>Pix</code> occurrence of that device, but how would I know which of 3 active pixels it is?</p>
  
  <p>Also, how can I "classify" events in Python? I am thinking of a dictionary of shapes. And some function checks to assign a certain occurrence to such a shape. How is this implemented in a dictionary?</p>