Skip to content

Commit 4d4a492

Browse files
authored
Merge pull request #23 from OSeMOSYS/refactor_filter
2 parents 1fcd300 + 93442d6 commit 4d4a492

File tree

13 files changed

+614
-408
lines changed

13 files changed

+614
-408
lines changed

.github/workflows/pytest.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ jobs:
3232
python-version: ${{ matrix.python-version }}
3333

3434
- name: Install pytest
35-
run: pip install pytest
36-
pip install pytest-cov
35+
run: |
36+
pip install pytest
37+
pip install pytest-cov
3738
3839
- name: Install the package
39-
run: pip install .
40+
run: |
41+
pip install .
42+
43+
44+
- name: Install editable openentrance
45+
run: |
46+
pip uninstall --yes openentrance
47+
pip install -e git+https://github.com/openENTRANCE/openentrance.git@main#egg=openentrance
4048
4149
- name: Test with pytest
4250
run: pytest

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ MANIFEST
5858

5959
# Outputs
6060
*.csv
61-
!tests/fixtures/*.csv
61+
!tests/fixtures/*.csv
62+
63+
# Dependencies
64+
src/openentrance

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022 Will Usher
3+
Copyright (c) 2022 Will Usher, Hauke Henke
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ Convert OSeMOSYS results to IAMC format
44

55
## Install from Github repository
66

7-
pip install git+https://github.com/osesmosys/osemosys2iamc@main#egg=osemosys2iamc
7+
It is currently necessary to install the OpenEntrance dependency as an editable installation.
8+
See [issue](https://github.com/openENTRANCE/openentrance/issues/202)
89

9-
## Run the demo
10+
pip install git+https://github.com/osemosys/osemosys2iamc@main#egg=osemosys2iamc
11+
pip install -e git+https://github.com/openENTRANCE/openentrance.git@main#egg=openentrance
1012

11-
osemosys2iamc results config.yaml test.csv
13+
## Run the package
1214

13-
Check out the IAMC formatted results in `test.csv` and plots `emissions.csv`
15+
$ osemosys2iamc --help
16+
osemosys2iamc <inputs_path> <results_path> <config_path> <output_path>
17+
18+
`inputs_path`: Path to a folder of csv files (OSeMOSYS inputs). File names should correspond to OSeMOSYS parameter names.
19+
`results_path`: Path to a folder of csv files (OSeMOSYS results). File names should correspond to OSeMOSYS variable names.
20+
`config_path`: Path to the configuration file (see below)
21+
`output_path`: Path to the .xlsx file you wish to write out
1422

1523
## The IAMC format
1624

@@ -30,7 +38,70 @@ in the contribution by Working Group III to the IPCC's Sixth Assessment Report (
3038
Please refer to the Horizon 2020 project [openENTRANCE](https://github.com/openENTRANCE/openentrance#data-format-structure)
3139
for more information about the format and its usage in that project.
3240

33-
## Usage for OSeMOSYS
41+
## Writing a configuration file
42+
43+
Write a configuration file in YAML format. A simple configuration file with one result variable looks like this:
44+
45+
model: OSeMBE v1.0.0
46+
scenario: DIAG-C400-lin-ResidualFossil
47+
region: ['Austria'] # select countries to plot summary results
48+
results:
49+
- iamc_variable: 'Carbon Capture|Biomass'
50+
tech_emi: ['(?=^.{2}(BM))^.{4}(CS)']
51+
emissions: [CO2]
52+
unit: kt CO2/yr
53+
transform: abs
54+
osemosys_param: AnnualTechnologyEmissions
55+
56+
The first section of the configuration file with the keys `model`, `scenario`, and `region` are used to define the metadata for
57+
the IAMC template.
58+
59+
The second section `results:` is where you describe each of the IAMC variables and provide instructions to osemosys2iamc on how
60+
to compute the values.
61+
62+
`iamc_variable` - this should match one of the IAMC variable names
63+
`unit` - provide the units of the OSeMOSYS results
64+
`transform` - only `abs` is currently available. This returns the absolute value of the results
65+
`osemosys_param` - provide the name of the result file from which the script should extract the result data
66+
67+
One or more of the following filter keys. These filter the
68+
results by one or more columns found in OSeMOSYS results.
69+
Following the fitering, the remaining columns except region
70+
and year are discarded and rows are summed.
71+
72+
`tech_emi` - filter the results by TECHNOLOGY and EMISSION columns using the provide regular expression and an `emissions` entry
73+
`emissions` - a list of emissions to filter the results by the EMISSION column
74+
`fuel` - filter by the FUEL column
75+
`capacity` - filter the TECHNOLOGY column
76+
`primary_technology` - filter the TECHNOLOGY column (can be replaced by `capacity` key)
77+
`excluded_prod_tech` - filter the TECHNOLOGY column (can be replaced by `capacity` key)
78+
`el_prod_technology` - filter the TECHNOLOGY column (can be replaced by `capacity` key)
79+
`demand` - filters by the FUEL column (final energy)
80+
81+
The value for each of these keys is a list of regular expressions. These regular expressions are used to filter the rows of data in the chosen column to those that match the
82+
regular expression.
83+
84+
Writing regular expressions can be tricky, but there are [useful tools](https://regexr.com/) to help.
85+
Below we provide some examples:
86+
87+
`^.{2}(WI)` match rows with any two characters followed by `WI`
88+
89+
`(?=^.{2}(HF))^((?!00).)*$` match rows with `HF` in 3rd and 4th position which do not include `00`
90+
91+
`(?=^.{2}(NG))^((?!(00)|(CS)).)*$` match rows with `NG` in 3rd and 4th position that do not include `00` or `CS`
92+
93+
`^.{6}(I0)` match rows which contain any 6 characters followed by `IO` in the 7th and 8th position
94+
95+
Putting this together, the following entry extracts results from the result file `ProductionByTechnologyAnnual.csv`, filters out the rows
96+
by matching values in the TECHNOLOGY column with a list of 6 regular expressions (this is an OR operation)
97+
and assigns the unit `PJ/yr` and adds the aggregated (summing over region and year) total under `Primary Energy` in the IAMC template format.
98+
99+
- iamc_variable: 'Primary Energy'
100+
primary_technology: ['^.{6}(I0)','^.{6}(X0)','^.{2}(HY)','^.{2}(OC)','^.{2}(SO)','^.{2}(WI)']
101+
unit: PJ/yr
102+
osemosys_param: ProductionByTechnologyAnnual
103+
104+
## List of relevant IAMC variables for OSeMOSYS
34105

35106
### Primary Energy
36107

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
matplotlib
22
pandas
33
pyam-iamc >= 1.0 # the pyam package is released on pypi under this name
4+
-e git+https://github.com/openENTRANCE/openentrance.git@main#egg=openentrance

0 commit comments

Comments
 (0)