Skip to content
Snippets Groups Projects
Commit 39467625 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Rework get_mem_cell_order

parent 1e6522fd
No related branches found
No related tags found
1 merge request!851[LPD] Automatically decide whether to inject & use memory cell order
...@@ -772,21 +772,32 @@ class LpdCorrections: ...@@ -772,21 +772,32 @@ class LpdCorrections:
flat_fields) flat_fields)
def get_mem_cell_order(run, sources) -> str: def get_mem_cell_order(run, sources, use_param) -> Optional[str]:
"""Load the memory cell order to use as a condition to find constants""" """Load the memory cell order to use as a condition to find constants"""
res = set() if use_param == 'never':
return None
patterns = []
for source in sources: for source in sources:
cell_id_data = run[source, 'image.cellId'].drop_empty_trains() cell_id_data = run[source, 'image.cellId'].drop_empty_trains()
if len(cell_id_data.train_ids) == 0: if len(cell_id_data.train_ids) == 0:
continue # No data for this module continue # No data for this module
cell_ids = cell_id_data[0].ndarray() cell_ids = cell_id_data[0].ndarray().flatten()
# Trailing comma required so e.g. "...,1" doesn't match "...,10" if not any(np.array_equal(cell_ids, p) for p in patterns):
res.add(",".join([str(c) for c in cell_ids.flatten()]) + ",") patterns.append(cell_ids)
if len(res) > 1: if len(patterns) > 1:
warn("Memory cell order varies between detector modules: " warn("Memory cell order varies between detector modules: "
"; ".join([f"{s[:10]}...{s[-10:]}" for s in res])) "; ".join([f"{s[:10]}...{s[-10:]}" for s in patterns]))
elif not res: elif not patterns:
raise ValueError("Couldn't find memory cell order for any modules") raise ValueError("Couldn't find memory cell order for any modules")
return res.pop() cellid_pattern = patterns[0]
use = (use_param == 'always') or (
# auto: use cell order if it wraps around (cell IDs not monotonic)
len(cellid_pattern) > 2 and (np.diff(cellid_pattern) < 0).any()
)
# Trailing comma required so e.g. "...,1" doesn't match "...,10"
return ",".join([str(c) for c in cellid_pattern]) + "," if use else None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment