/
pixel.py
executable file
·68 lines (48 loc) · 1.52 KB
/
pixel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Pixel:
"""
Class representing a (hit) pixel.
The "direction" value corresponds to the i^th value in these lists:
dir_x = [-1, -1, 0, 1, 1, 1, 0, -1]
dir_y = [ 0, 1, 1, 1, 0, -1, -1, -1]
"""
def __init__(self, x, y, C, m, rows, cols):
## The pixel x position.
self.x = x
## The pixel y position.
self.y = y
## The number of counts.
self.__C = C
## The pixel mask value (for clustering).
self.m = m
## The number of rows in the detector matrix.
self.__rows = rows
## The number of columns in the detector matrix.
self.__cols = cols
self.neighbours = {} # {direction: XY}
def get_x(self):
return self.x
def get_y(self):
return self.y
def getC(self):
return self.__C
def getX(self):
return (self.__cols * self.y) + self.x
def get_mask(self):
return self.m
def set_mask(self, m):
self.m = m
def get_neighbours(self):
return self.neighbours
def get_neighbour(self, direction):
if direction in self.neighbours:
return self.neighbours[direction]
else:
return False
def set_neighbour(self, direction, pixel_xy):
self.neighbours[direction] = pixel_xy
def pixel_entry(self):
return "{\"x\":%d, \"y\":%d, \"c\":%d},\n" % (self.x, self.y, self.__C)
def output(self):
print(self.pixel_entry)