예제 #1
0
def construct_args_burdenator_cleanup(parser, cli_args=None):
    """Creates arguments from parser for rearranging the draw files at the end
    of the burdenator run"""
    if cli_args is None:
        cli_args = sys.argv[1:]
    args = parser.parse_args(cli_args)
    args.tool_name = 'burdenator'
    args.gbd_round, args.gbd_round_id = ac.populate_gbd_round_args(
        args.gbd_round, args.gbd_round_id)

    # Create log directory
    top_out_dir = args.out_dir
    args.cache_dir = '{}/cache'.format(args.out_dir)
    args.log_dir = os.path.join(top_out_dir, 'log_cleanup', str(args.year_id),
                                str(args.measure_id))

    log_filename = "{}_{}_{}.log".format(args.measure_id, args.location_id,
                                         args.year_id)

    makedirs_safely(args.log_dir)

    log_level = logging.DEBUG if args.verbose else logging.INFO
    args.logger = create_logger_in_memory("dalynator", log_level,
                                          args.log_dir + "/" + log_filename)

    # Get cod/epi env directories
    if args.cod_version is None:
        args.cod_version = ac.best_version('cod', args.gbd_round_id)
    if args.epi_version is None:
        args.epi_version = ac.best_version('como', args.gbd_round_id)
    args.cod_dir = (args.input_data_root + "/codcorrect/" +
                    str(args.cod_version) + "/draws")
    args.epi_dir = get_como_folder_structure(
        os.path.join(args.input_data_root, 'como', str(args.epi_version)))
    return args
예제 #2
0
def get_args_pct_change(parser, cli_args=None):
    """Creates arguments from parser for pct change calculation"""
    if cli_args is None:
        cli_args = sys.argv[1:]
    args = parser.parse_args(cli_args)
    args.gbd_round, args.gbd_round_id = ac.populate_gbd_round_args(
        args.gbd_round, args.gbd_round_id)

    args.log_dir = os.path.join(args.out_dir, 'log_pct_change',
                                str(args.location_id))
    makedirs_safely(args.log_dir)
    logfn = "FILEPATH".format(args.start_year, args.end_year)
    log_level = logging.DEBUG if args.verbose else logging.INFO
    args.logger = create_logger_in_memory("dalynator", log_level,
                                          "FILEPATH".format(args.log_dir, logfn),
                                          ['aggregator.aggregators', 'jobmon'])
    # Get cod/epi env directories
    if args.codcorrect_version == 'best':
        args.codcorrect_version = ac.best_version(
            'codcorrect', args.gbd_round_id, args.decomp_step)
    if args.fauxcorrect_version == 'best':
        args.fauxcorrect_version = ac.best_version(
            'fauxcorrect', args.gbd_round_id, args.decomp_step)
    if args.epi_version is None:
        args.epi_version = ac.best_version('como', args.gbd_round_id,
                                           args.decomp_step)
    args.epi_dir = get_como_folder_structure(os.path.join(
        args.input_data_root, 'como', str(args.epi_version)))
    cod_object = to.cod_or_faux_correct(
        args.input_data_root,
        codcorrect_version=args.codcorrect_version,
        fauxcorrect_version=args.fauxcorrect_version)
    args.cod_dir = cod_object.abs_path_to_draws
    args.cod_pattern = cod_object.file_pattern
    return args
예제 #3
0
def get_args_burdenator_loc_agg(parser, cli_args=None):
    """Creates arguments from parser for burdenator location aggregation"""
    if cli_args is None:
        cli_args = sys.argv[1:]
    args = parser.parse_args(cli_args)
    args.gbd_round, args.gbd_round_id = ac.populate_gbd_round_args(
        args.gbd_round, args.gbd_round_id)

    # Create log directory
    top_out_dir = args.data_root
    args.cache_dir = 'FILEPATH'.format(args.data_root)
    args.log_dir = os.path.join(top_out_dir, 'log_loc_agg',
                                str(args.year_id), str(args.measure_id))

    log_filename = "FILEPATH".format(
        args.measure_id, args.rei_id, args.year_id, args.sex_id)

    makedirs_safely(args.log_dir)

    log_level = logging.DEBUG if args.verbose else logging.INFO
    args.logger = create_logger_in_memory(
        "dalynator", log_level, args.log_dir + "/" + log_filename,
        ['aggregator.aggregators', 'jobmon'])

    return args
예제 #4
0
def get_args_and_create_dirs(parser, cli_args=None):
    """Parses the command line using the parser and creates output directory
    and logger. Called by run_pipeline_*. Not used by run_all."""

    if cli_args is None:
        cli_args = sys.argv[1:]
    args = parser.parse_args(cli_args)

    # resolve defaults for cod and epi versions
    args.gbd_round, args.gbd_round_id = ac.populate_gbd_round_args(
        args.gbd_round, args.gbd_round_id)
    if args.cod_version is None:
        args.cod_version = ac.best_version('cod', args.gbd_round_id)
    if args.epi_version is None:
        args.epi_version = ac.best_version('como', args.gbd_round_id)

    # Store all years for each location in one directory
    top_out_dir = args.out_dir
    args.cache_dir = '{}/cache'.format(args.out_dir)
    args.log_dir = os.path.join(top_out_dir, 'log', str(args.location_id))
    args.out_dir = os.path.join(top_out_dir, 'draws', str(args.location_id))

    makedirs_safely(args.out_dir)
    makedirs_safely(args.log_dir)

    log_level = logging.DEBUG if args.verbose else logging.INFO
    args.logger = create_logger_in_memory(
        "dalynator", log_level, args.log_dir +
        "/daly_{}_{}.log".format(args.location_id, args.year_id))

    args.cod_dir = "{}/codcorrect/{}/draws/".format(args.input_data_root,
                                                    args.cod_version)
    if hasattr(args, 'daly_version'):
        args.daly_dir = "{}/dalynator/{}/draws/".format(
            args.input_data_root, args.daly_version)
    else:
        args.daly_dir = None
    args.epi_dir = get_como_folder_structure(
        os.path.join(args.input_data_root, 'como', str(args.epi_version)))

    if hasattr(args, 'paf_version'):
        args.paf_dir = "{}/pafs/{}".format(args.input_data_root,
                                           args.paf_version)
    else:
        args.paf_dir = None

    return args
