MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / key_iterator

Method key_iterator

monai/transforms/transform.py:468–489  ·  view source on GitHub ↗

Iterate across keys and optionally extra iterables. If key is missing, exception is raised if `allow_missing_keys==False` (default). If `allow_missing_keys==True`, key is skipped. Args: data: data that the transform will be applied to extra_iterables

(self, data: Mapping[Hashable, Any], *extra_iterables: Iterable | None)

Source from the content-addressed store, hash-verified

466 raise NotImplementedError(f"Subclass {self.__class__.__name__} must implement this method.")
467
468 def key_iterator(self, data: Mapping[Hashable, Any], *extra_iterables: Iterable | None) -> Generator:
469 """
470 Iterate across keys and optionally extra iterables. If key is missing, exception is raised if
471 `allow_missing_keys==False` (default). If `allow_missing_keys==True`, key is skipped.
472
473 Args:
474 data: data that the transform will be applied to
475 extra_iterables: anything else to be iterated through
476 """
477 # if no extra iterables given, create a dummy list of Nones
478 ex_iters = extra_iterables or [[None] * len(self.keys)]
479
480 # loop over keys and any extra iterables
481 _ex_iters: list[Any]
482 for key, *_ex_iters in zip(self.keys, *ex_iters):
483 # all normal, yield (what we yield depends on whether extra iterables were given)
484 if key in data:
485 yield (key,) + tuple(_ex_iters) if extra_iterables else key
486 elif not self.allow_missing_keys:
487 raise KeyError(
488 f"Key `{key}` of transform `{self.__class__.__name__}` was missing in the data and allow_missing_keys==False."
489 )
490
491 def first_key(self, data: dict[Hashable, Any]):
492 """

Callers 15

first_keyMethod · 0.95
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
inverseMethod · 0.80

Calls

no outgoing calls

Tested by 3

__call__Method · 0.64
__call__Method · 0.64
inverseMethod · 0.64