Exemple #1
0
def _main():
    """Main entry point.

    """
    for m, institution_id, model_id, repo in _yield_targets():
        if not os.path.exists(repo):
            logger.log_warning(
                'unmappable cmip5 institution: {}'.format(model_id))
            continue
        _write(m, institution_id, model_id, repo)
Exemple #2
0
def convert_tab_to_dict(spreadsheet_tab):
    """Return the full dictionary of inputs extracted from a machine tab."""
    all_input_cells = find_input_cells(
        spreadsheet_tab, get_ws_questions_to_input_cells_mapping())

    final_dict = {}
    for label, input_cell_or_cells in all_input_cells.items():
        if not isinstance(input_cell_or_cells, list):
            user_input = spreadsheet_tab.cell(row=input_cell_or_cells,
                                              column=INPUT_COLUMN + 1).value

            # Distinguish from Falsy values e.g. False and "None" as user input
            if user_input is None:
                # Use a placeholder/default that is unlikely to be specified
                # (not None, False, etc.) to avoid potential clash with any
                # user input, for keeping track of input cells left empty.
                final_dict[label] = EMPTY_CELL_MARKER
            else:  # else store the value, which may (rarely) be string "None"!
                # For cases where questions are populated based on institute
                # specific values (e.g. applicable models and exps questions),
                # also note these values for validation
                if label.startswith("1.8.2."):
                    name = get_top_cell_model_or_exp_name(
                        input_cell_or_cells, spreadsheet_tab)
                    final_dict[label] = {name: str(user_input)}
                else:
                    try:
                        final_dict[label] = str(user_input)
                    except:
                        # Python 2 only unicode-escape
                        logger.log_warning(
                            "WARNING: Python 2 only unicode issue with:",
                            label)
                        final_dict[label] = user_input
        elif label.startswith("1.9.2."):
            if not spreadsheet_tab.cell(row=input_cell_or_cells[0],
                                        column=INPUT_COLUMN + 1).value:
                # Institutes may, against advice, have left some
                # experiment input cells blank to indicate no applicable
                # experiments by MIP, so to cater for these cases, replace
                # empty values with 'NONE'
                final_dict[label] = "NONE"
            else:
                name = get_top_cell_model_or_exp_name(input_cell_or_cells,
                                                      spreadsheet_tab)
                final_dict[label] = {
                    name:
                    extract_inputs_at_input_cells(input_cell_or_cells,
                                                  spreadsheet_tab)
                }
        else:
            final_dict[label] = extract_inputs_at_input_cells(
                input_cell_or_cells, spreadsheet_tab)

    return final_dict
Exemple #3
0
def _write(i):
    """Writes citation JSON file for a particular institute.

    """
    try:
        spreadsheet = _get_spreadsheet(i)
    except IOError:
        msg = '{} citations spreadsheet not found'.format(i.canonical_name)
        logger.log_warning(msg)
    else:
        content = _get_content(i, spreadsheet)
        if content:
            _write_content(i, content)
Exemple #4
0
def _main(args):
    """Main entry point.

    """
    for i, s, t in vocabs.yield_topics(args.institution_id):
        try:
            wb = _get_spreadsheet(i, s, t)
        except IOError:
            warning = '{} :: {} :: {} :: spreadsheet not found'
            warning = warning.format(i.canonical_name, s.canonical_name,
                                     t.canonical_name)
            logger.log_warning(warning)
            continue

        # Set JSON content.
        content = _get_content(i, s, t, wb)

        # Write JSON file.
        io_mgr.write_model_topic_json(i, s, t, content)
Exemple #5
0
def _main(args):
    """Main entry point.

    """
    # Write a CIM file per CMIP6 institute | source combination.
    institutes = vocabs.get_institutes(args.institution_id)
    for i in institutes:
        # Escape if settings file not found.
        try:
            all_settings = io_mgr.load_model_settings(
                i, _MODEL_PUBLICATION_FNAME)
        except IOError:
            warning = '{} model_publications.json not found'
            warning = warning.format(i.canonical_name)
            logger.log_warning(warning)
            continue

        for s in vocabs.get_institute_sources(i):
            # Escape if source settings undeclared.
            try:
                settings = all_settings[s.canonical_name]
            except KeyError:
                warning = '{} :: {} publication settings not found'
                warning = warning.format(i.canonical_name, s.canonical_name)
                logger.log_warning(warning)
                continue

            # Escape if no settings are switched 'on'.
            settings = {
                k: v
                for (k, v) in settings.items()
                if settings[k]['publish'] == 'on'
            }
            if not settings:
                continue

            # Generate content.
            content = _get_content(i, s, settings)
            if content is None:
                warning = '{} :: {} CIM file not found'
                warning = warning.format(i.canonical_name, s.canonical_name)
                logger.log_warning(warning)
                continue

            # Write CIM file to fs.
            io_mgr.write_model_cim(i, s, content)
Exemple #6
0
                        for offset in offsets
                    ]

                    break

                # Otherwise it is a simple offset, apply it:
                input_box_row = row[INPUT_COLUMN].row + offset
                label_to_input_cell_mapping[label] = input_box_row
                break

        # Remove inapplicable numbers for MIPs and experiments:
        if not label_to_input_cell_mapping.get(label, False):
            if label.startswith("1.9.2.") or label.startswith("1.8.2."):
                # Numbers not valid in this case, too few objects, so it
                # we can just skip these...
                logger.log_warning("Inapplicable model or MIP number skipped:",
                                   label)

    return label_to_input_cell_mapping


def extract_inputs_at_input_cells(input_cells, spreadsheet_tab):
    """Extract and return as a list values at the given input cells."""
    values = []
    if not isinstance(input_cells, list):
        input_cells = [input_cells]
    for index, input_cell in enumerate(input_cells):
        user_input = spreadsheet_tab.cell(row=input_cell,
                                          column=INPUT_COLUMN + 1).value

        # Distinguish from Falsy values e.g. False and 0 as user input
        if user_input is None: