Parsing

heudiconv.parser.find_files(regex: str, topdir: list[str] | tuple[str, ...] | str = '.', exclude: str | None = None, exclude_vcs: bool = True, dirs: bool = False) Iterator[str]

Generator to find files matching regex

Parameters:
  • regex (string) –

  • exclude (string, optional) – Matches to exclude

  • exclude_vcs – If True, excludes commonly known VCS subdirectories. If string, used as regex to exclude those files (regex: /.(?:git|gitattributes|svn|bzr|hg)(?:/|$))

  • topdir (string or list, optional) – Directory where to search

  • dirs (bool, optional) – Either to match directories as well as files

heudiconv.parser.get_extracted_dicoms(fl: Iterable[str]) ItemsView[str | None, list[str]]

Given a collection of files and/or directories, list out and possibly extract the contents from archives.

Parameters:

fl – Files (possibly archived) to process.

Returns:

The absolute paths of (possibly newly extracted) files.

Return type:

ItemsView[str | None, list[str]]

Notes

For ‘classical’ heudiconv, if multiple archives are provided, they correspond to different sessions, so here we would group into sessions and return pairs sessionid, files with sessionid being None if no “sessions” detected for that file or there was just a single tarball in the list.

When contents of fl appear to be an unpackable archive, the contents are extracted into utils.TempDirs(f’heudiconvDCM’) and the mode of all extracted files is set to 700.

When contents of fl are a list of unarchived files, they are treated as a single session.

When contents of fl are a list of unarchived and archived files, the unarchived files are grouped into a single session (key: None). If there is only one archived file, the contents of that file are grouped with the unarchived file. If there are multiple archived files, they are grouped into separate sessions.

heudiconv.parser.get_study_sessions(dicom_dir_template: str | None, files_opt: list[str] | None, heuristic: ModuleType, outdir: str, session: str | None, sids: list[str] | None, grouping: str = 'studyUID') dict[StudySessionInfo, list[str] | dict[SeqInfo, list[str]]]

Sort files or dicom seqinfos into study_sessions.

study_sessions put together files for a single session of a subject in a study. Two major possible workflows:

  • if dicom_dir_template provided – doesn’t pre-load DICOMs and just loads files pointed by each subject and possibly sessions as corresponding to different tarballs.

  • if files_opt is provided, sorts all DICOMs it can find under those paths