def add_pp_limit(table_collection, year): """ Parameters ---------- table_collection year Returns ------- """ if len(cfg.get_list("creator", "limited_transformer")) > 0: # Multiply with 1000 to get MWh (bmwi: GWh) repp = bmwi.bmwi_re_energy_capacity() * 1000 trsf = table_collection["power plants"] for limit_trsf in cfg.get_list("creator", "limited_transformer"): trsf = table_collection["power plants"] try: limit = repp.loc[year, (limit_trsf, "energy")] except KeyError: msg = "Cannot calculate limit for {0} in {1}." raise ValueError(msg.format(limit_trsf, year)) cond = trsf["fuel"] == limit_trsf cap_sum = trsf.loc[pd.Series(cond)[cond].index, "capacity"].sum() trsf.loc[pd.Series(cond)[cond].index, "limit_elec_pp"] = ( trsf.loc[pd.Series(cond)[cond].index, "capacity"].div(cap_sum).multiply(limit) + 0.5) trsf["limit_elec_pp"] = trsf["limit_elec_pp"].fillna(float("inf")) table_collection["power plants"] = trsf return table_collection
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 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, )
def aggregate_by_region_hydro(pp, regions, year, outfile_name): """Aggregate hydro power plants by region.""" hydro = bmwi.bmwi_re_energy_capacity()["water"] hydro_capacity = pp.loc["Hydro", "capacity_{0}".format(year)].sum() full_load_hours = hydro.loc[year, "energy"] / hydro_capacity * 1000 hydro_path = os.path.abspath(os.path.join(*outfile_name.split("/")[:-1])) if not os.path.isdir(hydro_path): os.makedirs(hydro_path) idx = pd.date_range( start="{0}-01-01 00:00".format(year), end="{0}-12-31 23:00".format(year), freq="H", tz="Europe/Berlin", ) feed_in = pd.DataFrame(columns=regions, index=idx) feed_in[feed_in.columns] = full_load_hours / len(feed_in) feed_in.to_csv(outfile_name)
def add_pp_limit(table_collection, year): """ Parameters ---------- table_collection year Returns ------- """ if len(cfg.get_dict("limited_transformer").keys()) > 0: # Multiply with 1000 to get MWh (bmwi: GWh) repp = bmwi.bmwi_re_energy_capacity() * 1000 trsf = table_collection["transformer"] for limit_trsf in cfg.get_dict("limited_transformer").keys(): trsf = table_collection["transformer"] try: limit = repp.loc[year, (limit_trsf, "energy")] except KeyError: msg = "Cannot calculate limit for {0} in {1}." raise ValueError(msg.format(limit_trsf, year)) cap_sum = trsf.loc["capacity", (slice(None), slice(limit_trsf))].sum() for region in trsf.columns.get_level_values(level=0).unique(): trsf.loc["limit_elec_pp", (region, limit_trsf)] = round(trsf.loc["capacity", (region, limit_trsf)] / cap_sum * limit + 0.5) trsf.loc["limit_elec_pp"] = trsf.loc["limit_elec_pp"].fillna( float("inf")) table_collection["transformer"] = trsf return table_collection