DM_append_attribute.py
## @package python.DM_append_attribute
#
# example script showing how to append attribute to an existing
# OPALS datamanager using the Kernel/Processor concept
#
from __future__ import print_function # print function syntax as in python 3
import sys
# import pyDM_d as pyDM #for pyDM in debug mode
from opals import pyDM # for pyDM in release mode
##
# callback object computing an user-defined attribute '_dummy'
class Kernel(pyDM.PointKernel):
def __init__(self):
# initialize the base class (mandatory!)
super(Kernel, self).__init__()
return
def tileFilter(self):
return None
##
# callback notifies about a changed leaf
def leafChanged(self, leaf):
print("leafChanged called")
return
##
# callback for processing a point
def process(self, pt):
# formula _dummy = Amplitude * EchoWidth
pt.info().set(0, pt.info().get(1) * pt.info().get(2))
# return True if the point was changed otherwise False
# this internally marks the current point leaf as changed (=needs to be written to disk)
return True
odm = "fullwave.odm" # odm test file
# pyDM.Datamanager.load parameter: filename(string), readOnly(bool) threadSafety(bool)
dm = pyDM.Datamanager.load(odm, False, False)
if not dm:
print("Unable to open ODM '" + odm + "'")
sys.exit(1)
# creates the appropriate attribute layout for processing
lf = pyDM.AddInfoLayoutFactory()
lf.addColumn(pyDM.ColumnType.float_, "_dummy") # column 0
lf.addColumn(pyDM.ColumnSemantic.Amplitude) # column 1
lf.addColumn(pyDM.ColumnSemantic.EchoWidth) # column 2
layout = lf.getLayout()
print("Ready to append attribute '_dummy' to 'fullwave.odm'")
raw_input("Press Enter to continue...")
# create kernel object
k = Kernel()
# create processor
# pyDM.Processor parameter: dm(datamnager), layout, readOnlyView(bool)
processor = pyDM.Processor(dm, layout, False)
processor.run(k) # perform computation
# save manager object
print("Save manager")
dm.save()
print("done")