DM_iterate.py
## @package python.DM_iterate
## @brief unkown python script prefix=autobuild.swdvlp64.opals.distro.demo
#
# example script showing how to load an OPALS datamanager
# and iterate through all points
# (script works in python 2 and 3)
#
from __future__ import print_function # print function syntax as in python 3
import sys
from opals.tools.flags import Debug_Mode
if Debug_Mode == False:
from opals import pyDM # for pyDM in release mode
else:
from opals import pyDM_d as pyDM # for pyDM in debug mode
odm = "fullwave.odm" # odm test file
# load the "fullwave" data set from the opals demo distro
# pyDM.Datamanager.load parameter: filename(string), readOnly(bool) threadSafety(bool)
dm = pyDM.Datamanager.load(odm, True, False)
if not dm:
print("Unable to open ODM '" + odm + "'")
sys.exit(1)
limit = dm.getLimit()
# output some pyDM statistics
print("ODM contains", dm.sizePoint(), "points")
print("2D-limit (%.3f," % limit.xmin, "%.3f) -" % limit.ymin, "(%.3f," % limit.xmax, "%.3f)" % limit.ymax)
# create an attribute layout for iteration (optional)
lf = pyDM.AddInfoLayoutFactory()
lf.addColumn(pyDM.ColumnSemantic.Amplitude)
lf.addColumn(pyDM.ColumnSemantic.EchoWidth)
layout = lf.getLayout()
maxOutput = 1000
print("Output the first", maxOutput, "points of '"+odm+"'")
if sys.version_info >= (3, 0):
input("Press Enter to continue...")
else:
raw_input("Press Enter to continue...")
# list the first <maxOutput> points of the pyDM
i = 0
for pt in dm.points(layout):
i = i + 1
print("Point", "%5d" % i, "%.3f" % pt.x, "%.3f" % pt.y, "%.3f" % pt.z, "amp=%4.0f" % pt.info().get(0),
"ew=%4.1f" % pt.info().get(1))
if i == maxOutput:
break
print(i, "points listed")