DM_create.py
## @package python.DM_create
#
# Small example script showing how to create points and fill them
# into a new manager
#
from __future__ import print_function # print function syntax as in python 3
import random, sys
# import pyDM_d as pyDM #for pyDM in debug mode
from opals import pyDM # for pyDM in release mode
# raw_input("Press Enter to continue...")
# create an attribute layout for generating points with the corresponding attributes
lf = pyDM.AddInfoLayoutFactory()
lf.addColumn(pyDM.ColumnSemantic.GPSTime)
lf.addColumn(pyDM.ColumnSemantic.Amplitude)
layout = lf.getLayout()
# now create 100 random points
print("Generate 100 random points")
pts = []
for i in range(100):
pt = pyDM.Point(layout)
pt.x = random.uniform(-10, 10)
pt.y = random.uniform(-10, 10)
pt.z = random.uniform(-10, 10)
pt.info().set(0, 132 + i / 1000.) # GPSTime
pt.info().set(1, random.uniform(1, 342.3)) # Amplitude
pts.append(pt)
odm = "test.odm" # odm test file
# write points to pyDM 'test.pyDM'
print("Write points into manager '" + odm + "'")
# pyDM.Datamanager.create parameter: file, threadSafety(bool)
dm = pyDM.Datamanager.create(odm, False)
if not dm:
print("Unable to create ODM '" + odm + "'")
sys.exit(1)
for pt in pts:
dm.addPoint(pt)
dm.save()
# change a point
for p in dm.points():
pt = p.clone()
pt.x = pt.x + 13.4
pt.y = pt.y - 10.3
dm.replacePoint(pt)
dm.save()
for p in dm.points():
print(p.x, p.y, p.z)
# output some pyDM statistics
limit = dm.getLimit()
print("ODM contains", dm.sizePoint(), "points")
print("2D-limit (%.3f," % limit.xmin, "%.3f) -" % limit.ymin, "(%.3f," % limit.xmax, "%.3f)" % limit.ymax)