mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-04-22 06:40:03 +02:00
bounds checking on subfiles
This commit is contained in:
parent
7ce02006f2
commit
d0f435a7ab
@ -14,99 +14,103 @@ base = Path('/mnt/sls_det_storage/matterhorn_data/aare_test_data/')
|
|||||||
|
|
||||||
f = File(base/'Moench03new/cu_half_speed_master_4.json')
|
f = File(base/'Moench03new/cu_half_speed_master_4.json')
|
||||||
|
|
||||||
|
for i, frame in enumerate(f):
|
||||||
|
print(f'{i}', end='\r')
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
from aare._aare import ClusterFinderMT, ClusterCollector, ClusterFileSink
|
from aare._aare import ClusterFinderMT, ClusterCollector, ClusterFileSink
|
||||||
|
|
||||||
|
|
||||||
cf = ClusterFinderMT((400,400), (3,3), n_threads = 3)
|
# cf = ClusterFinderMT((400,400), (3,3), n_threads = 3)
|
||||||
# collector = ClusterCollector(cf)
|
# # collector = ClusterCollector(cf)
|
||||||
out_file = ClusterFileSink(cf, "test.clust")
|
# out_file = ClusterFileSink(cf, "test.clust")
|
||||||
|
|
||||||
for i in range(1000):
|
|
||||||
img = f.read_frame()
|
|
||||||
cf.push_pedestal_frame(img)
|
|
||||||
print('Pedestal done')
|
|
||||||
cf.sync()
|
|
||||||
|
|
||||||
for i in range(100):
|
|
||||||
img = f.read_frame()
|
|
||||||
cf.find_clusters(img)
|
|
||||||
|
|
||||||
|
|
||||||
# time.sleep(1)
|
|
||||||
cf.stop()
|
|
||||||
time.sleep(1)
|
|
||||||
print('Second run')
|
|
||||||
cf.start()
|
|
||||||
for i in range(100):
|
|
||||||
img = f.read_frame()
|
|
||||||
cf.find_clusters(img)
|
|
||||||
|
|
||||||
cf.stop()
|
|
||||||
print('Third run')
|
|
||||||
cf.start()
|
|
||||||
for i in range(129):
|
|
||||||
img = f.read_frame()
|
|
||||||
cf.find_clusters(img)
|
|
||||||
|
|
||||||
cf.stop()
|
|
||||||
out_file.stop()
|
|
||||||
print('Done')
|
|
||||||
|
|
||||||
|
|
||||||
cfile = ClusterFile("test.clust")
|
|
||||||
i = 0
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
cv = cfile.read_frame()
|
|
||||||
i+=1
|
|
||||||
except RuntimeError:
|
|
||||||
break
|
|
||||||
print(f'Read {i} frames')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# cf = ClusterFinder((400,400), (3,3))
|
|
||||||
# for i in range(1000):
|
# for i in range(1000):
|
||||||
# cf.push_pedestal_frame(f.read_frame())
|
# img = f.read_frame()
|
||||||
|
# cf.push_pedestal_frame(img)
|
||||||
|
# print('Pedestal done')
|
||||||
|
# cf.sync()
|
||||||
|
|
||||||
# fig, ax = plt.subplots()
|
# for i in range(100):
|
||||||
# im = ax.imshow(cf.pedestal())
|
# img = f.read_frame()
|
||||||
# cf.pedestal()
|
# cf.find_clusters(img)
|
||||||
# cf.noise()
|
|
||||||
|
|
||||||
|
# # time.sleep(1)
|
||||||
|
# cf.stop()
|
||||||
|
# time.sleep(1)
|
||||||
|
# print('Second run')
|
||||||
|
# cf.start()
|
||||||
|
# for i in range(100):
|
||||||
|
# img = f.read_frame()
|
||||||
|
# cf.find_clusters(img)
|
||||||
|
|
||||||
|
# cf.stop()
|
||||||
|
# print('Third run')
|
||||||
|
# cf.start()
|
||||||
|
# for i in range(129):
|
||||||
|
# img = f.read_frame()
|
||||||
|
# cf.find_clusters(img)
|
||||||
|
|
||||||
|
# cf.stop()
|
||||||
|
# out_file.stop()
|
||||||
|
# print('Done')
|
||||||
|
|
||||||
|
|
||||||
|
# cfile = ClusterFile("test.clust")
|
||||||
|
# i = 0
|
||||||
|
# while True:
|
||||||
|
# try:
|
||||||
|
# cv = cfile.read_frame()
|
||||||
|
# i+=1
|
||||||
|
# except RuntimeError:
|
||||||
|
# break
|
||||||
|
# print(f'Read {i} frames')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# N = 500
|
|
||||||
# t0 = time.perf_counter()
|
|
||||||
# hist1 = bh.Histogram(bh.axis.Regular(40, -2, 4000))
|
|
||||||
# f.seek(0)
|
|
||||||
|
|
||||||
# t0 = time.perf_counter()
|
# # cf = ClusterFinder((400,400), (3,3))
|
||||||
# data = f.read_n(N)
|
# # for i in range(1000):
|
||||||
# t_elapsed = time.perf_counter()-t0
|
# # cf.push_pedestal_frame(f.read_frame())
|
||||||
|
|
||||||
|
# # fig, ax = plt.subplots()
|
||||||
|
# # im = ax.imshow(cf.pedestal())
|
||||||
|
# # cf.pedestal()
|
||||||
|
# # cf.noise()
|
||||||
|
|
||||||
|
|
||||||
# n_bytes = data.itemsize*data.size
|
|
||||||
|
|
||||||
# print(f'Reading {N} frames took {t_elapsed:.3f}s {N/t_elapsed:.0f} FPS, {n_bytes/1024**2:.4f} GB/s')
|
# # N = 500
|
||||||
|
# # t0 = time.perf_counter()
|
||||||
|
# # hist1 = bh.Histogram(bh.axis.Regular(40, -2, 4000))
|
||||||
|
# # f.seek(0)
|
||||||
|
|
||||||
|
# # t0 = time.perf_counter()
|
||||||
|
# # data = f.read_n(N)
|
||||||
|
# # t_elapsed = time.perf_counter()-t0
|
||||||
|
|
||||||
|
|
||||||
# for frame in data:
|
# # n_bytes = data.itemsize*data.size
|
||||||
# a = cf.find_clusters(frame)
|
|
||||||
|
|
||||||
# clusters = cf.steal_clusters()
|
# # print(f'Reading {N} frames took {t_elapsed:.3f}s {N/t_elapsed:.0f} FPS, {n_bytes/1024**2:.4f} GB/s')
|
||||||
|
|
||||||
# t_elapsed = time.perf_counter()-t0
|
|
||||||
# print(f'Clustering {N} frames took {t_elapsed:.2f}s {N/t_elapsed:.0f} FPS')
|
|
||||||
|
|
||||||
|
|
||||||
# t0 = time.perf_counter()
|
# # for frame in data:
|
||||||
# total_clusters = clusters.size
|
# # a = cf.find_clusters(frame)
|
||||||
|
|
||||||
# hist1.fill(clusters.sum())
|
# # clusters = cf.steal_clusters()
|
||||||
|
|
||||||
# t_elapsed = time.perf_counter()-t0
|
# # t_elapsed = time.perf_counter()-t0
|
||||||
# print(f'Filling histogram with the sum of {total_clusters} clusters took: {t_elapsed:.3f}s, {total_clusters/t_elapsed:.3g} clust/s')
|
# # print(f'Clustering {N} frames took {t_elapsed:.2f}s {N/t_elapsed:.0f} FPS')
|
||||||
# print(f'Average number of clusters per frame {total_clusters/N:.3f}')
|
|
||||||
|
|
||||||
|
# # t0 = time.perf_counter()
|
||||||
|
# # total_clusters = clusters.size
|
||||||
|
|
||||||
|
# # hist1.fill(clusters.sum())
|
||||||
|
|
||||||
|
# # t_elapsed = time.perf_counter()-t0
|
||||||
|
# # print(f'Filling histogram with the sum of {total_clusters} clusters took: {t_elapsed:.3f}s, {total_clusters/t_elapsed:.3g} clust/s')
|
||||||
|
# # print(f'Average number of clusters per frame {total_clusters/N:.3f}')
|
@ -278,6 +278,10 @@ void RawFile::get_frame_into(size_t frame_index, std::byte *frame_buffer, Detect
|
|||||||
if (n_subfile_parts != 1) {
|
if (n_subfile_parts != 1) {
|
||||||
for (size_t part_idx = 0; part_idx != n_subfile_parts; ++part_idx) {
|
for (size_t part_idx = 0; part_idx != n_subfile_parts; ++part_idx) {
|
||||||
auto subfile_id = frame_index / m_master.max_frames_per_file();
|
auto subfile_id = frame_index / m_master.max_frames_per_file();
|
||||||
|
if (subfile_id >= subfiles.size()) {
|
||||||
|
throw std::runtime_error(LOCATION +
|
||||||
|
" Subfile out of range. Possible missing data.");
|
||||||
|
}
|
||||||
frame_numbers[part_idx] =
|
frame_numbers[part_idx] =
|
||||||
subfiles[subfile_id][part_idx]->frame_number(
|
subfiles[subfile_id][part_idx]->frame_number(
|
||||||
frame_index % m_master.max_frames_per_file());
|
frame_index % m_master.max_frames_per_file());
|
||||||
@ -311,6 +315,10 @@ void RawFile::get_frame_into(size_t frame_index, std::byte *frame_buffer, Detect
|
|||||||
for (size_t part_idx = 0; part_idx != n_subfile_parts; ++part_idx) {
|
for (size_t part_idx = 0; part_idx != n_subfile_parts; ++part_idx) {
|
||||||
auto corrected_idx = frame_indices[part_idx];
|
auto corrected_idx = frame_indices[part_idx];
|
||||||
auto subfile_id = corrected_idx / m_master.max_frames_per_file();
|
auto subfile_id = corrected_idx / m_master.max_frames_per_file();
|
||||||
|
if (subfile_id >= subfiles.size()) {
|
||||||
|
throw std::runtime_error(LOCATION +
|
||||||
|
" Subfile out of range. Possible missing data.");
|
||||||
|
}
|
||||||
|
|
||||||
// This is where we start writing
|
// This is where we start writing
|
||||||
auto offset = (m_module_pixel_0[part_idx].y * m_cols +
|
auto offset = (m_module_pixel_0[part_idx].y * m_cols +
|
||||||
@ -343,6 +351,10 @@ void RawFile::get_frame_into(size_t frame_index, std::byte *frame_buffer, Detect
|
|||||||
auto pos = m_module_pixel_0[part_idx];
|
auto pos = m_module_pixel_0[part_idx];
|
||||||
auto corrected_idx = frame_indices[part_idx];
|
auto corrected_idx = frame_indices[part_idx];
|
||||||
auto subfile_id = corrected_idx / m_master.max_frames_per_file();
|
auto subfile_id = corrected_idx / m_master.max_frames_per_file();
|
||||||
|
if (subfile_id >= subfiles.size()) {
|
||||||
|
throw std::runtime_error(LOCATION +
|
||||||
|
" Subfile out of range. Possible missing data.");
|
||||||
|
}
|
||||||
|
|
||||||
subfiles[subfile_id][part_idx]->seek(corrected_idx % m_master.max_frames_per_file());
|
subfiles[subfile_id][part_idx]->seek(corrected_idx % m_master.max_frames_per_file());
|
||||||
subfiles[subfile_id][part_idx]->read_into(part_buffer, header);
|
subfiles[subfile_id][part_idx]->read_into(part_buffer, header);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user