예제 #1
0
    def from_files(cls, template_filepath, additional_filepaths_list, tag='__KP'):
        # Read in template
        logger.info("Reading template from file:" + template_filepath)
        content = json2dict(template_filepath)

        # Get the filename and create a TaggedTemplate
        template_filename = os.path.basename(template_filepath)

        for additional_filepath in additional_filepaths_list:
            print(additional_filepath)
            logger.info("Reading additional events from file:" + additional_filepath)
            additional_content = json2dict(additional_filepath)
            content['Events'] += additional_content['Events']

        return cls(template_filename, content, tag)
예제 #2
0
    def from_files(cls, config_name, campaign_name=None, **kwargs):
        """
        Build up a simulation configuration from the path to an existing
        config.json and optionally a campaign.json file on disk.

        Attributes:
            config_name (string): Path to the config file to load.
            campaign_name (string): Path to the campaign file to load.
            kwargs (dict): Additional overrides of config parameters
        """

        config = json2dict(config_name)
        campaign = json2dict(
            campaign_name) if campaign_name else empty_campaign

        return cls(config, campaign, **kwargs)
예제 #3
0
    def from_file(cls, template_filepath, tag='__KP'):
        # Read in template
        logger.info("Reading template from file:" + template_filepath)
        content = json2dict(template_filepath)

        # Get the filename and create a TaggedTemplate
        template_filename = os.path.basename(template_filepath)

        return cls(template_filename, content, tag)
예제 #4
0
def add_immune_overlays(cb, tags, directory=None, site=None):
    """
    Add an immunity overlay.

    To do so, reads the demographics files and find the corresponding immunity initialization overlay.

    :param cb: The :py:class:`DTKConfigBuilder <dtk.utils.core.DTKConfigBuilder>` holding the configuration
    :param tags: List of immunity tags that have corresponding initialization files
    :param directory: Main directory where the ..._immune_init_x_...json files are stored
    :param site: If the site is specified, the files will be expected to be found in the immune_init/site subdirectory.
    :return: Nothing
    """
    if not directory:
        directory = SetupParser().get('input_root')
    demogfiles = cb.get_param("Demographics_Filenames")

    if len(demogfiles) != 1:
        print(demogfiles)
        raise Exception(
            'add_immune_init function is expecting only a single demographics file.'
        )

    demog_filename = demogfiles[0]

    subdirs, demog_filename = os.path.split(demog_filename)
    if '2.5' not in demog_filename:
        prefix = demog_filename.split('.')[0]
    else:
        prefix = '.'.join(demog_filename.split('.')[:2])

    # e.g. DataFiles/Zambia/Sinamalima_single_node/immune_init/SinazongweConstant/..._immune_init_x_...json
    if site:
        subdirs = os.path.join(subdirs, 'immune_init', site)

    if 'demographics' not in prefix:
        raise Exception(
            'add_immune_init function expecting a base demographics layer with demographics in the name.'
        )

    for tag in tags:
        immune_init_name = prefix.replace("demographics", "immune_init_" + tag,
                                          1)
        if directory:
            cb.add_demog_overlay(
                immune_init_name,
                json2dict(
                    os.path.join(directory, subdirs,
                                 '%s.json' % immune_init_name)))
        else:
            cb.append_overlay(
                os.path.join(subdirs, '%s.json' % immune_init_name))

    cb.enable("Immunity_Initialization_Distribution"
              )  # compatibility with EMOD v2.0 and earlier
    cb.set_param("Immunity_Initialization_Distribution_Type",
                 "DISTRIBUTION_COMPLEX")
예제 #5
0
    def from_file(cls, template_filepath):
        """
        Initialize a BaseTemplate from a file path.
        :param template_file: Path to the file on disk.
        """
        # Read in template
        logger.info("Reading config template from file: %s" %
                    template_filepath)
        contents = json2dict(template_filepath)

        # Get the filename and create a ConfigTemplate
        template_filename = os.path.basename(template_filepath)

        return cls(template_filename, contents)