def simple_profile(self, annual_demand, **kwargs): """ Create industrial load profile Parameters ---------- annual_demand : float Total demand. Other Parameters ---------------- am : datetime.time beginning of workday pm : datetime.time end of workday week : list list of weekdays weekend : list list of weekend days profile_factors : dictionary dictionary with scaling factors for night and day of weekdays and weekend days """ # Day(am to pm), night (pm to am), week day (week), # weekend day (weekend) am = kwargs.get('am', settime(7, 00, 0)) pm = kwargs.get('pm', settime(23, 30, 0)) week = kwargs.get('week', [1, 2, 3, 4, 5]) weekend = kwargs.get('weekend', [0, 6, 7]) default_factors = {'week': {'day': 0.8, 'night': 0.6}, 'weekend': {'day': 0.9, 'night': 0.7}} profile_factors = kwargs.get('profile_factors', default_factors) self.dataframe['ind'] = 0 self.dataframe['ind'].mask( self.dataframe['weekday'].between_time(am, pm).isin(week), profile_factors['week']['day'], True) self.dataframe['ind'].mask( self.dataframe['weekday'].between_time(pm, am).isin(week), profile_factors['week']['night'], True) self.dataframe['ind'].mask( self.dataframe['weekday'].between_time(am, pm).isin(weekend), profile_factors['weekend']['day'], True) self.dataframe['ind'].mask( self.dataframe['weekday'].between_time(pm, am).isin(weekend), profile_factors['weekend']['night'], True) if self.dataframe['ind'].isnull().any(axis=0): logging.error('NAN value found in industrial load profile') time_interval = self.dataframe.index.freq.nanos / 3.6e12 return (self.dataframe['ind'] / self.dataframe['ind'].sum() * annual_demand / time_interval)
def ind_profile_parameters(): """ Get parameters for industrial load profiles. """ am = settime(7, 0, 0) pm = settime(20, 00, 0) profile_factors = { 'week': { 'day': 0.8, 'night': 0.6 }, 'weekend': { 'day': 0.9, 'night': 0.7 } } return am, pm, profile_factors
def power_example(): year = 2010 ann_el_demand_per_sector = { 'g0': 3000, 'h0': 3000, 'i0': 3000, 'i1': 5000, 'i2': 6000, 'g6': 5000} # read standard load profiles e_slp = bdew.ElecSlp(year, holidays=holidays) # multiply given annual demand with timeseries elec_demand = e_slp.get_profile(ann_el_demand_per_sector) # Add the slp for the industrial group ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index, holidays=holidays) # Beginning and end of workday, weekdays and weekend days, and scaling # factors by default elec_demand['i0'] = ilp.simple_profile(ann_el_demand_per_sector['i0']) # Set beginning of workday to 9 am elec_demand['i1'] = ilp.simple_profile(ann_el_demand_per_sector['i1'], am=settime(9, 0, 0)) # Change scaling factors elec_demand['i2'] = ilp.simple_profile( ann_el_demand_per_sector['i2'], profile_factors={'week': {'day': 1.0, 'night': 0.8}, 'weekend': {'day': 0.8, 'night': 0.6}}) print("Be aware that the values in the DataFrame are 15minute values with " "a power unit. If you sum up a table with 15min values the result " "will be of the unit 'kW15minutes'.") print(elec_demand.sum()) print("You will have to divide the result by 4 to get kWh.") print(elec_demand.sum() / 4) print("Or resample the DataFrame to hourly values using the mean() " "method.") # Resample 15-minute values to hourly values. elec_demand = elec_demand.resample('H').mean() print(elec_demand.sum()) if plt is not None: # Plot demand ax = elec_demand.plot() ax.set_xlabel("Date") ax.set_ylabel("Power demand") plt.show()
def add_sectoral_peak_load(load_areas, **kwargs): r"""Add peak load per sector based on given annual consumption """ # define data year # TODO: in the future get this from somewhere else year = 2011 # call demandlib # TODO: change to use new demandlib # read standard load profiles e_slp = bdew.ElecSlp(year, holidays=holidays) # multiply given annual demand with timeseries # elec_demand = e_slp.get_profile(load_areas['h0', 'g0', 'l0', 'i0'].to_dict()) elec_demand = e_slp.get_profile(load_areas.to_dict()) # tmp_peak_load = dm.electrical_demand(method='calculate_profile', # year=year, # ann_el_demand_per_sector= { # 'h0': # load_areas['sector_consumption_residential'], # 'g0': # load_areas['sector_consumption_retail'], # 'i0': # load_areas['sector_consumption_industrial'], # 'l0': # load_areas['sector_consumption_agricultural']} # ).elec_demand # hack correct industrial profile into dataframe # print(load_areas['sector_consumption_industrial']) # if load_areas['sector_consumption_industrial'] == 0: # load_areas['sector_consumption_industrial'] = 0.1 # Add the slp for the industrial group ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index, holidays=holidays) # Beginning and end of workday, weekdays and weekend days, and scaling factors # by default elec_demand['i0'] = ilp.simple_profile(load_areas['i0'], am=settime(6, 0, 0), pm=settime(22, 0, 0), profile_factors={ 'week': { 'day': 0.8, 'night': 0.6 }, 'weekend': { 'day': 0.6, 'night': 0.6 } }) # Resample 15-minute values to hourly values and sum across sectors elec_demand = elec_demand.resample('H').mean().fillna(0).max().to_frame().T # demand_industry = eb.IndustrialLoadProfile('simple_industrial_profile', # **{'annual_demand': load_areas['sector_consumption_industrial'], # 'year': year, # 'am': settime(6, 0, 0), # 'pm': settime(22, 0, 0), # 'profile_factors': # {'week': {'day': 0.8, 'night': 0.6}, # 'weekend': {'day': 0.6, 'night': 0.6}} # }) # ind_demand = demand_industry.profile # elec_demand['i0'] = ind_demand peak_load = elec_demand.max(axis=0) return peak_load
holidays=holidays) # counter ctr = 0 # iterate over substation retrieving sectoral demand at each of it for it, row in load_areas.iterrows(): row = row.fillna(0) # multiply given annual demand with timeseries elec_demand = e_slp.get_profile(row.to_dict()) # Beginning and end of workday, weekdays and weekend days, and scaling factors # by default elec_demand['i0'] = ilp.simple_profile(row['i0'], am=settime(6, 0, 0), pm=settime(22, 0, 0), profile_factors={ 'week': { 'day': 0.8, 'night': 0.6 }, 'weekend': { 'day': 0.6, 'night': 0.6 } }) # Resample 15-minute values to hourly values and sum across sectors elec_demand = elec_demand.resample('H').mean().fillna( 0).max().to_frame().T #.max(axis=0)#.to_frame().unstack()#.\
def power_example(ann_el_demand_per_sector=None, testmode=False): if ann_el_demand_per_sector is None: ann_el_demand_per_sector = { 'g0': 3000, 'h0': 3000, 'i0': 3000, 'i1': 5000, 'i2': 6000, 'g6': 5000 } year = 2010 # read standard load profiles e_slp = bdew.ElecSlp(year, holidays=holidays) # multiply given annual demand with timeseries elec_demand = e_slp.get_profile(ann_el_demand_per_sector, dyn_function_h0=False) # Add the slp for the industrial group ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index, holidays=holidays) # Beginning and end of workday, weekdays and weekend days, and scaling # factors by default if 'i0' in ann_el_demand_per_sector: elec_demand['i0'] = ilp.simple_profile(ann_el_demand_per_sector['i0']) # Set beginning of workday to 9 am if 'i1' in ann_el_demand_per_sector: elec_demand['i1'] = ilp.simple_profile(ann_el_demand_per_sector['i1'], am=settime(9, 0, 0)) # Change scaling factors if 'i2' in ann_el_demand_per_sector: elec_demand['i2'] = ilp.simple_profile(ann_el_demand_per_sector['i2'], profile_factors={ 'week': { 'day': 1.0, 'night': 0.8 }, 'weekend': { 'day': 0.8, 'night': 0.6 } }) if not testmode: print( "Be aware that the values in the DataFrame are 15 minute values" + "with a power unit. If you sum up a table with 15min values" + "the result will be of the unit 'kW15minutes'.") print(elec_demand.sum()) print("You will have to divide the result by 4 to get kWh.") print(elec_demand.sum() / 4) print("Or resample the DataFrame to hourly values using the mean() " "method.") # Resample 15-minute values to hourly values. elec_demand = elec_demand.resample('H').mean() print(elec_demand.sum()) if plt is not None: # Plot demand ax = elec_demand.plot() ax.set_xlabel("Date") ax.set_ylabel("Power demand") plt.show() return elec_demand
def demand_per_mv_grid_district(): year = 2011 schema = orm_demand.__table_args__['schema'] target_table = orm_demand.__tablename__ db_group = 'oeuser' columns_names = {'h0': 'residential', 'g0': 'retail', 'i0': 'industrial', 'l0': 'agricultural'} inv_columns_names = {v: k for k, v in columns_names.items()} # The following dictionary is create by "workalendar" # pip3 install workalendar cal = Germany() holidays = dict(cal.holidays(2011)) # retrieve sectoral demand from oedb # get database connection conn = io.oedb_session(section='oedb') Session = sessionmaker(bind=conn) session = Session() query_demand = session.query(orm_loads.otg_id, func.sum(orm_loads.sector_consumption_residential).\ label('residential'), func.sum(orm_loads.sector_consumption_retail).label('retail'), func.sum(orm_loads.sector_consumption_industrial).\ label('industrial'), func.sum(orm_loads.sector_consumption_agricultural).\ label('agricultural')).\ group_by(orm_loads.otg_id) annual_demand_df = pd.read_sql_query( query_demand.statement, session.bind, index_col='otg_id').fillna(0) annual_demand_df = annual_demand_df.loc[~pd.isnull(annual_demand_df.index)] write_scenario_log(conn=conn, version='v0.4.5', project='eGoDP', io='input', schema='model_draft', table=orm_loads.__tablename__, script='ego_dp_powerflow_griddistrict_demand.py', entries=len(annual_demand_df)) large_scale_industrial = pd.read_sql_table( 'ego_demand_hv_largescaleconsumer', conn, schema, index_col='polygon_id') write_scenario_log(conn=conn, version='v0.4.5', project='eGoDP', io='input', schema='model_draft', table='ego_demand_hv_largescaleconsumer', script='ego_dp_powerflow_griddistrict_demand.py', entries=len(large_scale_industrial)) # add extra industrial demand ontop of MV industrial demand annual_demand_df = pd.concat( [annual_demand_df, large_scale_industrial.groupby( by='otg_id').sum()['consumption']], axis=1) annual_demand_df['industrial'] = annual_demand_df[ ['industrial', 'consumption']].sum(axis=1) annual_demand_df.drop('consumption', axis=1, inplace=True) # rename columns according to demandlib definitions annual_demand_df.rename(columns=inv_columns_names, inplace=True) # empty table or create try: orm_demand.__table__.create(conn) except: session.query(orm_demand).delete() session.commit() # iterate over substation retrieving sectoral demand at each of it for it, row in annual_demand_df.iterrows(): # read standard load profiles e_slp = bdew.ElecSlp(year, holidays=holidays) # multiply given annual demand with timeseries elec_demand = e_slp.get_profile(row.to_dict()) # Add the slp for the industrial group ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index, holidays=holidays) # Beginning and end of workday, weekdays and weekend days, and scaling factors # by default elec_demand['i0'] = ilp.simple_profile( row['i0'], am=settime(6, 0, 0), pm=settime(22, 0, 0), profile_factors= {'week': {'day': 0.8, 'night': 0.6}, 'weekend': {'day': 0.6, 'night': 0.6}}) # Resample 15-minute values to hourly values and sum across sectors elec_demand = elec_demand.resample('H').mean().sum(axis=1) # Convert from GW to MW active_power = elec_demand * 1e3 # derive reactive power from active power reactive_power = ((active_power / 0.95)**2 - active_power**2).apply(sqrt) # Write to database demand2db = orm_demand(id=it, p_set=active_power.tolist(), q_set=reactive_power.tolist()) session.add(demand2db) session.commit() # grant access to db_group db.grant_db_access(conn, schema, target_table, db_group) # change owner of table to db_group db.change_owner_to(conn, schema, target_table, db_group) # # add primary key constraint on id column # db.add_primary_key(conn, schema, target_table, 'id') # create metadata json str json_str = metadata.create_metadata_json( 'Load time series at transition points', '', '2011', time.strftime("%d.%m.%Y"), 'Open Energy Database, schema: {0}, table: {1}'.format(schema, target_table), 'Germany', 'Active and reactive power demand time series per transition point', [{'Name': 'id', 'Description': 'Unique identifier', 'Unit': '-'}, {'Name': 'active_power', 'Description': 'Active power demand', 'Unit': 'MW'}, {'Name': 'reactive_power', 'Description': 'Reactive power demand', 'Unit': 'MW'} ], {'Name': 'Guido Pleßmann', 'Mail': '*****@*****.**', 'Date': time.strftime("%d.%m.%Y"), 'Comment': 'Initial creation of dataset'}, 'Be aware of applicability. Data bases on synthetic load profiles', '', '' ) metadata.submit_comment(conn, json_str, schema, target_table) write_scenario_log(conn=conn, version='v0.4.5', project='eGoDP', io='output', schema=schema, table=target_table, script='ego_dp_powerflow_griddistrict_demand.py', entries=len(annual_demand_df)) conn.close()
def demand_per_mv_grid_district(): year = 2011 schema = orm_demand.__table_args__['schema'] target_table = orm_demand.__tablename__ db_group = 'oeuser' columns_names = { 'h0': 'residential', 'g0': 'retail', 'i0': 'industrial', 'l0': 'agricultural' } inv_columns_names = {v: k for k, v in columns_names.items()} # The following dictionary is create by "workalendar" # pip3 install workalendar cal = Germany() holidays = dict(cal.holidays(2011)) # retrieve sectoral demand from oedb # get database connection conn = io.oedb_session(section='oedb') Session = sessionmaker(bind=conn) session = Session() query_demand = session.query(orm_loads.otg_id, func.sum(orm_loads.sector_consumption_residential).\ label('residential'), func.sum(orm_loads.sector_consumption_retail).label('retail'), func.sum(orm_loads.sector_consumption_industrial).\ label('industrial'), func.sum(orm_loads.sector_consumption_agricultural).\ label('agricultural')).\ group_by(orm_loads.otg_id) annual_demand_df = pd.read_sql_query(query_demand.statement, session.bind, index_col='otg_id').fillna(0) annual_demand_df = annual_demand_df.loc[~pd.isnull(annual_demand_df.index)] write_scenario_log(conn=conn, version='v0.4.5', project='eGoDP', io='input', schema='model_draft', table=orm_loads.__tablename__, script='ego_dp_powerflow_griddistrict_demand.py', entries=len(annual_demand_df)) large_scale_industrial = pd.read_sql_table( 'ego_demand_hv_largescaleconsumer', conn, schema, index_col='polygon_id') write_scenario_log(conn=conn, version='v0.4.5', project='eGoDP', io='input', schema='model_draft', table='ego_demand_hv_largescaleconsumer', script='ego_dp_powerflow_griddistrict_demand.py', entries=len(large_scale_industrial)) # add extra industrial demand ontop of MV industrial demand annual_demand_df = pd.concat([ annual_demand_df, large_scale_industrial.groupby(by='otg_id').sum()['consumption'] ], axis=1) annual_demand_df['industrial'] = annual_demand_df[[ 'industrial', 'consumption' ]].sum(axis=1) annual_demand_df.drop('consumption', axis=1, inplace=True) # rename columns according to demandlib definitions annual_demand_df.rename(columns=inv_columns_names, inplace=True) # empty table or create try: orm_demand.__table__.create(conn) except: session.query(orm_demand).delete() session.commit() # iterate over substation retrieving sectoral demand at each of it for it, row in annual_demand_df.iterrows(): # read standard load profiles e_slp = bdew.ElecSlp(year, holidays=holidays) # multiply given annual demand with timeseries elec_demand = e_slp.get_profile(row.to_dict()) # Add the slp for the industrial group ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index, holidays=holidays) # Beginning and end of workday, weekdays and weekend days, and scaling factors # by default elec_demand['i0'] = ilp.simple_profile(row['i0'], am=settime(6, 0, 0), pm=settime(22, 0, 0), profile_factors={ 'week': { 'day': 0.8, 'night': 0.6 }, 'weekend': { 'day': 0.6, 'night': 0.6 } }) # Resample 15-minute values to hourly values and sum across sectors elec_demand = elec_demand.resample('H').mean().sum(axis=1) # Convert from GW to MW active_power = elec_demand * 1e3 # derive reactive power from active power reactive_power = ((active_power / 0.95)**2 - active_power**2).apply(sqrt) # Write to database demand2db = orm_demand(id=it, p_set=active_power.tolist(), q_set=reactive_power.tolist()) session.add(demand2db) session.commit() # grant access to db_group db.grant_db_access(conn, schema, target_table, db_group) # change owner of table to db_group db.change_owner_to(conn, schema, target_table, db_group) # # add primary key constraint on id column # db.add_primary_key(conn, schema, target_table, 'id') # create metadata json str json_str = metadata.create_metadata_json( 'Load time series at transition points', '', '2011', time.strftime("%d.%m.%Y"), 'Open Energy Database, schema: {0}, table: {1}'.format( schema, target_table), 'Germany', 'Active and reactive power demand time series per transition point', [{ 'Name': 'id', 'Description': 'Unique identifier', 'Unit': '-' }, { 'Name': 'active_power', 'Description': 'Active power demand', 'Unit': 'MW' }, { 'Name': 'reactive_power', 'Description': 'Reactive power demand', 'Unit': 'MW' }], { 'Name': 'Guido Pleßmann', 'Mail': '*****@*****.**', 'Date': time.strftime("%d.%m.%Y"), 'Comment': 'Initial creation of dataset' }, 'Be aware of applicability. Data bases on synthetic load profiles', '', '') metadata.submit_comment(conn, json_str, schema, target_table) write_scenario_log(conn=conn, version='v0.4.5', project='eGoDP', io='output', schema=schema, table=target_table, script='ego_dp_powerflow_griddistrict_demand.py', entries=len(annual_demand_df)) conn.close()
# iterate over substation retrieving sectoral demand at each of it for it, row in annual_demand_df.iterrows(): # read standard load profiles e_slp = bdew.ElecSlp(year, holidays=holidays) # multiply given annual demand with timeseries elec_demand = e_slp.get_profile(row.to_dict()) # Add the slp for the industrial group ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index, holidays=holidays) # Beginning and end of workday, weekdays and weekend days, and scaling factors # by default elec_demand['i0'] = ilp.simple_profile( row['i0'], am=settime(6, 0, 0), pm=settime(22, 0, 0), profile_factors= {'week': {'day': 0.8, 'night': 0.6}, 'weekend': {'day': 0.6, 'night': 0.6}}) # Resample 15-minute values to hourly values and sum across sectors elec_demand = elec_demand.resample('H').mean().sum(axis=1) # Write to database demand2db = orm_demand(id=it, demand=elec_demand.tolist()) session.add(demand2db) session.commit() # orm_demand.__table__.create(conn)
def add_sectoral_peak_load(load_areas, **kwargs): r"""Add peak load per sector based on given annual consumption """ # define data year # TODO: in the future get this from somewhere else year = 2011 # call demandlib # TODO: change to use new demandlib # read standard load profiles e_slp = bdew.ElecSlp(year, holidays=holidays) # multiply given annual demand with timeseries # elec_demand = e_slp.get_profile(load_areas['h0', 'g0', 'l0', 'i0'].to_dict()) elec_demand = e_slp.get_profile(load_areas.to_dict()) # tmp_peak_load = dm.electrical_demand(method='calculate_profile', # year=year, # ann_el_demand_per_sector= { # 'h0': # load_areas['sector_consumption_residential'], # 'g0': # load_areas['sector_consumption_retail'], # 'i0': # load_areas['sector_consumption_industrial'], # 'l0': # load_areas['sector_consumption_agricultural']} # ).elec_demand # hack correct industrial profile into dataframe # print(load_areas['sector_consumption_industrial']) # if load_areas['sector_consumption_industrial'] == 0: # load_areas['sector_consumption_industrial'] = 0.1 # Add the slp for the industrial group ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index, holidays=holidays) # Beginning and end of workday, weekdays and weekend days, and scaling factors # by default elec_demand['i0'] = ilp.simple_profile( load_areas['i0'], am=settime(6, 0, 0), pm=settime(22, 0, 0), profile_factors= {'week': {'day': 0.8, 'night': 0.6}, 'weekend': {'day': 0.6, 'night': 0.6}}) # Resample 15-minute values to hourly values and sum across sectors elec_demand = elec_demand.resample('H').mean().fillna(0).max().to_frame().T # demand_industry = eb.IndustrialLoadProfile('simple_industrial_profile', # **{'annual_demand': load_areas['sector_consumption_industrial'], # 'year': year, # 'am': settime(6, 0, 0), # 'pm': settime(22, 0, 0), # 'profile_factors': # {'week': {'day': 0.8, 'night': 0.6}, # 'weekend': {'day': 0.6, 'night': 0.6}} # }) # ind_demand = demand_industry.profile # elec_demand['i0'] = ind_demand peak_load = elec_demand.max(axis=0) return peak_load