def read_bmwi_sheet_7_test(): test_path = os.path.join(os.path.dirname(__file__), 'data', 'temp') os.makedirs(test_path, exist_ok=True) cfg.tmp_set('paths', 'general', test_path) eq_(bmwi.bmwi_re_energy_capacity().loc[2016, ('water', 'capacity')], 5601) eq_(bmwi.get_annual_electricity_demand_bmwi(2014), 523.988) eq_(bmwi.get_annual_electricity_demand_bmwi(1900), None) fs = bmwi.read_bmwi_sheet_7('a').sort_index() total = int(float(fs.loc[('Industrie', 'gesamt'), 2014])) eq_(total, 2545) fs = bmwi.read_bmwi_sheet_7('b').sort_index() total = int(float(fs.loc[('private Haushalte', 'gesamt'), 2014])) eq_(total, 2188)
def get_ego_demand_bmwi_by_region(year, regions, name): demand = ego_demand_by_region(regions, name) summe = demand['consumption'].sum() annual = bmwi.get_annual_electricity_demand_bmwi(year) factor = annual * 1000 / summe demand['consumption'] = demand['consumption'].mul(factor) return demand
def fig_energy_demand_germany_bmwi(): """ Time series of the energy demand of Germany from 1991 to 2015. """ df = pd.Series() ax = plt.figure(figsize=(9, 4)).add_subplot(1, 1, 1) for year in range(1991, 2016): print(year) df.loc[year] = bmwi.get_annual_electricity_demand_bmwi(year) df.plot(ax=ax) ax.set_ylabel("energy demand [TWh]") plt.ylim(0, 600) plt.title("Energy demand in Germany from 1991 to 2015") return "energy_demand_germany_bmwi"
def test_read_bmwi_sheet_7(): test_path = os.path.join(os.path.dirname(__file__), "data", "temp") os.makedirs(test_path, exist_ok=True) eq_(bmwi.bmwi_re_energy_capacity().loc[2016, ("water", "capacity")], 5629) eq_(bmwi.get_annual_electricity_demand_bmwi(2014), 523.988) fs = bmwi.read_bmwi_sheet_7("a").sort_index() total = int(float(fs.loc[("Industrie", "gesamt"), 2014])) eq_(total, 2545) fs = bmwi.read_bmwi_sheet_7("b").sort_index() total = int(float(fs.loc[("private Haushalte", "gesamt"), 2014])) eq_(total, 2188) assert_raises_regexp( ValueError, "No BMWi electricity demand found", bmwi.get_annual_electricity_demand_bmwi, year=1900, )
return ego_demand def get_ego_demand_by_federal_states(year=None): federal_states = geometries.load( cfg.get('paths', 'geometry'), cfg.get('geometry', 'federalstates_polygon')) if year is None: return ego_demand_by_region(federal_states, 'federal_states') else: return get_ego_demand_bmwi_by_region(year, federal_states, 'federal_states') def get_ego_demand_bmwi_by_region(year, regions, name): demand = ego_demand_by_region(regions, name) summe = demand['consumption'].sum() annual = bmwi.get_annual_electricity_demand_bmwi(year) factor = annual * 1000 / summe demand['consumption'] = demand['consumption'].mul(factor) return demand if __name__ == "__main__": logger.define_logging() my_demand = get_ego_demand_by_federal_states().groupby( 'federal_states').sum()['consumption'] print(my_demand.sum()) print(bmwi.get_annual_electricity_demand_bmwi(2014) * 1000) print(get_ego_demand_by_federal_states(year=2014).sum()['consumption'])
def get_entsoe_profile_by_region(region, year, name, annual_demand, version=None): """ Parameters ---------- region year name annual_demand : str or numeric A numeric annual value or a method to fetch the annual value. Valid methods are: bmwi, entsoe, openego version : str or None Version of the opsd file. If set to "None" the latest version is used. Returns ------- pandas.DataFrame : A table with a time series for each region. The unit is MW for the internal methods or the same unit order as the input of the annual_demand parameter. Examples -------- >>> my_fs=geometries.get_federal_states_polygon() >>> d1=get_entsoe_profile_by_region(my_fs, 2014, 'federal_states', 'entsoe' ... ) # doctest: +SKIP >>> int(d1.sum().sum()) # doctest: +SKIP 519757349 >>> d2=get_entsoe_profile_by_region(my_fs, 2014, 'federal_states', 'bmwi' ... ) # doctest: +SKIP >>> int(d2.sum().sum()) # doctest: +SKIP 523988000 >>> d3=get_entsoe_profile_by_region(my_fs, 2014, 'federal_states', 200000 ... ) # doctest: +SKIP >>> round(d3.sum().sum()) # doctest: +SKIP 200000.0 """ logging.debug("Get entsoe profile {0} for {1}".format(name, year)) profile = entsoe.get_entsoe_load(year, version=version)["DE_load_"] idx = profile.index profile.reset_index(drop=True, inplace=True) norm_profile = profile.div(profile.sum() / 1000000) ego_demand = openego.get_ego_demand_by_region(region, name, grouped=True) if annual_demand == "bmwi": annual_demand = (bmwi_data.get_annual_electricity_demand_bmwi(year) * 10**6) elif annual_demand == "entsoe": annual_demand = profile.sum() elif annual_demand == "openego": annual_demand = ego_demand.sum() * 10**3 elif isinstance(annual_demand, (int, float)): pass else: msg = ("{0} of type {1} is not a valid input for 'annual_demand'.\n" "Use 'bmwi', 'entsoe' or a float/int value.") raise ValueError(msg.format(annual_demand, type(annual_demand))) demand_fs = (ego_demand.div(ego_demand.sum() / 1000).mul(annual_demand).div(1000)) df = (pd.DataFrame([demand_fs.values] * len(norm_profile), columns=demand_fs.index).mul(norm_profile, axis=0).div(1000000)) return df.set_index(idx.tz_convert("Europe/Berlin"))
def table_model_regions(path, year=2014): table = pd.DataFrame( columns=pd.MultiIndex(levels=[[], []], codes=[[], []])) # table = pd.read_excel( # os.path.join(path, 'kennzahlen_modellregionen' + '.xlsx'), # index_col=[0], header=[0, 1]) # inhabitants ew = inhabitants.get_ew_by_federal_states(year) ew_bln = friedrichshagen.calculate_inhabitants_districts(year)['EW'].sum() fhg_ew = friedrichshagen.calculate_inhabitants_friedrichshagen(year) ew_de01 = deflex.inhabitants.get_ew_by_deflex(2014, rmap='de21')['DE01'] # electricity_demand fhg_elec = friedrichshagen.calculate_elec_demand_friedrichshagen( year).sum() bln_share = deflex.demand.openego_demand_share()['DE22'] de01_share = deflex.demand.openego_demand_share()[['DE22', 'DE01']].sum() bln_usage = berlin_hp.electricity.get_electricity_demand(year).sum()[ 'usage'] de_demand = bmwi.get_annual_electricity_demand_bmwi(2014) * 1000 # heat demand bln_heat = berlin_hp.heat.create_heat_profiles(2014).sum().sum() / 1000 fhg_heat = berlin_hp.heat.create_heat_profiles( 2014, region=90517).sum().sum() / 1000 heat_states = deflex.demand.get_heat_profiles_by_state(2014).groupby( level=0, axis=1).sum().sum().div(3.6) de01_heat = deflex.demand.get_heat_profiles_deflex( 2014, separate_regions=['DE01'])['DE01'].sum().sum() / 1000 sec = 'Bevölkerung' table.loc[sec, ('Berlin (deflex)', 'absolut')] = int(ew['BE']) table.loc[sec, ('Berlin', 'absolut')] = ew_bln table.loc[sec, ('Modellregion', 'absolut')] = int(fhg_ew) table.loc[sec, ('Deutschland', 'absolut')] = int(ew.sum()) table.loc[sec, ('DE01 (de21)', 'absolut')] = int(ew_de01) sec = 'Strombedarf [GWh]' table.loc[sec, ('Berlin (deflex)', 'absolut')] = int(bln_share * de_demand) table.loc[sec, ('Berlin', 'absolut')] = bln_usage table.loc[sec, ('Modellregion', 'absolut')] = int(fhg_elec.sum()) table.loc[sec, ('Deutschland', 'absolut')] = int(de_demand) table.loc[sec, ('DE01 (de21)', 'absolut')] = int(de01_share * de_demand) sec = 'Wärmebedarf [GWh]' table.loc[sec, ('Berlin (deflex)', 'absolut')] = int(heat_states['BE']) table.loc[sec, ('Berlin', 'absolut')] = int(bln_heat) table.loc[sec, ('Modellregion', 'absolut')] = int(fhg_heat) table.loc[sec, ('Deutschland', 'absolut')] = int(heat_states.sum()) table.loc[sec, ('DE01 (de21)', 'absolut')] = int(de01_heat) for c in table.columns.get_level_values(0).unique(): table[c, '%'] = round(table[c, 'absolut'].div( table['Deutschland', 'absolut']).multiply(100), 2) table = table[['Modellregion', 'Berlin', 'Berlin (deflex)', 'DE01 (de21)', 'Deutschland']] print(table) table.to_csv(os.path.join(path, 'kennzahlen_modellregionen' + '.csv'))