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

Restructure the yaml file format to separate variable types from fuels #64

Merged
merged 12 commits into from
Aug 5, 2020
Merged
46 changes: 45 additions & 1 deletion nomenclature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# path to nomenclature definitions
DEF_PATH = Path(__file__).parent / 'definitions'

# auxiliary dictionary to add CCS subcategories
CCS_TYPES = [
('w/ CCS', 'with a CO2 capture component'),
('w/o CCS', 'with freely vented CO2 emissions')
]


def _parse_yaml(path, file='**/*', ext='.yaml'):
"""Parse `file` in `path` (or all files in subfolders if `file='**/*'`)"""
Expand All @@ -28,9 +34,47 @@ def _parse_yaml(path, file='**/*', ext='.yaml'):
return dct


variables = _parse_yaml(DEF_PATH / 'variable')
def _copy_dict(dct, description):
"""Return a copy of `dct` after overwriting the `description`"""
_dct = dct.copy()
_dct['description'] = description
return _dct


variables = dict()
"""Dictionary of variables"""

# read all variable definitions to auxiliary dictionary
_variables = _parse_yaml(DEF_PATH / 'variable')

# explode <Fuels> tags to full lists
fuel_types = _variables.pop('<Fuel>')
d = 'description'
for key, value in _variables.items():
# if the key contains the tag, loop over all fuel types to add mapping
if '<Fuel>' in key:
for f, attr in fuel_types.items():
# ignore the file attribute in the <Fuel> dictionary
if f == 'file':
continue

# change generic tag to specific item in key and description
_key = key.replace('<Fuel>', f)
_description = value[d].replace('<this fuel>', attr[d].lower())
variables[_key] = _copy_dict(value, _description)

# add CCS subcategories (if applicable)
if 'ccs' in attr and attr['ccs'] is True:
for sub, desc in CCS_TYPES:
_key_ccs = f'{_key}|{sub}'
_description_ccs = f'{_description} {desc}'
variables[_key_ccs] = _copy_dict(value, _description_ccs)
# otherwise, move items from auxiliary to public dictionary
else:
variables[key] = _variables[key]

# remove auxiliary dictionary
del _variables

regions = _parse_yaml(DEF_PATH / 'region')
"""Dictionary of all regions"""
Expand Down
164 changes: 4 additions & 160 deletions nomenclature/definitions/variable/energy/energy-secondary.yaml
Original file line number Diff line number Diff line change
@@ -1,169 +1,13 @@
# List of variables related to energy

# The tag <Fuels> can be replaced by any item in the list in `fuel_types.yaml`

Secondary Energy|Electricity:
description: Total net electricity production
unit: EJ/yr

Secondary Energy|Electricity|Biomass:
description: Net electricity production from municipal solid waste,
purpose-grown biomass, crop residues, forest industry waste,
biogas
unit: EJ/yr

Secondary Energy|Electricity|Biomass|w/ CCS:
description: Net electricity production from municipal solid waste,
purpose-grown biomass, crop residues, forest industry waste
with a co2 capture component
unit: EJ/yr

Secondary Energy|Electricity|Biomass|w/o CCS:
description: Net electricity production from municipal solid waste,
purpose-grown biomass, crop residues, forest industry waste
with freely vented co2 emissions
unit: EJ/yr

Secondary Energy|Electricity|Coal:
description: Net electricity production from coal
unit: EJ/yr

Secondary Energy|Electricity|Coal|w/ CCS:
description: Net electricity production from coal with a co2 capture
component
unit: EJ/yr

Secondary Energy|Electricity|Coal|w/o CCS:
description: Net electricity production from coal with freely vented co2
emissions
unit: EJ/yr

Secondary Energy|Electricity|Fossil:
description: Net electricity production from fossil fuels
unit: EJ/yr

Secondary Energy|Electricity|Gas:
description: Net electricity production from natural gas (including methane from biomass or hydrogenation)
unit: EJ/yr