예제 #5
0
def get_args_pct_change(parser, cli_args=None):
    """Creates arguments from parser for pct change calculation"""
    if cli_args is None:
        cli_args = sys.argv[1:]
    args = parser.parse_args(cli_args)
    args.gbd_round, args.gbd_round_id = ac.populate_gbd_round_args(
        args.gbd_round, args.gbd_round_id)

    args.log_dir = os.path.join(args.out_dir, 'log_pct_change',
                                str(args.location_id))
    makedirs_safely(args.log_dir)
    logfn = "pc_{}_{}.log".format(args.start_year, args.end_year)
    log_level = logging.DEBUG if args.verbose else logging.INFO
    args.logger = create_logger_in_memory("dalynator", log_level,
                                          "{}/{}".format(args.log_dir, logfn))

    return args
예제 #6
0
def construct_args_burdenator_cleanup(parser, cli_args=None):
    """Creates arguments from parser for rearranging the draw files at the end
    of the burdenator run"""
    if cli_args is None:
        cli_args = sys.argv[1:]
    args = parser.parse_args(cli_args)
    args.tool_name = 'burdenator'
    args.gbd_round, args.gbd_round_id = ac.populate_gbd_round_args(
        args.gbd_round, args.gbd_round_id)

    # Create log directory
    top_out_dir = args.out_dir
    args.cache_dir = 'FILEPATH'.format(args.out_dir)
    args.log_dir = os.path.join(top_out_dir, 'log_cleanup',
                                str(args.year_id), str(args.measure_id))

    log_filename = "FILEPATH".format(
        args.measure_id, args.location_id, args.year_id)

    makedirs_safely(args.log_dir)

    log_level = logging.DEBUG if args.verbose else logging.INFO
    args.logger = create_logger_in_memory(
        "dalynator", log_level, args.log_dir + "/" + log_filename,
        ['aggregator.aggregators', 'jobmon'])

    # Get cod/epi env directories
    if args.codcorrect_version == 'best':
        args.codcorrect_version = ac.best_version(
            'codcorrect', args.gbd_round_id, args.decomp_step)
    if args.fauxcorrect_version == 'best':
        args.fauxcorrect_version = ac.best_version(
            'fauxcorrect', args.gbd_round_id, args.decomp_step)
    if args.epi_version is None:
        args.epi_version = ac.best_version('como', args.gbd_round_id,
                                           args.decomp_step)
    args.epi_dir = get_como_folder_structure(os.path.join(
        args.input_data_root, 'como', str(args.epi_version)))
    cod_object = to.cod_or_faux_correct(
        args.input_data_root,
        codcorrect_version=args.codcorrect_version,
        fauxcorrect_version=args.fauxcorrect_version)
    args.cod_dir = cod_object.abs_path_to_draws
    args.cod_pattern = cod_object.file_pattern
    return args
예제 #7
0
    def parse(self, tool_name="dalynator", cli_args=None):
        """
        Perform ALL argument parsing - argparse parsing, setting of defaults,
        checking of argument consistency. NO side effects in the file system.

        Args:
            tool_name: 'dalynator' or 'burdenator'
            cli_args: None or a list of strings. If None then read use sys.argv
        """
        self._construct_base_parser(tool_name)
        args = self.parser.parse_known_args(cli_args)
        if args[0].resume:
            print("Nator run in resume mode. Reading args from file")
            args = self.load_args_from_file(args, tool_name)
            args = self.set_phase_defaults(args)
            return args
        self._add_non_resume_args_to_parser()
        args = self.parser.parse_args(cli_args)
        args = self.set_phase_defaults(args)
        args.tool_name = tool_name

        args.gbd_round, args.gbd_round_id = ac.populate_gbd_round_args(
            args.gbd_round, args.gbd_round_id)

        if args.cod_version is None:
            args.cod_version = ac.best_version('cod', args.gbd_round_id)
        if args.epi_version is None:
            args.epi_version = ac.best_version('como', args.gbd_round_id)

        args.location_set_version_id = ac.location_set_to_location_set_version(
            args.location_set_id, args.location_set_version_id, args.gbd_round)
        args.sge_project = ac.create_sge_project(args.sge_project,
                                                 args.tool_name)
        year_n_draws_map = ac.construct_year_n_draws_map(
            args.year_ids_1, args.n_draws_1, args.year_ids_2, args.n_draws_2)
        ac.validate_multi_mode_years(year_n_draws_map, args.year_ids_1,
                                     args.n_draws_1, args.year_ids_2,
                                     args.n_draws_2, args.start_year_ids,
                                     args.end_year_ids)

        args.out_dir, args.log_dir, args.cache_dir = (
            self._construct_extra_paths(args.out_dir_without_version,
                                        args.log_dir, args.tool_name,
                                        args.version))
        return args