populse_mia package

MIA (Multiparametric Image Analysis) is a comprehensive image processing environment primarily designed for the analysis and visualization of large MRI datasets.

MRI data analysis often requires executing complex processing pipelines on datasets acquired during single or multiple MRI exams. In large-scale studies, where data processing must be repeated across numerous acquisition sessions, manually running processing modules or relying on simple ad-hoc scripts can become error-prone, cumbersome, and difficult to reproduce. Additionally, data processing pipelines are often distributed across various heterogeneous toolboxes, developed either in-house or by other researchers, further increasing the complexity of manually invoking these modules.

MIA (populse_mia) aims to simplify complex data processing by providing intuitive tools that define inputs and outputs at a conceptual level. It organizes data based on their roles in an analysis project, such as “scan type,” “subject,” or “subject group,” making it easier to structure and automate workflows.

Contents:

  • Packages

    • data_manager: Manages projects and their associated databases.

    • sources_images: Contains a collection of images used in MIA.

    • user_interface: Handles the graphical user interface of MIA.

    • utils: Provides various utility functions for MIA operations.

  • Modules

    • info.py: Defines software version, description, and requirements.

    • main.py: The primary module executed at runtime.

    • __main__.py: Allows populse_mia to be executed as a module.

    • software_properties.py: Manages the software’s configuration.

    • test.py: Contains unit tests.

Subpackages

Submodules

populse_mia.info module

Define software version, description and requirements

Contains:
Function:
  • get_populse_mia_gitversion

populse_mia.info.get_populse_mia_gitversion()[source]

Mia version as reported by the last commit in git.

Returns:

The short commit hash as the version or None if not found.

populse_mia.main module

The first module used at the mia runtime.

Basically, this module is dedicated to the initialisation of the basic parameters and the various checks necessary for a successful launch of the mia’s GUI.

Contains:
Function:
  • add_to_sys_path

  • check_package

  • main

  • qt_message_handler

populse_mia.main.add_to_sys_path(path, name, index=0)[source]

Adds the specified path to the system path if it’s a valid directory.

