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 create_pvlib_sets(): """Create pvlib parameter sets from the solar.ini file. Returns ------- dict """ # get module and inverter parameter from sandia database sandia_modules = pvlib.pvsystem.retrieve_sam('sandiamod') sapm_inverters = pvlib.pvsystem.retrieve_sam('sandiainverter') pvlib_sets = cfg.get_list('solar', 'set_list') pvsets = {} for pvlib_set in pvlib_sets: set_name = cfg.get(pvlib_set, 'pv_set_name') module_name = cfg.get(pvlib_set, 'module_name') module_key = cfg.get(pvlib_set, 'module_key') inverter = cfg.get(pvlib_set, 'inverter_name') azimuth_angles = cfg.get_list(pvlib_set, 'surface_azimuth') tilt_angles = cfg.get_list(pvlib_set, 'surface_tilt') albedo_values = cfg.get_list(pvlib_set, 'albedo') set_idx = 0 pvsets[set_name] = {} for t in tilt_angles: if t == '0': az_angles = (0, ) else: az_angles = azimuth_angles for a in az_angles: for alb in albedo_values: set_idx += 1 pvsets[set_name][set_idx] = { 'module_parameters': sandia_modules[module_name], 'inverter_parameters': sapm_inverters[inverter], 'surface_azimuth': float(a), 'surface_tilt': t, 'albedo': float(alb) } pvsets[set_name][set_idx]['p_peak'] = ( pvsets[set_name][set_idx]['module_parameters'].Impo * pvsets[set_name][set_idx]['module_parameters'].Vmpo) pvsets[set_name][set_idx]['name'] = "_".join([ module_key, inverter[:3], "tlt{}".format(t[:3].rjust(3, '0')), "az{}".format(str(a).rjust(3, '0')), "alb{}".format(str(alb).replace('.', '')) ]) logging.debug("PV set: {}".format( pvsets[set_name][set_idx]['name'])) return pvsets
def create_windpowerlib_sets(): """Create parameter sets for the windpowerlib from wind.ini. Returns ------- dict Examples -------- >>> wind_set = create_windpowerlib_sets()['ENERCON_82_hub98_2300'][1] >>> wind_set['hub_height'] 98 >>> sorted(list(create_windpowerlib_sets().keys()))[:2] ['ENERCON_127_hub135_7500', 'ENERCON_82_hub138_2300'] >>> for key in sorted(wind_set.keys()): ... print(key) fetch_curve hub_height name nominal_power rotor_diameter """ windpowerlib_sets = cfg.get_list('wind', 'set_list') # Only one subset is created but following the pvlib sets it is possible # to create subsets. windsets = {} for windpowerlib_set in windpowerlib_sets: w_set = {1: cfg.get_dict(windpowerlib_set)} set_name = w_set[1].pop('set_name') windsets[set_name] = w_set return windsets
def pp_reegis2deflex(clean_offshore=True): 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 deflex_regions = deflex.geometries.deflex_regions() name = '{0}_region'.format(cfg.get('init', 'map')) pp = reegis.powerplants.add_regions_to_powerplants(deflex_regions, name) federal_states = reegis.geometries.load( cfg.get('paths', 'geometry'), cfg.get('geometry', 'federalstates_polygon')) pp = reegis.powerplants.add_regions_to_powerplants(federal_states, 'federal_states', pp=pp) # Remove PHES (storages) if cfg.get('powerplants', 'remove_phes'): pp = pp.loc[pp.technology != 'Pumped storage'] # Remove powerplants outside Germany for state in cfg.get_list('powerplants', 'remove_states'): pp = pp.loc[pp.state != state] if clean_offshore: pp = remove_onshore_technology_from_offshore_regions(pp) pp.to_hdf(filename_out, 'pp') return filename_out
def test_get_function(): """Read config file.""" files = [ os.path.join(os.path.dirname(__file__), "data", "config_test.ini") ] config.init(files=files) ok_(config.get("type_tester", "my_bool")) ok_(isinstance(config.get("type_tester", "my_int"), int)) ok_(isinstance(config.get("type_tester", "my_float"), float)) ok_(isinstance(config.get("type_tester", "my_string"), str)) ok_(isinstance(config.get("type_tester", "my_None"), type(None))) ok_(isinstance(config.get("type_tester", "my_list"), str)) eq_(int(config.get_list("type_tester", "my_list")[2]), 7)
def create_windpowerlib_sets(): """Create parameter sets for the windpowerlib from wind.ini. Returns ------- dict """ windpowerlib_sets = cfg.get_list('wind', 'set_list') # Only one subset is created but following the pvlib sets it is possible # to create subsets. windsets = {} for windpowerlib_set in windpowerlib_sets: w_set = {1: cfg.get_dict(windpowerlib_set)} set_name = w_set[1].pop('set_name') windsets[set_name] = w_set return windsets
def get_map_config(): maps = {} keys = cfg.get_list('fis_broker', 'maps') for key in keys: maps[key] = cfg.get_dict(key) return maps
def create_pvlib_sets(): """Create pvlib parameter sets from the solar.ini file. Returns ------- dict Examples -------- >>> pv_set=create_pvlib_sets()['M_LG290G3__I_ABB_MICRO_025_US208'][3] >>> int(pv_set['surface_azimuth']) 180 >>> for key in sorted(pv_set.keys()): ... print(key) albedo inverter_parameters module_parameters name p_peak surface_azimuth surface_tilt """ # get module and inverter parameter from sandia database sandia_modules = pvlib.pvsystem.retrieve_sam("sandiamod") sapm_inverters = pvlib.pvsystem.retrieve_sam("sandiainverter") pvlib_sets = cfg.get_list("solar", "set_list") pvsets = {} for pvlib_set in pvlib_sets: set_name = cfg.get(pvlib_set, "pv_set_name") module_name = cfg.get(pvlib_set, "module_name") module_key = cfg.get(pvlib_set, "module_key") inverter = cfg.get(pvlib_set, "inverter_name") azimuth_angles = cfg.get_list(pvlib_set, "surface_azimuth") tilt_angles = cfg.get_list(pvlib_set, "surface_tilt") albedo_values = cfg.get_list(pvlib_set, "albedo") set_idx = 0 pvsets[set_name] = {} for t in tilt_angles: if t == "0": az_angles = (0, ) else: az_angles = azimuth_angles for a in az_angles: for alb in albedo_values: set_idx += 1 pvsets[set_name][set_idx] = { "module_parameters": sandia_modules[module_name], "inverter_parameters": sapm_inverters[inverter], "surface_azimuth": float(a), "surface_tilt": t, "albedo": float(alb), } pvsets[set_name][set_idx]["p_peak"] = ( pvsets[set_name][set_idx]["module_parameters"].Impo * pvsets[set_name][set_idx]["module_parameters"].Vmpo) pvsets[set_name][set_idx]["name"] = "_".join([ module_key, inverter[:3], "tlt{}".format(t[:3].rjust(3, "0")), "az{}".format(str(a).rjust(3, "0")), "alb{}".format(str(alb).replace(".", "")), ]) logging.debug("PV set: {}".format( pvsets[set_name][set_idx]["name"])) return pvsets
def get_heat_profiles_deflex(deflex_geo, year, time_index=None, weather_year=None, keep_unit=False): """ Parameters ---------- year deflex_geo time_index weather_year keep_unit Returns ------- """ # separate_regions=keep all demand connected to the region separate_regions = cfg.get_list("creator", "separate_heat_regions") # Add lower and upper cases to be not case sensitive separate_regions = [x.upper() for x in separate_regions ] + [x.lower() for x in separate_regions] # add second fuel to first # combine_fuels = cfg.get_dict("combine_heat_fuels") combine_fuels = {"natural gas": "gas"} # fuels to be dissolved per region region_fuels = cfg.get_list("creator", "local_fuels") fn = os.path.join( cfg.get("paths", "demand"), "heat_profiles_{year}_{map}".format(year=year, map=deflex_geo.name), ) demand_region = (demand_heat.get_heat_profiles_by_region( deflex_geo, year, to_csv=fn, weather_year=weather_year).groupby(level=[0, 1], axis=1).sum()) # Decentralised demand is combined to a nation-wide demand if not part # of region_fuels. regions = list( set(demand_region.columns.get_level_values(0).unique()) - set(separate_regions)) # If region_fuels is 'all' fetch all fuels to be local. if "all" in region_fuels: region_fuels = demand_region.columns.get_level_values(1).unique() for fuel in demand_region.columns.get_level_values(1).unique(): demand_region["DE", fuel] = 0 for region in regions: for f1, f2 in combine_fuels.items(): demand_region[region, f1] += demand_region[region, f2] demand_region.drop((region, f2), axis=1, inplace=True) cols = list(set(demand_region[region].columns) - set(region_fuels)) for col in cols: demand_region["DE", col] += demand_region[region, col] demand_region.drop((region, col), axis=1, inplace=True) if time_index is not None: demand_region.index = time_index if not keep_unit: msg = ("The unit of the source is 'TJ'. " "Will be divided by {0} to get 'MWh'.") converter = 0.0036 demand_region = demand_region.div(converter) logging.debug(msg.format(converter)) demand_region.sort_index(1, inplace=True) for c in demand_region.columns: if demand_region[c].sum() == 0: demand_region.drop(c, axis=1, inplace=True) return demand_region