Example #1
0
    def initialize_module(self):
        """ Set up FSL environment variables according to current
        configuration.
        """
        if self.study_config.use_fsl is False:
            # Configuration is explicitely asking not to use FSL
            return
        if self.study_config.use_fsl is Undefined:
            # If use_fsl is not defined, FSL configuration will
            # be done if possible but there will be no error if it cannot be
            # done.
            force_configuration = False
        else:
            # If use_fsl is True configuration must be valid otherwise
            # an EnvironmentError is raised
            force_configuration = True

        # Get the fsl.sh path from the study configuration elements
        fsl_config_file = self.study_config.fsl_config

        # If the fsl.sh path has been defined
        if fsl_config_file is not Undefined and \
           os.path.exists(fsl_config_file):
            # Parse the fsl environment
            envfsl = environment(fsl_config_file)
            if "FSLDIR" not in envfsl and "FSLDIR" not in os.environ:
                # assume the fsl.sh script is in $FSLDIR/etc/fslconf/fsl.sh
                envfsl["FSLDIR"] = os.path.dirname(os.path.dirname(
                    os.path.dirname(fsl_config_file)))
            if envfsl.get("FSLDIR", "") != os.environ.get("FSLDIR", ""):
                # Set the fsl environment
                for envname, envval in six.iteritems(envfsl):
                    if envname in os.environ:
                        if envname.startswith("FSL"):
                            os.environ[envname] = envval
                        else:
                            os.environ[envname] += ":" + envval
                    else:
                        os.environ[envname] = envval

                # No error detected in configuration, set use_fsl to
                # True
                self.study_config.use_fsl = True
        else:
            # Error in configuration, do not let use_fsl = Undefined
            self.study_config.use_fsl = False
            if force_configuration:
                raise EnvironmentError(
                    "No valid FSL configuration file specified. "
                    "It is impossible to configure FSL.")
Example #2
0
    def initialize_module(self):
        """ Set up Freesurfer environment variables according to current
        configuration.
        """
        if self.study_config.use_freesurfer is False:
            # Configuration is explicitely asking not to use FreeSurfer
            return
        if self.study_config.use_freesurfer is Undefined:
            # If use_freesurfer is not defined, FreeSurfer configuration will
            # be done if possible but there will be no error if it cannot be
            # done.
            force_configuration = False
        else:
            # If use_freesurfer is True configuration must be valid otherwise
            # an EnvironmentError is raised
            force_configuration = True

        # Get the 'SetUpFreeSurfer.sh' path from the study configuration
        # elements
        fs_config_file = self.study_config.freesurfer_config

        # If the 'SetUpFreeSurfer.sh' path has been defined
        if fs_config_file is not Undefined:
            if os.path.exists(fs_config_file):
                # Parse the fs environment: check if the 'FREESURFER_HOME'
                # environment varibale is already set and use it to configure
                # freesurfer
                fs_home = os.environ.get("FREESURFER_HOME", None)
                env = {}
                if fs_home is not None:
                    env["FREESURFER_HOME"] = fs_home
                envfs = environment(fs_config_file, env)

                # Set the fs environment
                for envname, envval in six.iteritems(envfs):
                    if envname in os.environ:
                        if envname.startswith(("FS", "FREESURFER")):
                            os.environ[envname] = envval
                        else:
                            os.environ[envname] += ":" + envval
                    else:
                        os.environ[envname] = envval

                # No error detected in configuration, set use_freesurfer to
                # True
                self.study_config.use_freesurfer = True
            else:
                #Error in configuration, do not let use_freesurfer = Undefined
                self.study_config.use_freesurfer = False
                if force_configuration:
                    raise EnvironmentError(
                        "FreeSurfer configuration file (%s) does not exist. "
                        "It is impossible to configure FreeSurfer." % \
                        fs_config_file)
        else:
            # Error in configuration, do not let use_freesurfer = Undefined
            self.study_config.use_freesurfer = False
            if force_configuration:
                raise EnvironmentError(
                    "No FreeSurfer configuration file specified. "
                    "It is impossible to configure FreeSurfer.")
    def initialize_module(self):
        """ Set up Freesurfer environment variables according to current
        configuration.
        """
        if self.study_config.use_freesurfer is False:
            # Configuration is explicitely asking not to use FreeSurfer
            return
        if self.study_config.use_freesurfer is Undefined:
            # If use_freesurfer is not defined, FreeSurfer configuration will
            # be done if possible but there will be no error if it cannot be
            # done.
            force_configuration = False
        else:
            # If use_freesurfer is True configuration must be valid otherwise
            # an EnvironmentError is raised
            force_configuration = True

        # Get the 'SetUpFreeSurfer.sh' path from the study configuration
        # elements
        fs_config_file = self.study_config.freesurfer_config

        # If the 'SetUpFreeSurfer.sh' path has been defined
        if fs_config_file is not Undefined:
            if os.path.exists(fs_config_file):
                # Parse the fs environment: check if the 'FREESURFER_HOME'
                # environment varibale is already set and use it to configure
                # freesurfer
                fs_home = os.environ.get("FREESURFER_HOME", None)
                env = {}
                if fs_home is not None:
                    env["FREESURFER_HOME"] = fs_home
                envfs = environment(fs_config_file, env)

                # Set the fs environment
                for envname, envval in envfs.iteritems():
                    if envname in os.environ:
                        if envname.startswith(("FS", "FREESURFER")):
                            os.environ[envname] = envval
                        else:
                            os.environ[envname] += ":" + envval
                    else:
                        os.environ[envname] = envval

                # No error detected in configuration, set use_freesurfer to
                # True
                self.study_config.use_freesurfer = True
            else:
                #Error in configuration, do not let use_freesurfer = Undefined
                self.study_config.use_freesurfer = False
                if force_configuration:
                    raise EnvironmentError(
                        "FreeSurfer configuration file (%s) does not exist. "
                        "It is impossible to configure FreeSurfer." % \
                        fs_config_file)
        else:
            # Error in configuration, do not let use_freesurfer = Undefined
            self.study_config.use_freesurfer = False
            if force_configuration:
                raise EnvironmentError(
                  "No FreeSurfer configuration file specified. "
                  "It is impossible to configure FreeSurfer.")