Skip to content

Commit

Permalink
Can't combine hits_cross_extra_offset with event chip edge correction
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulVanSchayck committed Feb 17, 2022
1 parent 52164b5 commit ff032a5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
12 changes: 0 additions & 12 deletions correct_edge.py

This file was deleted.

1 change: 1 addition & 0 deletions events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
from events.localise import cnn
from events.super_resolution import subpixel_event_redistribution
from events.chip_edge_correct import chip_edge_correct
from events.localise import calculate_image_shape
from events.predictions import calculate_predictions
from events.localise import event_info_datatype
12 changes: 8 additions & 4 deletions events/chip_edge_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ def chip_edge_correct(e):
ex = e['x']
ey = e['y']

# Shift x and y coordinate by 4 pixels for events right/bottom of the edge
ex[ex > 257] = ex[ex > 257] + 4
ey[ey > 257] = ey[ey > 257] + 4

# Take second horizontal row and redivide over itself and two lower pixels
x_edge1 = np.logical_and(ex > 260, ex < 261)
ex[x_edge1] = ex[x_edge1] - np.random.random_integers(0, 2, len(ex[x_edge1]))
x_edge1 = np.logical_and(ex > 256, ex < 257)
ex[x_edge1] = ex[x_edge1] + np.random.random_integers(2, 4, len(ex[x_edge1]))

# Take first horizontal row and redivide over three pixels
x_edge2 = np.logical_and(ex > 255, ex < 256)
ex[x_edge2] = ex[x_edge2] + np.random.random_integers(0, 2, len(ex[x_edge2]))

# Take second vertical column and redivide over three pixels
y_edge1 = np.logical_and(ey > 260, ey < 261)
ey[y_edge1] = ey[y_edge1] - np.random.random_integers(0, 2, len(ey[y_edge1]))
y_edge1 = np.logical_and(ey > 256, ey < 257)
ey[y_edge1] = ey[y_edge1] + np.random.random_integers(2, 4, len(ey[y_edge1]))

# Take second vertical column and redivide over three pixels
y_edge2 = np.logical_and(ey > 255, ey < 256)
Expand Down
7 changes: 7 additions & 0 deletions events/localise.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,10 @@ def event_info_datatype(cluster_stats):
dt = dt + dt_event_extended

return numpy.dtype(dt)


def calculate_image_shape(hits_cross_extra_offset, events_correct_chip_edges):
if events_correct_chip_edges:
return 512 + 2 * 2
else:
return 512 + 2 * hits_cross_extra_offset
3 changes: 3 additions & 0 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def parse_config(argv=None):
if settings.hits_correct_chip_edges and settings.C:
parser.error("Cannot combine correcting for hit chip edges and parsing clusters at the same time.")

if settings.hits_cross_extra_offset > 0 and settings.event_correct_chip_edges:
parser.error("Cannot give hits data an extra cross offset when correct events for chip edges")

return settings


Expand Down
4 changes: 2 additions & 2 deletions lib/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def write_event_chunk(self, events, cluster_stats):
events_f.resize(old + len(events), 0)
events_f[old:] = events

def store_events(self, algorithm, cnn_model, hits_cross_extra_offset, min_toa, max_toa):
def store_events(self, algorithm, cnn_model, hits_cross_extra_offset, min_toa, max_toa, event_correct_chip_edges):
if 'events' not in self.write:
logger.warning("There was no dataset /events written to the output file. Was nothing processed?")
return
Expand All @@ -157,7 +157,7 @@ def store_events(self, algorithm, cnn_model, hits_cross_extra_offset, min_toa, m
self.write['events'].attrs['algorithm'] = algorithm
self.write['events'].attrs['min_toa'] = min_toa
self.write['events'].attrs['max_toa'] = max_toa
self.write['events'].attrs['shape'] = tpx3format.calculate_image_shape(hits_cross_extra_offset)
self.write['events'].attrs['shape'] = ev.calculate_image_shape(hits_cross_extra_offset, event_correct_chip_edges)

if algorithm == 'cnn':
self.write['events'].attrs['cnn_model'] = cnn_model
Expand Down
2 changes: 1 addition & 1 deletion orchestration/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def finalise(self):

if self.settings.store_events:
self.io.store_events(self.settings.algorithm, self.settings.event_cnn_model,
self.settings.hits_cross_extra_offset, self.min_toa, self.max_toa)
self.settings.hits_cross_extra_offset, self.min_toa, self.max_toa, self.settings.event_correct_chip_edges)

self.io.close_write()

Expand Down

0 comments on commit ff032a5

Please sign in to comment.