Secondary Energy|Electricity|Gas|w/ CCS:
description: Net electricity production from natural gas (including methane from biomass or hydrogenation) with a co2 capture
component
unit: EJ/yr

Secondary Energy|Electricity|Gas|w/o CCS:
description: Net electricity production from natural gas (including methane from biomass or hydrogenation) with freely vented
co2 emissions
unit: EJ/yr

Secondary Energy|Electricity|Gas|Fossil:
description: Net electricity production from (fossil) natural gas
unit: EJ/yr

Secondary Energy|Electricity|Gas|Fossil|w/ CCS:
description: Net electricity production from (fossil) natural gas with a co2 capture
component
unit: EJ/yr

Secondary Energy|Electricity|Gas|Fossil|w/o CCS:
description: Net electricity production from (fossil) natural gas with freely vented
co2 emissions
unit: EJ/yr

Secondary Energy|Electricity|Gas|Biomethane:
description: Net electricity production from biomethane (upgraded biogas)
unit: EJ/yr

Secondary Energy|Electricity|Gas|Biomethane|w/ CCS:
description: Net electricity production from biomethane (upgraded biogas) with a co2 capture
component
unit: EJ/yr

Secondary Energy|Electricity|Gas|Biomethane|w/o CCS:
description: Net electricity production from biomethane (upgraded biogas) with freely vented
co2 emissions
unit: EJ/yr

Secondary Energy|Electricity|Gas|Synthetic Methane:
description: Net electricity production from synthetic methane (methanation of hydrogen)
unit: EJ/yr

Secondary Energy|Electricity|Gas|Synthetic Methane|w/ CCS:
description: Net electricity production from synthetic methane (methanation of hydrogen) with a co2 capture
component
unit: EJ/yr

Secondary Energy|Electricity|Gas|Synthetic Methane|w/o CCS:
description: Net electricity production from synthetic methane (methanation of hydrogen) with freely vented
co2 emissions
unit: EJ/yr

Secondary Energy|Electricity|Hydrogen:
description: Net electricity production from hydrogen (via fuelcells or hydrogen OCGTs)
unit: EJ/yr

Secondary Energy|Electricity|Geothermal:
description: Net electricity production from all sources of geothermal
energy (e.g., hydrothermal, enhanced geothermal systems)
unit: EJ/yr

Secondary Energy|Electricity|Hydro:
description: Net hydroelectric production
unit: EJ/yr

Secondary Energy|Electricity|Non-Biomass Renewables:
description: Net electricity production from hydro, wind, solar, geothermal,
ocean, and other renewable sources (excluding bioenergy). this
is a summary category for all the non-biomass renewables.
unit: EJ/yr

Secondary Energy|Electricity|Nuclear:
description: Net electricity production from nuclear energy
unit: EJ/yr

Secondary Energy|Electricity|Ocean:
description: Net electricity production from ocean energy
unit: EJ/yr

Secondary Energy|Electricity|Oil:
description: Net electricity production from refined liquid oil products
unit: EJ/yr

Secondary Energy|Electricity|Oil|w/ CCS:
description: Net electricity production from refined liquids with a co2
capture component
unit: EJ/yr

Secondary Energy|Electricity|Oil|w/o CCS:
description: Net electricity production from refined liquids with freely
vented co2 emissions
unit: EJ/yr

Secondary Energy|Electricity|Other:
description: Net electricity production from other sources
unit: EJ/yr

Secondary Energy|Electricity|Solar:
description: Net electricity production from all sources of solar energy
(e.g., pv and concentrating solar power)
unit: EJ/yr

Secondary Energy|Electricity|Solar|CSP:
description: Net electricity production from concentrating solar power (csp)
unit: EJ/yr

Secondary Energy|Electricity|Solar|PV:
description: Net electricity production from solar photovoltaics (pv)
unit: EJ/yr

Secondary Energy|Electricity|Wind:
description: Net electricity production from wind energy (on- and offshore)
unit: EJ/yr

Secondary Energy|Electricity|Wind|Offshore:
description: Net electricity production from offshore wind energy
unit: EJ/yr