Parameters:
  • (pathlib.Path) (path) – The directory path to be added to the system path.

  • (str) (name) – The name of the package being added.

  • optional) (index (int,) – The index at which to insert the path into sys.path. Defaults to 0.

Return (bool):

True if the path is a valid directory and was added to sys.path, False otherwise.

populse_mia.main.check_package(name)[source]

Attempts to import a package by its name, logs the location of the package if successful, and logs an error if the package is missing.

Parameters:

(str) (name) – The name of the package to be imported.

Return (bool):

True if the package is imported successfully; False if the package is missing.

populse_mia.main.main(args)[source]

Make basic configuration check, then actual launch of Mia.

Checks if Mia is called from the site/dist packages (user mode) or from a cloned git repository (developer mode).

~/.populse_mia/configuration_path.yml is mandatory, if it doesn’t exist or is corrupted, try to create one with a valid properties path.

  • If launched from a cloned git repository (developer mode):
    • the properties_path is the “properties_dev_path” parameter in ~/.populse_mia/configuration_path.yml

  • If launched from the site/dist packages (user mode):
    • the properties_path is the “properties_user_path” parameter in ~/.populse_mia/configuration_path.yml

Launches the verify_processes() function, then the launch_mia() function (Mia’s real launch).

populse_mia.main.qt_message_handler(message)[source]

Custom Qt message handler to filter out specific unwanted messages and output the remaining ones.

Parameters:

(str) (message) – The message to be handled, potentially filtered and then output.

populse_mia.software_properties module

Module that handle the configuration of the software

Load and save the parameters from the miniviewer and the MIA preferences pop-up in the config.yml file.

Contains:
Class:
  • Config

class populse_mia.software_properties.Config(properties_path=None)[source]

Bases: object

Object that handles the configuration of the software

Contains:
Methods:
  • get_admin_hash: get the value of the hash of the admin password

  • get_afni_path: returns the path of AFNI

  • get_ants_path: returns the path of ANTS

  • getBackgroundColor: get background color

  • get_capsul_config: get CAPSUL config dictionary

  • get_capsul_engine: get a global CapsulEngine object used for all

    operations in MIA application

  • getChainCursors: returns if the “chain cursors” checkbox of the

    mini-viewer is activated

  • get_freesurfer_setup: get freesurfer path

  • get_fsl_config: returns the path of the FSL config file

  • get_mainwindow_maximized: get the maximized (full-screen) flag

  • get_mainwindow_size: get the main window size

  • get_matlab_command: returns Matlab command

  • get_matlab_path: returns the path of Matlab’s executable

  • get_matlab_standalone_path: returns the path of Matlab Compiler

    Runtime

  • get_max_projects: returns the maximum number of projects

    displayed in the “Saved projects” menu

  • get_max_thumbnails: get max thumbnails number at the data

    browser bottom

  • get_properties_path: returns the software’s properties path

  • get_mri_conv_path: returns the MRIManager.jar path

  • get_mrtrix_path: returns mrtrix path

  • getNbAllSlicesMax: returns the maximum number of slices to

    display in the mini viewer

  • get_opened_projects: returns the opened projects

  • get_projects_save_path: returns the folder where the projects

    are saved

  • get_referential: returns boolean to indicate DataViewer

    referential

  • get_resources_path: get the resources path

  • getShowAllSlices: returns if the “show all slices” checkbox of

    the mini viewer is activated

  • getSourceImageDir: get the source directory for project images

  • get_spm_path: returns the path of SPM12 (license version)

  • get_spm_standalone_path: returns the path of SPM12 (standalone

    version)

  • getTextColor: return the text color

  • getThumbnailTag: returns the tag that is displayed in the mini

    viewer

  • get_use_afni: returns the value of “use afni” checkbox in the

    preferences

  • get_use_ants: returns the value of “use ants” checkbox in the

    preferences

  • get_use_clinical: returns the value of “clinical mode” checkbox

    in the preferences

  • get_use_freesurfer: returns the value of “use freesurfer”

    checkbox in the preferences

  • get_use_fsl: returns the value of “use fsl” checkbox in the

    preferences

  • get_use_matlab: returns the value of “use matlab” checkbox in

    the preferences

  • get_use_matlab_standalone: returns the value of “use matlab

    standalone” checkbox in the preferences

  • get_use_mrtrix: returns the value of “use mrtrix” checkbox in

    the preferences

  • get_user_level: get the user level in the Capsul config

  • get_user_mode: returns the value of “user mode” checkbox

    in the preferences

  • get_use_spm: returns the value of “use spm” checkbox in the

    preferences

  • get_use_spm_standalone: returns the value of “use spm standalone”

    checkbox in the preferences

  • getViewerConfig: returns the DataViewer configuration (neuro or

    radio), by default neuro

  • getViewerFramerate: returns the DataViewer framerate for

    automatic time running images

  • isAutoSave: checks if auto-save mode is activated

  • isControlV1: checks if the selected display of the controller is

    of V1 type

  • isRadioView: checks if miniviewer in radiological orientation (if

    not, then it is in neurological orientation)

  • loadConfig: reads the config in the config.yml file

  • saveConfig: saves the config to the config.yml file

  • set_admin_hash: set the password hash

  • set_afni_path: set the path of the AFNI

  • set_ants_path: set the path of the ANTS

  • set_mrtrix_path: set the path of mrtrix

  • setAutoSave: sets the auto-save mode

  • setBackgroundColor: sets the background color

  • set_capsul_config: set CAPSUL configuration dict into MIA config

  • setChainCursors: set the “chain cursors” checkbox of the mini

    viewer

  • set_clinical_mode: set the value of “clinical mode” in

    the preferences

  • setControlV1: Set controller display mode (True if V1)

  • set_freesurfer_setup: set freesurfer path

  • set_fsl_config: set the path of the FSL config file

  • set_mainwindow_maximized: set the maximized (fullscreen) flag

  • set_mainwindow_size: set main window size

  • set_matlab_path: set the path of Matlab’s executable

  • set_matlab_standalone_path: set the path of Matlab Compiler

    Runtime

  • set_max_projects: set the maximum number of projects displayed in

    the “Saved projects” menu

  • set_max_thumbnails: set max thumbnails number at the data browser

    bottom

  • set_mri_conv_path: set the MRIManager.jar path

  • setNbAllSlicesMax: set the maximum number of slices to display in

    the mini viewer

  • set_opened_projects: set the opened projects

  • set_projects_save_path: set the folder where the projects are

    saved

  • set_radioView: set the orientation in miniviewer (True for

    radiological, False for neurological orientation)

  • set_referential: set the DataViewer referential

  • set_resources_path: Set the resources path

  • setShowAllSlices: set the “show all slices” checkbox of the mini

    viewer

  • setSourceImageDir: set the source directory for project images

  • set_spm_path: set the path of SPM12 (license version)

  • set_spm_standalone_path: set the path of SPM12 (standalone

    version)

  • setTextColor: set the text color

  • setThumbnailTag: set the tag that is displayed in the mini viewer

  • set_use_afni: set the value of “use afni” checkbox in the

    preferences

  • set_use_ants: set the value of “use ants” checkbox in the

    preferences

  • set_use_freesurfer: set the value of “use freesurfer” checkbox

    in the preferences

  • set_use_fsl: set the value of “use fsl” checkbox in the

    preferences

  • set_use_matlab: set the value of “use matlab” checkbox in the

    preferences

  • set_use_matlab_standalone: set the value of “use matlab

    standalone” checkbox in the preferences

  • set_use_mrtrix: set the value of “use mrtrix” checkbox in the

    preferences

  • set_user_mode: set the value of “user mode” checkbox in

    the preferences

  • set_use_spm: set the value of “use spm” checkbox in the

    preferences

  • set_use_spm_standalone: set the value of “use spm standalone”

    checkbox in the preferences

  • setViewerConfig: set the Viewer configuration neuro or radio

  • setViewerFramerate: set the Viewer frame rate for automatic

    running time images

  • update_capsul_config: update a global CapsulEngine object used

    for all operations in MIA application

__init__(properties_path=None)[source]

Initialization of the Config class

Parameters:

(str) (properties_path) – If provided, the configuration file will be loaded/saved from the given directory. Otherwise, the regular heuristics will be used to determine the config path. This option allows to use an alternative config directory (for tests for instance).

capsul_engine = None
getBackgroundColor()[source]

Get background color.

Return (str):

Background color, or “” if unknown.

getChainCursors()[source]

Get the value of the checkbox ‘chain cursor’ in miniviewer.

Return (bool):

Value of the checkbox.

getNbAllSlicesMax()[source]

Get number the maximum number of slices to display in the miniviewer.

Return (int):

Maximum number of slices to display in miniviewer.

getShowAllSlices()[source]

Get whether the show_all_slices parameters was enabled or not in the miniviewer.

Return (bool):

True if the show_all_slices parameters was enabled.

getSourceImageDir()[source]

Get the source directory for project images.

Return (str):

A path.

getTextColor()[source]

Get the text color.

Return (str):

The text color.

getThumbnailTag()[source]

Get the tag of the thumbnail displayed in the miniviewer.

Return (str):

The tag of the thumbnail displayed in miniviewer.

getViewerConfig()[source]

Get the viewer config “neuro” or “radio”, “neuro” by default.

Return (str):

The viewer config (“neuro” or “radio”).

getViewerFramerate()[source]

Get the Viewer framerate.

Return (str):

The Viewer framerat (ex. “5”).

get_admin_hash()[source]

Retrieves the hashed admin password from the configuration.

Returns:

The hashed admin password if found in config, False if not present in config.

get_afni_path()[source]

Get the AFNI path.

Return (str):

Path to AFNI, or “” if unknown.

get_ants_path()[source]

Get the ANTS path.

Return (str):

Path to ANTS, or “” if unknown.

get_capsul_config(sync_from_engine=True)[source]

Retrieve and construct the Capsul configuration dictionary.

This function builds a configuration dictionary for Capsul, incorporating settings for various neuroimaging tools and processing engines. It manages configurations for tools like SPM, FSL, FreeSurfer, MATLAB, AFNI, ANTs, and MRTrix.

The function first retrieves local settings for each tool from the Mia preferences, then constructs the appropriate configuration structure. If requested, it can synchronize the configuration with the current Capsul engine state.

Parameters:

(bool) (sync_from_engine) – If True, synchronizes the configuration with the current Capsul engine settings after building the base configuration.

Return (dict):

A nested dictionary containing the complete Capsul configuration, structured with the following main sections: - engine_modules: List of available processing modules - engine: Contains global and environment-specific

settings

  • tool-specific configurations (SPM, FSL, etc.)

Private functions:
  • _configure_spm: Configure SPM settings.

  • _configure_tool:

static get_capsul_engine()[source]

Get or create a global CapsulEngine singleton for Mia application operations.

The engine is created only once when first needed (lazy initialization). Subsequent calls return the same instance.

Returns:

CapsulEngine: The global CapsulEngine instance.

get_freesurfer_setup()[source]

Get the freesurfer path.

Return (str):

Path to freesurfer, or “” if unknown.

get_fsl_config()[source]

Get the FSL config file path.

Return (str):

Path to the fsl/etc/fslconf/fsl.sh file.

get_mainwindow_maximized()[source]

Get the maximized (fullscreen) flag.

Return (bool):

Maximized (fullscreen) flag.

get_mainwindow_size()[source]

Get the main window size.

Return (list):

Main window size.

get_matlab_command()[source]

Retrieves the appropriate Matlab command based on the configuration.

Return (str):

The Matlab executable path or None if no path is specified.

get_matlab_path()[source]

Get the path to the matlab executable.

Return (str):

A path.

get_matlab_standalone_path()[source]

Get the path to matlab compiler runtime.

Return (str):

A path.

get_max_projects()[source]

Retrieves the maximum number of projects displayed in the “Saved projects” menu.

Return (int):

The maximum number of projects. Defaults to 5 if not specified.

get_max_thumbnails()[source]

Retrieves the maximum number of thumbnails displayed in the mini-viewer at the bottom of the data browser.

Return (int):

The maximum number of thumbnails. Defaults to 5 if not specified.

get_mri_conv_path()[source]

Get the MRIManager.jar path.

Return (str):

A path.

get_mrtrix_path()[source]

Get the mrtrix path

Return (str):

A path.

get_opened_projects()[source]

Get opened projects.

Return (list):

Opened projects.

get_projects_save_path()[source]

Get the path where projects are saved.

Return (str):

A path.

get_properties_path()[source]

Retrieves the path to the folder containing the “processes” and “properties” directories of Mia.

The properties path is defined in the configuration_path.yml file, located in ~/.populse_mia.

  • In user mode, the path is retrieved from the properties_user_path parameter.

  • In developer mode, the path is retrieved from the properties_dev_path parameter.

If outdated parameters (mia_path, mia_user_path) are found, they are automatically updated in the configuration file.

Return (str):

The absolute path to the properties folder.

get_referential()[source]

Retrieves the chosen referential from the anatomist_2 data viewer.

Return (str):

“0” for World Coordinates, “1” for Image ref.

get_resources_path()[source]

Get the resources path.

Return (str):

A path.

get_spm_path()[source]

Get the path of SPM12.

Return (str):

A path.

get_spm_standalone_path()[source]

Get the path to the SPM12 standalone version.

Return (str):

A path.

get_use_afni()[source]

Get the value of “use afni” checkbox in the preferences.

Return (bool):

The value of “use afni” checkbox.

get_use_ants()[source]

Get the value of “use ants” checkbox in the preferences.

Return (bool):

The value of “use ants” checkbox.

get_use_clinical()[source]

Get the clinical mode in the preferences.

Return (bool):

The clinical mode.

get_use_freesurfer()[source]

Get the value of “use freesurfer” checkbox in the preferences.

Return (bool):

The value of “use freesurfer” checkbox.

get_use_fsl()[source]

Get the value of “use fsl” checkbox in the preferences.

Return (bool):

The value of “use fsl” checkbox.

get_use_matlab()[source]

Get the value of “use matlab” checkbox in the preferences.

Return (bool):

The value of “use matlab” checkbox.

get_use_matlab_standalone()[source]

Get the value of “use matlab standalone” checkbox in the preferences.

Return (bool):

The value of “use matlab standalone” checkbox.

get_use_mrtrix()[source]

Get the value of “use mrtrix” checkbox in the preferences.

Return (bool):

The value of “use mrtrix” checkbox.

get_use_spm()[source]

Get the value of “use spm” checkbox in the preferences.

Return (bool):

The value of “use spm” checkbox.

get_use_spm_standalone()[source]

Get the value of “use spm standalone” checkbox in the preferences.

Return (bool):

The value of “use spm standalone” checkbox.

get_user_level()[source]

Get the user level in the Capsul config.

Return (int):

The user level in the Capsul config.

get_user_mode()[source]

Get if user mode is disabled or enabled in the preferences.

Return (bool):

If True, the user mode is enabled.

isAutoSave()[source]

Get if the auto-save mode is enabled or not.

Return (bool):

If True, auto-save mode is enabled.

isControlV1()[source]

Gets whether the controller display is of type V1.

Return (bool):

If True, V1 controller display.

isRadioView()[source]

Get if the display in miniviewer is in radiological orientation.

Return (bool):

If True, radiological orientation, otherwise neurological orientation.

loadConfig()[source]

Read the config from config.yml file.

Attempts to read an encrypted YAML configuration file from the properties directory, decrypt it using Fernet encryption, and parse it as YAML.

Return (dict):

Parsed configuration from the YAML file. Returns empty dict if parsing fails.

saveConfig()[source]

Save the current parameters in the config.yml file.

Encrypts and writes the current configuration (self.config) to config.yml using Fernet encryption. Creates the necessary directory structure if it doesn’t exist. After saving, updates the capsul configuration.

setAutoSave(save)[source]

Set auto-save mode.

Parameters:

save – A boolean.

setBackgroundColor(color)[source]

Set background color and save configuration.

Parameters:

color – Color string (‘Black’, ‘Blue’, ‘Green’, ‘Grey’, ‘Orange’, ‘Red’, ‘Yellow’, ‘White’)

setChainCursors(chain_cursors)[source]

Set the value of the checkbox ‘chain cursor’ in the mini viewer.

Parameters:

chain_cursors – A boolean.

setControlV1(controlV1)[source]

Set controller display mode (True if V1).

Parameters:

controlV1 – A boolean.

setNbAllSlicesMax(nb_slices_max)[source]

Set the number of slices to display in the mini-viewer.

Parameters:

(int) (nb_slices_max) – maximum number of slices to display.

setShowAllSlices(show_all_slices)[source]

Set the show_all_slides setting in miniviewer.

Parameters:

show_all_slices – A boolean.

setSourceImageDir(source_image_dir)[source]

Set the source directory for project images.

Parameters:

source_image_dir – A path (str).

setTextColor(color)[source]

Set text color and save configuration.

Parameters:

color – Color string (‘Black’, ‘Blue’, ‘Green’, ‘Grey’, ‘Orange’, ‘Red’, ‘Yellow’, ‘White’)

setThumbnailTag(thumbnail_tag)[source]

Set the tag that is displayed in the mini-viewer.

Parameters:

thumbnail_tag – A string.

setViewerConfig(config_NeuRad)[source]

sets user’s configuration neuro or radio for data_viewer.

  • neuro: neurological

  • radio: radiological

Parameters:

config_NeuRad – A string.

setViewerFramerate(im_sec)[source]

sets user’s framerate for data_viewer.

Parameters:

(int) (im_sec) – Number of images per second.

set_admin_hash(admin_hash)[source]

Set the password hash.

Parameters:

admin_hash – A string.

set_afni_path(path)[source]

Set the AFNI path.

Parameters:

path – A path (str).

set_ants_path(path)[source]

Set the ANTS path

Parameters:

path – A path (str).

set_capsul_config(capsul_config_dict)[source]

Update Mia configuration with Capsul settings and synchronize tools configuration.

Called after editing Capsul config (via File > Mia preferences > Pipeline tab > Edit CAPSUL config) to synchronize Capsul settings with Mia preferences. Configures various neuroimaging tools AFNI, ANTs, FSL, etc.) based on the Capsul engine configuration.

