Skip to content

Documentation for OutputSettings

Configuration class that specifies the format in which the results are saved. Results can be saved to a MongoDB or a simple son-file. You can also choose whether to save predictions and/or feature importances.

Source code in photonai/base/hyperpipe.py
class OutputSettings:
    """
    Configuration class that specifies the format in which
    the results are saved. Results can be saved to a MongoDB
    or a simple son-file. You can also choose whether to save
    predictions and/or feature importances.
    """
    def __init__(self,
                 mongodb_connect_url: str = None,
                 save_output: bool = True,
                 overwrite_results: bool = False,
                 generate_best_model: bool = True,
                 user_id: str = '',
                 wizard_object_id: str = '',
                 wizard_project_name: str = '',
                 project_folder: str = ''):
        """
        Initialize the object.

        Parameters:
            mongodb_connect_url:
                Valid mongodb connection url that specifies a database for storing the results.

            save_output:
                Controls the general saving of the results.

            overwrite_results:
                Allows overwriting the results folder if it already exists.

            generate_best_model:
                Determines whether an optimum_pipe should be created and fitted.
                If False, no dependent files are created.

            user_id:
               The user name of the according PHOTONAI Wizard login.

            wizard_object_id:
               The object id to map the designed pipeline in the PHOTONAI Wizard
               to the results in the PHOTONAI CORE Database.

            wizard_project_name:
                How the project is titled in the PHOTONAI Wizard.

            project_folder:
                Deprecated Parameter - transferred to Hyperpipe.

        """
        if project_folder:
            msg = "Deprecated: The parameter 'project_folder' was moved to the Hyperpipe. " \
                  "Please use Hyperpipe(..., project_folder='')."
            logger.error(msg)
            raise DeprecationWarning(msg)
        self.mongodb_connect_url = mongodb_connect_url
        self.overwrite_results = overwrite_results

        self.user_id = user_id
        self.wizard_object_id = wizard_object_id
        self.wizard_project_name = wizard_project_name

        self.generate_best_model = generate_best_model
        self.save_output = save_output
        self.save_predictions_from_best_config_inner_folds = None

        self.verbosity = 0
        self.results_folder = ''
        self.project_folder = ''
        self.log_file = ''
        self.logging_file_handler = None

    # this is only allowed from hyperpipe
    def set_project_folder(self, project_folder):
        self.project_folder = project_folder
        self.initialize_log_file()

    @property
    def setup_error_file(self):
        if self.project_folder:
            return os.path.join(self.project_folder, 'photon_setup_errors.log')
        else:
            return ""

    def initialize_log_file(self):
        self.log_file = self.setup_error_file

    def update_settings(self, name, timestamp):

        if self.save_output:
            if not os.path.exists(self.project_folder):
                os.makedirs(self.project_folder)

            # Todo: give rights to user if this is done by docker container
            if self.overwrite_results:
                self.results_folder = os.path.join(self.project_folder, name + '_results')
            else:
                self.results_folder = os.path.join(self.project_folder, name + '_results_' + timestamp)

            logger.info("Output Folder: " + self.results_folder)

            if not os.path.exists(self.results_folder):
                os.makedirs(self.results_folder)

            if os.path.basename(self.log_file) == "photon_setup_errors.log":
                self.log_file = 'photon_output.log'
            self.log_file = self._add_timestamp(self.log_file)
            self.set_log_file()

        # if we made it here, there should be no further setup errors, every error that comes
        # now can go to the standard logger instance
        if os.path.isfile(self.setup_error_file):
            os.remove(self.setup_error_file)

    def _add_timestamp(self, file):
        return os.path.join(self.results_folder, os.path.basename(file))

    def _get_log_level(self):
        if self.verbosity == 0:
            level = 25
        elif self.verbosity == 1:
            level = logging.INFO  # 20
        elif self.verbosity == 2:
            level = logging.DEBUG  # 10
        else:
            level = logging.WARN  # 30
        return level

    def set_log_file(self):
        logfile_directory = os.path.dirname(self.log_file)
        if not os.path.exists(logfile_directory):
            os.makedirs(logfile_directory)
        if self.logging_file_handler is None:
            self.logging_file_handler = logging.FileHandler(self.log_file)
            self.logging_file_handler.setLevel(self._get_log_level())
            logger.addHandler(self.logging_file_handler)
        else:
            self.logging_file_handler.close()
            self.logging_file_handler.baseFilename = self.log_file

    def set_log_level(self):
        verbose_num = self._get_log_level()
        logger.setLevel(verbose_num)
        for handler in logger.handlers:
            handler.setLevel(verbose_num)

__init__(self, mongodb_connect_url=None, save_output=True, overwrite_results=False, generate_best_model=True, user_id='', wizard_object_id='', wizard_project_name='', project_folder='') special

Initialize the object.

Parameters:

Name Type Description Default
mongodb_connect_url str

Valid mongodb connection url that specifies a database for storing the results.

None
save_output bool

Controls the general saving of the results.

True
overwrite_results bool

Allows overwriting the results folder if it already exists.

False
generate_best_model bool

Determines whether an optimum_pipe should be created and fitted. If False, no dependent files are created.

True
user_id str

The user name of the according PHOTONAI Wizard login.

''
wizard_object_id str

The object id to map the designed pipeline in the PHOTONAI Wizard to the results in the PHOTONAI CORE Database.

''
wizard_project_name str

How the project is titled in the PHOTONAI Wizard.

''
project_folder str

Deprecated Parameter - transferred to Hyperpipe.

''
Source code in photonai/base/hyperpipe.py
def __init__(self,
             mongodb_connect_url: str = None,
             save_output: bool = True,
             overwrite_results: bool = False,
             generate_best_model: bool = True,
             user_id: str = '',
             wizard_object_id: str = '',
             wizard_project_name: str = '',
             project_folder: str = ''):
    """
    Initialize the object.

    Parameters:
        mongodb_connect_url:
            Valid mongodb connection url that specifies a database for storing the results.

        save_output:
            Controls the general saving of the results.

        overwrite_results:
            Allows overwriting the results folder if it already exists.

        generate_best_model:
            Determines whether an optimum_pipe should be created and fitted.
            If False, no dependent files are created.

        user_id:
           The user name of the according PHOTONAI Wizard login.

        wizard_object_id:
           The object id to map the designed pipeline in the PHOTONAI Wizard
           to the results in the PHOTONAI CORE Database.

        wizard_project_name:
            How the project is titled in the PHOTONAI Wizard.

        project_folder:
            Deprecated Parameter - transferred to Hyperpipe.

    """
    if project_folder:
        msg = "Deprecated: The parameter 'project_folder' was moved to the Hyperpipe. " \
              "Please use Hyperpipe(..., project_folder='')."
        logger.error(msg)
        raise DeprecationWarning(msg)
    self.mongodb_connect_url = mongodb_connect_url
    self.overwrite_results = overwrite_results

    self.user_id = user_id
    self.wizard_object_id = wizard_object_id
    self.wizard_project_name = wizard_project_name

    self.generate_best_model = generate_best_model
    self.save_output = save_output
    self.save_predictions_from_best_config_inner_folds = None

    self.verbosity = 0
    self.results_folder = ''
    self.project_folder = ''
    self.log_file = ''
    self.logging_file_handler = None