Skip to content
Snippets Groups Projects

[AGIPD][DARK] FIX: Make sure to process darks out of sequence file with the highest trainIds

Merged Karim Ahmed requested to merge fix/process_sequences_with_highest_trainIds into master
All threads resolved!
1 file
+ 16
10
Compare changes
  • Side-by-side
  • Inline
``` python
``` python
# set everything up filewise
# set everything up filewise
os.makedirs(out_folder, exist_ok=True)
os.makedirs(out_folder, exist_ok=True)
gain_mapped_files, total_files, total_file_size = map_gain_stages(
gain_mapped_files, _, total_file_size = map_gain_stages(
in_folder, offset_runs, path_template, karabo_da, sequences
in_folder, offset_runs, path_template, karabo_da, sequences
)
)
print(f"Will process a total of {total_files} files ({total_file_size:.02f} GB).")
# TODO: Keep this commented out to use it later again, this is false information at the moment.
 
# print(f"Will process a total of {total_files} files ({total_file_size:.02f} GB).")
inp = []
# TODO: Remove all of this nonsense with Extra-data.
 
inp = [None]*3*len(modules)
for gain_index, (gain, qm_file_map) in enumerate(gain_mapped_files.items()):
for gain_index, (gain, qm_file_map) in enumerate(gain_mapped_files.items()):
gain_input = []
gain_input = []
for module_index in modules:
for module_index in modules:
 
max_trainIds = 0
 
inp_idx = gain_index * len(modules) + module_index
qm = module_index_to_qm(module_index)
qm = module_index_to_qm(module_index)
if qm not in qm_file_map:
if qm not in qm_file_map:
print(f"Did not find files for {qm}")
print(f"Did not find files for {qm}")
# TODO: remove after using EXtra-data to read files
# TODO: remove after using EXtra-data to read files
# and skip empty trains.
# and skip empty trains.
with h5py.File(filename, "r") as fin:
with h5py.File(filename, "r") as fin:
if fin[h5path.format(module_index)+"/trainId"].shape[0] != 0:
trainIds = fin[h5path.format(module_index)+"/trainId"].shape[0]
print(f"Process {filename} for {qm}")
if trainIds != 0 and trainIds > max_trainIds:
gain_input.append((filename, module_index, gain_index))
inp[inp_idx] = (filename, module_index, gain_index)
else:
max_trainIds= trainIds
print(f"Do not process {filename} because it is empty.")
if not gain_input:
print(f"Process {inp[inp_idx][0]} for {qm}")
 
if inp[inp_idx] is None:
raise ValueError(
raise ValueError(
"No images to process for run: "
"No images to process for run: "
f"{[v for v in offset_runs.values()][gain_index]}"
f"{[v for v in offset_runs.values()][gain_index]}"
)
)
inp += gain_input
inp = [x for x in inp if x is not None]
 
total_files = len(inp)
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Loading