Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
khaeru opened this issue Feb 20, 2025 · 0 comments
Open

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

khaeru opened this issue Feb 20, 2025 · 0 comments
Labels
costs `.tools.costs`/cost data preparation

Comments

@khaeru
Copy link
Member

khaeru commented Feb 20, 2025

@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()
@khaeru khaeru added the costs `.tools.costs`/cost data preparation label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
costs `.tools.costs`/cost data preparation
Projects
None yet
Development

No branches or pull requests

1 participant