Classes | Functions | Variables
txt_utils Namespace Reference

Classes

class  PixelmapGenerator
 

Functions

def parse_text (line)
 
def check_electron_prong (deposit)
 
def check_nue_event (deposit)
 
def check_muon_prong (deposit)
 
def check_numu_event (deposit)
 
def add_event_energy (targets, i, deposit)
 
def add_prong_energy (targets, i, deposit)
 
def add_vertex (vertices, i, deposit)
 
def divide_plane (features, i, deposit)
 
def constant_scale (features, vertices, targets)
 
def energy_ratio_cut (features, vertices, targets)
 
def event_iter_from_txt (file_path, pixel_map_dim, check_criterion, add_target, formula, preprocess)
 
def prong_iter_from_txt (file_path, pixel_map_dim, check_criterion, formula, preprocess)
 

Variables

int MAX_EXAMPLES = 2000
 
float PIXEL_SCALE = 100.0
 
float VERTEX_SCALE = 0.01
 
float CUT_THRESHOLD = 0.05
 

Function Documentation

def txt_utils.add_event_energy (   targets,
  i,
  deposit 
)
Add neutrino energy to regression targets.

Definition at line 80 of file txt_utils.py.

Referenced by event_iter_from_txt().

80 def add_event_energy(targets, i, deposit):
81  """
82  Add neutrino energy to regression targets.
83  """
84  targets[i, 0] = deposit['trueNuE']
85 
def add_event_energy(targets, i, deposit)
Definition: txt_utils.py:80
def txt_utils.add_prong_energy (   targets,
  i,
  deposit 
)
Add lepton energy and momentum to regression targets.

Definition at line 86 of file txt_utils.py.

Referenced by prong_iter_from_txt().

86 def add_prong_energy(targets, i, deposit):
87  """
88  Add lepton energy and momentum to regression targets.
89  """
90  targets[i, 0] = deposit['trueE']
91  targets[i, 1] = deposit['truePx']
92  targets[i, 2] = deposit['truePy']
93  targets[i, 3] = deposit['truePz']
94 
def add_prong_energy(targets, i, deposit)
Definition: txt_utils.py:86
def txt_utils.add_vertex (   vertices,
  i,
  deposit 
)
Add vertex X or Y.

Definition at line 95 of file txt_utils.py.

Referenced by event_iter_from_txt(), and prong_iter_from_txt().

95 def add_vertex(vertices, i, deposit):
96  """
97  Add vertex X or Y.
98  """
99  if deposit['view'] == 0:
100  vertices[i, 0] = deposit['cell']
101  else:
102  vertices[i, 1] = deposit['cell']
103 
def add_vertex(vertices, i, deposit)
Definition: txt_utils.py:95
def txt_utils.check_electron_prong (   deposit)
Check whether a deposit belongs to a electron prong.

Definition at line 56 of file txt_utils.py.

56 def check_electron_prong(deposit):
57  """
58  Check whether a deposit belongs to a electron prong.
59  """
60  return(deposit['trueProng'] == 11 or deposit['trueProng'] == -11)
61 
def check_electron_prong(deposit)
Definition: txt_utils.py:56
def txt_utils.check_muon_prong (   deposit)
Check whether a deposit belongs to a muon prong.

Definition at line 68 of file txt_utils.py.

68 def check_muon_prong(deposit):
69  """
70  Check whether a deposit belongs to a muon prong.
71  """
72  return(deposit['trueProng'] == 13 or deposit['trueProng'] == -13)
73 
def check_muon_prong(deposit)
Definition: txt_utils.py:68
def txt_utils.check_nue_event (   deposit)
Check whether a deposit belongs to a nue event.

Definition at line 62 of file txt_utils.py.

62 def check_nue_event(deposit):
63  """
64  Check whether a deposit belongs to a nue event.
65  """
66  return(deposit['trueNuPdg'] == 12 or deposit['trueNuPdg'] == -12)
67 
def check_nue_event(deposit)
Definition: txt_utils.py:62
def txt_utils.check_numu_event (   deposit)
Check whether a deposit belongs to a numu event.

Definition at line 74 of file txt_utils.py.

74 def check_numu_event(deposit):
75  """
76  Check whether a deposit belongs to a numu event.
77  """
78  return(deposit['trueNuPdg'] == 14 or deposit['trueNuPdg'] == -14)
79 
def check_numu_event(deposit)
Definition: txt_utils.py:74
def txt_utils.constant_scale (   features,
  vertices,
  targets 
)
Preprocess data by constant scaling.

Definition at line 110 of file txt_utils.py.

