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 36 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
15 changes: 2 additions & 13 deletions co2calculator/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from ._types import Kilogram, Kilometer
from .constants import (
KWH_TO_TJ,
Size,
CarFuel,
BusFuel,
Expand Down Expand Up @@ -68,9 +67,7 @@ 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 * energy_share * co2e


def calc_co2_heating(
Expand Down Expand Up @@ -110,9 +107,7 @@ def calc_co2_heating(
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 * area_share / co2e


def calc_co2_businesstrip(
Expand All @@ -122,7 +117,6 @@ def calc_co2_businesstrip(
distance: Kilometer = None,
size: Size = None,
fuel_type: CarFuel | BusFuel | TrainFuel = None,
occupancy: int = None,
seating: FlightClass | FerryClass = None,
passengers: int = None,
roundtrip: bool = False,
Expand All @@ -137,7 +131,6 @@ def calc_co2_businesstrip(
:param fuel_type: Fuel type of the vehicle
[average, cng, diesel, electric, gasoline, hybrid, hydrogen, plug-in_hybrid]
- only used for car, bus and train
:param occupancy: Occupancy of the vehicle in % [20, 50, 80, 100] - only used for bus
:param seating: seating class ["average", "Economy class", "Premium economy class", "Business class", "First class"]
- only used for plane
:param passengers: Number of passengers in the vehicle (including the participant), number from 1 to 9
Expand All @@ -147,7 +140,6 @@ def calc_co2_businesstrip(
:type distance: Kilometer
:type size: str
:type fuel_type: str
:type occupancy: int
:type seating: str
:type passengers: int
:type roundtrip: bool
Expand Down Expand Up @@ -211,7 +203,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 @@ -220,13 +211,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
Loading
Loading