diff --git a/correct_edge.py b/correct_edge.py deleted file mode 100644 index c5a493a..0000000 --- a/correct_edge.py +++ /dev/null @@ -1,12 +0,0 @@ -import sys -import lib -from events import chip_edge_correct - -io = lib.io() - -events = io.read_events(sys.argv[1]) -new_events = chip_edge_correct(events) -io.open_write(sys.argv[2]) -io.write_event_chunk(new_events, False) -io.store_events('cnn', 'cnn-tot-chip-edge', 2, events.attrs['min_toa'], events.attrs['max_toa']) -io.close_write() \ No newline at end of file diff --git a/events/__init__.py b/events/__init__.py index 0692027..0b9589e 100644 --- a/events/__init__.py +++ b/events/__init__.py @@ -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 diff --git a/events/chip_edge_correct.py b/events/chip_edge_correct.py index d8facb7..4f8fe5b 100644 --- a/events/chip_edge_correct.py +++ b/events/chip_edge_correct.py @@ -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) diff --git a/events/localise.py b/events/localise.py index a3c7a5f..9afd3b1 100644 --- a/events/localise.py +++ b/events/localise.py @@ -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 \ No newline at end of file diff --git a/lib/config.py b/lib/config.py index 964a100..a560733 100644 --- a/lib/config.py +++ b/lib/config.py @@ -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 diff --git a/lib/io.py b/lib/io.py index c3f2804..51ee834 100644 --- a/lib/io.py +++ b/lib/io.py @@ -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 @@ -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 diff --git a/orchestration/writer.py b/orchestration/writer.py index a80f146..0e256a5 100644 --- a/orchestration/writer.py +++ b/orchestration/writer.py @@ -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()