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

Add industry module #340

Merged
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0cf664e
Create industry modulle file structure
Apr 8, 2024
b995777
Initial setup for steel/iron industry
Apr 8, 2024
65ebb01
added formatting of steel and iron industry
Apr 9, 2024
c04b284
Finish the addition of the steel industry processing.
Apr 10, 2024
80e6e6d
Minor fix: correct config[input] usage in rule: steel industry
Apr 10, 2024
dc4240e
Minor PR fixes
Apr 10, 2024
4151c5e
PR fixes: passed scrap steel share to the cnf. Fixed year range.
Apr 11, 2024
5c60a7f
Update modules/industry/src/steel_industry.py
brynpickering Apr 11, 2024
1f892bf
Add documentation of the industry module
Apr 11, 2024
fd0aa3c
minor corrections and initial schema file
irm-codebase Apr 11, 2024
7e4f565
Add validation for the industry module configuration.
irm-codebase Apr 11, 2024
3a647f3
Remove changes to Snakefile
irm-codebase Apr 11, 2024
f40ccf1
Merge remote-tracking branch 'origin/develop' into add-industry-module
irm-codebase Apr 11, 2024
2820d7b
Fix reintroduction of Snakefile merge issue
irm-codebase Apr 11, 2024
fb4844e
PR fixes: change folder names
irm-codebase Apr 11, 2024
fa3f456
Add schema validation for the industry module
irm-codebase Apr 12, 2024
632f92c
Fix conflict with schema validation in GitHub.
irm-codebase Apr 12, 2024
3f3048f
Merge remote-tracking branch 'origin/add-jrc-idees-industry-processin…
irm-codebase Apr 12, 2024
87dfea5
Integrate JRC processing script, removed raw_data
Apr 12, 2024
7e1160f
xarray processing for steel up to specific demand
irm-codebase Apr 18, 2024
80ea10a
Generalized JRC functions.
irm-codebase Apr 19, 2024
931ff81
Added formatting xarray support
irm-codebase Apr 20, 2024
c83c40f
Final xarray updates. Steel output is now .nc
irm-codebase Apr 22, 2024
d518419
Merge remote-tracking branch 'origin/develop' into add-industry-module
irm-codebase May 7, 2024
626b5d1
Updated to newest JRC processing version.
irm-codebase May 8, 2024
e49651d
Improved naming and assertion tests. Updated type annotations.
irm-codebase May 13, 2024
21d0195
Fix default.env merge conflict (no longer used in industry module)
irm-codebase May 14, 2024
09e708c
Merge branch 'develop' into add-industry-module
irm-codebase May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/schemavalidation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ jobs:
run: python ./tests/validate_schema.py ./tests/resources/schema.yaml --config ./tests/resources/test.yaml
- name: Validate test schema itself
run: python ./tests/validate_schema.py ./tests/resources/schema.yaml
# Modules
- name: Validate industry config
run: python ./tests/validate_schema.py ./modules/industry/schema.yaml --config ./modules/industry/config.yaml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ __pycache__
# Snakemake
.snakemake/
dag.pdf
**/out/*
**/tmp/*
4 changes: 4 additions & 0 deletions CHANGELOG.md
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Added (models)

* **ADD** industry module and steel industry energy demand processing. NOT CONNECTED TO THE MAIN WORKFLOW. Industry sectors pending: chemical, "other" (#308, #310).

### Added (models)

* **ADD** fully-electrified heat demand (#284).

* **ADD** fully-electrified road transportation (#270), (#271). A parameter allows to define the share of uncontrolled (timeseries) vs controlled charging (optimised) by the solver (PR #338).
Expand Down
13 changes: 12 additions & 1 deletion Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ from snakemake.utils import validate, min_version, makedirs
configfile: "config/default.yaml"
validate(config, "config/schema.yaml")

# >>>>>> Include modules >>>>>>
# Industry
configfile: "modules/industry/config.yaml"
validate(config, "modules/industry/schema.yaml")

module module_industry:
snakefile: "modules/industry/industry.smk"
config: config["industry"]
use rule * from module_industry as module_industry_*
# <<<<<< Include modules <<<<<<


root_dir = config["root-directory"] + "/" if config["root-directory"] not in ["", "."] else ""
__version__ = open(f"{root_dir}VERSION").readlines()[0].strip()
test_dir = f"{root_dir}tests/"
Expand Down Expand Up @@ -87,7 +99,6 @@ rule all:
"build/models/continental/summary-of-potentials.nc",
"build/models/continental/summary-of-potentials.csv"


rule all_tests:
message: "Generate euro-calliope pre-built models and run all tests."
input:
Expand Down
3 changes: 2 additions & 1 deletion envs/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ dependencies:
- pycountry=18.12.8
- jinja2=2.11.3
- pip=21.0.1
- xarray=0.17.0
- xarray=2022.9.0
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved
- scipy=1.5.3
- netCDF4=1.5.6
- hdf5=1.10
- h5py=3.1.0
Expand Down
5 changes: 5 additions & 0 deletions lib/eurocalliopelib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,8 @@ def pj_to_twh(array):
def tj_to_twh(array):
"""Convert TJ to TWh"""
return pj_to_twh(array) / 1000


def tj_to_ktoe(array):
"""Convert TJ to Ktoe"""
return array * 23.88e-3
21 changes: 21 additions & 0 deletions modules/industry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# About

This module is dedicated to getting and processing energy demand for industry.

Basic info of this module:

- Main data sources: JRC IDEES and eurostat
- Spatial resolution: national (because of JRC IDEES)
- Temporal resolution: annual aggregated

Some industries are specified as 'sub-module' in this module, such as iron and steel industry. This allows you to flexibly configure the decarbonisation level of each industry separately. All other industries are grouped into 'other industries'.

For workflow users, i.e. non-developers, `config.yaml` is the main file to look into.
Here, one can specify parameters such as the years to be included in the data processing, assumptions such as the share of recycled steel, and the specific industry sector to be included (such as iron and steel industry).
The structure of the `config.yaml` file is:

- inputs - the needed data sources from other modules in euro-calliope (for now, we assume this module depends on other modules and is not yet a stand-alone module)
- outputs - the output of the whole industry module, usually files, possibly passed on to other modules in euro-calliope.
- params - the parameters that affect the calculation process and result in this module.
By changing the value of the parameters, each user can tailor the workflow to their own needs.
- setup - anything that concerns the general data pipeline of the module.
13 changes: 13 additions & 0 deletions modules/industry/config.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have a schema for this config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've created issue #347 to tackle this.

A schema is a great idea, but the module's configuration might change too much while we port features. We'd prefer to do it once the chemical and "other" sectors are ported, to ensure the configuration file is mature enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config must go into the metadata that we create for model builds. See the build_metadata rule.

Copy link
Contributor Author

@irm-codebase irm-codebase Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config must go into the metadata that we create for model builds. See the build_metadata rule.

The general config already includes our module's configuration. So it is already in the metadata :)

# Include modules
configfile: "modules/industry/config.yaml"

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
industry:
inputs:
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved
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
outputs:
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved
placeholder-out1:
placeholder-out2:
params:
steel:
recycled-steel-share: 0.5 # % of recycled scrap steel for H-DRI
18 changes: 18 additions & 0 deletions modules/industry/env_industry.yaml
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: module-industry
channels:
- conda-forge
- bioconda
dependencies:
- python=3.11
- ipdb=0.13.13
- numpy=1.23
- pandas=1.5.3
- pycountry=18.12.8
- snakemake-minimal=8.10.7
- netcdf4=1.6.5
- xarray=2022.9.0
- bottleneck=1.3.8
- pip=21.0.1
- pip:
- styleframe==4.2
- -e ./lib
56 changes: 56 additions & 0 deletions modules/industry/industry.smk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Paths dependent on main Snakefile
MODULE_PATH = "modules/industry"
BUILD_PATH = f"{MODULE_PATH}/build"
DATA_PATH = f"{MODULE_PATH}/raw_data"
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved

# Paths relative to this snakefile (snakemake behaviour is inconsitent)
SCRIPT_PATH = "scripts" # scripts are called relative to this file
CONDA_PATH = "./env_industry.yaml"

# Ensure rules are defined in order.
# Otherwise commands like "rules.rulename.output" won't work!
rule steel_industry:
message: "Calculate energy demand for the 'Iron and steel' sector in JRC-IDEES."
conda: CONDA_PATH
irm-codebase marked this conversation as resolved.
Show resolved Hide resolved
params:
config_steel = config["params"]["steel"]
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_industry.py"

rule chemical_industry:
message: "."
conda: CONDA_PATH
params:
input:
output:
script: f"{SCRIPT_PATH}/chemicals.py"

rule other_industry:
message: "."
conda: CONDA_PATH
params:
input:
output: f"{BUILD_PATH}/other_industry.csv"
script: f"{SCRIPT_PATH}/other_industry.py"

# rule combine_and_scale:
# message: "."
# conda: CONDA_PATH
# params:
# input:
# output:
# script:

# rule verify:
# message: "."
# params:
# input:
# output:
# script:
55 changes: 55 additions & 0 deletions modules/industry/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
$schema: https://json-schema.org/draft/2020-12/schema
type: object
additionalProperties: true
properties:
industry:
description: Module subsection to ensure no name conflicts are possible between modules.
type: object
additionalProperties: false
properties:
inputs:
type: object
additionalProperties: false
description: Inputs are paths of prerequired files.
properties:
path-energy-balances:
type: string
description: |
Annual energy balance file.
Columns [cat_code,carrier_code,unit,country,year,value].
path-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:
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:
type: string
description: |
JRC processed industry energy demand .nc file.
path-jrc-industry-production:
type: string
description: |
JRC processed industrial production .nc file.
outputs:
type: object
description: Outputs are paths for the files produced by the module.
params:
type: object
additionalProperties: false
description: Parameters allow users to configure module behaviour.
properties:
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
Empty file.
Empty file.
Loading
Loading