mosaik-emissions 0.1.0__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ **/__pycache__
2
+ dist
3
+ .coverage
4
+ coverage.xml
5
+ pytest-*.xml
6
+ uv.lock
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 mosaik development team
3
+ Copyright (c) 2025 Danila Valko & mosaik development team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: mosaik-emissions
3
+ Version: 1.0.0
4
+ Summary: Carbon emissions simulator for mosaik.
5
+ Author-email: Danila Valko <mosaik@offis.de>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Danila Valko & mosaik development team
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Requires-Python: >=3.10
29
+ Requires-Dist: mosaik-api-v3<4,>=3.0.4
30
+ Requires-Dist: numpy>=1.26.1
31
+ Requires-Dist: pandas>=2.1.2
32
+ Requires-Dist: rapidfuzz>=3.14.3
33
+ Description-Content-Type: text/markdown
34
+
35
+ This simulator implements CO₂-emissions calculations for a given [mosaik] scenario and power-unit configuration.
36
+
37
+ > **Note:** This simulator is still a work in progress. Not all desired attributes are implemented yet. If you need support for a specific attribute, please open an [issue here].
38
+
39
+ [mosaik]: https://mosaik.offis.de
40
+ [issue here]: https://gitlab.com/mosaik/components/energy/mosaik-emissions/-/issues
41
+
42
+
43
+ ## Installation
44
+
45
+ ```python
46
+ pip install mosaik-emissions
47
+ ```
48
+
49
+ ## Methodology and Usage
50
+
51
+ CO₂ emissions are dynamically aggregated based on predefined power-unit characteristics.
52
+ The following attributes are currently implemented:
53
+
54
+ * P[MW] – power (input/output)
55
+ * E[tCO₂eq] – total emissions (output)
56
+ * I[tCO₂eq/MWh] – average carbon intensity (output)
57
+
58
+ The basic calculation converts input power into estimated total carbon emissions by multiplying it with the designated carbon-intensity value (emission factor), typically expressed in gCO₂eq/kWh.
59
+
60
+ If multiple inputs assigned with different carbon-intensity values, the resulting intensity is computed as a power-weighted average. While the average carbon intensity is always reported in tCO₂eq/MWh (numerically equivalent to gCO₂eq/kWh), total emissions take the simulation step size into account.
61
+
62
+ The emission factor / carbon intensity is defined as part of the model parameters when simulator entities are created, as commonly done in a [mosaik] scenario.
63
+
64
+ The available parameters depend on the selected data source. Several data sources are integrated (see the table below). For each data source, identified by an `id`, multiple filtering parameters may be used, such as reference year, country, state, fuel type, etc.
65
+
66
+ | Source & Description | Parameters |
67
+ |--------|------------|
68
+ *id: "2006IPCC"* - [2006 IPCC Default Fuel Emission Factors](https://ghgprotocol.org/sites/default/files/2024-05/Emission_Factors_for_Cross_Sector_Tools_V2.0_0.xlsx) | **year**: 2006, **fuel**: [Crude oil, Natural gas, ..]
69
+ *id: "OWD"* - [Our World in Data](https://ourworldindata.org/grapher/carbon-intensity-electricity), country average carbon intencity of electricity, yearly resolution | **year**: 1990-2023, **country_code**: [AFG, DNK, DEU, ..]
70
+ *id: "CO2MAP"* - INATECH [CO2Map](https://co2map.de), carbon intensity in hourly resolution, estimates based on `production` and `consumption` | **year**: 2020-2024, **country_code**: DEU, **state_code**: [BY, BB, SL, ..], **scope**: [prod, cons]
71
+ *id: "EMAPS"* - [Electricity Maps](https://app.electricitymaps.com/datasets), carbon intensity in hourly resolution, `direct` and `lifecycle` estimates | **year**: 2021-2024, **country_code**: DEU, **scope**: [direct, lifecycle]
72
+
73
+
74
+ Parameters are applied from the most specific to the least specific; the exact priority corresponds to the reversed column order of the respective data file (see the files in the `data` directory).
75
+
76
+
77
+ ### Usage example
78
+
79
+ ```python
80
+ emission_config = {
81
+ "id": "CO2MAP",
82
+ "country_code": "DEU",
83
+ "state_code": "BY",
84
+ "scope": "cons",
85
+ }
86
+ emission = world.start("EmissionSim").Emission(**emission_config)
87
+ const = world.start("Const").Const(value=5)
88
+ world.connect(const, emission, ("value", "P[MW]"))
89
+ world.connect(emission, csv_writer, "P[MW]")
90
+ world.connect(emission, csv_writer, "E[tCO₂eq]")
91
+ world.connect(emission, csv_writer, "I[tCO₂eq/MWh]")
92
+ world.run(until=1)
93
+ ```
94
+
95
+ If the selected data source provides suitable (that matches the parameters) historical time series, the simulator will use them.
96
+ If no appropriate time series are available or if manual configuration is preferred one may directly define the emission factor for a specific entity or provide a callable.
97
+
98
+ ### Manual configuration examples
99
+
100
+ ```python
101
+ # Manual emission factor
102
+ em.create(1, "Emission", **{
103
+ "emission_factor": 8.0,
104
+ })
105
+ ```
106
+
107
+ ```python
108
+ # Manual method
109
+ def get_value(**kwargs):
110
+ print("print from a method call:", kwargs)
111
+ return 100.0
112
+
113
+ em.create(1, "Emission", **{
114
+ "method": get_value,
115
+ })
116
+ ```
117
+
118
+ The `start` parameter sets the starting time for the time series, but the simulator will use the data point *nearest* to the reference `year`. If only one data point is available, it will be the sole result. If no reference year is specified, the year is taken from the `start` parameter. The default value of `start` is `"2020-01-01 00:00:00"`.
119
+
120
+ A simple `multiplier` parameter is also available (default: `1.0`) and is applied to the resulting carbon-intensity value.
121
+
122
+ ## Custom Data
123
+
124
+ ### Data structure
125
+ Data files can be extended or replaced, and additional sources may be added directly to the `data` directory as .csv or zip. To be automatically detected and merged with the internal database, each data file must follow the required column structure:
126
+
127
+ ```python
128
+ datetime;carbon_intensity[gCO₂eq/kWh];id;year
129
+ 2020-01-01 00:00:00+00:00;651.0;CO2MAP;2020
130
+ 2020-01-01 01:00:00+00:00;679.0;CO2MAP;2020
131
+ ```
132
+
133
+ * datetime – timeseries index
134
+ * carbon_intensity[gCO₂eq/kWh] – intensity values (float)
135
+ * id – data source identifier (str)
136
+ * year – reference year (int)
137
+
138
+
139
+ Any additional columns may follow. As long as the first three columns match this structure, the simulator will automatically read the file and incorporate it into the available data sources.
140
+
141
+ Other columns, beyond the required first three, are interpreted as filtering parameters. These parameters are applied in reversed column order (i.e., the rightmost column has the highest priority). This allows you to filter data by fields such as fuel type, region, year, or any other metadata you include.
142
+
143
+ If you introduce parameter columns that do not match the existing ones, you will also need to update the mosaik `meta` structure in `emission_simulator.py` accordingly so that the simulator can recognize these new parameters.
144
+
145
+ ### Other Usage
146
+
147
+ If you only want to access carbon-intensity data or test whether a configuration and custom database work correctly, you can use the `get_stored_values` function. By default, it uses parameters that correspond directly to the data columns.
148
+
149
+ ```python
150
+ em = Simulator()
151
+ em.init()
152
+ values = em.get_stored_values(**{
153
+ "id": "2006IPCC",
154
+ "fuel": "Natural gas",
155
+ })
156
+ print(values)
157
+ assert str(values["intensity"].index[0]) == "2020-01-01 00:00:00+00:00"
158
+ ```
159
+
160
+
161
+ ## Citation
162
+
163
+ #### APA-like format
164
+ ```tex
165
+ Valko, D., Alsharif, S., & Tolk, D. (2024). An Open-Source Carbon Emissions Simulator for Smart Grid Co-Simulation Scenarios. European Simulation and Modelling Conference 2024 (ESM 2024), San Sebastian, Spain. https://doi.org/10.5281/zenodo.13984401
166
+ ```
167
+ #### BibTeX format
168
+ ```tex
169
+ @inproceedings{ValkoAlsharifTolk2024,
170
+ title={An Open-Source Carbon Emissions Simulator for Smart Grid Co-Simulation Scenarios},
171
+ author={Danila Valko and Sharaf Alsharif and Deborah Tolk},
172
+ year={2024},
173
+ pages={355-360},
174
+ publisher={EUROSIS-ETI},
175
+ booktitle={European Simulation and Modelling Conference 2024 (ESM 2024)},
176
+ doi={10.5281/zenodo.13984401},
177
+ }
178
+ ```
179
+
180
+ ## Sources and References
181
+
182
+ * Ember - Yearly Electricity Data (2023); Ember - European Electricity Review (2022); Energy Institute - Statistical Review of World Energy (2023) – with major processing by Our World in Data. “Carbon intensity of electricity generation” [dataset]. Ember, “Yearly Electricity Data”; Ember, “European Electricity Review”; Energy Institute, “Statistical Review of World Energy” [original data]. Retrieved February 27, 2024 from https://ourworldindata.org/grapher/carbon-intensity-electricity
183
+
184
+ * Hourly consumption-based CO2 emissions intensity in Germany / [co2map.de](https://co2map.de/), INATECH, University of Freiburg. Retrieved February 27, 2024 from https://api.co2map.de/docs
@@ -0,0 +1,150 @@
1
+ This simulator implements CO₂-emissions calculations for a given [mosaik] scenario and power-unit configuration.
2
+
3
+ > **Note:** This simulator is still a work in progress. Not all desired attributes are implemented yet. If you need support for a specific attribute, please open an [issue here].
4
+
5
+ [mosaik]: https://mosaik.offis.de
6
+ [issue here]: https://gitlab.com/mosaik/components/energy/mosaik-emissions/-/issues
7
+
8
+
9
+ ## Installation
10
+
11
+ ```python
12
+ pip install mosaik-emissions
13
+ ```
14
+
15
+ ## Methodology and Usage
16
+
17
+ CO₂ emissions are dynamically aggregated based on predefined power-unit characteristics.
18
+ The following attributes are currently implemented:
19
+
20
+ * P[MW] – power (input/output)
21
+ * E[tCO₂eq] – total emissions (output)
22
+ * I[tCO₂eq/MWh] – average carbon intensity (output)
23
+
24
+ The basic calculation converts input power into estimated total carbon emissions by multiplying it with the designated carbon-intensity value (emission factor), typically expressed in gCO₂eq/kWh.
25
+
26
+ If multiple inputs assigned with different carbon-intensity values, the resulting intensity is computed as a power-weighted average. While the average carbon intensity is always reported in tCO₂eq/MWh (numerically equivalent to gCO₂eq/kWh), total emissions take the simulation step size into account.
27
+
28
+ The emission factor / carbon intensity is defined as part of the model parameters when simulator entities are created, as commonly done in a [mosaik] scenario.
29
+
30
+ The available parameters depend on the selected data source. Several data sources are integrated (see the table below). For each data source, identified by an `id`, multiple filtering parameters may be used, such as reference year, country, state, fuel type, etc.
31
+
32
+ | Source & Description | Parameters |
33
+ |--------|------------|
34
+ *id: "2006IPCC"* - [2006 IPCC Default Fuel Emission Factors](https://ghgprotocol.org/sites/default/files/2024-05/Emission_Factors_for_Cross_Sector_Tools_V2.0_0.xlsx) | **year**: 2006, **fuel**: [Crude oil, Natural gas, ..]
35
+ *id: "OWD"* - [Our World in Data](https://ourworldindata.org/grapher/carbon-intensity-electricity), country average carbon intencity of electricity, yearly resolution | **year**: 1990-2023, **country_code**: [AFG, DNK, DEU, ..]
36
+ *id: "CO2MAP"* - INATECH [CO2Map](https://co2map.de), carbon intensity in hourly resolution, estimates based on `production` and `consumption` | **year**: 2020-2024, **country_code**: DEU, **state_code**: [BY, BB, SL, ..], **scope**: [prod, cons]
37
+ *id: "EMAPS"* - [Electricity Maps](https://app.electricitymaps.com/datasets), carbon intensity in hourly resolution, `direct` and `lifecycle` estimates | **year**: 2021-2024, **country_code**: DEU, **scope**: [direct, lifecycle]
38
+
39
+
40
+ Parameters are applied from the most specific to the least specific; the exact priority corresponds to the reversed column order of the respective data file (see the files in the `data` directory).
41
+
42
+
43
+ ### Usage example
44
+
45
+ ```python
46
+ emission_config = {
47
+ "id": "CO2MAP",
48
+ "country_code": "DEU",
49
+ "state_code": "BY",
50
+ "scope": "cons",
51
+ }
52
+ emission = world.start("EmissionSim").Emission(**emission_config)
53
+ const = world.start("Const").Const(value=5)
54
+ world.connect(const, emission, ("value", "P[MW]"))
55
+ world.connect(emission, csv_writer, "P[MW]")
56
+ world.connect(emission, csv_writer, "E[tCO₂eq]")
57
+ world.connect(emission, csv_writer, "I[tCO₂eq/MWh]")
58
+ world.run(until=1)
59
+ ```
60
+
61
+ If the selected data source provides suitable (that matches the parameters) historical time series, the simulator will use them.
62
+ If no appropriate time series are available or if manual configuration is preferred one may directly define the emission factor for a specific entity or provide a callable.
63
+
64
+ ### Manual configuration examples
65
+
66
+ ```python
67
+ # Manual emission factor
68
+ em.create(1, "Emission", **{
69
+ "emission_factor": 8.0,
70
+ })
71
+ ```
72
+
73
+ ```python
74
+ # Manual method
75
+ def get_value(**kwargs):
76
+ print("print from a method call:", kwargs)
77
+ return 100.0
78
+
79
+ em.create(1, "Emission", **{
80
+ "method": get_value,
81
+ })
82
+ ```
83
+
84
+ The `start` parameter sets the starting time for the time series, but the simulator will use the data point *nearest* to the reference `year`. If only one data point is available, it will be the sole result. If no reference year is specified, the year is taken from the `start` parameter. The default value of `start` is `"2020-01-01 00:00:00"`.
85
+
86
+ A simple `multiplier` parameter is also available (default: `1.0`) and is applied to the resulting carbon-intensity value.
87
+
88
+ ## Custom Data
89
+
90
+ ### Data structure
91
+ Data files can be extended or replaced, and additional sources may be added directly to the `data` directory as .csv or zip. To be automatically detected and merged with the internal database, each data file must follow the required column structure:
92
+
93
+ ```python
94
+ datetime;carbon_intensity[gCO₂eq/kWh];id;year
95
+ 2020-01-01 00:00:00+00:00;651.0;CO2MAP;2020
96
+ 2020-01-01 01:00:00+00:00;679.0;CO2MAP;2020
97
+ ```
98
+
99
+ * datetime – timeseries index
100
+ * carbon_intensity[gCO₂eq/kWh] – intensity values (float)
101
+ * id – data source identifier (str)
102
+ * year – reference year (int)
103
+
104
+
105
+ Any additional columns may follow. As long as the first three columns match this structure, the simulator will automatically read the file and incorporate it into the available data sources.
106
+
107
+ Other columns, beyond the required first three, are interpreted as filtering parameters. These parameters are applied in reversed column order (i.e., the rightmost column has the highest priority). This allows you to filter data by fields such as fuel type, region, year, or any other metadata you include.
108
+
109
+ If you introduce parameter columns that do not match the existing ones, you will also need to update the mosaik `meta` structure in `emission_simulator.py` accordingly so that the simulator can recognize these new parameters.
110
+
111
+ ### Other Usage
112
+
113
+ If you only want to access carbon-intensity data or test whether a configuration and custom database work correctly, you can use the `get_stored_values` function. By default, it uses parameters that correspond directly to the data columns.
114
+
115
+ ```python
116
+ em = Simulator()
117
+ em.init()
118
+ values = em.get_stored_values(**{
119
+ "id": "2006IPCC",
120
+ "fuel": "Natural gas",
121
+ })
122
+ print(values)
123
+ assert str(values["intensity"].index[0]) == "2020-01-01 00:00:00+00:00"
124
+ ```
125
+
126
+
127
+ ## Citation
128
+
129
+ #### APA-like format
130
+ ```tex
131
+ Valko, D., Alsharif, S., & Tolk, D. (2024). An Open-Source Carbon Emissions Simulator for Smart Grid Co-Simulation Scenarios. European Simulation and Modelling Conference 2024 (ESM 2024), San Sebastian, Spain. https://doi.org/10.5281/zenodo.13984401
132
+ ```
133
+ #### BibTeX format
134
+ ```tex
135
+ @inproceedings{ValkoAlsharifTolk2024,
136
+ title={An Open-Source Carbon Emissions Simulator for Smart Grid Co-Simulation Scenarios},
137
+ author={Danila Valko and Sharaf Alsharif and Deborah Tolk},
138
+ year={2024},
139
+ pages={355-360},
140
+ publisher={EUROSIS-ETI},
141
+ booktitle={European Simulation and Modelling Conference 2024 (ESM 2024)},
142
+ doi={10.5281/zenodo.13984401},
143
+ }
144
+ ```
145
+
146
+ ## Sources and References
147
+
148
+ * Ember - Yearly Electricity Data (2023); Ember - European Electricity Review (2022); Energy Institute - Statistical Review of World Energy (2023) – with major processing by Our World in Data. “Carbon intensity of electricity generation” [dataset]. Ember, “Yearly Electricity Data”; Ember, “European Electricity Review”; Energy Institute, “Statistical Review of World Energy” [original data]. Retrieved February 27, 2024 from https://ourworldindata.org/grapher/carbon-intensity-electricity
149
+
150
+ * Hourly consumption-based CO2 emissions intensity in Germany / [co2map.de](https://co2map.de/), INATECH, University of Freiburg. Retrieved February 27, 2024 from https://api.co2map.de/docs
@@ -0,0 +1,12 @@
1
+ import mosaik_api_v3
2
+ from mosaik_components.emissions.emission_simulator import Simulator
3
+
4
+ __all__ = ["Simulator"]
5
+
6
+
7
+ def main():
8
+ mosaik_api_v3.start_simulation(Simulator(), "run the emission simulator for mosaik")
9
+
10
+
11
+ if __name__ == "__main__":
12
+ main()