def test_allocate_emissions(): emissions_dict = {} for method in ['iea', 'efficiency', 'finnish']: emissions_dict[method] = allocate_emissions(total_emissions=200, eta_el=0.3, eta_th=0.5, method=method, eta_el_ref=0.525, eta_th_ref=0.82) result = { 'iea': (75.0, 125.0), 'efficiency': (125.0, 75.0), 'finnish': (96.7551622418879, 103.24483775811208) } assert emissions_dict == result
def test_allocate_emission_series(): emissions_dict = {} for method in ['iea', 'efficiency', 'finnish']: emissions_dict[method] = allocate_emissions( total_emissions=pd.Series([200, 200]), eta_el=pd.Series([0.3, 0.3]), eta_th=pd.Series([0.5, 0.5]), method=method, eta_el_ref=pd.Series([0.525, 0.525]), eta_th_ref=pd.Series([0.82, 0.82])) default = { 'iea': (pd.Series([75.0, 75.0]), pd.Series([125.0, 125.0])), 'efficiency': (pd.Series([125.0, 125.0]), pd.Series([75.0, 75.0])), 'finnish': (pd.Series([96.7551622418879, 96.7551622418879]), pd.Series([103.24483775811208, 103.24483775811208])) } for key in default: for em_result, em_default in zip(emissions_dict[key], default[key]): assert em_result.equals(em_default),\ f"Result \n{em_result} does not match default \n{em_default}"
Example on emission allocation in cogeneration. """ import pandas as pd import matplotlib.pyplot as plt from oemof.thermal.cogeneration import allocate_emissions emissions_dict = {} for method in ['iea', 'efficiency', 'finnish']: emissions_dict[method] = allocate_emissions( total_emissions=200, # Arbitrary units. Assume [kgCO2]. eta_el=0.3, eta_th=0.5, method=method, eta_el_ref=0.525, eta_th_ref=0.82) df = pd.DataFrame(emissions_dict, index=['el', 'th']).T print(df) fig, ax = plt.subplots() df.loc[:, 'el'] *= -1 bars = df.plot.barh(stacked=True, ax=ax) for i, (el, th) in enumerate(zip(df['el'], df['th'])): ax.text(el, i, round(-el), ha='left') ax.text(th, i, round(th), ha='right')