Skip to content

Commit

Permalink
Merge branch '263-round-error-in-build_base_energy_total' of https://…
Browse files Browse the repository at this point in the history
…github.com/pypsa-meets-earth/pypsa-earth-sec into 263-round-error-in-build_base_energy_total
  • Loading branch information
doneachh committed Jan 22, 2024
2 parents 7ad5824 + 448a98e commit ac08b6e
Showing 1 changed file with 66 additions and 81 deletions.
147 changes: 66 additions & 81 deletions scripts/build_base_energy_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,149 +70,134 @@ def calc_sector(sector):
sectors_dfs[sector] = df_sector.copy()

if sector == "consumption by households":
energy_totals_base.at[country, "electricity residential"] = (
round(
energy_totals_base.at[country, "electricity residential"] = round(
df_sector[
(df_sector.Commodity == "Electricity")
| df_sector.Commodity.isin(other_fuels)
]
.Quantity_TWh.sum(), 4)
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "residential oil"] = (
round(
df_sector[df_sector.Commodity.isin(oil_fuels)]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "residential oil"] = round(
df_sector[df_sector.Commodity.isin(oil_fuels)].Quantity_TWh.sum(), 4
)
energy_totals_base.at[country, "residential biomass"] = (
round(
df_sector[df_sector.Commodity.isin(biomass_fuels)]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "residential biomass"] = round(
df_sector[
df_sector.Commodity.isin(biomass_fuels)
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "residential gas"] = (
round(
df_sector[df_sector.Commodity.isin(gas_fuels)]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "residential gas"] = round(
df_sector[df_sector.Commodity.isin(gas_fuels)].Quantity_TWh.sum(), 4
)
energy_totals_base.at[country, "total residential space"] = (
round(
df_sector[df_sector.Commodity.isin(heat)]
.Quantity_TWh.sum(), 4)
df_sector[df_sector.Commodity.isin(heat)].Quantity_TWh.sum(), 4
)
* snakemake.config["sector"]["space_heat_share"]
)
energy_totals_base.at[country, "total residential water"] = round(df_sector[
df_sector.Commodity.isin(heat)
].Quantity_TWh.sum(), 4) * (
1 - snakemake.config["sector"]["space_heat_share"]
)
energy_totals_base.at[country, "total residential water"] = round(
df_sector[df_sector.Commodity.isin(heat)].Quantity_TWh.sum(), 4
) * (1 - snakemake.config["sector"]["space_heat_share"])

elif sector == "services":
energy_totals_base.at[country, "services electricity"] = (
round(
energy_totals_base.at[country, "services electricity"] = round(
df_sector[
(df_sector.Commodity == "Electricity")
| df_sector.Commodity.isin(other_fuels)
]
.Quantity_TWh.sum(), 4)
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "services oil"] = (
round(
df_sector[df_sector.Commodity.isin(oil_fuels)]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "services oil"] = round(
df_sector[df_sector.Commodity.isin(oil_fuels)].Quantity_TWh.sum(), 4
)
energy_totals_base.at[country, "services biomass"] = (
round(
df_sector[df_sector.Commodity.isin(biomass_fuels)]
.Quantity_TWh.sum(), 4)
)
energy_totals_base.at[country, "services gas"] = (
round(
df_sector[df_sector.Commodity.isin(gas_fuels)]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "services gas"] = round(
df_sector[df_sector.Commodity.isin(gas_fuels)].Quantity_TWh.sum(), 4
)
energy_totals_base.at[country, "total services space"] = (
round(
df_sector[df_sector.Commodity.isin(heat)]
.Quantity_TWh.sum(), 4)
df_sector[df_sector.Commodity.isin(heat)].Quantity_TWh.sum(), 4
)
* snakemake.config["sector"]["space_heat_share"]
)
energy_totals_base.at[country, "total services water"] = round(df_sector[
df_sector.Commodity.isin(heat)
].Quantity_TWh.sum(), 4) * (
1 - snakemake.config["sector"]["space_heat_share"]
)
energy_totals_base.at[country, "total services water"] = round(
df_sector[df_sector.Commodity.isin(heat)].Quantity_TWh.sum(), 4
) * (1 - snakemake.config["sector"]["space_heat_share"])

elif sector == "road":
energy_totals_base.at[
country, "total road"
] = round(df_sector.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "total road"] = round(
df_sector.Quantity_TWh.sum(), 4
)

elif sector == "agriculture":
energy_totals_base.at[country, "agriculture electricity"] = (
round(
energy_totals_base.at[country, "agriculture electricity"] = round(
df_sector[
(df_sector.Commodity == "Electricity")
| df_sector.Commodity.isin(other_fuels)
]
.Quantity_TWh.sum(), 4)
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "agriculture oil"] = (
round(
df_sector[df_sector.Commodity.isin(oil_fuels)]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "agriculture oil"] = round(
df_sector[df_sector.Commodity.isin(oil_fuels)].Quantity_TWh.sum(), 4
)
energy_totals_base.at[country, "agriculture biomass"] = (
round(
df_sector[df_sector.Commodity.isin(biomass_fuels)]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "agriculture biomass"] = round(
df_sector[
df_sector.Commodity.isin(biomass_fuels)
].Quantity_TWh.sum(),
4,
)
# energy_totals_base.at[country, "electricity rail"] = round(df_house[(df_house.Commodity=="Electricity")].Quantity_TWh.sum(), 4)

elif sector == "rail":
energy_totals_base.at[country, "total rail"] = (
round(
energy_totals_base.at[country, "total rail"] = round(
df_sector[
(df_sector.Commodity == "Gas Oil/ Diesel Oil")
| (df_sector.Commodity == "Biodiesel")
| (df_sector.Commodity == "Electricity")
]
.Quantity_TWh.sum(), 4)
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "electricity rail"] = (
round(
df_sector[(df_sector.Commodity == "Electricity")]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[country, "electricity rail"] = round(
df_sector[
(df_sector.Commodity == "Electricity")
].Quantity_TWh.sum(),
4,
)

elif sector == "aviation":
energy_totals_base.at[country, "total international aviation"] = (
round(
energy_totals_base.at[country, "total international aviation"] = round(
df_sector[
(df_sector.Commodity == "Kerosene-type Jet Fuel")
& (df_sector.Transaction == "International aviation bunkers")
]
.Quantity_TWh.sum(), 4)
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "total domestic aviation"] = (
round(
energy_totals_base.at[country, "total domestic aviation"] = round(
df_sector[
(df_sector.Commodity == "Kerosene-type Jet Fuel")
& (df_sector.Transaction == "Consumption by domestic aviation")
]
.Quantity_TWh.sum(), 4)
].Quantity_TWh.sum(),
4,
)

elif sector == "navigation":
energy_totals_base.at[country, "total international navigation"] = (
round(
df_sector[df_sector.Transaction == "International marine bunkers"]
.Quantity_TWh.sum(), 4)
energy_totals_base.at[
country, "total international navigation"
] = round(
df_sector[
df_sector.Transaction == "International marine bunkers"
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "total domestic navigation"] = (
round(
energy_totals_base.at[country, "total domestic navigation"] = round(
df_sector[
df_sector.Transaction == "Consumption by domestic navigation"
]
.Quantity_TWh.sum(), 4)
].Quantity_TWh.sum(),
4,
)

else:
Expand Down

0 comments on commit ac08b6e

Please sign in to comment.