o # i@srddlmZddlmZmZddlZddlmZddlm Z gdZ dd d Z GdddeZ Gddde Z dS)) annotations)ABCabstractmethodN)PathLike)create_file_basename)FolderLayoutBase FolderLayoutdefault_name_formattermetadictdictsavermonai.transforms.TransformreturncCsP|r|tjjjt|ddnt|dd}|r |tjjjdnd}||dS)zxReturns a kwargs dict for :py:meth:`FolderLayout.filename`, according to the input metadata and SaveImage transform. _data_indexrN)subjectidx)getmonaiutils ImageMetaKeyFILENAME_OR_OBJgetattr PATCH_INDEX)r r r patch_indexrZ/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/data/folder_layout.pyr s   r c@seZdZdZedddZdS)ra Abstract base class to define a common interface for FolderLayout and derived classes Mainly, defines the ``filename(**kwargs) -> PathLike`` function, which must be defined by the deriving class. Example: .. code-block:: python from monai.data import FolderLayoutBase class MyFolderLayout(FolderLayoutBase): def __init__( self, basepath: Path, extension: str = "", makedirs: bool = False ): self.basepath = basepath if not extension: self.extension = "" elif extension.startswith("."): self.extension = extension: else: self.extension = f".{extension}" self.makedirs = makedirs def filename(self, patient_no: int, image_name: str, **kwargs) -> Path: sub_path = self.basepath / patient_no if not sub_path.exists(): sub_path.mkdir(parents=True) file = image_name for k, v in kwargs.items(): file += f"_{k}-{v}" file += self.extension return sub_path / file rrcKst)zu Create a filename with path based on the input kwargs. Abstract method, implement your own. )NotImplementedError)selfkwargsrrrfilenameMszFolderLayoutBase.filenameN)rr)__name__ __module__ __qualname____doc__rrrrrrr#s)rc@s2eZdZdZ     ddd dZddddZdS)ra6 A utility class to create organized filenames within ``output_dir``. The ``filename`` method could be used to create a filename following the folder structure. Example: .. code-block:: python from monai.data import FolderLayout layout = FolderLayout( output_dir="/test_run_1/", postfix="seg", extension="nii", makedirs=False) layout.filename(subject="Sub-A", idx="00", modality="T1") # return value: "/test_run_1/Sub-A_seg_00_modality-T1.nii" The output filename is a string starting with a ``subject`` ID, and includes additional information about a customized index and image modality. This utility class doesn't alter the underlying image data, but provides a convenient way to create filenames. F output_dirrpostfixstr extensionparentboolmakedirs data_root_dircCs(||_||_||_||_||_||_dS)a Args: output_dir: output directory. postfix: a postfix string for output file name appended to ``subject``. extension: output file extension to be appended to the end of an output filename. parent: whether to add a level of parent folder to contain each image to the output filename. makedirs: whether to create the output parent directories if they do not exist. data_root_dir: an optional `PathLike` object to preserve the folder structure of the input `subject`. Please see :py:func:`monai.data.utils.create_file_basename` for more details. N)r%r&extr)r+r,)rr%r&r(r)r+r,rrr__init__os  zFolderLayout.__init__rNrc Ks~t|j||j|j|j||jd}|D]\}}|d|d|7}q|jdur=|j}||r9|ds9d|n|7}|S)a  Create a filename based on the input ``subject`` and ``idx``. The output filename is formed as: ``output_dir/[subject/]subject[_postfix][_idx][_key-value][ext]`` Args: subject: subject name, used as the primary id of the output filename. When a `PathLike` object is provided, the base filename will be used as the subject name, the extension name of `subject` will be ignored, in favor of ``extension`` from this class's constructor. idx: additional index name of the image. kwargs: additional keyword arguments to be used to form the output filename. The key-value pairs will be appended to the output filename as ``f"_{k}-{v}"``. )r&input_file_name folder_pathr,separate_folderrr+_-N.) rr&r%r,r)r+itemsr- startswith)rrrr full_namekvr-rrrrs  "zFolderLayout.filename)r$r$FFr$) r%rr&r'r(r'r)r*r+r*r,r)rN)rrrr)r r!r"r#r.rrrrrrVs r)r r r r rr ) __future__rabcrrr monai.configrmonai.data.utilsr__all__r rrrrrrs     3