def pp_reegis2deflex(regions, name, filename_in=None, filename_out=None): """ Add federal states and deflex regions to powerplant table from reegis. As the process takes a while the result is stored for further usage. Returns ------- str : The full path where the result file is stored. """ if filename_out is None: filename_out = os.path.join( cfg.get("paths", "powerplants"), cfg.get("powerplants", "deflex_pp"), ).format(map=cfg.get("init", "map")) # Add deflex regions to powerplants pp = powerplants.add_regions_to_powerplants(regions, name, dump=False, filename=filename_in) # Add federal states to powerplants federal_states = reegis_geometries.get_federal_states_polygon() pp = powerplants.add_regions_to_powerplants(federal_states, "federal_states", pp=pp, dump=False) # store the results for further usage of deflex pp.to_hdf(filename_out, "pp") return filename_out
def test_opsd2reegis(): path = os.path.join(os.path.dirname(__file__), 'data') cfg.tmp_set('paths', 'opsd', path) cfg.tmp_set('paths', 'powerplants', path) fn_opsd = opsd.opsd_power_plants() fn_reegis = powerplants.pp_opsd2reegis() os.remove(fn_opsd) filename = str(fn_reegis.split(os.sep)[-1]) geo_path = cfg.get('paths', 'geometry') geo_file = cfg.get('geometry', 'federalstates_polygon') gdf = geo.load(path=geo_path, filename=geo_file) powerplants.add_regions_to_powerplants( gdf, 'fed_states', filename=filename, path=path, dump=True) geo_path = cfg.get('paths', 'geometry') geo_file = cfg.get('coastdat', 'coastdatgrid_polygon') gdf = geo.load(path=geo_path, filename=geo_file) pp = powerplants.add_regions_to_powerplants( gdf, 'coastdat2', filename=filename, path=path, dump=False) os.remove(fn_reegis) eq_(int(pp.groupby('fed_states').sum().loc['BE', 'capacity']), 2427) year = 2000 pp = powerplants.get_reegis_powerplants(year, pp=pp) eq_(int(pp.groupby('fed_states').sum().loc['BE', 'capacity_2000']), 2391) eq_(coastdat.windzone_region_fraction( pp, name='fed_states', year=year).round(2).loc['NI', 3], 0.24)
def test_004(self): opsd.opsd_power_plants = MagicMock(return_value="/home/pet/pp.h5") with assert_raises_regexp(Exception, "File /home/pet/pp.h5 does not exist"): powerplants.add_regions_to_powerplants(self.gdf1, "fed_states") with assert_raises_regexp(Exception, "File /home/pet/pp.h5 does not exist"): powerplants.get_reegis_powerplants(2013)
def setup_class(cls): path = os.path.join(os.path.dirname(__file__), "data") cfg.tmp_set("paths_pattern", "opsd", path) cfg.tmp_set("paths", "powerplants", path) fn_opsd = opsd.opsd_power_plants() os.remove(fn_opsd) fn_opsd = os.path.join(cfg.get("paths_pattern", "opsd"), cfg.get("opsd", "opsd_prepared")) fn_test = fn_opsd.replace(".h5", "_test.h5") copyfile(fn_test, fn_opsd) fn_reegis = powerplants.pp_opsd2reegis() os.remove(fn_opsd) filename = str(fn_reegis.split(os.sep)[-1]) cls.gdf1 = geo.get_federal_states_polygon() powerplants.add_regions_to_powerplants(cls.gdf1, "fed_states", filename=filename, path=path, dump=True) geo_path = cfg.get("paths", "geometry") geo_file = cfg.get("coastdat", "coastdatgrid_polygon") gdf2 = geo.load(path=geo_path, filename=geo_file) cls.pp = powerplants.add_regions_to_powerplants(gdf2, "coastdat2", filename=filename, path=path, dump=False) year = 2014 cls.pp2 = powerplants.get_powerplants_by_region( cls.gdf1, year, "my_states") cls.pp2["efficiency_{0}".format(year)] = cls.pp2["capacity_{0}".format( year)].div(cls.pp2["capacity_in_{0}".format(year)]) cls.pp2.drop( ["capacity", "capacity_in", "thermal_capacity"], axis=1, inplace=True, ) fn_reegis2 = fn_reegis.replace(".h5", "_my_states.h5") os.remove(fn_reegis2) os.remove(fn_reegis) rmtree(os.path.join(path, "messages"))
def get_feedin_per_region( year, region, name, weather_year=None, windzones=True, subregion=False, pp=None, ): """ Aggregate feed-in time series for the given geometry set. Parameters ---------- year : int region : geopandas.geoDataFrame name : str weather_year : int windzones : bool pp : pd.DataFrame or None subregion : bool Set to True if all region polygons together are a subregion of Germany. This will switch off the buffer in the spatial_join function. Notes ----- The feedin is calculated per region entry (row of the region CSV / GeoDF), the output file will contain columns per region entry and generator set entry. E.g. a file with 10 regions and 2 wind generators will result in 20 different feedin timeseries. Example region file: federalstates_polygon.csv You may want to use geometries.load() to import a region CSV. """ # create and dump reegis basic powerplants table (created from opsd data) fn = powerplants.pp_opsd2reegis() filename = fn.split(os.sep)[-1] path = fn.replace(filename, "") # Add column name "coastdat2" with the id of the coastdat weather cell for # each power plant. geo_path = cfg.get("paths", "geometry") geo_file = cfg.get("coastdat", "coastdatgrid_polygon") gdf = geometries.load(path=geo_path, filename=geo_file) pp = powerplants.add_regions_to_powerplants(gdf, "coastdat2", filename=filename, path=path, pp=pp) # Add a column named with the name parameter, adding the region id to # each power plant pp = powerplants.add_regions_to_powerplants(region, name, filename=filename, path=path, pp=pp, subregion=subregion) # Get only the power plants that are online in the given year. pp = powerplants.get_reegis_powerplants(year, pp=pp) if windzones: windzone_region_fraction(pp, name, year=year, dump=True) # Aggregate feedin time series for each region return aggregate_feedin_by_region(year, pp, name, weather_year=weather_year)