Parameters:

(dict) (capsul_config_dict) –

Dictionary containing Capsul

configuration with structure:

{
‘engine’: {

‘environment_name’: {…configuration…}

}, ‘engine_modules’: […]

}

Contains:
Private function:
  • _configure_standalone_spm: Configures standalone SPM and

    MCR.

  • _configure_matlab_spm: Configures SPM and MATLAB.

  • _configure_matlab_only: Configures MATLAB without SPM.

  • _configure_mcr_only: Configures MCR without SPM.

  • _disable_matlab_spm: Disables all MATLAB and SPM

    configurations.

  • _get_module_config: Extracts module configuration from the

    global Capsul configuration.

set_clinical_mode(clinical_mode)[source]

Enable or disable clinical mode.

Parameters:

clinical_mode – A boolean.

set_freesurfer_setup(path)[source]

Set the freesurfer config file.

Parameters:

(str) (path) – Path to freesurfer/FreeSurferEnv.sh.

set_fsl_config(path)[source]

Set the FSL config file.

Parameters:

(str) (path) – Path to fsl/etc/fslconf/fsl.sh.

set_mainwindow_maximized(enabled)[source]

Set the maximized (full-screen) flag.

Parameters:

enabled – A boolean.

set_mainwindow_size(size)[source]

Set main window size.

