Set node or node's data in the decomposition tree. Nodes are identified by string `path`. Parameters ---------- path : str String composed of node names. data : array or BaseNode subclass.
(self, path, data)
| 270 | raise TypeError(errmsg) |
| 271 | |
| 272 | def __setitem__(self, path, data): |
| 273 | """ |
| 274 | Set node or node's data in the decomposition tree. Nodes are |
| 275 | identified by string `path`. |
| 276 | |
| 277 | Parameters |
| 278 | ---------- |
| 279 | path : str |
| 280 | String composed of node names. |
| 281 | data : array or BaseNode subclass. |
| 282 | """ |
| 283 | |
| 284 | if isinstance(path, str): |
| 285 | if ( |
| 286 | self.maxlevel is not None and |
| 287 | len(self.path) + len(path) > self.maxlevel * self.PART_LEN |
| 288 | ): |
| 289 | raise IndexError("Path length out of range.") |
| 290 | if path: |
| 291 | subnode = self.get_subnode(path[0:self.PART_LEN], False) |
| 292 | if subnode is None: |
| 293 | self._create_subnode(path[0:self.PART_LEN], None) |
| 294 | subnode = self.get_subnode(path[0:self.PART_LEN], False) |
| 295 | subnode[path[self.PART_LEN:]] = data |
| 296 | else: |
| 297 | if isinstance(data, BaseNode): |
| 298 | self.data = np.asarray(data.data) |
| 299 | else: |
| 300 | self.data = np.asarray(data) |
| 301 | # convert data to nearest supported dtype |
| 302 | dtype = _check_dtype(data) |
| 303 | if self.data.dtype != dtype: |
| 304 | self.data = self.data.astype(dtype) |
| 305 | else: |
| 306 | raise TypeError("Invalid path parameter type - expected string but" |
| 307 | " got %s." % type(path)) |
| 308 | |
| 309 | def __delitem__(self, path): |
| 310 | """ |
nothing calls this directly
no test coverage detected