IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
compute_dynamic_threshold.py
1"""@namespace IMP.emseqfinder.compute_dynamic_threshold
2 Determine a threshold for an EM map."""
3
4
5import sys
6
7
8def compute_threshold(map_path):
9 import mrcfile
10 import numpy as np
11 with mrcfile.open(map_path, permissive=True) as mrc:
12 data = mrc.data.astype(np.float32)
13
14 # Remove NaNs or infinities
15 data = data[np.isfinite(data)]
16
17 # Optionally trim outliers
18 data = data[(data > np.percentile(data, 1))
19 & (data < np.percentile(data, 99))]
20
21 # Use a percentile-based threshold close to Chimera's visual level
22 return np.percentile(data, 99.9)
23
24
25def main():
26 threshold = compute_threshold(sys.argv[1])
27 print(round(threshold, 4))
28
29
30if __name__ == '__main__':
31 main()