110 def constant_scale(features, vertices, targets):
111  """
112  Preprocess data by constant scaling.
113  """
114  features = features * PIXEL_SCALE
115  vertices = vertices * VERTEX_SCALE
116 
def constant_scale(features, vertices, targets)
Definition: txt_utils.py:110
def txt_utils.divide_plane (   features,
  i,
  deposit 
)
Divide plane number by 2 to reduce dimension by half.

Definition at line 104 of file txt_utils.py.

104 def divide_plane(features, i, deposit):
105  """
106  Divide plane number by 2 to reduce dimension by half.
107  """
108  features[i, deposit['view'], (deposit['planeLocal'] + 30) // 2, deposit['cellLocal'] + 70] = deposit['energy']
109 
def divide_plane(features, i, deposit)
Definition: txt_utils.py:104
def txt_utils.energy_ratio_cut (   features,
  vertices,
  targets 
)
Remove examples where the sum of energy deposits is too low.

Definition at line 117 of file txt_utils.py.

117 def energy_ratio_cut(features, vertices, targets):
118  """
119  Remove examples where the sum of energy deposits is too low.
120  """
121  sum_energy = np.sum(np.sum(np.sum(features, axis=1), axis=1), axis=1)
122  ratio = targets[:, 0] / sum_energy
123  select = ratio < CUT_THRESHOLD
124  features = features[select, :, :, :] * PIXEL_SCALE
125  vertices = vertices[select, :] * VERTEX_SCALE
126  targets = targets[select, :]
127 
def energy_ratio_cut(features, vertices, targets)
Definition: txt_utils.py:117
def txt_utils.event_iter_from_txt (   file_path,
  pixel_map_dim,
  check_criterion,
  add_target,
  formula,
  preprocess 
)
Generic function to iterate events from a txt file. 

Args
    file_path: string of txt file path
    pixel_map_dim: tuple of pixel map dimensions
    check_criterion: boolean function for event/prong inclusion criterion
    formula: function for adding features
    preprocess: function for preprocessing
    
Returns
    features: 4d numpy array of pixel maps
    vertices: 2d numpy array of vertices
    targets: 2d numpy array of regression targets

Definition at line 128 of file txt_utils.py.

References add_event_energy(), add_vertex(), open(), and parse_text().

Referenced by txt_utils.PixelmapGenerator.flow().

128 def event_iter_from_txt(file_path, pixel_map_dim, check_criterion, add_target, formula, preprocess):
129  """
130  Generic function to iterate events from a txt file.
131 
132  Args
133  file_path: string of txt file path
134  pixel_map_dim: tuple of pixel map dimensions
135  check_criterion: boolean function for event/prong inclusion criterion
136  formula: function for adding features
137  preprocess: function for preprocessing
138 
139  Returns
140  features: 4d numpy array of pixel maps
141  vertices: 2d numpy array of vertices
142  targets: 2d numpy array of regression targets
143  """
144  features = np.zeros((MAX, 2, pixel_map_dim[0], pixel_map_dim[1]))
145  vertices = np.zeros((MAX, 2))
146  targets = np.zeros((MAX, 1))
147  i = -1
148  current_event_tag = -1
149  match = False
150  with open(file_path, 'r') as f:
151  for line in f:
152  deposit = parse_text(line)
153  if current_event_tag != deposit['event_tag']:
154  current_event_tag = deposit['event_tag']
155  if check_criterion(deposit):
156  match = True
157  i += 1
158  if i == MAX_EXAMPLES:
159  break
160  add_event_energy(targets, i, deposit)
161  if match:
162  formula(features, i, deposit)
163  if deposit['prong_tag'] is not None:
164  add_vertex(vertices, i, deposit)
165  features = features[0:(i + 1), :, :, :]
166  vertices = vertices[0:(i + 1), :]
167  targets = targets[0:(i + 1), :]
168  return(features, vertices, targets)
169 
def add_event_energy(targets, i, deposit)
Definition: txt_utils.py:80
def parse_text(line)
Definition: txt_utils.py:9
procfile open("FD_BRL_v0.txt")
def add_vertex(vertices, i, deposit)
Definition: txt_utils.py:95
def event_iter_from_txt(file_path, pixel_map_dim, check_criterion, add_target, formula, preprocess)
Definition: txt_utils.py:128
def txt_utils.parse_text (   line)
Create a data dictionary based on a single line of text.

Args
line (str): one line of raw data from the CSV

Returns
(dict) with keys/values of extracted variables

Definition at line 9 of file txt_utils.py.

References check_time_usage.float, and makeTrainCVSamples.int.

Referenced by event_iter_from_txt(), and prong_iter_from_txt().

9 def parse_text(line):
10  """
11  Create a data dictionary based on a single line of text.
12 
13  Args
14  line (str): one line of raw data from the CSV
15 
16  Returns
17  (dict) with keys/values of extracted variables
18  """
19  data = line.split(' ')[:35]
20  info = {}
21  info['run'] = data[0]
22  info['subrun'] = data[1]
23  info['event'] = data[2]
24  info['subevent'] = data[3]
25  info['slice'] = data[4]
26  info['sheId'] = data[5]
27  # event and prong identifiers
28  info['event_tag'] = int(info['run'] + info['subrun'] + info['event'] + info['subevent'] + info['slice'])
29  if info['sheId'] != '-1':
30  info['prong_tag'] = int(info['run'] + info['subrun'] + info['event'] + info['subevent'] + info['slice'] + info['sheId'])
31  else:
32  info['prong_tag'] = None
33  # current reconstruction
34  info['sheE'] = float(data[6])
35  info['sheNuE'] = float(data[7])
36  # location
37  info['view'] = int(data[17])
38  info['planeLocal'] = int(data[18])
39  info['cellLocal'] = int(data[19])
40  info['plane'] = int(data[20])
41  info['cell'] = int(data[21])
42  info['energy'] = float(data[22])
43  # true prong
44  info['trueProng'] = int(data[23])
45  info['truePx'] = float(data[24])
46  info['truePy'] = float(data[25])
47  info['truePz'] = float(data[26])
48  info['trueE'] = float(data[27])
49  # true nu
50  info['trueNuPdg'] = int(data[31])
51  info['trueCC'] = int(data[32])
52  info['trueNuMode'] = int(data[33])
53  info['trueNuE'] = float(data[34])
54  return(info)
55 
def parse_text(line)
Definition: txt_utils.py:9
def txt_utils.prong_iter_from_txt (   file_path,
  pixel_map_dim,
  check_criterion,
  formula,
  preprocess 
)
Generic function to iterate prongs from a txt file. 

Args
    file_path: string of txt file path
    pixel_map_dim: tuple of pixel map dimensions
    check_criterion: boolean function for event/prong inclusion criterion
    formula: function for adding features
    preprocess: function for preprocessing
    
Returns
    features: 4d numpy array of pixel maps
    vertices: 2d numpy array of vertices
    targets: 2d numpy array of regression targets

Definition at line 170 of file txt_utils.py.

References add_prong_energy(), add_vertex(), open(), and parse_text().

Referenced by txt_utils.PixelmapGenerator.flow().

170 def prong_iter_from_txt(file_path, pixel_map_dim, check_criterion, formula, preprocess):
171  """
172  Generic function to iterate prongs from a txt file.
173 
174  Args
175  file_path: string of txt file path
176  pixel_map_dim: tuple of pixel map dimensions
177  check_criterion: boolean function for event/prong inclusion criterion
178  formula: function for adding features
179  preprocess: function for preprocessing
180 
181  Returns
182  features: 4d numpy array of pixel maps
183  vertices: 2d numpy array of vertices
184  targets: 2d numpy array of regression targets
185  """
186  features = np.zeros((MAX, 2, pixel_map_dim[0], pixel_map_dim[1]))
187  vertices = np.zeros((MAX, 2))
188  targets = np.zeros((MAX, 1))
189  i = -1
190  current_prong_tag = -1
191  match = False
192  with open(file_path, 'r') as f:
193  for line in f:
194  deposit = parse_text(line)
195  if deposit['prong_tag'] is None:
196  continue
197  if current_prong_tag != deposit['prong_tag']:
198  current_prong_tag = deposit['prong_tag']
199  if check_criterion(deposit):
200  match = True
201  i += 1
202  if i == MAX_EXAMPLES:
203  break
204  add_prong_energy(targets, i, deposit)
205  if match:
206  formula(features, i, deposit)
207  add_vertex(vertices, i, deposit)
208  features = features[0:(i + 1), :, :, :]
209  vertices = vertices[0:(i + 1), :]
210  targets = targets[0:(i + 1), :]
211  preprocess(features, vertices, targets)
212  return(features, vertices, targets)
213 
214 
def prong_iter_from_txt(file_path, pixel_map_dim, check_criterion, formula, preprocess)
Definition: txt_utils.py:170
def add_prong_energy(targets, i, deposit)
Definition: txt_utils.py:86
def parse_text(line)
Definition: txt_utils.py:9
procfile open("FD_BRL_v0.txt")
def add_vertex(vertices, i, deposit)
Definition: txt_utils.py:95

Variable Documentation

float txt_utils.CUT_THRESHOLD = 0.05

Definition at line 7 of file txt_utils.py.

int txt_utils.MAX_EXAMPLES = 2000

Definition at line 4 of file txt_utils.py.

float txt_utils.PIXEL_SCALE = 100.0

Definition at line 5 of file txt_utils.py.

float txt_utils.VERTEX_SCALE = 0.01

Definition at line 6 of file txt_utils.py.