Exemple #1
0
def write_model_cim(i, s, content):
    """Writes a model topic JSON file to file system.

    """
    fpath = get_model_cim(i, s)
    logger.log('writing --> {}'.format(fpath.split('/')[-1]), app='SH')
    with open(fpath, 'w') as fstream:
        fstream.write(content)
Exemple #2
0
def write_model_cim(i, d, s, obj):
    """Writes a model topic JSON file to file system.

    """
    fpath = get_model_cim(i, d, s)
    logger.log('writing --> {}'.format(fpath), app='SH')
    with open(fpath, 'w') as fstream:
        fstream.write(obj)
Exemple #3
0
def _main(args):
    """Main entry point.

    """
    errs = []
    for i in vocabs.get_institutes(args.institution_id):
        for verifier in _VERIFIERS:
            verifier(i, errs)

    for err in errs:
        logger.log(err)
Exemple #4
0
def _main(args):
    """Main entry point.

    """
    for i in vocabs.get_institutes(args.institution_id):
        for m in vocabs.get_models_by_institution(i):
            for t in vocabs.get_topics():
                for d in vocabs.get_domains():
                    xl = Spreadsheet(i, m, t, d)
                    logger.log("generating --> {}".format(xl.fpath), app="SH")
                    xl.write()
Exemple #5
0
def _main(args):
    """Main entry point.

    """
    for i in vocabs.get_institutes(args.institution_id):
        logger.log("verifying {}:".format(i.raw_name))
        errs = []
        for verifier in _VERIFIERS:
            verifier(i, errs)
        for err in errs:
            logger.log("... {}".format(err))
        logger.log_line()
Exemple #6
0
def _main(args):
    """Main entry point.

    """
    domains = vocabs.get_domains()
    topics = vocabs.get_topics()
    for institution in vocabs.get_institutes(args.institution_id):
        for model in vocabs.get_models_by_institution(institution):
            for domain in domains:
                fpath = io_mgr.get_model_cim(institution, domain, model)
                document = _get_document(institution, domain, model, topics)
                if document is not None:
                    pyesdoc.write(document, fpath)
                    logger.log("CIM document written to -> {}".format(fpath))
Exemple #7
0
def _main(args):
    """Main entry point.

    """
    # Initialise CMIP5 to CMIP6 mappings.
    mappings.init()

    # Write a JSON file for each CMIP6 institute | CMIP5 document combination.
    for institution_id in vocabs.get_institutes():
        if not args.institution_id in ["all", institution_id.canonical_name]:
            continue
        if not cmip5_documents.init(institution_id.canonical_name):
            continue
        for output in _yield_outputs(institution_id):
            output.save()
            logger.log('... {};'.format(output.fpath))
Exemple #8
0
def _main(args):
    """Main entry point.

    """
    # Defensive programming.
    if not os.path.exists(args.xls_template):
        raise ValueError("XLS template file does not exist")

    # Take generic template ready to process with institute-specific info.
    template_name = args.xls_template

    # Write out a customised template file for every institute.
    for institution in vocabs.get_institutes(args.institution_id):
        # !!! Must define this on each iteration instead of outside the 'for'
        # loop else iterations will include previous changes. !!!
        generic_template = load_workbook(filename=template_name)

        # Styles needed for clear, coordinated formatting of processed cells.
        generic_template.add_named_style(QUESTION_HEADER_STYLE)
        generic_template.add_named_style(QUESTION_INPUT_BOX_STYLE)
        
        # Customise the template appropriately to the given institute:
        #     1. Set the institute name
        set_institute_name_in_xls(institution, generic_template)

        #     2. Set the applicable CMIP6 models for this institute
        end_cell = set_applicable_models_in_xls(institution, generic_template)

        #     3. Set the applicable CMIP6 experiments for this institute
        tab_end_cell = set_applicable_experiments_in_xls(
            institution, generic_template, end_cell)

        # Add a note that the tab is done, with a reminder, for clarity.
        set_end_of_sheet_note(generic_template["Machine 1"], tab_end_cell + 2)

        # Close template and write the customised template to a new XLS file.
        generic_template.close()
        final_spreadsheet_name = "{}_{}_machines.xlsx".format(
            constants.CMIP6_MIP_ERA, institution.canonical_name)
        generic_template.save(final_spreadsheet_name)

        # Place the template into the appropriate directory.
        # Write one file per institute.
        dest = io_mgr.get_machines_spreadsheet(institution)
        logger.log("moving xls file for {}".format(institution.raw_name))
        print(final_spreadsheet_name, dest)
        shutil.copy(final_spreadsheet_name, dest)
Exemple #9
0
def init(ctx):
    """Write topic workbook.

    """
    path = os.path.join(os.getenv('CMIP6_HOME'), 'repos/institutions')
    path = os.path.join(path, ctx.institution_id)
    path = os.path.join(path, ctx.CMIP6_MIP_ERA)
    path = os.path.join(path, 'models')
    path = os.path.join(path, ctx.source_id)
    if not os.path.isdir(path):
        os.makedirs(path)
    fname = '_'.join([ctx.CMIP6_MIP_ERA, ctx.institution_id, ctx.source_id])
    fname += '_coupling.xlsx'
    path = os.path.join(path, fname)

    logger.log('generating --> {}'.format(fname), app='SH')
    ctx.wb = xlsxwriter.Workbook(path)
Exemple #10
0
def _main(args):
    """Main entry point.

    """
    # Defensive programming.
    if not os.path.exists(args.xls_template):
        raise ValueError("XLS template file does not exist")

    # Take generic template ready to process with institute-specific info.
    template_name = args.xls_template

    # Write out a customised template file for every institute
    for institution in vocabs.get_institutes(args.institution_id):
        institute_inputs_map = get_all_qs_to_inputs_mapping_for_institute(
            institution)
        for machine, machine_json_map in institute_inputs_map.items():
            all_models_run_on_machine = get_applicable_models(machine_json_map)
            appl_exps = formatted_applicable_experiments(machine_json_map)

            for model in all_models_run_on_machine:
                # Open the template and customise it to the specific loop vars
                generic_template = load_workbook(filename=template_name)
                customise_performance_template(
                    generic_template, institution, machine, model, appl_exps)

                # Close template and save customised XLS to a new XLS file
                generic_template.close()
                final_spreadsheet_name = (
                    "{}_performance_of_{}_on_{}_{}.xlsx".format(
                        constants.CMIP6_MIP_ERA, model,
                        institution.canonical_name, machine
                    )
                )
                generic_template.save(final_spreadsheet_name)

                # Place the file into the appropriate directory, ultimately
                # writing one file per machine and applicable model combination
                dest = io_mgr.get_performance_spreadsheet(
                    institution, machine, model)
                logger.log(
                    "moving xls file for {}".format(institution.raw_name))
                shutil.copy(final_spreadsheet_name, dest)
Exemple #11
0
def _main():
    """Main entry point.

    """
    for i in vocabs.get_institutes():
        logger.log(i.canonical_name)