Args: data: a dictionary containing the tensor-like data to be processed. The ``keys`` specified in this dictionary must be tensor like arrays that are channel first and have at most three spatial dimensions lazy: a flag to indicate wh
(self, data: Mapping[Hashable, torch.Tensor], lazy: bool | None = None)
| 484 | self.spacing_transform.lazy = val |
| 485 | |
| 486 | def __call__(self, data: Mapping[Hashable, torch.Tensor], lazy: bool | None = None) -> dict[Hashable, torch.Tensor]: |
| 487 | """ |
| 488 | Args: |
| 489 | data: a dictionary containing the tensor-like data to be processed. The ``keys`` specified |
| 490 | in this dictionary must be tensor like arrays that are channel first and have at most |
| 491 | three spatial dimensions |
| 492 | lazy: a flag to indicate whether this transform should execute lazily or not |
| 493 | during this call. Setting this to False or True overrides the ``lazy`` flag set |
| 494 | during initialization for this call. Defaults to None. |
| 495 | |
| 496 | Returns: |
| 497 | a dictionary containing the transformed data, as well as any other data present in the dictionary |
| 498 | """ |
| 499 | d: dict = dict(data) |
| 500 | |
| 501 | _init_shape, _pixdim, should_match = None, None, False |
| 502 | output_shape_k = None # tracking output shape |
| 503 | lazy_ = self.lazy if lazy is None else lazy |
| 504 | |
| 505 | for key, mode, padding_mode, align_corners, dtype, scale_extent in self.key_iterator( |
| 506 | d, self.mode, self.padding_mode, self.align_corners, self.dtype, self.scale_extent |
| 507 | ): |
| 508 | if self.ensure_same_shape and isinstance(d[key], MetaTensor): |
| 509 | if _init_shape is None and _pixdim is None: |
| 510 | _init_shape, _pixdim = d[key].peek_pending_shape(), d[key].pixdim |
| 511 | else: |
| 512 | should_match = np.allclose(_init_shape, d[key].peek_pending_shape()) and np.allclose( |
| 513 | _pixdim, d[key].pixdim, atol=1e-3 |
| 514 | ) |
| 515 | d[key] = self.spacing_transform( |
| 516 | data_array=d[key], |
| 517 | mode=mode, |
| 518 | padding_mode=padding_mode, |
| 519 | align_corners=align_corners, |
| 520 | dtype=dtype, |
| 521 | scale_extent=scale_extent, |
| 522 | output_spatial_shape=output_shape_k if should_match else None, |
| 523 | lazy=lazy_, |
| 524 | ) |
| 525 | if isinstance(d[key], MetaTensor): |
| 526 | meta_keys = [k for k in d.keys() if k is not None and k.startswith(f"{key}_")] |
| 527 | for meta_key in meta_keys: |
| 528 | if "filename_or_obj" in d[key].meta and is_supported_format( |
| 529 | d[key].meta["filename_or_obj"], ["nii", "nii.gz"] |
| 530 | ): |
| 531 | d[meta_key].update(d[key].meta) |
| 532 | if output_shape_k is None: |
| 533 | output_shape_k = d[key].peek_pending_shape() if isinstance(d[key], MetaTensor) else d[key].shape[1:] |
| 534 | return d |
| 535 | |
| 536 | def inverse(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, NdarrayOrTensor]: |
| 537 | d = dict(data) |
nothing calls this directly
no test coverage detected