DM_histogram.py
1 ## @package python.demo.DM_histogram
2 #
3 # iterating over all points of an existing ODM within python
4 # (script works in python 2 and 3)
5 #
6 
7 from __future__ import print_function # print function syntax as in python 3
8 import sys
9 
10 from opals import pyDM
11 
12 
13 def DM_histogram(filename):
14  # open the odm / pyDM.Datamanager.load parameters: filename(string), readOnly(bool) threadSafety(bool)
15  dm = pyDM.Datamanager.load(filename, True, False)
16 
17  # if the dm wasn't opened successful exit function
18  if not dm:
19  print("Unable to open ODM '" + filename + "'")
20  return
21 
22  f = pyDM.AddInfoLayoutFactory()
23  f.addColumn(pyDM.ColumnSemantic.EchoNumber)
24  layout = f.getLayout()
25 
26  print("Compute histogram of attribute 'EchoNumber'")
27  histoSet = dm.getHistogramSet(layout)
28 
29  for histo in histoSet.histograms():
30  for value, count in histo.values():
31  print(value, "=", count)
32 
33  print("done")
34 
35 
36 if len(sys.argv) == 1:
37  print("ODM parameter missing")
38  sys.exit(-1)
39 
40 DM_histogram(sys.argv[1])