From f734975310ca7228137f6a16a90016a26031354c Mon Sep 17 00:00:00 2001 From: Ivan Ruiz Manuel <72193617+irm-codebase@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:00:56 +0200 Subject: [PATCH] PR fixes: better naming, better rules, more assert checks --- CHANGELOG.md | 2 +- modules/industry/config.yaml | 20 ++-- modules/industry/industry.smk | 84 ++++++++--------- modules/industry/schema.yaml | 40 ++++---- .../industry/scripts/generic_processing.py | 92 +++++++++---------- modules/industry/scripts/steel_processing.py | 83 ++++++++--------- modules/industry/scripts/utils/filling.py | 7 +- .../scripts/utils/jrc_idees_parser.py | 22 +++-- 8 files changed, 172 insertions(+), 178 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3031f51..48e37fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added (models) -* **ADD** industry module and steel industry energy demand processing. NOT CONNECTED TO THE MAIN WORKFLOW. Industry sectors pending: chemical. (Fixes #308, #309, #310, #347, #345 and #346) +* **ADD** Industry module: iron and steel, "default" combined categories. NOT CONNECTED TO THE MAIN WORKFLOW. (Fixes #308, #309, #310, #347, #345 and #346) * **ADD** Spatial resolution that aligns with the regions defined by the [e-Highway 2050 project](https://cordis.europa.eu/project/id/308908/reporting) (`ehighways`) (#370). diff --git a/modules/industry/config.yaml b/modules/industry/config.yaml index ef0a263b..d641648d 100644 --- a/modules/industry/config.yaml +++ b/modules/industry/config.yaml @@ -1,18 +1,18 @@ industry: - inputs: - path-energy-balances: build/data/annual-energy-balances.csv - path-cat-names: config/energy-balances/energy-balance-category-names.csv - path-carrier-names: config/energy-balances/energy-balance-carrier-names.csv - path-jrc-industry-energy: build/data/jrc-idees/industry/processed-energy.nc - path-jrc-industry-production: build/data/jrc-idees/industry/processed-production.nc + input-paths: + energy-balances: build/data/annual-energy-balances.csv + cat-names: config/energy-balances/energy-balance-category-names.csv + carrier-names: config/energy-balances/energy-balance-carrier-names.csv + jrc-industry-energy: build/data/jrc-idees/industry/processed-energy.nc + jrc-industry-production: build/data/jrc-idees/industry/processed-production.nc outputs: placeholder-out1: placeholder-out2: params: - non-generic-categories: ["Iron and steel", "Chemicals Industry"] - steel-config: - recycled-steel-share: 0.5 # % of recycled scrap steel for H-DRI - generic-config: + specific-categories: ["Iron and steel", "Chemicals Industry"] + config-combined-categories: final-energy-method: "by priority" final-energy-carriers: ["Electricity", "Natural gas (incl. biogas)", "Diesel oil (incl. biofuels)"] useful-demands: ["Low enthalpy heat"] + config-iron-and-steel: + recycled-steel-share: 0.5 # % of recycled scrap steel for H-DRI diff --git a/modules/industry/industry.smk b/modules/industry/industry.smk index 9459a230..e2e8ea86 100644 --- a/modules/industry/industry.smk +++ b/modules/industry/industry.smk @@ -1,7 +1,7 @@ from snakemake.utils import validate # Paths dependent on main Snakefile -MODULE_PATH = "modules/industry" +MODULE_PATH = "modules/industry" # TODO: remove if the module becomes an imported external workflow BUILD_PATH = f"{MODULE_PATH}/build" DATA_PATH = f"{MODULE_PATH}/raw_data" @@ -9,58 +9,60 @@ DATA_PATH = f"{MODULE_PATH}/raw_data" SCRIPT_PATH = "scripts" # scripts are called relative to this file CONDA_PATH = "./env_industry.yaml" +configfile: "./config.yaml" validate(config, "./schema.yaml") # Ensure rules are defined in order. # Otherwise commands like "rules.rulename.output" won't work! -if "Iron and steel" in config["params"]["non-generic-categories"]: - rule steel_processing: - message: "Calculate energy demand for the 'Iron and steel' sector in JRC-IDEES." - conda: CONDA_PATH - params: - steel_config = config["params"]["steel-config"] - input: - path_energy_balances = config["inputs"]["path-energy-balances"], - path_cat_names = config["inputs"]["path-cat-names"], - path_carrier_names = config["inputs"]["path-carrier-names"], - path_jrc_industry_energy = config["inputs"]["path-jrc-industry-energy"], - path_jrc_industry_production = config["inputs"]["path-jrc-industry-production"], - output: - path_output = f"{BUILD_PATH}/annual_demand_steel.nc" - script: f"{SCRIPT_PATH}/steel_processing.py" +rule iron_and_steel: + message: "Calculate energy demand for the 'Iron and steel' sector in JRC-IDEES." + conda: CONDA_PATH + params: + config = config["params"]["config-iron-and-steel"] + input: + energy_balances = config["input-paths"]["energy-balances"], + cat_names = config["input-paths"]["cat-names"], + carrier_names = config["input-paths"]["carrier-names"], + jrc_industry_energy = config["input-paths"]["jrc-industry-energy"], + jrc_industry_production = config["input-paths"]["jrc-industry-production"], + output: + path_output = f"{BUILD_PATH}/annual_demand_iron_and_steel.nc" + script: f"{SCRIPT_PATH}/steel_processing.py" -if "Chemicals Industry" in config["params"]["non-generic-categories"]: - rule chemicals_processing: - message: "." - conda: CONDA_PATH - params: - input: - output: - script: f"{SCRIPT_PATH}/chemicals_processing.py" +rule chemicals_industry: + message: "." + # conda: CONDA_PATH + params: + input: + output: f"{BUILD_PATH}/annual_demand_chemicals_industry.nc" + shell: + "touch {output}" + # script: f"{SCRIPT_PATH}/annual_demand_chemicals_industry.py" -rule generic_processing: +rule combined_categories: message: "Calculate energy demand for all other industry sectors in JRC-IDEES." conda: CONDA_PATH params: - non_generic_categories = config["params"]["non-generic-categories"], - generic_config = config["params"]["generic-config"], + specific_categories = config["params"]["specific-categories"], + config = config["params"]["config-combined-categories"], input: - path_energy_balances = config["inputs"]["path-energy-balances"], - path_cat_names = config["inputs"]["path-cat-names"], - path_carrier_names = config["inputs"]["path-carrier-names"], - path_jrc_industry_energy = config["inputs"]["path-jrc-industry-energy"], - path_jrc_industry_production = config["inputs"]["path-jrc-industry-production"], - output: - path_output = f"{BUILD_PATH}/annual_demand_generic.nc" + energy_balances = config["input-paths"]["energy-balances"], + cat_names = config["input-paths"]["cat-names"], + carrier_names = config["input-paths"]["carrier-names"], + jrc_industry_energy = config["input-paths"]["jrc-industry-energy"], + jrc_industry_production = config["input-paths"]["jrc-industry-production"], + output: f"{BUILD_PATH}/annual_demand_combined_categories.nc" script: f"{SCRIPT_PATH}/generic_processing.py" -# rule combine_and_scale: -# message: "." -# conda: CONDA_PATH -# params: -# input: -# output: -# script: +SUFFIXES = [i.lower().replace(" ", "_") for i in config["params"]["specific-categories"]] +rule combine_and_scale: + message: "Identify the category scripts to run based on the configuration." + conda: CONDA_PATH + input: + expand("{path}/annual_demand_{sample}.nc", path=[BUILD_PATH], sample=SUFFIXES), + rules.combined_categories.output + # output: "{BUILD_PATH}/annual_demand_aggregated.nc" + # rule verify: # message: "." diff --git a/modules/industry/schema.yaml b/modules/industry/schema.yaml index a76e5899..57a433fd 100644 --- a/modules/industry/schema.yaml +++ b/modules/industry/schema.yaml @@ -2,31 +2,31 @@ $schema: https://json-schema.org/draft/2020-12/schema type: object additionalProperties: false properties: - inputs: + input-paths: type: object additionalProperties: false description: Inputs are paths of prerequired files. properties: - path-energy-balances: + energy-balances: type: string description: | Annual energy balance file. Columns [cat_code,carrier_code,unit,country,year,value]. - path-cat-names: + cat-names: type: string description: | Category mapping file. Columns [cat_code,top_cat,sub_cat_contribution,sub_cat_1,sub_cat_2,jrc_idees]. - path-carrier-names: + carrier-names: type: string description: | Carrier mapping file. Columns [carrier_code,carrier_name,hh_carrier_name,com_carrier_name,ind_carrier_name,oth_carrier_name]. - path-jrc-industry-energy: + jrc-industry-energy: type: string description: | JRC processed industry energy demand .nc file. - path-jrc-industry-production: + jrc-industry-production: type: string description: | JRC processed industrial production .nc file. @@ -38,24 +38,16 @@ properties: additionalProperties: false description: Parameters allow users to configure module behaviour. properties: - non-generic-categories: + specific-categories: type: array - description: "Specifies which JRC industry categories will be processed separately." + description: | + Specifies which JRC industry categories will be processed through category-specific rules. + Omitted categories will instead be processed through the "combined" category rule. uniqueItems: true items: type: string enum: ["Iron and steel", "Chemicals Industry"] - steel-config: - type: object - additionalProperties: false - description: "Parameters specific to the 'Iron and steel' industry category." - properties: - recycled-steel-share: - type: number - description: "Share of recycled metal in the H-DRI steel process." - minimum: 0 - maximum: 1 - generic-config: + config-combined-categories: type: object additionalProperties: false description: "Parameters for default/generic category processing." @@ -82,3 +74,13 @@ properties: uniqueItems: true items: type: string + config-iron-and-steel: + type: object + additionalProperties: false + description: "Parameters specific to the 'Iron and steel' industry category." + properties: + recycled-steel-share: + type: number + description: "Share of recycled metal in the H-DRI steel process." + minimum: 0 + maximum: 1 diff --git a/modules/industry/scripts/generic_processing.py b/modules/industry/scripts/generic_processing.py index df371700..20106102 100644 --- a/modules/industry/scripts/generic_processing.py +++ b/modules/industry/scripts/generic_processing.py @@ -1,5 +1,3 @@ -from typing import Optional - import pandas as pd import xarray as xr from utils import filling @@ -7,82 +5,80 @@ def get_generic_demand( - non_generic_categories: list, - generic_config: dict, - path_energy_balances: str, - path_cat_names: str, - path_carrier_names: str, - path_jrc_industry_energy: str, - path_jrc_industry_production: str, - path_output: Optional[str] = None, -) -> xr.DataArray: - """Processing of industry categories not selected for individual processing. + specific_categories: list, + config: dict, + energy_balances: str, + cat_names: str, + carrier_names: str, + jrc_industry_energy: str, + jrc_industry_production: str, + output_path: str, +): + """Processing of industry categories not selected for specific processing. Merges all energy demand into a single `generic` category using a configurable data processing pipeline. Args: - non_generic_categories (list): categories with separate processing (will be ignored). - generic_config (dict): configuration for generic category processing. - path_energy_balances (str): country energy balances (usually from eurostat). - path_cat_names (str): eurostat category mapping file. - path_carrier_names (str): eurostat carrier name mapping file. - path_jrc_industry_energy (str): jrc country-specific industrial energy demand file. - path_jrc_industry_production (str): jrc country-specific industrial production file. - path_output (str): location of steel demand output file. + specific_categories (list): categories with separate processing (will be ignored). + config (dict): configuration for generic category processing. + energy_balances (str): country energy balances (usually from eurostat). + cat_names (str): eurostat category mapping file. + carrier_names (str): eurostat carrier name mapping file. + jrc_industry_energy (str): jrc country-specific industrial energy demand file. + jrc_industry_production (str): jrc country-specific industrial production file. + output_path (str): location of steel demand output file. Returns: pd.DataFrame: dataframe with industrial demand per country. """ # Load data energy_balances_df = pd.read_csv( - path_energy_balances, index_col=[0, 1, 2, 3, 4] + energy_balances, index_col=[0, 1, 2, 3, 4] ).squeeze("columns") - cat_names_df = pd.read_csv(path_cat_names, header=0, index_col=0) - carrier_names_df = pd.read_csv(path_carrier_names, header=0, index_col=0) - jrc_energy = xr.open_dataset(path_jrc_industry_energy) - jrc_prod = xr.open_dataarray(path_jrc_industry_production) + cat_names_df = pd.read_csv(cat_names, header=0, index_col=0) + carrier_names_df = pd.read_csv(carrier_names, header=0, index_col=0) + jrc_energy = xr.open_dataset(jrc_industry_energy) + jrc_prod = xr.open_dataarray(jrc_industry_production) + jrc.check_units(jrc_energy, jrc_prod) # Remove data from all specifically processed industries - cat_names_df = cat_names_df[~cat_names_df["jrc_idees"].isin(non_generic_categories)] - jrc_energy = jrc_energy.drop_sel(cat_name=non_generic_categories) - jrc_prod = jrc_prod.drop_sel(cat_name=non_generic_categories) + cat_names_df = cat_names_df[~cat_names_df["jrc_idees"].isin(specific_categories)] + jrc_energy = jrc_energy.drop_sel(cat_name=specific_categories) + jrc_prod = jrc_prod.drop_sel(cat_name=specific_categories) # Process data: - # Extract useful dem. -> remove useful dem. from rest -> extract final dem. - selected_useful = generic_config["useful-demands"] + # Extract useful demand -> remove useful demand from rest -> extract final demand + selected_useful = config["useful-demands"] other_useful_demand = jrc.convert_subsection_demand_to_carrier( jrc_energy, selected_useful ) - final_method = generic_config["final-energy-method"] + final_method = config["final-energy-method"] jrc_energy = jrc_energy.drop_sel(subsection=selected_useful) match final_method: case "by priority": other_final_demand = transform_final_demand_by_priority( - jrc_energy, generic_config["final-energy-carriers"] + jrc_energy, config["final-energy-carriers"] ) case "keep everything": other_final_demand = jrc_energy["final"].sum(["section", "subsection"]) other_final_demand = jrc.standardize(other_final_demand, "twh") case _: raise ValueError(f"Unsupported final energy method: {final_method}.") - # Combine and fill missing countries other_demand = xr.concat( [other_useful_demand, other_final_demand], dim="carrier_name" ) + assert other_demand.sum() < jrc_energy["final"].sum(), "Potential double counting!" + other_demand = filling.fill_missing_countries_years( energy_balances_df, cat_names_df, carrier_names_df, other_demand ) - other_demand = jrc.standardize(other_demand, "twh") - - if path_output: - other_demand.to_netcdf(path_output) - - return other_demand + other_demand = jrc.standardize(other_demand, "twh", "demand") + other_demand.to_netcdf(output_path) def transform_final_demand_by_priority( @@ -110,7 +106,7 @@ def transform_final_demand_by_priority( carrier_final_dem = {} for carrier in carrier_priority: - dem_replaced = jrc.replace_final_demand_by_carrier(carrier, jrc_energy) + dem_replaced = jrc.replace_carrier_final_demand(carrier, jrc_energy) dem_replaced = dem_replaced.to_dataframe().dropna() for dem_replaced_prev in carrier_final_dem.values(): dem_replaced = dem_replaced.drop(dem_replaced_prev.index, errors="ignore") @@ -131,12 +127,12 @@ def transform_final_demand_by_priority( if __name__ == "__main__": get_generic_demand( - non_generic_categories=snakemake.params.non_generic_categories, - generic_config=snakemake.params.generic_config, - path_energy_balances=snakemake.input.path_energy_balances, - path_cat_names=snakemake.input.path_cat_names, - path_carrier_names=snakemake.input.path_carrier_names, - path_jrc_industry_energy=snakemake.input.path_jrc_industry_energy, - path_jrc_industry_production=snakemake.input.path_jrc_industry_production, - path_output=snakemake.output.path_output, + specific_categories=snakemake.params.specific_categories, + config=snakemake.params.config, + energy_balances=snakemake.input.energy_balances, + cat_names=snakemake.input.cat_names, + carrier_names=snakemake.input.carrier_names, + jrc_industry_energy=snakemake.input.jrc_industry_energy, + jrc_industry_production=snakemake.input.jrc_industry_production, + output_path=snakemake.output[0], ) diff --git a/modules/industry/scripts/steel_processing.py b/modules/industry/scripts/steel_processing.py index f39a3a70..38b8cde4 100644 --- a/modules/industry/scripts/steel_processing.py +++ b/modules/industry/scripts/steel_processing.py @@ -1,5 +1,3 @@ -from typing import Optional - import pandas as pd import xarray as xr from utils import filling @@ -18,36 +16,34 @@ def _get_h2_to_steel(recycled_steel_share: float) -> float: def get_steel_demand_df( - steel_config: dict, - path_energy_balances: str, - path_cat_names: str, - path_carrier_names: str, - path_jrc_industry_energy: str, - path_jrc_industry_production: str, - path_output: Optional[str] = None, -) -> xr.DataArray: + config: dict, + energy_balances: str, + cat_names: str, + carrier_names: str, + jrc_industry_energy: str, + jrc_industry_production: str, + output_path: str, +): """Execute the data processing pipeline for the "Iron and steel" sub-sector. Args: - steel_config (dict): steel sector configuration. - path_energy_balances (str): country energy balances (usually from eurostat). - path_cat_names (str): eurostat category mapping file. - path_carrier_names (str): eurostat carrier name mapping file. - path_jrc_industry_energy (str): jrc country-specific industrial energy demand file. - path_jrc_industry_production (str): jrc country-specific industrial production file. - path_output (str): location of steel demand output file. - - Returns: - xr.DataArray: steel demand per country. + config (dict): steel sector configuration. + energy_balances (str): country energy balances (usually from eurostat). + cat_names (str): eurostat category mapping file. + carrier_names (str): eurostat carrier name mapping file. + jrc_industry_energy (str): jrc country-specific industrial energy demand file. + jrc_industry_production (str): jrc country-specific industrial production file. + output_path (str): location of steel demand output file. Defaults to None. """ # Load data energy_balances_df = pd.read_csv( - path_energy_balances, index_col=[0, 1, 2, 3, 4] + energy_balances, index_col=[0, 1, 2, 3, 4] ).squeeze("columns") - cat_names_df = pd.read_csv(path_cat_names, header=0, index_col=0) - carrier_names_df = pd.read_csv(path_carrier_names, header=0, index_col=0) - jrc_energy = xr.open_dataset(path_jrc_industry_energy) - jrc_prod = xr.open_dataarray(path_jrc_industry_production) + cat_names_df = pd.read_csv(cat_names, header=0, index_col=0) + carrier_names_df = pd.read_csv(carrier_names, header=0, index_col=0) + jrc_energy = xr.open_dataset(jrc_industry_energy) + jrc_prod = xr.open_dataarray(jrc_industry_production) + jrc.check_units(jrc_energy, jrc_prod) # Ensure dataframes only have data specific to this industry cat_names_df = cat_names_df[cat_names_df["jrc_idees"] == CAT_NAME_STEEL] @@ -55,17 +51,11 @@ def get_steel_demand_df( jrc_prod = jrc_prod.sel(cat_name=CAT_NAME_STEEL) # Process data - new_steel_demand = transform_jrc_subsector_demand( - jrc_energy, jrc_prod, steel_config - ) + new_steel_demand = transform_jrc_subsector_demand(jrc_energy, jrc_prod, config) new_steel_demand = filling.fill_missing_countries_years( energy_balances_df, cat_names_df, carrier_names_df, new_steel_demand ) - - if path_output is not None: - new_steel_demand.to_netcdf(path_output) - - return new_steel_demand + new_steel_demand.to_netcdf(output_path) def transform_jrc_subsector_demand( @@ -99,7 +89,7 @@ def transform_jrc_subsector_demand( xr.Dataset: processed dataframe with the expected steel energy consumption. """ # Gather relevant industrial processes - sintering_intensity = jrc.get_sec_subsec_final_intensity( + sintering_intensity = jrc.get_section_subsection_final_intensity( "Integrated steelworks", "Steel: Sinter/Pellet making", "Integrated steelworks", @@ -109,7 +99,7 @@ def transform_jrc_subsector_demand( fill_empty=True, ) - eaf_smelting_intensity = jrc.get_sec_subsec_final_intensity( + eaf_smelting_intensity = jrc.get_section_subsection_final_intensity( "Electric arc", "Steel: Smelters", "Electric arc", @@ -118,7 +108,7 @@ def transform_jrc_subsector_demand( jrc_prod, fill_empty=True, ) - eaf_intensity = jrc.get_sec_subsec_final_intensity( + eaf_intensity = jrc.get_section_subsection_final_intensity( "Electric arc", "Steel: Electric arc", "Electric arc", @@ -127,7 +117,7 @@ def transform_jrc_subsector_demand( jrc_prod, fill_empty=True, ) - refining_intensity = jrc.get_sec_subsec_final_intensity( + refining_intensity = jrc.get_section_subsection_final_intensity( "Electric arc", "Steel: Furnaces, Refining and Rolling", "Electric arc", @@ -136,7 +126,7 @@ def transform_jrc_subsector_demand( jrc_prod, fill_empty=True, ) - finishing_intensity = jrc.get_sec_subsec_final_intensity( + finishing_intensity = jrc.get_section_subsection_final_intensity( "Electric arc", "Steel: Products finishing", "Electric arc", @@ -145,7 +135,7 @@ def transform_jrc_subsector_demand( jrc_prod, fill_empty=True, ) - auxiliary_intensity = jrc.get_sec_final_intensity_auxiliary_electric( + auxiliary_intensity = jrc.get_section_final_intensity_auxiliary_electric( "Electric arc", "Electric arc", jrc_energy, jrc_prod, fill_empty=True ) @@ -208,17 +198,18 @@ def transform_jrc_subsector_demand( # Prettify steel_energy_demand = steel_energy_demand.assign_attrs(units="twh") steel_energy_demand.name = "demand" + steel_energy_demand = jrc.standardize(steel_energy_demand, "twh", "demand") return steel_energy_demand if __name__ == "__main__": get_steel_demand_df( - steel_config=snakemake.params.steel_config, - path_energy_balances=snakemake.input.path_energy_balances, - path_cat_names=snakemake.input.path_cat_names, - path_carrier_names=snakemake.input.path_carrier_names, - path_jrc_industry_energy=snakemake.input.path_jrc_industry_energy, - path_jrc_industry_production=snakemake.input.path_jrc_industry_production, - path_output=snakemake.output.path_output, + config=snakemake.params.config, + energy_balances=snakemake.input.energy_balances, + cat_names=snakemake.input.cat_names, + carrier_names=snakemake.input.carrier_names, + jrc_industry_energy=snakemake.input.jrc_industry_energy, + jrc_industry_production=snakemake.input.jrc_industry_production, + output_path=snakemake.output[0], ) diff --git a/modules/industry/scripts/utils/filling.py b/modules/industry/scripts/utils/filling.py index 350da1d2..e5ea225e 100644 --- a/modules/industry/scripts/utils/filling.py +++ b/modules/industry/scripts/utils/filling.py @@ -81,13 +81,12 @@ def fill_missing_countries_years( _to_fill = _to_fill.bfill(dim="year") all_filled = _to_fill.ffill(dim="year") - # TODO: CHE has no values for "Wood and wood products" and "Transport Equipment". - # We fill this with zeros for now (equivalent to SCEC). Should CHE data be improved/filled in another way? + # ASSUME: remaining empty category combinations have no demand all_filled = all_filled.fillna(0) all_filled = jrc.standardize(all_filled, "twh") - assert ~all_filled.isnull().any(), "Filling failed, found null values." - assert ~np.isinf(all_filled).any(), "Filling failed, found inf values." + assert not all_filled.isnull().any(), "Filling failed (nan values)." + assert not np.isinf(all_filled).any(), "Filling failed (inf values)." return all_filled diff --git a/modules/industry/scripts/utils/jrc_idees_parser.py b/modules/industry/scripts/utils/jrc_idees_parser.py index e428c3b8..546bd83a 100644 --- a/modules/industry/scripts/utils/jrc_idees_parser.py +++ b/modules/industry/scripts/utils/jrc_idees_parser.py @@ -6,6 +6,13 @@ STANDARD_COORDS = ["cat_name", "year", "country_code", "carrier_name"] +def check_units(jrc_energy: xr.Dataset, jrc_prod: xr.DataArray) -> None: + """Check that the JRC data is in the right units.""" + for var in jrc_energy: + assert jrc_energy[var].attrs["units"].lower() == "twh" + assert jrc_prod.attrs["units"].lower() == "kt" + + def standardize( da: xr.DataArray, units: str, name: Optional[str] = None ) -> xr.DataArray: @@ -45,7 +52,7 @@ def standardize( return da -def get_sec_final_intensity_auxiliary_electric( +def get_section_final_intensity_auxiliary_electric( section: str, material: str, jrc_energy: xr.Dataset, @@ -55,7 +62,7 @@ def get_sec_final_intensity_auxiliary_electric( """Wrapper for auxiliary electrical processes.""" auxiliaries = ["Lighting", "Air compressors", "Motor drives", "Fans and pumps"] auxiliary_intensity = sum( - get_sec_subsec_final_intensity( + get_section_subsection_final_intensity( section, aux, material, "Electricity", jrc_energy, jrc_prod, fill_empty ) for aux in auxiliaries @@ -64,7 +71,7 @@ def get_sec_final_intensity_auxiliary_electric( return auxiliary_intensity -def get_sec_subsec_final_intensity( +def get_section_subsection_final_intensity( section: str, subsection: str, material: str, @@ -122,7 +129,7 @@ def get_section_subsection_useful_intensity( return useful_intensity.fillna(0) -def replace_final_demand_by_carrier( +def replace_carrier_final_demand( carrier: str, jrc_energy: xr.Dataset, ) -> xr.DataArray: @@ -142,7 +149,7 @@ def replace_final_demand_by_carrier( carrier_tot = jrc_energy.sel(carrier_name=carrier) carrier_eff = carrier_tot["useful"] / carrier_tot["final"] - # Fill NaNs (where there is demand, but no consumption in that country) + # ASSUME: fill NaNs (where there is demand, but no consumption in that country) # First by country avg. (all years), then by year avg. (all countries). carrier_eff = carrier_eff.fillna(carrier_eff.mean(dim="year")) carrier_eff = carrier_eff.fillna(carrier_eff.mean(dim="country_code")) @@ -182,7 +189,4 @@ def convert_subsection_demand_to_carrier( "subsection": "carrier_name" }) - # Prettify - new_carrier_useful_dem = standardize(new_carrier_useful_dem, "twh") - - return new_carrier_useful_dem + return standardize(new_carrier_useful_dem, "twh")