Parameters:

size – A list of two integers.

set_matlab_path(path)[source]

Set the path of Matlab’s executable.

Parameters:

path – A path (str).

set_matlab_standalone_path(path)[source]

Set the path of Matlab Compiler Runtime.

Parameters:

path – A path (str).

set_max_projects(nb_max_projects)[source]

Set the maximum number of projects displayed in the “Saved projects” menu.

Parameters:

nb_max_projects – An integer.

set_max_thumbnails(nb_max_thumbnails)[source]

Set max thumbnails number at the data browser bottom.

Parameters:

nb_max_thumbnails – An integer.

set_mri_conv_path(path)[source]

Set the MRIManager.jar path.

Parameters:

path – A path (str).

set_mrtrix_path(path)[source]

Set the mrtrix path.

Parameters:

path – A path (str).

set_opened_projects(new_projects)[source]

Set the list of opened projects and saves the modification.

Parameters:

(list[str]) (new_projects) – A list of paths.

set_projects_save_path(path)[source]

Set the folder where the projects are saved.

Parameters:

path – A path (str).

set_radioView(radio_view)[source]

Set the radiological/neurological orientation in mini viewer.

  • True for radiological

  • False for neurological

Parameters:

radio_view – A boolean.

set_referential(ref)[source]

Set the referential to “image Ref” or “World Coordinates” in anatomist_2 data viewer.