Secondary Energy|Electricity|Wind|Onshore:
description: Net electricity production from onshore wind energy
Secondary Energy|Electricity|<Fuel>:
description: Net electricity production from <this fuel>
unit: EJ/yr

Secondary Energy|Gases:
Expand Down
80 changes: 80 additions & 0 deletions nomenclature/definitions/variable/fuel_types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This list of fuels will replace any occurrence of `<Fuel>`
# in a variable-definition yaml file

# All fuels that have the attribute "ccs: True" have two sub-categories
# "w/ CCS": with a CO2 capture component
danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
# "w/o CCS": with freely vented CO2 emissions
danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved

<Fuel>:
Biomass:
description: Purpose-grown biomass, crop residues, forest industry waste,
municipal solid waste
danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
ccs: True

danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
Coal:
description: Coal (including hard coal and lignite)
ccs: True

danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

@danielhuppmann I have a question: how do you declare the variable in the data file when eg it is Coal without CCS?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for this question @sandrinecharousset because it shows that the proposed notation is not yet sufficiently intuitive. The idea is that every fuel in fuel_types.yaml that has the attribute ccs: True has two sub-categories.

So following your example, there would be three variables:

  • Secondary Energy|Electricity|Coal (which is the total)
  • Secondary Energy|Electricity|Coal|w/ CCS
  • Secondary Energy|Electricity|Coal|w/o CCS

This is (tried to be) explained at the top of that file. Can you propose how to rename the attribute or extend the description to make this immediately obvious?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @danielhuppmann
When reading again the file, I find it clear. But I propose to add just examples so that too-quick readers (such as myself) will catch it....

Copy link
Member Author

Choose a reason for hiding this comment

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

thank you @sandrinecharousset - I rewrote it to make it even clearer that we are talking about three variables, not just the two sub-categories. hope you agree!

Fossil:
description: All fossil fuels (crude oil, coal, natural gas)
ccs: True

Gas:
description: Natural gas (including methane from biomass or hydrogenation)
ccs: True

danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
Gas|Fossil:
description: Natural gas (excluding methane from biomass or hydrogenation)
ccs: True

Gas|Biomethane:
description: Biomethane (upgraded biogas)
ccs: True

Gas|Synthetic Methane:
description: Synthetic methane (methanation of hydrogen)
ccs: True

Oil:
description: Refined liquid oil products
ccs: True

Nuclear:
description: Nuclear energy

Hydrogen:
description: Hydrogen

Non-Biomass Renewables:
description: Hydro, wind, solar, geothermal, ocean, and other renewable
sources excluding bioenergy

Hydro:
description: Hydropower

danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
danielhuppmann marked this conversation as resolved.
Show resolved Hide resolved
Solar:
description: Solar energy including PV and CSP

Solar|CSP:
description: Concentrating/concentrated solar power (CSP)

Solar|PV:
description: Solar photovoltaics (PV)

Wind:
description: Wind energy (on- and offshore)

Wind|Offshore:
description: Offshore wind energy

Wind|Onshore:
description: Onshore wind energy

Geothermal:
description: Geothermal energy (including hydrothermal systems)

Ocean:
description: Ocean energy

Other:
description: Other energy sources and fuels not explicitely listed
13 changes: 13 additions & 0 deletions nomenclature/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ def test_variables():
assert 'Emissions|CO2' in nc.variables


def test_variables_fuel_types():
# check that exploding of <Fuel> to fuels works (including CCS subcategory)
obs = nc.variables['Secondary Energy|Electricity|Gas']
exp = 'Net electricity production from natural gas ' \
'(including methane from biomass or hydrogenation)'
assert obs['description'] == exp

obs = nc.variables['Secondary Energy|Electricity|Gas|w/ CCS']
exp = 'Net electricity production from natural gas (including methane ' \
'from biomass or hydrogenation) with a CO2 capture component'
assert obs['description'] == exp


def test_regions():
# check that regions dictionary is not empty and has specific element
assert 'Europe' in nc.regions
Expand Down