scanometrics.utils package

scanometrics.utils module: utility functions for statistics (stats.py)

Submodules

scanometrics.utils.bids_util module

Several methods to automate edits to bids database.

scanometrics.utils.bids_util.CS_to_session(CS_database, sess_database, repeat_variable='age')

Converts a cross-sectional (CS) dataset with repeated values as separate subjects to a dataset with proper repeats. Dataset with repeats has one unique ID per subject, which can used to identify repeats from the same subject. Different repeats are distinguishable from the ‘repeated_metric_name’ variable (eg age, TR, TE, contrast, etc…). Currently used to convert a CS tsv file where subjects with repeats have a ‘-’ separating their ID from repeat 2/3/4 etc… Assumes repeats come after 1st appearance of subject in the table.

Parameters
  • CS_database

  • sess_database

Returns

scanometrics.utils.bids_util.add_session_files(bids_database, repeated_variables=['age'])
scanometrics.utils.bids_util.check_tsv_folder_congruency(bids_database)
scanometrics.utils.bids_util.load_participants(bids_database)

scanometrics.utils.dicom2bids module

Module to convert DICOMs organised in the sourcefile directory of a BIDS database folder. WIP: hs_pipeline functions need to be copied here, or reimplemented for users outside of SCAN to use this script

scanometrics.utils.dicom2bids.accession2hash(patient_id, accession_number, bids_directory, hash_length=8)

Function to retrieve hash code from local file, create and add random hash if not found. Automatically adds a .gitignore file to avoid unintended addition to a git repo.

scanometrics.utils.dicom2bids.main()
scanometrics.utils.dicom2bids.scannercode(institution, device)

scanometrics.utils.io module

Module for reading, writing data methods

scanometrics.utils.io.load_project(project_file)

Method to load a ScanOMetrics_project instance

Parameters

project_file (string) – path to file with ScanOMetrics_project info

Returns

ScanOMetrics_project instance

scanometrics.utils.io.save_project(som_project, project_file=None)

Method to save a ScanOMetrics_project instance

Parameters
  • som_project (ScanOMetrics_project instance) – ScanOMetrics instance to save

  • project_file (string) – path of file to save information to (defaults to None to save to SOM_project.bids_database)

scanometrics.utils.logging module

Implements logging functions throughout ScanOMetrics package

scanometrics.utils.logging.ERROR(msg, prefix='')
scanometrics.utils.logging.LOG(msg, prefix='')
scanometrics.utils.logging.NOTE(msg, prefix='')
scanometrics.utils.logging.PRINT(*args, **kwargs)
scanometrics.utils.logging.WARNING(msg, prefix='')
scanometrics.utils.logging.get_verbose()

Return global verbose level

scanometrics.utils.logging.set_verbose(verbose)

Set global verbose level.

Parameters

verbose (int) – verbose level (0: hide everything, 1: warning/errors, 2: notes/prints

Returns

no return as sets global variable __VERBOSE_LEVEL__

scanometrics.utils.misc module

Miscellaneous util functions

scanometrics.utils.stats module

stats.py : stats module for ScanOMetrics software

scanometrics.utils.stats.fdr(p, q=0.05)
Compute False Discovery Rate (FDR)’s parametric and non-parametric thresholds. Returns 0.0 if no sample is found

below the FDR.

Parameters
  • p (numpy (N,) array) – vector of input p-values

  • q (float, optional) – False Discovery Rate level, defaults to 0.05

Returns

FDR parametric (based on independence or positive dependence) and non-parametric thresholds

Return type

tuple

scanometrics.utils.zenodo_api module

Methods to query zenodo’s REST API. Separate datasets are uploaded for each normative model, with versions corresponding to the software used to process the data used for training. This allows keeping track of the different models trained with different processing software versions, without having files all over the place. Eg: ‘Polynomial_dldirect_cleanOASIS3.pkl’ has record id 14712271, whose version 1.0.0 has been fitted with dldirect v1.0.0

scanometrics.utils.zenodo_api.decode_model_filename(model_filename)
scanometrics.utils.zenodo_api.download_file(url: str, local_filename: str, chunk_size: Optional[int] = 131072) str
scanometrics.utils.zenodo_api.get_scannrad_records()
scanometrics.utils.zenodo_api.list_normative_models()

Lists available models on default ScanOMetrics normative model folder and on scan-nrad Zenodo repository. This will list model_ids like ‘Polynomial_dldirect-v1.0.3_NormColl_som-v1.0.0.pkl’ Output: list of models with [‘filename’, ‘proc_pipeline_id’, ‘version’]