From 07d13f58f922d3991d3fe054ae410a06eb5a7f7d Mon Sep 17 00:00:00 2001 From: christina Date: Sun, 5 May 2024 13:06:12 +0200 Subject: [PATCH] adapt EmissionFators so that it reades splitted csv files incl. tests --- co2calculator/constants.py | 18 +- .../data/emission_factors_electricity.csv | 244 ++++++++++++++++++ .../data/emission_factors_heating.csv | 7 + .../data/emission_factors_transport.csv | 61 +++++ co2calculator/data_handlers.py | 70 +++-- co2calculator/parameters.py | 12 +- data/emission_factors.csv | 2 +- docs/businesstrips.rst | 30 +++ tests/functional/test_data_code_compliance.py | 43 +++ tests/unit/test_data_handlers.py | 14 + 10 files changed, 469 insertions(+), 32 deletions(-) create mode 100644 co2calculator/data/emission_factors_electricity.csv create mode 100644 co2calculator/data/emission_factors_heating.csv create mode 100644 co2calculator/data/emission_factors_transport.csv create mode 100644 docs/businesstrips.rst create mode 100644 tests/functional/test_data_code_compliance.py create mode 100644 tests/unit/test_data_handlers.py diff --git a/co2calculator/constants.py b/co2calculator/constants.py index 40de5ca..f89c54a 100644 --- a/co2calculator/constants.py +++ b/co2calculator/constants.py @@ -17,26 +17,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 diff --git a/co2calculator/data/emission_factors_electricity.csv b/co2calculator/data/emission_factors_electricity.csv new file mode 100644 index 0000000..3fa440a --- /dev/null +++ b/co2calculator/data/emission_factors_electricity.csv @@ -0,0 +1,244 @@ +,country_code,category,source,name,unit,fuel_type,co2e_unit,co2e +1,AF,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.1241 +2,AL,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0 +3,DZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.44513 +4,AS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +5,AO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.18537 +6,AG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.74704 +7,AR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.2881 +8,AM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.18481 +9,AW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.66452 +10,AU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.77 +11,AT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.14723 +12,AZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.5212 +13,BS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +14,BH,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42529 +15,BD,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.56719 +16,BB,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.73307 +17,BY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.35708 +18,BE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.13882 +19,BZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.50149 +20,BJ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.7593 +21,BT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0 +22,BO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.26967 +23,BA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.9708 +24,BW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.85966 +25,BR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.1295 +26,VG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +27,BN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.66003 +28,BG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.55371 +29,BF,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.68818 +30,BI,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.24284 +31,KH,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.41038 +32,CM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.29822 +33,CA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.11 +34,CV,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.66906 +35,KY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.7706 +36,CF,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0 +37,TD,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.76675 +38,CL,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.32345 +39,CN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.5572 +40,CO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.1464 +41,KM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +42,CG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.35343 +43,CK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.47539 +44,CR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.01573 +45,CI,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.40343 +46,HR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.25469 +47,CU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.63716 +48,CY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.65493 +49,CZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.76413 +50,CD,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.00215 +51,DK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.18731 +52,DJ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +53,DM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.60588 +54,DO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.57048 +55,EC,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.19018 +56,EG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.46029 +57,SV,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.16363 +58,GQ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.54681 +59,ER,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.7747 +60,EE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.75353 +61,SZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.05916 +62,ET,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.00059 +63,FK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.39616 +64,FO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.49048 +65,FJ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.28849 +66,FI,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.0953 +67,FR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.06207 +68,GF,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.26934 +69,PF,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.53198 +70,GA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.43964 +71,GM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +72,GE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.10128 +73,DE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.44912 +74,GH,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.33563 +75,GR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.3784 +76,GL,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.13205 +77,GD,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +78,GP,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.61058 +79,GU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.75748 +80,GT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.29645 +81,GN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.2166 +82,GW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +83,GY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.70497 +84,HT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.68827 +85,HN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.38705 +86,HK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.68 +87,HK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.39 +88,HU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.27037 +89,IS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.00017 +90,IN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.7132 +91,ID,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.7848 +92,IR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.45473 +93,IQ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.46178 +94,IE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.35216 +95,IL,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.51764 +96,IT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.36425 +97,JM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.53139 +98,JP,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.4615 +99,JO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.35336 +100,KZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.64995 +101,KE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.08078 +102,KI,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +103,KW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42512 +104,KG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.08876 +105,LA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.23817 +106,LV,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.14807 +107,LB,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.62887 +108,LS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0 +109,LR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.33587 +110,LY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.53136 +111,LT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.2711 +112,LU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.08493 +113,MO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42542 +114,MG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.53016 +115,MW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.12332 +116,MY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.53834 +117,MV,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.73229 +118,ML,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.50868 +119,MT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42689 +120,MQ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +121,MR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.58159 +122,MU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.65073 +123,MX,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.3 +124,MD,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.69981 +125,MN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.80174 +126,ME,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.64377 +127,MS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +128,MA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.64226 +129,MZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.10527 +130,MM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.32444 +131,NA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.03809 +132,NR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +133,NP,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0 +134,NL,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.34089 +135,NC,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.68384 +136,NZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.13111 +137,NI,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.36238 +138,NE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.70428 +139,NG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.31727 +140,KP,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.14784 +141,MK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.53802 +142,NO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.00832 +143,OM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42358 +144,PK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.32737 +145,PS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.4758 +146,PA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.18387 +147,PG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.5825 +148,PY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.00143 +149,PE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.22693 +150,PH,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.60756 +151,PL,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.87761 +152,PT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.15641 +153,PR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.77062 +154,QA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42515 +155,RE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.55147 +156,RO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.31148 +157,RU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.34362 +158,RW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.31692 +159,KN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.7563 +160,LC,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +161,PM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +162,VC,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.59423 +163,WS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.51267 +164,ST,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.71308 +165,SA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.6142 +166,SN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.5428 +167,RS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.96323 +168,SC,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.6948 +169,SL,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.07546 +170,SG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.408 +171,SK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.17622 +172,SI,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.27329 +173,SB,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +174,SO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.71501 +175,ZA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.8665 +176,KR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.4113 +177,SS,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.77841 +178,ES,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.17709 +179,LK,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.48882 +180,SD,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.26763 +181,SR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.39223 +182,SE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.00731 +183,CH,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.00278 +184,SY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.53139 +185,TW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.55746 +186,TJ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.06352 +187,TZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.36013 +188,TH,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.446 +189,TG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.49698 +190,TO,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.69327 +191,TT,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42871 +192,TN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.40675 +193,TR,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.4261 +194,TM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.42542 +195,TC,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +196,UG,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.02414 +197,UA,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.20375 +198,AE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.41789 +199,GB,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.22499 +200,US,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.40706 +201,VI,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.76967 +202,UY,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.07148 +203,UZ,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.46613 +204,VU,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.56977 +205,VE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.19141 +206,VN,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.37789 +207,EH,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.79231 +208,YE,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.58073 +209,ZM,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.06617 +210,ZW,electricity,Carbon Footprint Ltd,Total production fuel mix factor,kWh,production fuel mix,kg/kWh,0.39607 +211,BA,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.84393 +212,BE,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.14427 +213,BG,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.51705 +214,CH,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0 +215,CY,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.6074 +216,CZ,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.6974 +217,DE,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.68403 +218,DK,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.5574 +219,EE,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.71518 +220,ES,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.27511 +221,FI,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.52077 +222,FR,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.12496 +223,GB,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.36515 +224,GR,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.53138 +225,HR,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.51506 +226,HU,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.31996 +227,IE,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.47484 +228,IS,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.53129 +229,IT,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.45715 +230,LT,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.46636 +231,LU,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.41968 +232,LV,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.51071 +233,ME,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.53859 +234,MT,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.40494 +235,NL,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.43897 +236,NO,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.50231 +237,PL,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.85812 +238,PT,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.44555 +239,RO,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.27575 +240,RS,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.95421 +241,SE,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.03895 +242,SI,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.3708 +243,SK,electricity,Carbon Footprint Ltd,Residual fuel mix factor,kWh,residual fuel mix,kg/kWh,0.1865 diff --git a/co2calculator/data/emission_factors_heating.csv b/co2calculator/data/emission_factors_heating.csv new file mode 100644 index 0000000..ae9e1a8 --- /dev/null +++ b/co2calculator/data/emission_factors_heating.csv @@ -0,0 +1,7 @@ +,country_code,category,source,name,unit,fuel_type,co2e_unit,co2e +0,global,heating,"UK, Department for Business, Energy & Industrial Strategy",coal (domestic),kWh,coal,kg/kWh,0.35 +1,global,heating,"UK, Department for Business, Energy & Industrial Strategy",natural gas,kWh,gas,kg/kWh,0.18 +2,global,heating,"UK, Department for Business, Energy & Industrial Strategy",LPG,kWh,liquid_gas,kg/kWh,0.21 +3,global,heating,"UK, Department for Business, Energy & Industrial Strategy",fuel oil,kWh,oil,kg/kWh,0.27 +4,global,heating,"UK, Department for Business, Energy & Industrial Strategy",wood pellets,kWh,wood pellets,kg/kWh,0.01074 +5,global,heating,"UK, Department for Business, Energy & Industrial Strategy",wood chips,kWh,wood chips,kg/kWh,0.01074 diff --git a/co2calculator/data/emission_factors_transport.csv b/co2calculator/data/emission_factors_transport.csv new file mode 100644 index 0000000..914a379 --- /dev/null +++ b/co2calculator/data/emission_factors_transport.csv @@ -0,0 +1,61 @@ +,country_code,category,subcategory,source,name,unit,size_class,range,fuel_type,co2e_unit,co2e,seating +1,global,transport,bus,mobitool,Stadtbus (9m),P.km,small,local,cng,kg/P.km,0.1464, +2,global,transport,bus,mobitool,Stadtbus (13m),P.km,medium,local,cng,kg/P.km,0.1034, +3,global,transport,bus,mobitool,Stadtbus (18m),P.km,large,local,cng,kg/P.km,0.0709, +4,global,transport,bus,mobitool,Stadtbus (13m),P.km,average,local,cng,kg/P.km,0.1034, +5,global,transport,bus,mobitool,Stadtbus (13m),P.km,average,local,diesel,kg/P.km,0.1338, +6,global,transport,bus,mobitool,Stadtbus (13m),P.km,medium,local,diesel,kg/P.km,0.1338, +7,global,transport,bus,mobitool,Stadtbus (18m),P.km,large,local,diesel,kg/P.km,0.0905, +8,global,transport,bus,mobitool,Stadtbus (9m),P.km,small,local,diesel,kg/P.km,0.1716, +9,global,transport,bus,mobitool,Reisebus,P.km,small,long-distance,diesel,kg/P.km,0.0465, +10,global,transport,bus,mobitool,Trolleybus,P.km,average,local,electric,kg/P.km,0.0296, +11,global,transport,car,mobitool,Personenkraftwagen,P.km,large,,cng,kg/P.km,0.1528, +12,global,transport,car,mobitool,Personenkraftwagen,P.km,small,,cng,kg/P.km,0.1033, +13,global,transport,car,mobitool,Personenkraftwagen,P.km,medium,,cng,kg/P.km,0.1233, +14,global,transport,car,mobitool,Personenkraftwagen,P.km,average,,average,kg/P.km,0.1864, +15,global,transport,car,mobitool,Personenkraftwagen,P.km,average,,gasoline,kg/P.km,0.186, +16,global,transport,car,mobitool,Personenkraftwagen,P.km,small,,gasoline,kg/P.km,0.1297, +17,global,transport,car,mobitool,Personenkraftwagen,P.km,medium,,gasoline,kg/P.km,0.1506, +18,global,transport,car,mobitool,Personenkraftwagen,P.km,large,,gasoline,kg/P.km,0.2004, +19,global,transport,car,mobitool,Personenkraftwagen,P.km,average,,diesel,kg/P.km,0.189, +20,global,transport,car,mobitool,Personenkraftwagen,P.km,small,,diesel,kg/P.km,0.1109, +21,global,transport,car,mobitool,Personenkraftwagen,P.km,medium,,diesel,kg/P.km,0.1322, +22,global,transport,car,mobitool,Personenkraftwagen,P.km,large,,diesel,kg/P.km,0.1757, +23,global,transport,train,mobitool,Eisenbahn,P.km,,long-distance,,kg/P.km,0.0068, +24,global,transport,train,mobitool,Eisenbahn,P.km,,local,,kg/P.km,0.008, +25,global,transport,train,mobitool,Eisenbahn,P.km,,average,,kg/P.km,0.007, +26,global,transport,tram,mobitool,Strassenbahn,P.km,,local,electric,kg/P.km,0.0428, +27,DE,transport,train,mobitool,Bahn Deutschland,P.km,,average,,kg/P.km,0.0408, +28,FR,transport,train,mobitool,Bahn Frankreich,P.km,,average,,kg/P.km,0.0125, +29,IT,transport,train,mobitool,Bahn Italien,P.km,,average,,kg/P.km,0.0747, +30,AT,transport,train,mobitool,Bahn �sterreich,P.km,,average,,kg/P.km,0.0151, +31,global,transport,car,mobitool,Personenkraftwagen,P.km,large,,hybrid,kg/P.km,0.1785, +32,global,transport,car,mobitool,Personenkraftwagen,P.km,small,,hybrid,kg/P.km,0.1182, +33,global,transport,car,mobitool,Personenkraftwagen,P.km,medium,,hybrid,kg/P.km,0.1397, +34,global,transport,car,mobitool,Personenkraftwagen,P.km,average,,hybrid,kg/P.km,0.1397, +35,global,transport,car,mobitool,Personenkraftwagen,P.km,average,,plug-in_hybrid,kg/P.km,0.1278, +36,global,transport,car,mobitool,Personenkraftwagen,P.km,small,,plug-in_hybrid,kg/P.km,0.0799, +37,global,transport,car,mobitool,Personenkraftwagen,P.km,medium,,plug-in_hybrid,kg/P.km,0.1278, +38,global,transport,car,mobitool,Personenkraftwagen,P.km,large,,plug-in_hybrid,kg/P.km,0.1718, +39,global,transport,car,mobitool,Personenkraftwagen,P.km,average,,electric,kg/P.km,0.0898, +40,global,transport,car,mobitool,Personenkraftwagen,P.km,small,,electric,kg/P.km,0.0599, +41,global,transport,car,mobitool,Personenkraftwagen,P.km,medium,,electric,kg/P.km,0.0697, +42,global,transport,car,mobitool,Personenkraftwagen,P.km,large,,electric,kg/P.km,0.091, +43,global,transport,plane,mobitool,Flugzeug,P.km,,average,kerosine,kg/P.km,0.263,average +44,global,transport,plane,mobitool,Flugzeug,P.km,,short-haul,kerosine,kg/P.km,0.3192,average +45,global,transport,plane,mobitool,Flugzeug,P.km,,short-haul,kerosine,kg/P.km,0.2918,economy_class +46,global,transport,plane,mobitool,Flugzeug,P.km,,short-haul,kerosine,kg/P.km,0.4488,business_class +47,global,transport,plane,mobitool,Flugzeug,P.km,,long-haul,kerosine,kg/P.km,0.2372,average +48,global,transport,plane,mobitool,Flugzeug,P.km,,long-haul,kerosine,kg/P.km,0.1895,economy_class +49,global,transport,plane,mobitool,Flugzeug,P.km,,long-haul,kerosine,kg/P.km,0.3914,business_class +50,global,transport,plane,mobitool,Flugzeug,P.km,,long-haul,kerosine,kg/P.km,0.6031,first_class +51,global,transport,ferry,"UK, Department for Business, Energy & Industrial Strategy","Ferry, Average",P.km,,,,kg/P.km,0.11286,average +52,global,transport,motorbike,mobitool,Motorrad,P.km,small,,,kg/P.km,0.121, +53,global,transport,motorbike,mobitool,Motorrad,P.km,medium,,,kg/P.km,0.1548, +54,global,transport,motorbike,mobitool,Motorrad,P.km,large,,,kg/P.km,0.2036, +55,global,transport,motorbike,mobitool,Motorrad,P.km,average,,,kg/P.km,0.1636, +56,global,transport,bicycle,mobitool,Fahrrad,P.km,,,,kg/P.km,0.0056, +57,global,transport,pedelec,mobitool,E-Bike,P.km,,,,kg/P.km,0.0113, +58,global,transport,ferry,"UK, Department for Business, Energy & Industrial Strategy","Ferry, Foot passenger",P.km,,,,kg/P.km,0.01874,foot_passenger +59,global,transport,ferry,"UK, Department for Business, Energy & Industrial Strategy","Ferry, Car passenger",P.km,,,,kg/P.km,0.12952,car_passenger +60,global,transport,bus,mobitool,Reisebus,P.km,large,long-distance,diesel,kg/P.km,0.0474, diff --git a/co2calculator/data_handlers.py b/co2calculator/data_handlers.py index 38a6997..2884ee7 100644 --- a/co2calculator/data_handlers.py +++ b/co2calculator/data_handlers.py @@ -12,40 +12,74 @@ class EmissionFactors: def __init__(self): """Init""" - self.emission_factors = pd.read_csv(f"{script_path}/data/emission_factors.csv") - self.column_names = self.emission_factors.columns + self.electricity = pd.read_csv( + f"{script_path}/data/emission_factors_electricity.csv" + ) + self.heating = pd.read_csv(f"{script_path}/data/emission_factors_heating.csv") + self.transport = pd.read_csv( + f"{script_path}/data/emission_factors_transport.csv" + ) + + self.databases = { + "electricity": self.electricity, + "heating": self.heating, + "transport": self.transport, + } def get(self, parameters: dict): """ - Returns factors from the database + Returns factor from the database :param parameters: :type parameters: :return: :rtype: """ - selected_factors = self.emission_factors + assert ( + "category" in parameters + ), "Please provide a category for the emission factor." + assert parameters["category"] in [ + "electricity", + "heating", + "transport", + ], "Please provide a valid emission factor category." - for k, v in parameters.items(): - # TODO: shortterm hack to make it work until occupancy is removed from emission factors - if not isinstance(v, int): - v = str(v.value) - if v is None or k not in self.column_names: - continue + # Search suitable emission factors + selected_factors = self._search_factors(parameters, parameters["category"]) - selected_factors_new = selected_factors[selected_factors[k] == v] - selected_factors = selected_factors_new - if selected_factors_new.empty: - raise EmissionFactorNotFound( - "No suitable emission factor found in database. Please adapt your query." - ) - - if len(selected_factors) > 1: + if len(selected_factors) == 0: + raise EmissionFactorNotFound( + "No suitable emission factor found in database. Please adapt your query." + ) + elif len(selected_factors) > 1: raise EmissionFactorNotFound( f"{len(selected_factors)} emission factors found. Please provide more specific selection criteria." ) else: return selected_factors["co2e"].values[0] + def _search_factors(self, parameters, emission_category): + """ + Searches for factors in the database + :param parameters: Search parameters + :type parameters: dict + :param emission_category: Category of emission factors + :type emission_category: str + """ + # Select table for emission category + candidates = self.databases[emission_category] + for k, v in parameters.items(): + # TODO: shortterm hack to make it work until occupancy is removed from emission factors + if not isinstance(v, int): + v = str(v.value) + if v is None or k not in candidates.columns: + continue + new_candidates = candidates[candidates[k] == v] + if new_candidates.empty: + return new_candidates + candidates = new_candidates + + return candidates + class Airports: def __init__(self): diff --git a/co2calculator/parameters.py b/co2calculator/parameters.py index 9582a1b..518b8ca 100644 --- a/co2calculator/parameters.py +++ b/co2calculator/parameters.py @@ -16,12 +16,14 @@ ElectricityFuel, HeatingFuel, Unit, + EmissionCategory, ) from typing import Union class TrainEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.TRANSPORT subcategory: TransportationMode = TransportationMode.TRAIN fuel_type: Union[TrainFuel, str] = TrainFuel.AVERAGE range: Union[BusTrainRange, str] = BusTrainRange.LONG_DISTANCE @@ -51,6 +53,7 @@ def check_size(cls, v): class TramEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.TRANSPORT subcategory: TransportationMode = TransportationMode.TRAM size: Union[Size, str] = Size.AVERAGE @@ -64,6 +67,7 @@ def check_size(cls, v): class CarEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.TRANSPORT subcategory: TransportationMode = TransportationMode.CAR fuel_type: Union[CarFuel, str] = CarFuel.AVERAGE size: Union[Size, str] = Size.AVERAGE @@ -86,6 +90,7 @@ def check_size(cls, v, values): class PlaneEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.TRANSPORT subcategory: TransportationMode = TransportationMode.PLANE seating: Union[FlightClass, str] = FlightClass.AVERAGE range: Union[FlightRange, str] @@ -108,6 +113,7 @@ def check_seating(cls, v): class FerryEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.TRANSPORT subcategory: TransportationMode = TransportationMode.FERRY seating: Union[FerryClass, str] = FerryClass.AVERAGE @@ -121,6 +127,7 @@ def check_seating(cls, v): class BusEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.TRANSPORT subcategory: TransportationMode = TransportationMode.BUS fuel_type: Union[BusFuel, str] = BusFuel.DIESEL size: Union[Size, str] = Size.AVERAGE @@ -151,6 +158,7 @@ def check_range(cls, v): class MotorbikeEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.TRANSPORT subcategory: TransportationMode = TransportationMode.MOTORBIKE size: Union[Size, str] = Size.AVERAGE @@ -164,7 +172,8 @@ def check_size(cls, v): class ElectricityEmissionParameters(BaseModel): - fuel_type: Union[Size, str] = ElectricityFuel.GERMAN_ENERGY_MIX + category: TransportationMode = EmissionCategory.ELECTRICITY + fuel_type: Union[Size, str] = ElectricityFuel.PRODUCTION_FUEL_MIX @validator("fuel_type", allow_reuse=True) def check_fueltype(cls, v): @@ -176,6 +185,7 @@ def check_fueltype(cls, v): class HeatingEmissionParameters(BaseModel): + category: TransportationMode = EmissionCategory.HEATING fuel_type: Union[Size, str] = HeatingFuel.GAS @validator("fuel_type", allow_reuse=True) diff --git a/data/emission_factors.csv b/data/emission_factors.csv index 2874f4b..664f412 100644 --- a/data/emission_factors.csv +++ b/data/emission_factors.csv @@ -1,4 +1,4 @@ -,country_code,category,subcategory,source,name,unit,size_class,range,fuel_type,co2e_unit,co2e,seating +,country_code,category,subcategory,source,name,unit,size,range,fuel_type,co2e_unit,co2e,seating 0,global,heating,,"UK, Department for Business, Energy & Industrial Strategy",coal (domestic),kWh,,,coal,kg/kWh,0.35, 1,global,heating,,"UK, Department for Business, Energy & Industrial Strategy",natural gas,kWh,,,gas,kg/kWh,0.18, 2,global,heating,,"UK, Department for Business, Energy & Industrial Strategy",LPG,kWh,,,liquid_gas,kg/kWh,0.21, diff --git a/docs/businesstrips.rst b/docs/businesstrips.rst new file mode 100644 index 0000000..ed1edbf --- /dev/null +++ b/docs/businesstrips.rst @@ -0,0 +1,30 @@ +============== +Business trips +============== + +.. toctree:: + :maxdepth: 2 + :caption: See also: + :titlesonly: + :includehidden: + + calculate/distances + calculate/transport_modes + +The calculation of emissions from business trips is currently supported for the following modes of transport: + +* car +* bus +* train +* plane +* ferry + +The user must specify either the distance of a trip or the location of departure and destination. +The distance (in km) may be used, when the user has the direct information of the distance travelled, e.g., from the speedometer of a car. +In other cases, the distance can be calculated from the given locations, see :ref:`Distance calculations `. +With the boolean paramter ``roundtrip``, users can indicate whether a trip was a roundtrip, in which case the distance wil be doubled. + +Aside of the mode of transport, the user should provide the specifica of the trip, depending on the mode of transport +(see :doc'Transportation modes ' :doc:`Emission factors `). + +.. autofunction:: co2calculator.calculate.calc_co2_businesstrip diff --git a/tests/functional/test_data_code_compliance.py b/tests/functional/test_data_code_compliance.py new file mode 100644 index 0000000..573175b --- /dev/null +++ b/tests/functional/test_data_code_compliance.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Check if values in the csv files are compliant with enums""" + +import pytest + +from co2calculator import HeatingFuel, emission_factors, ElectricityFuel + + +@pytest.mark.parametrize( + "column_name,enum,emission_category", + [ + pytest.param( + "fuel_type", HeatingFuel, "heating", id="fuel_type: 'HeatingFuel'" + ), + pytest.param( + "fuel_type", + ElectricityFuel, + "electricity", + id="fuel_type: 'ElectricityFuel'", + ), + ], +) +def test_enums_heating(column_name, enum, emission_category): + """Test whether all values in the csv files are present in the enums""" + + # Get unique values of the size column + column_values = emission_factors.databases[emission_category][column_name].unique() + + # Check if all column values are present in the enum + for v in column_values: + # skip is v is nan + if str(v) == "nan": + continue + assert v in ( + item.value for item in enum + ), f"'{v}' in column '{column_name}' of csv file is not contained in enum '{enum}'." + + # Check if all values in the enum are present in the emission factor csv file + for item in enum: + assert ( + item.value in column_values + ), f"Column '{enum}' in emission_factors.csv does not contain value '{item.value}' of enum 'Size'" diff --git a/tests/unit/test_data_handlers.py b/tests/unit/test_data_handlers.py new file mode 100644 index 0000000..004acbf --- /dev/null +++ b/tests/unit/test_data_handlers.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Test data handlers""" + +from co2calculator.data_handlers import EmissionFactors +import pandas as pd + + +def test_load_emission_factors(): + """Test if the emission factors are loaded correctly""" + emission_factors = EmissionFactors() + assert isinstance(emission_factors.heating, pd.DataFrame) + assert isinstance(emission_factors.electricity, pd.DataFrame) + assert isinstance(emission_factors.transport, pd.DataFrame)