populse_mia.software_properties

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.

Classes

Config([properties_path])

Object that handles the configuration of the software

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

Bases: object

Object that handles the configuration of the software

Contains:
Methods:
  • _configure_matlab_only: Configures MATLAB without SPM

  • _configure_matlab_spm: Configures SPM and MATLAB

  • _configure_mcr_only: Configures MCR without SPM

  • _configure_standalone_spm: Configures standalone SPM and MCR

  • _disable_matlab_spm: Disables all MATLAB and SPM configurations

  • 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_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_properties_path: Returns the software’s properties path

  • 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

  • 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

  • set_mrtrix_path: Set the path of mrtrix

  • 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

capsul_engine = None
__init__(properties_path=None)[source]

Initialization of the Config class

Parameters:

properties_path (str or None) – 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).

_configure_matlab_only(matlab_path: str) None[source]

Configures MATLAB without SPM, ensuring that only MATLAB is used.

Parameters:

matlab_path (str) – The directory path of the MATLAB installation.

_configure_matlab_spm(spm_dir, matlab_path)[source]

Configures SPM to use the specified SPM directory with a MATLAB installation.

Parameters:
  • spm_dir (str) – The directory path of the SPM installation.

  • matlab_path (str) – The directory path of the MATLAB installation.

_configure_mcr_only(mcr_dir: str) None[source]

Configures MATLAB Compiler Runtime (MCR) without SPM, ensuring that only MCR is used.

Parameters:

mcr_dir (str) – The directory path of the MATLAB Compiler Runtime (MCR).

_configure_standalone_spm(spm_dir, mcr_dir)[source]

Configures standalone SPM to use the specified SPM and MATLAB Compiler Runtime (MCR) directories.

Parameters:
  • spm_dir (str) – The directory path of the standalone SPM installation.

  • mcr_dir (str) – The directory path of the MATLAB Compiler Runtime (MCR).

_disable_matlab_spm() None[source]

Disables all MATLAB and SPM configurations, ensuring that neither MATLAB nor SPM is used.

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.

Return type:

str or bool

get_afni_path()[source]

Get the AFNI path.

Returns:

Path to AFNI, or “” if unknown.

Return type:

str

get_ants_path()[source]

Get the ANTS path.

Returns:

Path to ANTS, or “” if unknown.

Return type:

str

getBackgroundColor()[source]

Get background color.

Returns:

(str) Background color, or “” if unknown.

Return type:

str

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:

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

Returns:

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, as well as configurations specific to certain tools (SPM, FSL, etc.)

Return type:

dict

Contains:
Inner functions:
  • _configure_spm: Configure SPM settings.

  • _configure_tool: Configure various neuroimaging settings (e.g. ‘fsl’, ‘afni’, etc.)

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:

The global CapsulEngine instance.

Return type:

capsul.api.capsul_engine

getChainCursors()[source]

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

Returns:

Value of the checkbox.

Return type:

bool

get_freesurfer_setup()[source]

Get the freesurfer path.

Returns:

Path to freesurfer, or “” if unknown.

Return type:

str

get_fsl_config()[source]

Get the FSL config file path.

Returns:

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

Return type:

str

get_mainwindow_maximized()[source]

Get the maximized (fullscreen) flag.

Returns:

Maximized (fullscreen) flag.

Return type:

bool

get_mainwindow_size()[source]

Get the main window size.

Returns:

Main window size.

Return type:

list

get_matlab_command()[source]

Retrieves the appropriate Matlab command based on the configuration.

Returns:

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

Return type:

str or None

get_matlab_path()[source]

Get the path to the matlab executable.

Returns:

A path.

Return type:

str

get_matlab_standalone_path()[source]

Get the path to matlab compiler runtime.

Returns:

A path.

Return type:

str

get_max_projects()[source]

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

Returns:

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

Return type:

int

get_max_thumbnails()[source]

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

Returns:

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

Return type:

int

get_mri_conv_path()[source]

Get the MRIManager.jar path.

Returns:

A path.

Return type:

str

get_mrtrix_path()[source]

Get the mrtrix path.

Returns:

A path.

Return type:

str

getNbAllSlicesMax()[source]

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

Returns:

Maximum number of slices to display in miniviewer.

Return type:

int

get_opened_projects()[source]

Get opened projects.

Returns:

Opened projects.

Return type:

list

get_projects_save_path()[source]

Get the path where projects are saved.

Returns:

A path.

Return type:

str

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.

Returns:

The absolute path to the properties folder.

Return type:

str

get_referential()[source]

Retrieves the chosen referential from the anatomist_2 data viewer.

Returns:

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

Return type:

str

get_resources_path()[source]

Get the resources path.