Parameters:

(str) (ref) – “0” for World Coordinates, “1” for Image Ref.

set_resources_path(path)[source]

Set the resources path.

Parameters:

path – A path (str).

set_spm_path(path)[source]

Set the path of SPM (license version).

Parameters:

path – A path (str).

set_spm_standalone_path(path)[source]

Set the path of SPM (standalone version).

Parameters:

path – A path (str).

set_use_afni(use_afni)[source]

Set the value of “use_afni” checkbox in the preferences.

Parameters:

use_afni – A boolean.

set_use_ants(use_ants)[source]

Set the value of “use_ants” checkbox in the preferences.

Parameters:

use_ants – A boolean.

set_use_freesurfer(use_freesurfer)[source]

Set the value of “use_freesurfer” checkbox in the preferences.

Parameters:

use_freesurfer – A boolean.

set_use_fsl(use_fsl)[source]

Set the value of “use_fsl” checkbox in the preferences.

Parameters:

use_fsl – A boolean.

set_use_matlab(use_matlab)[source]

Set the value of “use matlab” checkbox in the preferences.

Parameters:

use_matlab – A boolean.

set_use_matlab_standalone(use_matlab_standalone)[source]

Set the value of “use_matlab_standalone” checkbox in the preferences.

Parameters:

use_matlab – A boolean.

set_use_mrtrix(use_mrtrix)[source]

Set the value of “use_mrtrix” checkbox in the preferences.

Parameters:

use_mrtrix – A boolean.

set_use_spm(use_spm)[source]

Set the value of “use spm” checkbox in the preferences.

Parameters:

use_spm – A boolean.

set_use_spm_standalone(use_spm_standalone)[source]

Set the value of “use spm standalone” checkbox in the preferences.

Parameters:

use_spm_standalone – A boolean.

set_user_mode(user_mode)[source]

Enable or disable user mode.

Parameters:

user_mode – A boolean.

update_capsul_config()[source]

Updates the global CapsulEngine object used for all operations in the Mia application.

The CapsulEngine is created once when needed and updated each time the configuration is saved. This method ensures that all necessary engine modules are loaded and configurations are properly imported from the saved settings.

Return (capsul.engine.CapsulEngine):

The updated CapsulEngine object, or None if the engine is not initialized.

populse_mia.test module