13 from __future__
import print_function
15 from opals
import pyDM
22 dm = pyDM.Datamanager.load(odm,
False,
False)
24 print(
"Unable to open ODM '" + odm +
"'")
29 lf = pyDM.AddInfoLayoutFactory()
30 type, inDM = lf.addColumn(dm,
"EchoWidth",
True);
assert inDM ==
True
31 type, inDM = lf.addColumn(dm,
"NrOfEchos",
True);
assert inDM ==
True
32 layoutRead = lf.getLayout()
34 lf.addColumn(pyDM.ColumnType.float_,
"_normalizedEchoWidth")
35 layoutWrite = lf.getLayout()
37 print(
"Get odm echo width as numpy object...")
39 numpyDict = pyDM.NumpyConverter.create(dm.sizePoint(),layoutRead,
False)
40 print(
"len(numpyDict)=",len(numpyDict))
41 pointindex = dm.getPointIndex()
45 count = float(pointindex.sizeLeaf())
46 for idx,leaf
in enumerate(pointindex.leafs()):
47 print(
"%5.1f%% finished" % (idx/count*100.) )
48 rowIdx += pyDM.NumpyConverter.fill(numpyDict,rowIdx,leaf)
50 print(
"100.0% finished.",rowIdx,
"values have been converted")
53 print(
"\nCompute min max echo width for single echos using numpy...")
54 mask = numpyDict[
"NrOfEchos"] == 1
55 minValue = (numpyDict[
"EchoWidth"][mask]).min()
56 maxValue = (numpyDict[
"EchoWidth"][mask]).max()
57 print(
"\tmin=%.2f" % minValue)
58 print(
"\tmax=%.2f" % maxValue)
61 k = 1./(maxValue-minValue)
63 normalizedEchoWidth = numpyDict[
"EchoWidth"]*k+d
66 minCheck = (normalizedEchoWidth[mask]).min();
assert abs(minCheck) < 1e-10
67 maxCheck = (normalizedEchoWidth[mask]).max();
assert abs(maxCheck-1) < 1e-10
71 storeDict[
"_normalizedEchoWidth"] = normalizedEchoWidth
72 print(
"\nStore normalised echo width values in ODM...")
74 for idx,leaf
in enumerate(pointindex.leafs()):
75 print(
"%5.1f%% finished" % (idx/count*100.) )
79 rowIdx += pyDM.NumpyConverter.set(storeDict, [], leaf, layoutWrite,
None, rowIdx)
84 print(
"100.0% finished.")
86 print(
"\nSave odm...")