DM_attributes_statistic.py
## @package python.DM_attributes_statistic
#
# Small example script showing how to access the attribute statistics
# of a datamanager
#
from __future__ import print_function # print function syntax as in python 3
import random, sys
from opals import pyDM # for pyDM in release mode
def DM_attributes_statistic(filename):
# pyDM.Datamanager.load parameter: filename(string), readOnly(bool) threadSafety(bool)
dm = pyDM.Datamanager.load(filename, True, False)
if not dm:
print("Unable to open ODM '" + filename + "'")
sys.exit(1)
# get point index object
pi = dm.getPointIndex()
print("ODM contains ", dm.sizePoint(), "points")
print("Estimated point density %.3f" % pi.estimatePointDensity(), "[points/m^2]")
# get attribute statistic object
stats = pi.getAddInfoStatistics()
print("Attribute statistics:")
print("Name\t type\t count\t min\t max\t mean\t sigma")
for i in range(0, stats.columns()):
colname = stats.min().name(i)
coltype = stats.min().type(i)
# output colname and coltype
print(colname + "\t" + str(coltype) + "\t", end="")
# output statistics
if stats.count(i) > 0:
print("%5d" % stats.count(i), "%.3f" % stats.min().get(i), "%.3f" % stats.max().get(i),
"%.3f" % stats.mean(i), "%.3f" % stats.sigma(i))
else:
print("%5d" % stats.count(i), "---", "---", "---", "---")
if len(sys.argv) == 1:
print("ODM parameter missing")
exit(-1)
DM_attributes_statistic(sys.argv[1])