class_docstr: Class that inherits from both `torch.Tensor` and `MetaObj`, adding support for metadata.
  
  Metadata is stored in the form of a dictionary. Nested, an affine matrix will be
  stored. This should be in the form of `torch.Tensor`.
  
  Behavior should be the same as `torch.Tensor` aside from the extended
  meta functionality.
  
  Copying of information:
  
      * For `c = a + b`, then auxiliary data (e.g., metadata) will be copied from the
        first instance of `MetaTensor` if `a.is_batch` is False
        (For batched data, the metadata will be shallow copied for efficiency purposes).
  
  Example:
      .. code-block:: python
  
          import torch
          from monai.data import MetaTensor
  
          t = torch.tensor([1,2,3])
          affine = torch.as_tensor([[2,0,0,0],
                                    [0,2,0,0],
                                    [0,0,2,0],
                                    [0,0,0,1]], dtype=torch.float64)
          meta = {"some": "info"}
          m = MetaTensor(t, affine=affine, meta=meta)
          m2 = m + m
          assert isinstance(m2, MetaTensor)
          assert m2.meta["some"] == "info"
          assert torch.all(m2.affine == affine)
  
  Notes:
      - Requires pytorch 1.9 or newer for full compatibility.
      - Older versions of pytorch (<=1.8), `torch.jit.trace(net, im)` may
        not work if `im` is of type `MetaTensor`. This can be resolved with
        `torch.jit.trace(net, im.as_tensor())`.
      - For pytorch < 1.8, sharing `MetaTensor` instances across processes may not be supported.
      - For pytorch < 1.9, next(iter(meta_tensor)) returns a torch.Tensor.
        see: https://github.com/pytorch/pytorch/issues/54457
      - A warning will be raised if in the constructor `affine` is not `None` and
        `meta` already contains the key `affine`.
      - You can query whether the `MetaTensor` is a batch with the `is_batch` attribute.
      - With a batch of data, `batch[0]` will return the 0th image
        with the 0th metadata. When the batch dimension is non-singleton, e.g.,
        `batch[:, 0]`, `batch[..., -1]` and `batch[1:3]`, then all (or a subset in the
        last example) of the metadata will be returned, and `is_batch` will return `True`.
      - When creating a batch with this class, use `monai.data.DataLoader` as opposed
        to `torch.utils.data.DataLoader`, as this will take care of collating the
        metadata properly.
class_docstr_tok: ["Class","that","inherits","from","both","`","torch.Tensor","`","and","`","MetaObj","`",",","adding","support","for","metadata",".","Metadata","is","stored","in","the","form","of","a","dictionary",".","Nested",",","an","affine","matrix","will","be","stored",".","This","should","be","in","the","form","of","`","torch.Tensor","`",".","Behavior","should","be","the","same","as","`","torch.Tensor","`","aside","from","the","extended","meta","functionality",".","Copying","of","information",":","*","For","`","c","=","a","+","b","`",",","then","auxiliary","data","(","e.g.",",","metadata",")","will","be","copied","from","the","first","instance","of","`","MetaTensor","`","if","`","a.is_batch","`","is","False","(","For","batched","data",",","the","metadata","will","be","shallow","copied","for","efficiency","purposes",")",".","Example",":","..","code-block",":",":","python","import","torch","from","monai.data","import","MetaTensor","t","=","torch.tensor","(","[","1,2,3","]",")","affine","=","torch.as_tensor","(","[","[","2,0,0,0","]",",","[","0,2,0,0","]",",","[","0,0,2,0","]",",","[","0,0,0,1","]","]",",","dtype=torch.float64",")","meta","=","{","``","some","''",":","``","info","''","}","m","=","MetaTensor","(","t",",","affine=affine",",","meta=meta",")","m2","=","m","+","m","assert","isinstance","(","m2",",","MetaTensor",")","assert","m2.meta","[","``","some","''","]","==","``","info","''","assert","torch.all","(","m2.affine","==","affine",")","Notes",":","-","Requires","pytorch","1.9","or","newer","for","full","compatibility",".","-","Older","versions","of","pytorch","(","<","=1.8",")",",","`","torch.jit.trace","(","net",",","im",")","`","may","not","work","if","`","im","`","is","of","type","`","MetaTensor","`",".","This","can","be","resolved","with","`","torch.jit.trace","(","net",",","im.as_tensor","(",")",")","`",".","-","For","pytorch","<","1.8",",","sharing","`","MetaTensor","`","instances","across","processes","may","not","be","supported",".","-","For","pytorch","<","1.9",",","next","(","iter","(","meta_tensor",")",")","returns","a","torch.Tensor",".","see",":","https",":","\/\/github.com\/pytorch\/pytorch\/issues\/54457","-","A","warning","will","be","raised","if","in","the","constructor","`","affine","`","is","not","`","None","`","and","`","meta","`","already","contains","the","key","`","affine","`",".","-","You","can","query","whether","the","`","MetaTensor","`","is","a","batch","with","the","`","is_batch","`","attribute",".","-","With","a","batch","of","data",",","`","batch","[","0","]","`","will","return","the","0th","image","with","the","0th","metadata",".","When","the","batch","dimension","is","non-singleton",",","e.g.",",","`","batch","[",":",",","0","]","`",",","`","batch","[","...",",","-1","]","`","and","`","batch","[","1:3","]","`",",","then","all","(","or","a","subset","in","the","last","example",")","of","the","metadata","will","be","returned",",","and","`","is_batch","`","will","return","`","True","`",".","-","When","creating","a","batch","with","this","class",",","use","`","monai.data.DataLoader","`","as","opposed","to","`","torch.utils.data.DataLoader","`",",","as","this","will","take","care","of","collating","the","metadata","properly","."]
docstr: Get the spacing
docstr_tok: ["Get","the","spacing"]
code: def pixdim(self):
      """Get the spacing"""
      if self.is_batch:
          return [affine_to_spacing(a) for a in self.affine]
      return affine_to_spacing(self.affine)
  
imports: from __future__ import annotations
  import functools
  import warnings
  from copy import deepcopy
  from typing import Any, Sequence
  import numpy
  import torch
  import monai
  from monai.config.type_definitions import NdarrayTensor
  from monai.data.meta_obj import MetaObj, get_track_meta
  from monai.data.utils import affine_to_spacing, decollate_batch, list_data_collate, remove_extra_metadata
  from monai.utils import look_up_option
  from monai.utils.enums import LazyAttr, MetaKeys, PostFix, SpaceKeys
  from monai.utils.type_conversion import convert_data_type, convert_to_dst_type, convert_to_numpy, convert_to_tensor
label_desc: Use image node_id 19 for calling the MetaTensor obj's underlying member method code with example usage: obj.pixdim() and returns: affine_to_spacing, unknown