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

Emissionfactors 2024 #173

Merged
merged 45 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e3c336b
Feat(emission_factors.csv): Add emission factors for electricity and …
veitu May 4, 2024
d72e470
Feat(emission_factors.csv): Add emission factors for transport
veitu May 4, 2024
f8ea8b9
Fix(emission_factors.csv): Remove unnecessary columns
veitu May 4, 2024
e02b75d
Fix(emission_factors.csv): Fix csv
veitu May 4, 2024
cd523a7
Feat(emission_factors.csv): Add residual mix emission factors where a…
veitu May 4, 2024
5704696
Fix(emission_factors.csv): Remove model column
veitu May 4, 2024
99c7a70
Docs(README.md): Update emission factor sources in README
veitu May 5, 2024
6ea73cf
Update index.rst
veitu May 5, 2024
8e0cd23
Fix(emission_factors.csv): Add subcategory tram
veitu May 5, 2024
f3e5872
Feat(emission_factors.csv): Add foot and car passenger for ferry again
veitu May 5, 2024
910f2c3
Fix(emission_factors.csv): Correct transport category
veitu May 5, 2024
2b2233a
Feat(emission_factors.csv): Add large long-distance bus
veitu May 5, 2024
083ad54
Move old emission factor files
veitu May 5, 2024
d808c4a
Delete data/emission_factors_old.csv
veitu May 5, 2024
3b99fc7
Make separate emission factor file for heating
veitu May 5, 2024
ad75730
Make separate emission factor file for electricity
veitu May 5, 2024
f3ea5b5
Make separate emission factor file for transport
veitu May 5, 2024
b9fb8d4
Merge branch 'main' into emissionfactors-2024
han16nah May 5, 2024
07d13f5
adapt EmissionFators so that it reades splitted csv files incl. tests
redfrexx May 5, 2024
0b16402
Merge branch 'main' into emissionfactors-2024
codingfabi May 5, 2024
5805fd9
Merge branch 'emissionfactors-2024' of https://github.com/pledge4futu…
codingfabi May 5, 2024
c883e0d
create test data folder
han16nah May 5, 2024
c510de6
rename size_class to class
han16nah May 5, 2024
522ed6d
remove occupancy stuff
han16nah May 5, 2024
4ffb06f
remove conversion factor TJ to kWh
han16nah May 5, 2024
e411cde
test: add tests for enums-data compliancy and adapt enums to new emis…
redfrexx May 5, 2024
74fea97
fix: remove old tests which have accidentally been re-added
redfrexx May 5, 2024
0a42f4f
fix: remove TrainFuel
redfrexx May 5, 2024
e8eeee8
use test data dir, add fixture, add heating emission param test
han16nah May 5, 2024
d7f4ead
test: test if default parameter combinations exist in csv files, add …
redfrexx May 5, 2024
4eed43a
add test for electricity emission factors
han16nah May 5, 2024
a65452f
test: adapt tests to only check if the result is float, instead of co…
redfrexx May 5, 2024
8d596fd
test: add test_enums.py
redfrexx May 5, 2024
e857944
test: skip tests for deprecated functions
redfrexx May 5, 2024
ae72bbb
test: fix tests, which fail because the combination of the passed use…
redfrexx May 5, 2024
23e0d16
add and skip problematic test for car emission factor
han16nah May 5, 2024
4d4e21d
deps: bump version (#183)
codingfabi May 5, 2024
9647bee
feat: add a calculation function that works generically for all trips…
codingfabi May 5, 2024
b972562
data: rename fuel types in emission factors and conversion factors fo…
redfrexx May 5, 2024
7c144ea
refactor: refactor energy_share and area_share to own_share
redfrexx May 5, 2024
d7575a0
add country_code param to calc_co2_electricity and fix respective test
han16nah May 6, 2024
761ca17
move range category tests to test_distances.py
han16nah May 6, 2024
5292c95
fix car test
han16nah May 6, 2024
9623fba
make sure heating fuel type is called the same in all data csv files
han16nah May 6, 2024
3dcaa80
Merge branch 'main' into emissionfactors-2024
han16nah May 6, 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ $ pytest

### Emission factors

- [Probas](https://www.probas.umweltbundesamt.de/php/index.php)
- [UBA (2021). "Umweltfreundlich mobil"](https://www.umweltbundesamt.de/en/publikationen/umweltfreundlich-mobil)
- [GOV.UK (2020). Greenhouse gas reporting: conversion factors 2020](https://www.gov.uk/government/publications/greenhouse-gas-reporting-conversion-factors-2020)
- [Carbon footprint (2023). International electricity factors](https://www.carbonfootprint.com/international_electricity_factors.html)
- [GOV.UK (2023). Greenhouse gas reporting: conversion factors 2023](https://www.gov.uk/government/publications/greenhouse-gas-reporting-conversion-factors-2023)
- [mobitoool (2023). mobitool-Faktoren v3.0](https://www.mobitool.ch/de/tools/mobitool-faktoren-v2-1-25.html)

### Conversion factors

- [BAFA (2020): Merkblatt zur Ermittlung des Gesamtenergieverbrauchs](https://www.bafa.de/SharedDocs/Downloads/DE/Energie/ea_ermittlung_gesamtenergieverbrauch.html)
- [Krajnc, N. (2015): Wood fuels handbook, FAO](https://agris.fao.org/agris-search/search.do?recordID=XF2017001919)
- [Krajnc, N. (2015): Wood fuels handbook, FAO](http://large.stanford.edu/courses/2017/ph240/timcheck1/docs/fao-krajnc-2015.pdf)

### Detour coefficients and constants

Expand Down
37 changes: 15 additions & 22 deletions co2calculator/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@

from ._types import Kilogram, Kilometer
from .constants import (
KWH_TO_TJ,
Size,
CarFuel,
BusFuel,
TrainFuel,
BusTrainRange,
FlightClass,
FerryClass,
ElectricityFuel,
HeatingFuel,
Unit,
TransportationMode,
CountryCode2,
)
from .data_handlers import EmissionFactors, ConversionFactors
from .distances import create_distance_request, get_distance, range_categories
from .parameters import (
ElectricityEmissionParameters,
HeatingEmissionParameters,
Expand All @@ -48,16 +44,21 @@


def calc_co2_electricity(
consumption: float, fuel_type: ElectricityFuel = None, energy_share: float = 1
consumption: float,
fuel_type: ElectricityFuel = None,
country_code: CountryCode2 = None,
own_share: float = 1,
) -> Kilogram:
"""Function to compute electricity emissions

:param consumption: energy consumption
:param fuel_type: energy (mix) used for electricity [german_energy_mix, solar]
:param fuel_type: energy (mix) used for electricity [production fuel mix, residual fuel mix]
:param country_code: 2 Letter ISO country code
:param energy_share: the research group's approximate share of the total electricity energy consumption
:type consumption: float
:type fuel_type: str
:type energy_share: float
:type country_code: str
:type own_share: float
:return: total emissions of electricity energy consumption
:rtype: Kilogram
"""
Expand All @@ -69,16 +70,14 @@ def calc_co2_electricity(
# Get the co2 factor
co2e = emission_factors.get(params.dict())

# co2 equivalents for heating and electricity refer to a consumption of 1 TJ
# so consumption needs to be converted to TJ
return consumption * energy_share / KWH_TO_TJ * co2e
return consumption * own_share * co2e


def calc_co2_heating(
consumption: float,
fuel_type: HeatingFuel,
unit: Unit = None,
area_share: float = 1.0,
own_share: float = 1.0,
) -> Kilogram:
"""Function to compute heating emissions

Expand All @@ -87,16 +86,16 @@ def calc_co2_heating(
[coal, district_heating, electricity, gas, heat_pump_air,
heat_pump_ground, liquid_gas, oil, pellet, solar, woodchips]
:param unit: unit of energy consumption [kwh, kg, l, m^3]
:param area_share: share of building area used by research group
:param own_share: share of building area used by research group
:type consumption: float
:type fuel_type: str
:type unit: str
:type area_share: float
:type own_share: float
:return: total emissions of heating energy consumption
:rtype: Kilogram
"""
# Validate parameters
assert 0 < area_share <= 1
assert 0 < own_share <= 1
params_extracted = {k: v for k, v in locals().items() if v is not None}
params = HeatingEmissionParameters(**params_extracted)

Expand All @@ -106,14 +105,11 @@ def calc_co2_heating(
if unit is not Unit.KWH:
# Get the conversion factor
conversion_factor = conversion_factors.get(fuel_type=fuel_type, unit=unit)

consumption_kwh = consumption * conversion_factor
else:
consumption_kwh = consumption

# co2 equivalents for heating and electricity refer to a consumption of 1 TJ
# so consumption needs to be converted to TJ
return consumption_kwh * area_share / KWH_TO_TJ * co2e
return consumption_kwh * co2e * own_share


def calc_co2_trip(
Expand Down Expand Up @@ -149,7 +145,6 @@ def calc_co2_commuting(
weekly_distance: Kilometer,
size: Size = None,
fuel_type: BusFuel | CarFuel | TrainFuel = None,
occupancy: int = None,
passengers: int = None,
) -> Kilogram:
"""Calculate co2 emissions for commuting per mode of transport
Expand All @@ -158,13 +153,11 @@ def calc_co2_commuting(
:param weekly_distance: distance in km per week
:param size: size of car or bus if applicable: [small, medium, large, average]
:param fuel_type: fuel type of car, bus or train if applicable
:param occupancy: occupancy [%], if applicable/known (only for bus): [20, 50, 80, 100]
:param passengers: number of passengers, if applicable (only for car)
:type transportation_mode: str
:type weekly_distance: Kilometer
:type size: str
:type fuel_type: str
:type occupancy: int
:type passengers: int
:return: total weekly emissions for the respective mode of transport
:rtype: Kilogram
Expand Down
22 changes: 7 additions & 15 deletions co2calculator/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import iso3166
import pandas as pd

KWH_TO_TJ = 277777.77777778

DF_AIRPORTS = pd.read_csv(
"https://davidmegginson.github.io/ourairports-data/airports.csv"
Expand All @@ -17,26 +16,20 @@
class HeatingFuel(enum.Enum):
"""Enum for heating fuel types"""

HEAT_PUMP_AIR = "heat_pump_air"
HEAT_PUMP_GROUND = "heat_pump_ground"
HEAT_PUMP_WATER = "heat_pump_water"
LIQUID_GAS = "liquid_gas"
OIL = "oil"
PELLETS = "pellets"
SOLAR = "solar"
WOODCHIPS = "woodchips"
ELECTRICITY = "electricity"
GAS = "gas"
COAL = "coal"
DISTRICT_HEATING = "district_heating"
GAS = "gas"
WOOD_PELLETS = "wood pellets"
WOOD_CHIPS = "wood chips"
LPG = "liquid gas"


@enum.unique
class ElectricityFuel(str, enum.Enum):
"""Enum for electricity fuel types"""

GERMAN_ENERGY_MIX = "german_energy_mix"
SOLAR = "solar"
PRODUCTION_FUEL_MIX = "production fuel mix"
RESIDUAL_FUEL_MIX = "residual fuel mix"


@enum.unique
Expand Down Expand Up @@ -87,7 +80,6 @@ class FlightClass(str, enum.Enum):
"""Enum for flight classes"""

ECONOMY = "economy_class"
PREMIUM_ECONOMY = "premium_economy_class"
BUSINESS = "business_class"
FIRST = "first_class"
AVERAGE = "average"
Expand All @@ -106,9 +98,9 @@ class FerryClass(str, enum.Enum):
class FlightRange(str, enum.Enum):
"""Enum for flight ranges"""

DOMESTIC = "domestic"
SHORT_HAUL = "short-haul"
LONG_HAUL = "long-haul"
AVERAGE = "average"


@enum.unique
Expand Down
6 changes: 3 additions & 3 deletions co2calculator/data/conversion_factors_heating.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
,fuel_type,unit,conversion_value
0,oil,l,10.6
1,liquid_gas,kg,14.1
1,liquid gas,kg,14.1
2,coal,kg,6.0
3,pellet,kg,5.4
4,woodchips,kg,5.2
3,wood pellets,kg,5.4
4,wood chips,kg,5.2
5,gas,m^3,10.8
Loading
Loading