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

Improve build_base_energy_totals.py #358

Open
hazemakhalek opened this issue Jul 18, 2024 · 0 comments
Open

Improve build_base_energy_totals.py #358

hazemakhalek opened this issue Jul 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@hazemakhalek
Copy link
Collaborator

hazemakhalek commented Jul 18, 2024

Refactoring and code optimization is needed in the script

Building on the reviews of PR #317, the following enhancements can be introduced to the script

The two sections can be made more efficient using a simple loop, or similar ideas.

if df_sector.empty:
if sector == "consumption by households":
energy_totals_base.at[country, "electricity residential"] = np.NaN
energy_totals_base.at[country, "residential oil"] = np.NaN
energy_totals_base.at[country, "residential biomass"] = np.NaN
energy_totals_base.at[country, "residential gas"] = np.NaN
energy_totals_base.at[country, "total residential space"] = np.NaN
energy_totals_base.at[country, "total residential water"] = np.NaN
elif sector == "services":
energy_totals_base.at[country, "services electricity"] = np.NaN
energy_totals_base.at[country, "services oil"] = np.NaN
energy_totals_base.at[country, "services biomass"] = np.NaN
energy_totals_base.at[country, "services gas"] = np.NaN
energy_totals_base.at[country, "total services space"] = np.NaN
energy_totals_base.at[country, "total services water"] = np.NaN

energy_totals_base.at[country, "road biomass"] = round(
df_sector[
df_sector.Commodity.isin(biomass_fuels)
].Quantity_TWh.sum(),
4,
)
energy_totals_base.at[country, "road oil"] = round(
df_sector[df_sector.Commodity.isin(oil_fuels)].Quantity_TWh.sum(), 4
)
elif sector == "agriculture":
energy_totals_base.at[country, "agriculture electricity"] = round(
df_sector[
(df_sector.Commodity == "Electricity")
].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 coal"] = round(
df_sector[df_sector.Commodity.isin(coal_fuels)].Quantity_TWh.sum(),
4,
)
# energy_totals_base.at[country, "electricity rail"] = round(df_house[(df_house.Commodity=="Electricity")].Quantity_TWh.sum(), 4)

Please give a clear and concise description and provide context why the feature would be useful.
Also, we'd appreciate any implementation ideas and references you already have.

@hazemakhalek hazemakhalek added the enhancement New feature or request label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant