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

Wrong calculation of country-specific system costs #31

Open
cpschau opened this issue Jan 13, 2025 · 1 comment
Open

Wrong calculation of country-specific system costs #31

cpschau opened this issue Jan 13, 2025 · 1 comment

Comments

@cpschau
Copy link
Contributor

cpschau commented Jan 13, 2025

With the current implementation of pypsa.Network.statistics the country-specific system costs cannot be retrieved as they currently are in the function get_economy. Links, that do not have a country assigned are not included in the calculation using the grouper get_country_and_carrier. Instead the grouper get_bus_and_carrier could be used, as it allows to filter for components of a specific country using the bus id. However, the CAPEX of transnational interconnector components such as AC lines, DC links or pipelines, would still have to be adjusted, as the costs should not be exclusively attributed to one country.

grouper = g.get_country_and_carrier

@cpschau
Copy link
Contributor Author

cpschau commented Jan 13, 2025

One possible solution could look like this assuming an equal distribution of costs between the two countries that are connected by an interconnector component:

def get_component_mask(lines_or_links, country, countries):
    return ((lines_or_links.bus0.str.contains(country) & lines_or_links.bus1.str.contains("|".join(countries))) | (lines_or_links.bus0.str.contains("|".join(countries)) & lines_or_links.bus0.str.contains(country)))

def calc_ic_capex(n, country):
    countries = n.buses.country.unique()

    countries = countries[(countries != '')&(countries != country)] 
    ic_links_mask = get_component_mask(n.links, country, countries)
    ic_links = n.links.loc[ic_links_mask]

    ic_lines_mask = get_component_mask(n.lines, country, countries)
    ic_lines = n.lines.loc[ic_lines_mask]

    capex_ic_links = ic_links.p_nom_opt.mul(ic_links.capital_cost).sum()
    capex_ic_lines = ic_lines.s_nom_opt.mul(ic_lines.capital_cost).sum()
    
    return capex_ic_lines + capex_ic_links

def calc_system_costs_country(n, country):
    s = n.statistics(groupby=n.statistics.groupers.get_bus_and_carrier)
    s_country = s.filter(regex=country, axis=0)
    system_costs_country = s_country[["Capital Expenditure", "Operational Expenditure"]].sum().sum()
    ic_costs = calc_ic_capex(n, country)
    return system_costs_country + 0.5 * ic_costs

calc_system_costs_country(n, "DE")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant