Skip to content

Update costs for pre-y₀ vintages in periods y₀ and later #298

Open
@khaeru

Description

@khaeru

@OFR-IIASA noted today in Slack that:

For historic vintages the the costs are not updated for the activity years in the model horizon.

The expectation is that the code should provide these values, by default.

He also provided this code as a work-around/starting point for a PR that would resolve the issue:

fix_cost = fix_cost[fix_cost["technology"].isin(model_tec_set)]

# Ensure that fix_costs are also added for activity years of vintage years
# prior to the firstmodelyear and remove any entries for activity years for
# which the technology is not active.
tmp_fc = pd.DataFrame()
remove = []
for node in fix_cost.node_loc.unique().tolist():
    for tec in fix_cost.loc[fix_cost.node_loc == node].technology.unique().tolist():
        yva_found = False
        tmp = fix_cost.loc[(fix_cost.node_loc == node) & (fix_cost.technology == tec)].copy()
        try:
            yva = scen.vintage_and_active_years([node, tec])
            yva_found = True
        except Exception:
            yva = scen.vintage_and_active_years()
        if yva_found == False or max(yva.year_vtg) < max(scen.set("year")):
            inp = scen.par("input", filters={"node_loc": node, "technology": tec})[["year_vtg", "year_act"]]
            inp = inp.loc[inp.year_act >= scen.firstmodelyear]
            out = scen.par("output", filters={"node_loc": node, "technology": tec})[["year_vtg", "year_act"]]
            out = out.loc[out.year_act >= scen.firstmodelyear]
            if not inp.empty:
                yva = yva.merge(inp, on=["year_vtg", "year_act"], how="right")
            elif not out.empty:
                yva = yva.merge(out, on=["year_vtg", "year_act"], how="right")
            else:
                yva = scen.par("relation_activity", filters={"node_loc": node, "technology": tec})[["year_rel", "year_act"]].drop_duplicates().rename(columns={"year_rel": "year_vtg"})
                if yva.empty:
                    yva = scen.par("relation_total_capacity", filters={"node_rel": node, "technology": tec})[["year_rel"]].drop_duplicates().rename(columns={"year_rel": "year_vtg"})
                    yva["year_act"] = yva["year_vtg"]
        if yva.empty:
            print(f"No data found for technology {tec} in node {node}. Continuing")
            remove.append([node, tec])
            continue
        
        tmp = tmp.merge(yva, on=["year_vtg", "year_act"], how="right").sort_values(by=["year_act", "year_vtg"]).bfill()
        tmp_fc = pd.concat([tmp_fc, tmp])

fix_cost = tmp_fc.copy()

Metadata

Metadata

Assignees

No one assigned

    Labels

    costs`.tools.costs`/cost data preparation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions