Repository: Project-MONAI/MONAI
File: monai/apps/auto3dseg/bundle_gen.py (Python)

Code before:

    """

    def __init__(self, template_path: str):
        """
        Create an Algo instance based on the predefined Algo template.

        Args:
            template_path: path to the root of the algo template.

        """

        self.template_path = template_path
        self.data_stats_files = ""
        self.data_list_file = ""
        self.output_path = ""
        self.name = ""
        self.best_metric = None
        # track records when filling template config: {"<config name>": {"<placeholder key>": value, ...}, ...}
        self.fill_records: dict = {}

    def pre_check_skip_algo(self):
        """
        Analyse the data analysis report and check if the algorithm needs to be skipped.
        """
        # skip generating bundles for this algo
        self.skip_bundlegen = False
        # info to print when skipped
        self.skip_info = ""

    def set_data_stats(self, data_stats_files: str) -> None:
        """
        Set the data analysis report (generated by DataAnalyzer).

        Args:
            data_stats_files: path to the datastats yaml file
        """
        self.data_stats_files = data_stats_files

    def set_data_source(self, data_src_cfg: str) -> None:
        """
        Set the data source configuration file

        Args:
            data_src_cfg: path to a configuration file (yaml) that contains datalist, dataroot, and other params.
                The config will be in a form of {"modality": "ct", "datalist": "path_to_json_datalist", "dataroot":
                "path_dir_data"}
        """
        self.data_list_file = data_src_cfg

    def fill_template_config(self, data_stats_filename: str, algo_path: str, **kwargs: Any) -> dict:

Review comment (suggestion):
Maybe we can make the function inputs more general? For example `pre_check_skip_algo(self, skip_bundlegen: bool = False, skip_info:str = "")

Code after:

    """

    def __init__(self, template_path: str):
        """
        Create an Algo instance based on the predefined Algo template.

        Args:
            template_path: path to the root of the algo template.

        """

        self.template_path = template_path
        self.data_stats_files = ""
        self.data_list_file = ""
        self.output_path = ""
        self.name = ""
        self.best_metric = None
        # track records when filling template config: {"<config name>": {"<placeholder key>": value, ...}, ...}
        self.fill_records: dict = {}

    def pre_check_skip_algo(self, skip_bundlegen: bool = False, skip_info: str = "") -> tuple[bool, str]:
        """
        Analyse the data analysis report and check if the algorithm needs to be skipped.
        This function is overriden within algo.
        Args:
            skip_bundlegen: skip generating bundles for this algo if true.
            skip_info: info to print when skipped.
        """
        return skip_bundlegen, skip_info

    def set_data_stats(self, data_stats_files: str) -> None:
        """
        Set the data analysis report (generated by DataAnalyzer).

        Args:
            data_stats_files: path to the datastats yaml file
        """
        self.data_stats_files = data_stats_files

    def set_data_source(self, data_src_cfg: str) -> None:
        """
        Set the data source configuration file

        Args:
            data_src_cfg: path to a configuration file (yaml) that contains datalist, dataroot, and other params.
                The config will be in a form of {"modality": "ct", "datalist": "path_to_json_datalist", "dataroot":
                "path_dir_data"}
        """
        self.data_list_file = data_src_cfg