Skip to content
Snippets Groups Projects
Commit 184601e8 authored by Ger van Diepen's avatar Ger van Diepen
Browse files

bug 1687:

Added support for argument baseKey
parent 2a24e426
No related branches found
No related tags found
No related merge requests found
...@@ -80,9 +80,25 @@ class parameterset(PyParameterSet): ...@@ -80,9 +80,25 @@ class parameterset(PyParameterSet):
"""Get the parametervalue object of a parameter.""" """Get the parametervalue object of a parameter."""
return self._get (key) return self._get (key)
def makeSubset (self, prefix): def makeSubset (self, baseKey, prefix=''):
"""Get a subset of all keys starting with the given prefix""" """Return a subset as a new parameterset object.
ps = self._makeSubset (prefix)
baseKey
The leading part of the parameter name denoting the subset.
A trailing period needs to be given.
prefix
The baseKey parameter name part is replaced by this new prefix.
The default new prefix is empty.
For example::
newps = ps.makeSubset ('p1.p2.', 'pr.')
creates a subset of all keys starting with `p1.p2.` and replaces
that prefix by `pr.`.
"""
ps = self._makeSubset (baseKey, prefix)
return parameterset (ps, _copyObj=True) return parameterset (ps, _copyObj=True)
def keys(self): def keys(self):
......
...@@ -172,27 +172,10 @@ namespace LOFAR { ...@@ -172,27 +172,10 @@ namespace LOFAR {
"Get the software version.") "Get the software version.")
.def ("size", &ParameterSet::size, .def ("size", &ParameterSet::size,
"Get the number of parameters.") "Get the number of parameters.")
.def ("__len__", &ParameterSet::size,
"Get the number of parameters.")
.def ("keywords", &PyParameterSet::keywords) .def ("keywords", &PyParameterSet::keywords)
.def ("_makeSubset", &PyParameterSet::makeSubset, .def ("_makeSubset", &PyParameterSet::makeSubset,
(boost::python::arg("baseKey"), (boost::python::arg("baseKey"),
boost::python::arg("prefix")=""), boost::python::arg("prefix")))
"Return a subset as a new parameterset object.\n"
"\n"
"baseKey\n"
" The leading part of the parameter name denoting the subset.\n"
" A trailing period has to be given.\n"
"prefix\n"
" The baseKey parameter name part is replaced by the prefix.\n"
"\n"
"For example::\n"
"\n"
" newps = ps.makeSubset ('p1,p2,', 'pr.')\n"
"\n"
"creates a subset of all keys starting with `p`1.p2.` and replaces\n"
"that prefix by `pr.`.\n"
)
.def ("subtractSubset", &ParameterSet::subtractSubset, .def ("subtractSubset", &ParameterSet::subtractSubset,
(boost::python::arg("baseKey")), (boost::python::arg("baseKey")),
"Remove all parameters starting with the baseKey.") "Remove all parameters starting with the baseKey.")
......
...@@ -84,7 +84,7 @@ checkps (ps) ...@@ -84,7 +84,7 @@ checkps (ps)
pss = ps.makeSubset('a.') pss = ps.makeSubset('a.')
print pss.keys() print pss.keys()
print 'b.c =', pss.getString ('b.c') print 'b.c =', pss.getString ('b.c')
print pss.makeSubset('b.').keys() print pss.makeSubset('b.', 'aa.bb.').keys()
print pss.makeSubset('b.').size() print pss.makeSubset('b.').size()
print pss.makeSubset('cc').keys() # should be empty print pss.makeSubset('cc').keys() # should be empty
print len(pss.makeSubset('cc')) print len(pss.makeSubset('cc'))
...@@ -80,7 +80,7 @@ True ...@@ -80,7 +80,7 @@ True
[5, 6, 7, 8, 9, 10] [5, 6, 7, 8, 9, 10]
['b', 'b.bool', 'b.c', 'b.double', 'b.lange_naam'] ['b', 'b.bool', 'b.c', 'b.double', 'b.lange_naam']
b.c = 5 b.c = 5
['bool', 'c', 'double', 'lange_naam'] ['aa.bb.bool', 'aa.bb.c', 'aa.bb.double', 'aa.bb.lange_naam']
4 4
[] []
0 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment