Recursively iterate over nodes hanging from where. Parameters ---------- where : str or Group, optional If supplied, the iteration starts from (and includes) this group. It can be a path string or a Group instance (see :ref:`GroupClassDesc
(
self, where: Group | str = "/", classname: str | None = None
)
| 2262 | return self.walk_nodes("/") |
| 2263 | |
| 2264 | def walk_nodes( |
| 2265 | self, where: Group | str = "/", classname: str | None = None |
| 2266 | ) -> Generator[Node]: |
| 2267 | """Recursively iterate over nodes hanging from where. |
| 2268 | |
| 2269 | Parameters |
| 2270 | ---------- |
| 2271 | where : str or Group, optional |
| 2272 | If supplied, the iteration starts from (and includes) |
| 2273 | this group. It can be a path string or a |
| 2274 | Group instance (see :ref:`GroupClassDescr`). |
| 2275 | classname |
| 2276 | If the name of a class derived from |
| 2277 | Node (see :ref:`GroupClassDescr`) is supplied, only instances of |
| 2278 | that class (or subclasses of it) will be returned. |
| 2279 | |
| 2280 | Notes |
| 2281 | ----- |
| 2282 | This version iterates over the leaves in the same group in order |
| 2283 | to avoid having a list referencing to them and thus, preventing |
| 2284 | the LRU cache to remove them after their use. |
| 2285 | |
| 2286 | Examples |
| 2287 | -------- |
| 2288 | :: |
| 2289 | |
| 2290 | # Recursively print all the nodes hanging from '/detector'. |
| 2291 | print("Nodes hanging from group '/detector':") |
| 2292 | for node in h5file.walk_nodes('/detector', classname='EArray'): |
| 2293 | print(node) |
| 2294 | |
| 2295 | """ |
| 2296 | class_ = get_class_by_name(classname) |
| 2297 | |
| 2298 | if class_ is Group: # only groups |
| 2299 | yield from self.walk_groups(where) |
| 2300 | elif class_ is Node: # all nodes |
| 2301 | yield self.get_node(where) |
| 2302 | for group in self.walk_groups(where): |
| 2303 | yield from self.iter_nodes(group) |
| 2304 | else: # only nodes of the named type |
| 2305 | for group in self.walk_groups(where): |
| 2306 | yield from self.iter_nodes(group, classname) |
| 2307 | |
| 2308 | def walk_groups(self, where: Group | str = "/") -> Generator[Group]: |
| 2309 | """Recursively iterate over groups (not leaves) hanging from where. |