Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

registration_metrics.py 2.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  1. import argparse
  2. import suite2p
  3. import numpy as np
  4. from typing import NamedTuple
  5. from pathlib import Path
  6. from suite2p.__main__ import add_args, parse_args
  7. class RegMetricResult(NamedTuple):
  8. nplane: int
  9. avg_offs: np.array
  10. max_offs: np.array
  11. def registration_metrics(data_path, tiff_list, ops, nPC=10):
  12. """
  13. Displays registration offsets calculated on pclow and pchigh frames. If registration was performed well,
  14. the PCs should not contain movement. All offsets calculated on pclow/pchigh frames should be close to zero.
  15. """
  16. ops['do_regmetrics'] = True
  17. ops['roidetect'] = False
  18. ops['reg_metric_n_pc'] = nPC
  19. ops['data_path'] = data_path
  20. if tiff_list:
  21. ops['tiff_list'] = tiff_list
  22. result_ops = suite2p.run_s2p(ops)
  23. if not isinstance(result_ops, list) or not isinstance(result_ops, np.ndarray):
  24. result_ops = [result_ops]
  25. metric_results = []
  26. for nplane, result_op in enumerate(result_ops):
  27. offsets = result_op['regDX']
  28. result = RegMetricResult(nplane=nplane, avg_offs=np.mean(offsets, axis=0), max_offs=np.max(offsets, axis=0))
  29. metric_results.append(result)
  30. return metric_results
  31. def main():
  32. default_parser = add_args(argparse.ArgumentParser(description='Suite2p parameters'))
  33. default_parser.add_argument('data_path', type=str, nargs=1, help='Path to directory with input files')
  34. default_parser.add_argument('--tiff_list', default=[], type=str, nargs='*', help='Input files selected')
  35. default_parser.add_argument('--n_pc', default=10, type=int, help='Number of PCs')
  36. args, ops = parse_args(default_parser)
  37. reg_metric_results = registration_metrics(
  38. data_path=args.data_path, tiff_list=args.tiff_list, ops=ops, nPC=args.n_pc
  39. )
  40. for r in reg_metric_results:
  41. print(
  42. f"""
  43. Plane {r.nplane}:
  44. Avg_Rigid: {r.avg_offs[0]:.6f} \tAvg_Average NR: {r.avg_offs[1]:.6f} \tAvg_Max NR: {r.avg_offs[2]:.6f}
  45. Max_Rigid: {r.max_offs[0]:.6f} \tMax_Average NR: {r.max_offs[1]:.6f} \tMax_Max NR: {r.max_offs[2]:.6f}
  46. """.replace(' ', '')
  47. )
  48. if __name__ == "__main__":
  49. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...