Returns:

A path.

Return type:

str

getShowAllSlices()[source]

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

Returns:

True if the show_all_slices parameters was enabled.

Return type:

bool

getSourceImageDir()[source]

Get the source directory for project images.

Returns:

A path.

Return type:

str

get_spm_path()[source]

Get the path of SPM.

Returns:

A path.

Return type:

str

get_spm_standalone_path()[source]

Get the path to the SPM12 standalone version.

Returns:

A path.

Return type:

str

getTextColor()[source]

Get the text color.

Returns:

The text color.

Return type:

str

getThumbnailTag()[source]

Get the tag of the thumbnail displayed in the miniviewer.

Returns:

The tag of the thumbnail displayed in miniviewer.

Return type:

str

get_use_afni()[source]

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

Returns:

The value of “use afni” checkbox.

Return type:

bool

get_use_ants()[source]

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

Returns:

The value of “use ants” checkbox.

Return type:

bool

get_use_clinical()[source]

Get the clinical mode in the preferences.

Returns:

The clinical mode.

Return type:

bool

get_use_freesurfer()[source]

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

Returns:

The value of “use freesurfer” checkbox.

Return type:

bool

get_use_fsl()[source]

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

Returns:

The value of “use fsl” checkbox.

Return type:

bool

get_use_matlab()[source]

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

Returns:

The value of “use matlab” checkbox.

Return type:

bool

get_use_matlab_standalone()[source]

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

Returns:

The value of “use matlab standalone” checkbox.

Return type:

bool

get_use_mrtrix()[source]

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

Returns:

The value of “use mrtrix” checkbox.

Return type:

bool

get_user_level()[source]

Get the user level in the Capsul config.

Returns:

The user level in the Capsul config.

Return type:

int

get_user_mode()[source]

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

Returns:

If True, the user mode is enabled.

Return type:

bool

get_use_spm()[source]

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

Returns:

The value of “use spm” checkbox.

Return type:

bool

get_use_spm_standalone()[source]

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

Returns:

The value of “use spm standalone” checkbox.

Return type:

bool

getViewerConfig()[source]

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

Returns:

The viewer config (neuro or radio).

Return type:

str

getViewerFramerate()[source]

Get the Viewer framerate.

Returns:

The Viewer framerat (ex. “5”).

Return type:

str

isAutoSave()[source]

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

Returns:

If True, auto-save mode is enabled.

Return type:

bool

isControlV1()[source]

Gets whether the controller display is of type V1.

Returns:

If True, V1 controller display.

Return type:

bool

isRadioView()[source]

Get if the display in miniviewer is in radiological orientation.

Returns:

If True, radiological orientation, otherwise neurological orientation.

Return type:

bool

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.

Returns:

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

Return type:

dict

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.

set_admin_hash(admin_hash)[source]

Set the administrator password hash.

Parameters:

admin_hash (str) – The hashed administrator password to store in the configuration.

set_afni_path(path)[source]

Set the AFNI path.

Parameters:

path (str) – A path.

set_ants_path(path)[source]

Set the ANTS path

Parameters:

path (str) – A path.

setAutoSave(save)[source]

Set the automatic saving mode.

Parameters:

save (bool) – True to enable automatic saving, False to disable it.

setBackgroundColor(color)[source]

Set background color and save configuration.

Parameters:

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

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:

capsul_config_dict (dict) – Dictionary containing Capsul configuration.

Structure of capsul_config_dict:

{
    'engine': {
        'environment_name': {...configuration...}
    },
    'engine_modules': [...]
}
Contains:
Inner functions:
  • _get_module_config: Extracts module configuration from the global Capsul configuration.

setChainCursors(chain_cursors)[source]

Enable or disable cursor synchronization in the mini viewer.

Parameters:

chain_cursors (bool) – True to synchronize the cursors across the mini viewer, False otherwise.

set_clinical_mode(clinical_mode)[source]

Enable or disable clinical mode.

Parameters:

clinical_mode (bool) – True to enable clinical mode, False to disable it.

setControlV1(controlV1)[source]

Set the controller display mode.

Parameters:

controlV1 (bool) – True to use the V1 controller display mode, False to use the alternative mode (V2).

set_freesurfer_setup(path)[source]

Set the freesurfer config file.

Parameters:

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

set_fsl_config(path)[source]

Set the FSL config file.

Parameters:

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

set_mainwindow_maximized(enabled)[source]

Set whether the main window is maximized.

Parameters:

enabled (bool) – Whether the main window should be maximized.

set_mainwindow_size(size)[source]

Set main window size.

Parameters:

size (list[int]) – A list of two integers.

set_matlab_path(path)[source]

Set the path of Matlab’s executable.

