nipoppy.utils.utils¶
Utility functions.
Module Contents¶
- nipoppy.utils.utils.add_path_suffix(path, suffix, sep='-')¶
Add a suffix to a path, before the last file extension (if any).
- Parameters:
path (nipoppy.env.StrOrPathLike)
suffix (str)
- Return type:
- nipoppy.utils.utils.add_path_timestamp(path, timestamp_format='%Y%m%d_%H%M', sep='-')¶
Add a timestamp to a path, before the last file extension (if any).
- Parameters:
path (nipoppy.env.StrOrPathLike)
- Return type:
- nipoppy.utils.utils.apply_substitutions_to_json(json_obj, substitutions)¶
Apply substitutions to a JSON object.
- nipoppy.utils.utils.get_pipeline_tag(pipeline_name, pipeline_version, pipeline_step=None, participant_id=None, session_id=None, sep='-')¶
Generate a tag for a pipeline.
- nipoppy.utils.utils.get_today()¶
Get today’s date in the format YYYY-MM-DD.
- nipoppy.utils.utils.is_nipoppy_project(cwd=Path.cwd())¶
Verify if the current directory is a nipoppy project.
This is done by checking if the .nipoppy directory exists in the current directory or any of its parents. If the directory is found, it returns the path to the .nipoppy directory. If not, it returns False.
- Parameters:
cwd (nipoppy.env.StrOrPathLike, optional) – Path to directory, by default Path.cwd()
- nipoppy.utils.utils.load_json(fpath, **kwargs)¶
Load a JSON file.
- Parameters:
fpath (nipoppy.env.StrOrPathLike) – Path to the JSON file
**kwargs – Keyword arguments to pass to json.load
- Returns:
The JSON object.
- Return type:
- nipoppy.utils.utils.process_template_str(template_str, resolve_paths=True, objs=None, **kwargs)¶
Replace template strings with values from kwargs or objects.
- nipoppy.utils.utils.save_df_with_backup(df, fpath_symlink, dname_backups=None, use_relative_path=True, dry_run=False, **kwargs)¶
Save a dataframe as a symlink pointing to a timestamped “backup” file.
- Parameters:
df (pd.DataFrame) – The dataframe to save
fpath_symlink (nipoppy.env.StrOrPathLike) – The path to the symlink
dname_backups (Optional[str], optional) – The directory where the timestamped backup file should be written (automatically determined if None), by default None
use_relative_path (bool, optional) – Use relative instead of absolute path for the symlink, by default True
dry_run (bool, optional) – Return the file path but do not save the file, by default False
- Returns:
None if no file was saved, otherwise the path to the backup file
- Return type:
Path or None
- nipoppy.utils.utils.save_json(obj, fpath, **kwargs)¶
Save a JSON object to a file.
- nipoppy.utils.utils.DPATH_DATA¶
- nipoppy.utils.utils.DPATH_EXAMPLES¶
- nipoppy.utils.utils.DPATH_HPC¶
- nipoppy.utils.utils.DPATH_LAYOUTS¶
- nipoppy.utils.utils.FIELD_DESCRIPTION_MAP¶
- nipoppy.utils.utils.FPATH_DEFAULT_LAYOUT¶
- nipoppy.utils.utils.FPATH_HPC_TEMPLATE¶
- nipoppy.utils.utils.FPATH_SAMPLE_CONFIG¶
- nipoppy.utils.utils.FPATH_SAMPLE_DICOM_DIR_MAP¶
- nipoppy.utils.utils.FPATH_SAMPLE_MANIFEST¶
- nipoppy.utils.utils.NIPOPPY_ROOT¶
- nipoppy.utils.utils.TEMPLATE_PIPELINE_PATH¶
- nipoppy.utils.utils.TEMPLATE_REPLACE_PATTERN¶