Skip to content

cosmotech.coal.cosmotech_api.parameters

parameters

Parameter handling functions.

This module provides functions for handling parameters in solution templates.

write_parameters(parameter_folder, parameters, write_csv, write_json)

Write parameters to CSV and/or JSON files.

Args: parameter_folder: The folder to write the parameters to parameters: The parameters to write write_csv: Whether to write the parameters to a CSV file write_json: Whether to write the parameters to a JSON file

Source code in cosmotech/coal/cosmotech_api/parameters.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def write_parameters(
    parameter_folder: str, parameters: List[Dict[str, Any]], write_csv: bool, write_json: bool
) -> None:
    """
    Write parameters to CSV and/or JSON files.

    Args:
        parameter_folder: The folder to write the parameters to
        parameters: The parameters to write
        write_csv: Whether to write the parameters to a CSV file
        write_json: Whether to write the parameters to a JSON file
    """
    if write_csv:
        tmp_parameter_file = os.path.join(parameter_folder, "parameters.csv")
        LOGGER.info(T("coal.cosmotech_api.runner.generating_file").format(file=tmp_parameter_file))
        with open(tmp_parameter_file, "w") as _file:
            _w = DictWriter(_file, fieldnames=["parameterId", "value", "varType", "isInherited"])
            _w.writeheader()
            _w.writerows(parameters)

    if write_json:
        tmp_parameter_file = os.path.join(parameter_folder, "parameters.json")
        LOGGER.info(T("coal.cosmotech_api.runner.generating_file").format(file=tmp_parameter_file))
        with open(tmp_parameter_file, "w") as _file:
            json.dump(parameters, _file, indent=2)