Parameters:

path (str) – Path to Matlab’s executable.

set_matlab_standalone_path(path)[source]

Set the path of Matlab Compiler Runtime.

Parameters:

path (str) – Path to Matlab Compiler Runtime.

set_max_projects(nb_max_projects)[source]

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

Parameters:

nb_max_projects (int) – Maximum number of recent projects to display.

set_max_thumbnails(nb_max_thumbnails)[source]

Set the maximum number of thumbnails displayed at the bottom of the Data Browser.

Parameters:

nb_max_thumbnails (int) – Maximum number of thumbnails to display.

set_mri_conv_path(path)[source]

Set the MRIManager.jar path.

Parameters:

path (str) – A path.

set_mrtrix_path(path)[source]

Set the mrtrix path.

Parameters:

path (str) – A path.

setNbAllSlicesMax(nb_slices_max)[source]

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

Parameters:

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

set_opened_projects(new_projects)[source]

Set the list of opened projects and saves the modification.

Parameters:

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

set_projects_save_path(path)[source]

Set the folder where the projects are saved.

Parameters:

path (str) – A path.

set_radioView(radio_view)[source]

Set the orientation displayed in the mini viewer.

Parameters:

radio_view (bool) – If True, use the radiological orientation; otherwise, use the neurological orientation.

set_referential(ref)[source]

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

Parameters:

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

set_resources_path(path)[source]

Set the resources path.

Parameters:

path (str) – A path.

setShowAllSlices(show_all_slices)[source]

Set whether all slices are displayed in the mini viewer.

Parameters:

show_all_slices (bool) – If True, display all slices; otherwise, display only the selected slice.

setSourceImageDir(source_image_dir)[source]

Set the source directory for project images.

Parameters:

source_image_dir (str) – A path.

set_spm_path(path)[source]

Set the path of SPM (MATLAB license version).

Parameters:

path (str) – A path.

set_spm_standalone_path(path)[source]

Set the path of SPM (standalone version).

Parameters:

path (str) – A path.

setTextColor(color)[source]

Set text color and save configuration.

Parameters:

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

setThumbnailTag(thumbnail_tag)[source]

Set the tag displayed in the mini viewer for thumbnails.

Parameters:

thumbnail_tag (str) – Name of the tag to display.

set_use_afni(use_afni)[source]

Set whether AFNI support is enabled in the preferences.

Parameters:

use_afni (bool) – If True, enable AFNI support; otherwise, disable it.

set_use_ants(use_ants)[source]

Set whether ANTs support is enabled in the preferences.

Parameters:

use_ants (bool) – If True, enable ANTs support; otherwise, disable it.

set_use_freesurfer(use_freesurfer)[source]

Set whether FreeSurfer support is enabled in the preferences.

Parameters:

use_freesurfer (bool) – If True, enable FreeSurfer support; otherwise, disable it.

set_use_fsl(use_fsl)[source]

Set whether FSL support is enabled in the preferences.

Parameters:

use_fsl (bool) – If True, enable FSL support; otherwise, disable it.

set_use_matlab(use_matlab)[source]

Set whether Matlab support is enabled in the preferences.

Parameters:

use_matlab (bool) – If True, enable Matlab support; otherwise, disable it.

set_use_matlab_standalone(use_matlab_standalone)[source]

Set whether Matlab standalone support is enabled in the preferences.

Parameters:

use_matlab_standalone (bool) – If True, enable Matlab standalone support; otherwise, disable it.

set_use_mrtrix(use_mrtrix)[source]

Set whether MRtrix support is enabled in the preferences.

Parameters:

use_mrtrix (bool) – If True, enable MRtrix support; otherwise, disable it.

set_user_mode(user_mode)[source]

Enable or disable user mode.

Parameters:

user_mode (bool) – If True, enable user mode; otherwise, disable it.

set_use_spm(use_spm)[source]

Set whether SPM support is enabled in the preferences.

Parameters:

use_spm (bool) – If True, enable SPM support; otherwise, disable it.

set_use_spm_standalone(use_spm_standalone)[source]

Set whether SPM standalone support is enabled in the preferences.

Parameters:

use_spm_standalone (bool) – If True, enable SPM standalone support; otherwise, disable it.

setViewerConfig(config_NeuRad)[source]

Set the orientation convention used by the data viewer.

Parameters:

config_NeuRad (str) – Orientation convention. Accepted values are "neuro" for neurological orientation and "radio" for radiological orientation.

setViewerFramerate(im_sec)[source]

Set the framerate for the data viewer.

Parameters:

im_sec (int) – Number of images per second.

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.

Returns:

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

Return type:

capsul.engine.CapsulEngine | None