MCPcopy Create free account
hub / github.com/PyWavelets/pywt / __getitem__

Method __getitem__

pywt/_wavelet_packets.py:234–270  ·  view source on GitHub ↗

Find node represented by the given path. Similar to `~BaseNode.get_subnode` method with `decompose=True`, but can access nodes on any level in the decomposition tree. Parameters ---------- path : str String composed of node names. See `N

(self, path)

Source from the content-addressed store, hash-verified

232 return subnode
233
234 def __getitem__(self, path):
235 """
236 Find node represented by the given path.
237
238 Similar to `~BaseNode.get_subnode` method with `decompose=True`, but
239 can access nodes on any level in the decomposition tree.
240
241 Parameters
242 ----------
243 path : str
244 String composed of node names. See `Node.node_name` and
245 `Node2D.node_name` for node naming convention.
246
247 Notes
248 -----
249 If node does not exist yet, it will be created by decomposition of its
250 parent node.
251 """
252 errmsg = ("Invalid path parameter type - expected string or "
253 "tuple of strings but got %s." % type(path))
254 if isinstance(path, tuple):
255 # concatenate tuple of strings into a single string
256 try:
257 path = ''.join(path)
258 except TypeError:
259 raise TypeError(errmsg)
260 if isinstance(path, str):
261 if (self.maxlevel is not None and
262 len(path) > self.maxlevel * self.PART_LEN):
263 raise IndexError("Path length is out of range.")
264 if path:
265 return self.get_subnode(path[0:self.PART_LEN], True)[
266 path[self.PART_LEN:]]
267 else:
268 return self
269 else:
270 raise TypeError(errmsg)
271
272 def __setitem__(self, path, data):
273 """

Callers

nothing calls this directly

Calls 1

get_subnodeMethod · 0.95

Tested by

no test coverage detected