def calculate_inhabitants_friedrichshagen(year, geo=None): if geo is None: fhg_fn = os.path.join(cfg.get('paths', 'geo_berlin'), cfg.get('geometry', 'friedrichshagen_block')) geo_fhg = geometries.load(fullname=fhg_fn, index_col='BZR_NAME') else: geo_fhg = geo return get_inhabitants(geo_fhg, 'brz_name').loc[geo_fhg.index[0], 'EW']
def calculate_inhabitants_districts(year, geo=None): if geo is None: berlin_district_fn = os.path.join( cfg.get('paths', 'geo_berlin'), cfg.get('geometry', 'berlin_bezirke')) geo_bln = geometries.load(fullname=berlin_district_fn, index_col='BEZIRK') else: geo_bln = geo return get_inhabitants(geo_bln, 'bezirk')
def installed_pv_capacity(): table = cfg.get('pv_map', 'table') path = os.path.join(cfg.get('paths', 'fis_broker'), table, 'shp') shapefile = os.path.join(path, table + '.shp') if not os.path.isfile(shapefile): new_shapefile = download.download_maps(single='pv_map') if new_shapefile != shapefile: msg = "Wrong path will download this file every time {0} : {1}" logging.error(msg.format(shapefile, new_shapefile)) shapefile = new_shapefile pv_cap = gpd.read_file(shapefile) pv_cap['spatial_na'] = pv_cap['gml_id'].str.split('.', expand=True)[1] pv_cap.set_index('spatial_na', inplace=True) return round(pv_cap.loc['090517'].BZR_GLEIST / 1000, 3)
def get_inhabitants(polygon, name): """The inhabitants of 2016 are used.""" table = 'ew' cfg_data = cfg.get_dict(table) ew_fn = os.path.join(cfg.get('paths', 'fis_broker'), cfg_data['table'], 'shp', cfg_data['table'] + '.shp') logging.debug("Reading {0}".format(ew_fn)) if not os.path.isfile(ew_fn): ew_fn = download.download_maps(single=table) ew = geometries.load(fullname=ew_fn) ew['centroid_column'] = ew.representative_point() ew = ew.set_geometry('centroid_column') neu = geometries.spatial_join_with_buffer( ew, polygon, name=name, limit=0, ) grp = neu.groupby(name).sum() grp['frac'] = grp['EW'].div(grp.sum()['EW']).multiply(100).round(1) return grp
def main(year, overwrite=False): stopwatch() name = '{0}_{1}_{2}'.format('friedrichshagen', year, 'single') sc = Scenario(name=name, year=year, debug=False) path = os.path.join(cfg.get('paths', 'scenario'), 'friedrichshagen') logging.info("Read scenario from excel-sheet: {0}".format(stopwatch())) excel_fn = os.path.join(path, name + '.xls') if not os.path.isfile(excel_fn) or overwrite: create_basic_scenario(year) sc.load_excel(excel_fn) sc.check_table('time_series') logging.info("Add nodes to the EnergySystem: {0}".format(stopwatch())) sc.es = sc.initialise_energy_system() nodes = sc.create_nodes(region='FHG') sc.es.add(*nodes.values()) # Save energySystem to '.graphml' file. sc.plot_nodes(filename=os.path.join(path, 'friedrichshagen'), remove_nodes_with_substrings=['bus_cs']) logging.info("Create the concrete model: {0}".format(stopwatch())) sc.create_model() logging.info("Solve the optimisation model: {0}".format(stopwatch())) sc.solve() logging.info("Solved. Dump results: {0}".format(stopwatch())) results_path = os.path.join( path, 'results_{0}'.format(cfg.get('general', 'solver'))) if not os.path.isdir(results_path): os.mkdir(results_path) sc.dump_es( os.path.join(results_path, 'friedrichshagen_{0}_single.esys'.format(str(year)))) logging.info( "All done. friedrichshagen finished without errors: {0}".format( stopwatch()))
def scenario_powerplants(year, ts): pp = pd.read_csv(os.path.join( cfg.get('paths', 'data_berlin'), cfg.get('powerplants', 'powerplants_friedrichshagen')), index_col=[0]) pp = pp.loc[(pp.commission < year) & (pp.decommission >= year)] pp.columns = pd.MultiIndex.from_product([['FHG'], pp.columns]) dec_dh = ts['district_heating_demand', 'decentralised_dh'] # # Fetch config values from scenario.ini # share_hp_chp = cfg.get('decentralised_chp', 'share_hp_chp') # over_cap = cfg.get('decentralised_chp', 'overcapacity_factor') # eff_chp_heat = cfg.get('decentralised_chp', 'efficiency_chp_heat') # eff_chp_elec = cfg.get('decentralised_chp', 'efficiency_chp_elec') # eff_heat = cfg.get('decentralised_chp', 'efficiency_heat') # heat_capacity = dec_dh.max() * over_cap # # # decentralised CHP blocks # pp.loc['decentralised CHP-blocks', ('BE', 'fuel')] = 'natural_gas' # pp.loc['decentralised CHP-blocks', ('BE', 'capacity_elec')] = round( # heat_capacity * (1 - share_hp_chp) / eff_chp_heat * eff_chp_elec) # pp.loc['decentralised CHP-blocks', ('BE', 'capacity_heat')] = round( # heat_capacity * (1 - share_hp_chp)) # pp.loc['decentralised CHP-blocks', ('BE', 'efficiency')] = ( # eff_chp_elec + eff_chp_heat) # pp.loc['decentralised CHP-blocks', ('BE', 'type')] = 'FIX' # pp.loc['decentralised CHP-blocks', ('BE', 'network')] = 'decentralised_dh' # # # decentralised heat devices # pp.loc['decentralised heat-blocks', ('BE', 'fuel')] = 'natural_gas' # pp.loc['decentralised heat-blocks', ('BE', 'capacity_heat')] = round( # heat_capacity * share_hp_chp) # pp.loc['decentralised heat-blocks', ('BE', 'efficiency')] = eff_heat # pp.loc['decentralised heat-blocks', ('BE', 'type')] = 'HP' # pp.loc['decentralised heat-blocks', ('BE', 'network')] = 'decentralised_dh' return pp
def create_basic_scenario(year, excel=None): table_collection = create_scenario(year) name = '{0}_{1}_{2}'.format('friedrichshagen', year, 'single') sce = scenario_tools.Scenario(table_collection=table_collection, name=name, year=year) path = os.path.join(cfg.get('paths', 'scenario'), 'friedrichshagen') if excel is None: excel = os.path.join(path, name + '.xls') csv_path = os.path.join(path, '{0}_csv'.format(name)) else: csv_path = excel[:-4] + '_csv' os.makedirs(csv_path, exist_ok=True) sce.to_excel(excel) sce.to_csv(csv_path)
def main(year): stopwatch() sc = berlin_hp.Scenario(name='berlin_hp', year=year, debug=False) path = os.path.join(cfg.get('paths', 'scenario'), 'berlin_hp', str(year)) logging.info("Read scenario from excel-sheet: {0}".format(stopwatch())) excel_fn = os.path.join( path, '_'.join(['berlin_hp', str(year), 'single']) + '.xls') if not os.path.isfile(excel_fn): berlin_hp.basic_scenario.create_basic_scenario(year) sc.load_excel(excel_fn) sc.check_table('time_series') logging.info("Add nodes to the EnergySystem: {0}".format(stopwatch())) sc.add_nodes2solph() # Save energySystem to '.graphml' file. sc.plot_nodes(filename=os.path.join(path, 'berlin_hp'), remove_nodes_with_substrings=['bus_cs']) logging.info("Create the concrete model: {0}".format(stopwatch())) sc.create_model() logging.info("Solve the optimisation model: {0}".format(stopwatch())) sc.solve() logging.info("Solved. Dump results: {0}".format(stopwatch())) sc.dump_es( os.path.join(path, 'berlin_hp_{0}_single.esys'.format(str(year)))) logging.info("All done. berlin_hp finished without errors: {0}".format( stopwatch()))
def decentralised_heating(): filename = os.path.join(cfg.get('paths', 'data_berlin'), cfg.get('heating', 'table')) return pd.read_csv(filename, header=[0, 1], index_col=[0])