diff --git a/scripts/build_energy_totals.py b/scripts/build_energy_totals.py index f4905927..18c13666 100644 --- a/scripts/build_energy_totals.py +++ b/scripts/build_energy_totals.py @@ -587,7 +587,7 @@ def build_idees(countries: List[str]) -> pd.DataFrame: def fill_missing_years(fill_values: pd.Series) -> pd.Series: """ - Fill missing years for some countries by first using forward fill (ffill) + Fill missing years for some countries by first using forward fill (ffill) and then backward fill (bfill). Parameters @@ -599,14 +599,14 @@ def fill_missing_years(fill_values: pd.Series) -> pd.Series: Returns ------- pd.Series - A pandas Series with zero values replaced by the forward-filled and + A pandas Series with zero values replaced by the forward-filled and backward-filled values of the corresponding country. Notes ----- - - The function groups the data by the 'country' level and performs forward fill + - The function groups the data by the 'country' level and performs forward fill and backward fill to fill zero values. - - Zero values in the original Series are replaced by the ffilled and bfilled + - Zero values in the original Series are replaced by the ffilled and bfilled value of their respective country group. """ # Replace zero values with NaN for correct filling @@ -913,9 +913,9 @@ def build_district_heat_share(countries: List[str], idees: pd.DataFrame) -> pd.S """ # district heating share - district_heat = idees[["distributed heat residential", "distributed heat services"]].sum( - axis=1 - ) + district_heat = idees[ + ["distributed heat residential", "distributed heat services"] + ].sum(axis=1) total_heat = ( idees[["thermal uses residential", "thermal uses services"]] .sum(axis=1) diff --git a/scripts/build_industrial_production_per_country.py b/scripts/build_industrial_production_per_country.py index 90bf5482..9c543303 100644 --- a/scripts/build_industrial_production_per_country.py +++ b/scripts/build_industrial_production_per_country.py @@ -167,7 +167,6 @@ eb_sectors = { } - # TODO: this should go in a csv in `data` # Annual energy consumption in Switzerland by sector in 2015 (in TJ) # From: Energieverbrauch in der Industrie und im Dienstleistungssektor, Der Bundesrat @@ -201,9 +200,9 @@ def get_energy_ratio(country, eurostat_dir, jrc_dir, year): if country == "CH": e_country = e_switzerland * tj_to_ktoe else: - ct_eurostat = country.replace("GB","UK") + ct_eurostat = country.replace("GB", "UK") if ct_eurostat == "UK": - year=2019 + year = 2019 logger.info("Assume Eurostat data for GB from 2019.") # estimate physical output, energy consumption in the sector and country fn = f"{eurostat_dir}/{ct_eurostat}-Energy-balance-sheets-April-2023-edition.xlsb" @@ -302,7 +301,7 @@ def separate_basic_chemicals(demand, year): logger.info(f"Following countries have no ammonia demand: {missing.tolist()}") demand["Ammonia"] = 0.0 - + year_to_use = min(max(year, 2018), 2022) if year_to_use != year: logger.info(f"Using data from {year_to_use} for ammonia production.") diff --git a/scripts/build_industry_sector_ratios.py b/scripts/build_industry_sector_ratios.py index 0f8bec24..760dca76 100644 --- a/scripts/build_industry_sector_ratios.py +++ b/scripts/build_industry_sector_ratios.py @@ -48,10 +48,9 @@ If the `config["industry"]["ammonia"] assume here value from JRC-2015 # eff_elec = s_ued[key] / s_fec[key] - eff_elec = 11.6/26 + eff_elec = 11.6 / 26 sel = [ "Ceramics: Mixing of raw material", @@ -844,13 +845,12 @@ def nonmetalic_mineral_products(): def pulp_paper_printing(): """ Models the energy consumption for the pulp, paper, and printing sector, - assuming complete electrification of all processes. This sector does not have - any process emissions associated with it. - + assuming complete electrification of all processes. This sector does not + have any process emissions associated with it. + Returns: pd.DataFrame: A DataFrame containing the energy consumption (in MWh/t material) for the pulp, paper, and printing sector. - """ sector = "Pulp, paper and printing" @@ -892,7 +892,7 @@ def pulp_paper_printing(): df.loc["elec", sector] += s_fec[sel].sum() # Efficiency changes due to biomass - eff_bio = s_ued['Biomass and waste'] / s_fec['Biomass and waste'] + eff_bio = s_ued["Biomass and waste"] / s_fec["Biomass and waste"] df.loc["biomass", sector] += s_ued["Pulp: Pulping thermal"] / eff_bio s_out = idees["out"][8:9] @@ -947,7 +947,7 @@ def pulp_paper_printing(): assert s_ued.index[0] == "Paper: Paper machine - Steam use" # Efficiency changes due to biomass - eff_bio = s_ued['Biomass and waste'] / s_fec['Biomass and waste'] + eff_bio = s_ued["Biomass and waste"] / s_fec["Biomass and waste"] df.loc["biomass", sector] += s_ued["Paper: Paper machine - Steam use"] / eff_bio s_fec = idees["fec"][68:79] @@ -956,7 +956,7 @@ def pulp_paper_printing(): assert s_ued.index[0] == "Paper: Product finishing - Steam use" # Efficiency changes due to biomass - eff_bio = s_ued['Biomass and waste'] / s_fec['Biomass and waste'] + eff_bio = s_ued["Biomass and waste"] / s_fec["Biomass and waste"] df.loc["biomass", sector] += s_ued["Paper: Product finishing - Steam use"] / eff_bio s_out = idees["out"][9:10] @@ -1003,13 +1003,12 @@ def pulp_paper_printing(): def food_beverages_tobacco(): """ - Calculates the energy consumption for the food, beverages, and tobacco sector, - assuming complete electrification of all processes. This sector does not have - any process emissions associated with it. + Calculates the energy consumption for the food, beverages, and tobacco + sector, assuming complete electrification of all processes. This sector + does not have any process emissions associated with it. - Returns: - pd.DataFrame: A DataFrame containing the energy consumption (in MWh/t material) + pd.DataFrame: A DataFrame containing the energy consumption (in MWh/t material) for the food, beverages, and tobacco sector. """ @@ -1099,12 +1098,12 @@ def non_ferrous_metals(): s_fec = idees["fec"][14:25] s_ued = idees["ued"][14:25] - assert s_fec.index[0] == 'Alumina production: High-enthalpy heat' - assert s_ued.index[0] == 'Alumina production: High-enthalpy heat' + assert s_fec.index[0] == "Alumina production: High-enthalpy heat" + assert s_ued.index[0] == "Alumina production: High-enthalpy heat" eff_met = s_ued["Natural gas and biogas"] / s_fec["Natural gas and biogas"] df.loc["methane", sector] += ( - s_fec['Alumina production: High-enthalpy heat'] / eff_met + s_fec["Alumina production: High-enthalpy heat"] / eff_met ) # Efficiency changes due to electrification @@ -1205,7 +1204,7 @@ def non_ferrous_metals(): key = "Aluminium processing (metallurgy e.g. cast house, reheating)" df.loc["elec", sector] += s_ued[key] / eff_elec - key = 'Aluminium finishing - Electric' + key = "Aluminium finishing - Electric" eff_elec = s_ued[key] / s_fec[key] df.loc["elec", sector] += s_ued["Aluminium finishing"] / eff_elec @@ -1305,7 +1304,7 @@ def transport_equipment(): df.loc["elec", sector] += s_fec["Trans. Eq.: Product finishing"] # Steam processing is supplied with biomass - eff_biomass = s_ued['Biomass and waste'] / s_fec['Biomass and waste'] + eff_biomass = s_ued["Biomass and waste"] / s_fec["Biomass and waste"] df.loc["biomass", sector] += s_ued["Trans. Eq.: Steam processing"] / eff_biomass s_out = idees["out"][3:4] @@ -1357,7 +1356,7 @@ def machinery_equipment(): df.loc["elec", sector] += s_fec["Mach. Eq.: Product finishing"] # Steam processing is supplied with biomass - eff_biomass = s_ued['Biomass and waste'] / s_fec['Biomass and waste'] + eff_biomass = s_ued["Biomass and waste"] / s_fec["Biomass and waste"] df.loc["biomass", sector] += s_ued["Mach. Eq.: Steam processing"] / eff_biomass s_out = idees["out"][3:4] @@ -1402,7 +1401,7 @@ def textiles_and_leather(): df.loc["elec", sector] += s_fec["Textiles: Finishing Electric"] # Steam processing is supplied with biomass - eff_biomass = s_ued[15:26]['Biomass and waste'] / s_fec[15:26]['Biomass and waste'] + eff_biomass = s_ued[15:26]["Biomass and waste"] / s_fec[15:26]["Biomass and waste"] df.loc["biomass", sector] += ( s_ued["Textiles: Pretreatment with steam"] / eff_biomass ) @@ -1450,7 +1449,7 @@ def wood_and_wood_products(): df.loc["elec", sector] += s_fec["Wood: Finishing Electric"] # Steam processing is supplied with biomass - eff_biomass = s_ued[15:25]['Biomass and waste'] / s_fec[15:25]['Biomass and waste'] + eff_biomass = s_ued[15:25]["Biomass and waste"] / s_fec[15:25]["Biomass and waste"] df.loc["biomass", sector] += ( s_ued["Wood: Specific processes with steam"] / eff_biomass ) @@ -1468,7 +1467,7 @@ def wood_and_wood_products(): def other_industrial_sectors(): - + sector = "Other industrial sectors" idees = load_idees_data(sector) @@ -1510,7 +1509,7 @@ def other_industrial_sectors(): df.loc["elec", sector] += s_fec[key] # Steam processing is supplied with biomass - eff_biomass = s_ued[15:25]['Biomass and waste'] / s_fec[15:25]['Biomass and waste'] + eff_biomass = s_ued[15:25]["Biomass and waste"] / s_fec[15:25]["Biomass and waste"] df.loc["biomass", sector] += ( s_ued["Other Industrial sectors: Steam processing"] / eff_biomass ) @@ -1534,9 +1533,8 @@ if __name__ == "__main__": snakemake = mock_snakemake("build_industry_sector_ratios") set_scenario_config(snakemake) - params = snakemake.params.industry - + year = params["reference_year"] df = pd.concat( diff --git a/scripts/retrieve_ammonia_demand.py b/scripts/retrieve_ammonia_demand.py index cdfa582b..56e326bb 100644 --- a/scripts/retrieve_ammonia_demand.py +++ b/scripts/retrieve_ammonia_demand.py @@ -33,10 +33,8 @@ if __name__ == "__main__": to_fn = snakemake.output[0] - # download .zip file logger.info(f"Downloading Ammonia demand from {url}.") progress_retrieve(url, to_fn, disable=disable_progress) - logger.info(f"Ammonia demand data available in '{to_fn}'.")