Skip to content

Make pypsa config

Script to create a PyPSA config file based on the REMIND output/config. NB: Needs to be run before the coupled PyPSA run.

Example

!! config file name needs to match the output of the snakemake rule

snakemake config_file_name -f --cores=1 # makes config_file_name snakemake --configfile=config_file_name # the run

get_currency_conversion(template_cfg)

Get the currency conversion factor from the template config.

Parameters:

Name Type Description Default
template_cfg dict

The template configuration dictionary.

required

Returns:

Name Type Description
float float

The currency conversion factor.

Source code in workflow/scripts/remind_coupling/make_pypsa_config.py
def get_currency_conversion(template_cfg: dict) -> float:
    """Get the currency conversion factor from the template config.

    Args:
        template_cfg (dict): The template configuration dictionary.

    Returns:
        float: The currency conversion factor.
    """
    # ugly stuff
    etl_cfg = template_cfg["remind_etl"]["etl_steps"]
    techec_cfg = [step for step in etl_cfg if step["name"] == "technoeconomic_data"][0]
    return techec_cfg["kwargs"]["currency_conversion"]

read_remind_em_prices(remind_outp_dir, region)

Read relevant REMIND data from the output directory.

Parameters:

Name Type Description Default
remind_outp_dir PathLike

Path to the REMIND output directory.

required
region str

Remind region to filter the data by.

required

Returns:

Name Type Description
dict dict

Dictionary containing REMIND data.

Source code in workflow/scripts/remind_coupling/make_pypsa_config.py
def read_remind_em_prices(remind_outp_dir: os.PathLike, region: str) -> dict:
    """
    Read relevant REMIND data from the output directory.

    Args:
        remind_outp_dir (os.PathLike): Path to the REMIND output directory.
        region (str): Remind region to filter the data by.

    Returns:
        dict: Dictionary containing REMIND data.
    """

    co2_p = (
        (
            coupl_utils.read_remind_csv(os.path.join(remind_outp_dir, "pm_taxCO2eq.csv"))
            .query("region == @region")
            .drop(columns=["region"])
            .set_index("year")
        )
        * 1000
        / MW_CO2
        * MW_C
    )  # gC to ton CO2

    # get remind version
    with open(os.path.join(remind_outp_dir, "c_model_version.csv")) as f:
        remind_v = f.read().split("\n")[1].replace(",", "").replace(" ", "")
    # get remind run name
    with open(os.path.join(remind_outp_dir, "c_expname.csv")) as f:
        remind_exp_name = f.read().split("\n")[1].replace(",", "").replace(" ", "")

    return {"co2_prices": co2_p, "version": remind_v, "expname": remind_exp_name}