def heat_example(testmode=False, ann_demands_per_type=None): if ann_demands_per_type is None: ann_demands_per_type = {'efh': 25000, 'mfh': 80000, 'ghd': 140000} holidays = { datetime.date(2010, 5, 24): 'Whit Monday', datetime.date(2010, 4, 5): 'Easter Monday', datetime.date(2010, 5, 13): 'Ascension Thursday', datetime.date(2010, 1, 1): 'New year', datetime.date(2010, 10, 3): 'Day of German Unity', datetime.date(2010, 12, 25): 'Christmas Day', datetime.date(2010, 5, 1): 'Labour Day', datetime.date(2010, 4, 2): 'Good Friday', datetime.date(2010, 12, 26): 'Second Christmas Day'} # Create DataFrame for 2010 demand = pd.DataFrame( index=pd.date_range(datetime.datetime(2010, 1, 1, 0), periods=8760, freq='H')) # Single family house (efh: Einfamilienhaus) if "efh" in ann_demands_per_type: demand['efh'] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type='EFH', building_class=1, wind_class=1, annual_heat_demand=ann_demands_per_type['efh'], name='EFH').get_bdew_profile() # Multi family house (mfh: Mehrfamilienhaus) if "mfh" in ann_demands_per_type: demand['mfh'] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type='MFH', building_class=2, wind_class=0, annual_heat_demand=ann_demands_per_type['mfh'], name='MFH').get_bdew_profile() # Industry, trade, service (ghd: Gewerbe, Handel, Dienstleistung) if "ghd" in ann_demands_per_type: demand['ghd'] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type='ghd', wind_class=0, annual_heat_demand=ann_demands_per_type['ghd'], name='ghd').get_bdew_profile() if not testmode: if plt is not None: # Plot demand of building ax = demand.plot() ax.set_xlabel("Date") ax.set_ylabel("Heat demand in kW") plt.show() else: print('Annual consumption: \n{}'.format(demand.sum())) return demand
def heat_example(): holidays = { datetime.date(2010, 5, 24): 'Whit Monday', datetime.date(2010, 4, 5): 'Easter Monday', datetime.date(2010, 5, 13): 'Ascension Thursday', datetime.date(2010, 1, 1): 'New year', datetime.date(2010, 10, 3): 'Day of German Unity', datetime.date(2010, 12, 25): 'Christmas Day', datetime.date(2010, 5, 1): 'Labour Day', datetime.date(2010, 4, 2): 'Good Friday', datetime.date(2010, 12, 26): 'Second Christmas Day' } # Create DataFrame for 2010 demand = pd.DataFrame(index=pd.date_range( pd.datetime(2010, 1, 1, 0), periods=8760, freq='H')) demand['efh'] = bdew.HeatBuilding(demand.index, holidays=holidays, temperature=temperature, shlp_type='EFH', building_class=1, wind_class=1, annual_heat_demand=25000, name='EFH').get_bdew_profile() demand['mfh'] = bdew.HeatBuilding(demand.index, holidays=holidays, temperature=temperature, shlp_type='MFH', building_class=2, wind_class=0, annual_heat_demand=80000, name='MFH').get_bdew_profile() demand['ghd'] = bdew.HeatBuilding(demand.index, holidays=holidays, temperature=temperature, shlp_type='ghd', wind_class=0, annual_heat_demand=140000, name='ghd').get_bdew_profile() # Plot demand of building ax = demand.plot() ax.set_xlabel("Date") ax.set_ylabel("Heat demand in MW") plt.show()
def get_heat_profile_from_demandlib(temperature, annual_demand, sector, year, build_class=1): cal = Germany() holidays = dict(cal.holidays(year)) if 'efh' in sector: shlp_type = 'EFH' elif 'mfh' in sector: shlp_type = 'MFH' elif 'domestic' in sector: shlp_type = 'MFH' elif 'retail' in sector: shlp_type = 'ghd' build_class = 0 elif 'industrial' in sector: shlp_type = 'ghd' build_class = 0 else: raise AttributeError('"{0}" is an unknown sector.'.format(sector)) return bdew.HeatBuilding(temperature.index, holidays=holidays, temperature=temperature, shlp_type=shlp_type, wind_class=0, building_class=build_class, annual_heat_demand=annual_demand, name=sector, ww_incl=True).get_bdew_profile()
def prepare_timeseries_demand_heat(year, bdew_parameters, temperature, output_file): """ Creates synthetic heat profiles using the BDEW method. """ # get holidays for germany cal = Germany() holidays = dict(cal.holidays(year)) # create a DataFrame to hold the timeseries demand = pd.DataFrame(index=pd.date_range( pd.datetime(year, 1, 1, 0), periods=8760, freq='H')) demand = pd.DataFrame(index=temperature.index) for key, param in bdew_parameters.items(): demand[key] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type=key, building_class=param['building_class'], wind_class=param['wind_class'], annual_heat_demand=param['annual_demand'], name=key).get_bdew_profile() # save heat demand time series demand.sum(axis=1).to_csv(output_file)
def get_heat_profile_from_demandlib(temperature, annual_demand, sector, year, build_class=1): """ Create an hourly load profile from the annual demand using the demandlib. Parameters ---------- temperature : pandas.Series annual_demand : float sector : str year : int build_class : int Returns ------- pandas.DataFrame Examples -------- >>> temperature=pd.Series(list(range(50)), index=pd.date_range( ... '2014-05-03 12:00', periods=50, freq='h')) >>> temperature = 10 + temperature * 0.1 >>> hp=get_heat_profile_from_demandlib( ... temperature, 5345, 'retail', 2014) >>> int(round(hp.sum())) 5302 """ cal = Germany() holidays = dict(cal.holidays(year)) if "efh" in sector: shlp_type = "EFH" elif "mfh" in sector: shlp_type = "MFH" elif "domestic" in sector: shlp_type = "MFH" elif "retail" in sector: shlp_type = "ghd" build_class = 0 elif "industrial" in sector: shlp_type = "ghd" build_class = 0 else: raise AttributeError('"{0}" is an unknown sector.'.format(sector)) return bdew.HeatBuilding( temperature.index, holidays=holidays, temperature=temperature, shlp_type=shlp_type, wind_class=0, building_class=build_class, annual_heat_demand=annual_demand, name=sector, ww_incl=True, ).get_bdew_profile()
def heat_example(): """holidays = { datetime.date(2010, 5, 24): 'Whit Monday', datetime.date(2010, 4, 5): 'Easter Monday', datetime.date(2010, 5, 13): 'Ascension Thursday', datetime.date(2010, 1, 1): 'New year', datetime.date(2010, 10, 3): 'Day of German Unity', datetime.date(2010, 12, 25): 'Christmas Day', datetime.date(2010, 5, 1): 'Labour Day', datetime.date(2010, 4, 2): 'Good Friday', datetime.date(2010, 12, 26): 'Second Christmas Day'} """ # Create DataFrame for 2010 demand = pd.DataFrame(index=pd.date_range( pd.datetime(2016, 1, 1, 0), periods=8760, freq='H')) """ # Single family house (efh: Einfamilienhaus) demand['efh'] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type='EFH', building_class=1, wind_class=1, annual_heat_demand=25000, name='EFH').get_bdew_profile() # Multi family house (mfh: Mehrfamilienhaus) demand['mfh'] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type='MFH', building_class=2, wind_class=0, annual_heat_demand=80000, name='MFH').get_bdew_profile() """ # Industry, trade, service (ghd: Gewerbe, Handel, Dienstleistung) demand['DH'] = bdew.HeatBuilding(demand.index, holidays=holidays, temperature=temperature, shlp_type='ghd', wind_class=0, annual_heat_demand=11900, name='DH').get_bdew_profile() if plt is not None: # Plot demand of building ax = demand.plot() ax.set_xlabel("Date") ax.set_ylabel("Heat demand in kW") plt.show() print('Annual consumption: \n{}'.format(demand.sum())) else: print('Annual consumption: \n{}'.format(demand.sum())) demand.to_csv('C:/Users/lovisaax/Desktop/data/industrial_heat_load.csv', index_label='Time (UTC)', header='DH')
def create_standardised_heat_load_profile(shlp, year): """ Parameters ---------- shlp : dict year : int Returns ------- pandas.DataFrame """ avg_temp_berlin = (reegis_tools.coastdat.federal_state_average_weather( year, 'temp_air')['BE']) # Calculate the average temperature in degree Celsius temperature = avg_temp_berlin - 272.15 # Fetch the holidays of Germany from the workalendar package cal = Germany() holidays = dict(cal.holidays(year)) fuel_list = shlp[list(shlp.keys())[0]]['demand'].index profile_fuel = pd.DataFrame() for fuel in fuel_list: fuel_name = fuel.replace('frac_', '') profile_type = pd.DataFrame() for shlp_type in shlp.keys(): shlp_name = str(shlp_type) profile_type[fuel_name + '_' + shlp_name] = bdew.HeatBuilding( temperature.index, holidays=holidays, temperature=temperature, shlp_type=shlp_type, wind_class=0, building_class=shlp[shlp_type]['build_class'], annual_heat_demand=shlp[shlp_type]['demand'][fuel], name=fuel_name + shlp_name, ww_incl=True).get_bdew_profile() # for district heating the systems the profile will not be summed up # but kept as different profiles ('district_heating_' + shlp_name). if fuel_name == 'district_heating': for n in profile_type.columns: profile_fuel[n] = profile_type[n] else: profile_fuel[fuel_name] = profile_type.sum(axis=1) return profile_fuel
def call_heat_demandlib(region, time_index, **kwargs): ''' Calls the demandlib and creates an object that includes the demand timeseries. Required Parameters ------------------- demand : Sink object region : Region object ''' load_profile = bdew.HeatBuilding( time_index, holidays=kwargs.get('holidays', None), temperature=region.temp, shlp_type=kwargs.get('shlp_type', None), building_class=(region.building_class if region.building_class is not None else 0), wind_class=region.wind_class, annual_heat_demand=kwargs.get('annual_heat_demand', None), name=kwargs.get('shlp_type', None), ww_incl=kwargs.get('ww_incl', True)).get_bdew_profile() return load_profile
def create_standardised_heat_load_profile(shlp, year): """ Parameters ---------- shlp : dict year : int Returns ------- pandas.DataFrame """ avg_temp_berlin = (reegis.coastdat.federal_state_average_weather( year, 'temp_air')['BE']) # Calculate the average temperature in degree Celsius temperature = avg_temp_berlin - 272.15 # Fetch the holidays of Germany from the workalendar package cal = Germany() holidays = dict(cal.holidays(year)) profile_type = pd.DataFrame() for shlp_type in shlp.keys(): shlp_name = str(shlp_type) profile_type[shlp_name] = bdew.HeatBuilding( temperature.index, holidays=holidays, temperature=temperature, shlp_type=shlp_type, wind_class=0, building_class=shlp[shlp_type]['build_class'], annual_heat_demand=1000, name=shlp_name, ww_incl=True).get_bdew_profile() return profile_type
def calculate_heat_demand( country, lat, lon, storeys, year, weather, column, static_inputs_directory=None, user_inputs_pvcompare_directory=None, user_inputs_mvs_directory=None, ): r""" Calculates heat demand profile for `storeys`, `country`, `year`. The heat demand of either space heating or space heating and warm water is calculated for a given number of houses with a given number of storeys in a certain country and year. In order to take heat demand from warm water into account the parameter `include warm water` in pvcompareās input file 'building_parameters.csv' is set to `True`. For further information regarding the calculation of the heat demand profile see `Heat demand <https://pvcompare.readthedocs.io/en/latest/model_assumptions.html#heat-demand>`_. Parameters ---------- country: str The country's name has to be in English and with capital first letter. storeys: int Number of storeys of the houses. year: int Year for which heat demand time series is calculated. Year can be chosen between 2008 and 2018. column: str name of the demand weather: :pandas:`pandas.DataFrame<frame>` hourly weather data frame with the columns: time, latitude, longitude, wind_speed, temp_air, ghi, dhi, dni, precipitable_water. static_inputs_directory: str or None Directory of the pvcompare static inputs. If None, `constants.DEFAULT_STATIC_INPUTS_DIRECTORY` is used. Default: None. user_inputs_pvcompare_directory: str or None Path to user input directory. If None, `constants.DEFAULT_USER_INPUTS_PVCOMPARE_DIRECTORY` is used. Default: None. user_inputs_mvs_directory: str or None Path to input directory containing files that describe the energy system and that are an input to MVS. If None, `constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY` is used. Default: None. Returns ------- shifted_heat_demand : :pandas:`pandas.DataFrame<frame>` Hourly heat demand time series. """ if static_inputs_directory == None: static_inputs_directory = constants.DEFAULT_STATIC_INPUTS_DIRECTORY if user_inputs_pvcompare_directory == None: user_inputs_pvcompare_directory = ( constants.DEFAULT_USER_INPUTS_PVCOMPARE_DIRECTORY) if user_inputs_mvs_directory == None: user_inputs_mvs_directory = constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY # load workelendar for country cal = get_workalendar_class(country) holidays = dict(cal.holidays(int(year))) # define temperature temp = weather["temp_air"] # Create DataFrame for demand timeseries demand = pd.DataFrame(index=pd.date_range( pd.datetime(int(year), 1, 1, 0), periods=temp.count(), freq="H")) # calculate annual demand # The annual heat consumption is calculated by adding up the total # consumption for SH and WH and subtracting the electrical consumption of # SH and WH for a country bp = pd.read_csv( os.path.join(user_inputs_pvcompare_directory, "building_parameters.csv"), index_col=0, ) filename_total_SH = os.path.join(static_inputs_directory, bp.at["filename_total_SH", "value"]) filename_total_WH = os.path.join(static_inputs_directory, bp.at["filename_total_WH", "value"]) population_per_storey = int(bp.at["population per storey", "value"]) number_of_houses = int(bp.at["number of houses", "value"]) population = storeys * population_per_storey * number_of_houses total_SH = pd.read_excel(filename_total_SH, header=1, index_col=0) total_WH = pd.read_excel(filename_total_WH, header=1, index_col=0) # load population filename_population = bp.at["filename_country_population", "value"] filename1 = os.path.join(static_inputs_directory, filename_population) populations = pd.read_csv(filename1, index_col=0, sep=",") # convert TWh in kWh # Heat demand of residential space heating heat_demand = total_SH.at[country, year] * 10**9 annual_heat_demand_per_population = ( heat_demand / float(populations.at[country, str(year)])) * population # Heat demand of residential water heating heat_demand_ww = total_WH.at[country, year] * 10**9 annual_heat_demand_ww_per_population = (heat_demand_ww / float( populations.at[country, str(year)])) * population # Multi family house (mfh: Mehrfamilienhaus) include_warm_water = eval(bp.at["include warm water", "value"]) # Calculate heat demand only for space heating demand["h0"] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temp, shlp_type="MFH", building_class=2, wind_class=0, annual_heat_demand=annual_heat_demand_per_population, name="MFH", ww_incl=False, # This must be False. Warm water calc follows ).get_bdew_profile() # Read heating limit temperature heating_lim_temp = int(bp.at["heating limit temperature", "value"]) if include_warm_water: # Calculate annual heat demand with warm water included annual_heat_demand_per_population = ( annual_heat_demand_per_population + annual_heat_demand_ww_per_population) # Create a copy of demand dataframe for warm water calculations demand_ww_calc = demand.copy() # Get total heat demand with warm water demand_ww_calc["h0_ww"] = bdew.HeatBuilding( demand_ww_calc.index, holidays=holidays, temperature=temp, shlp_type="MFH", building_class=2, wind_class=0, annual_heat_demand=annual_heat_demand_per_population, name="MFH", ww_incl=True, ).get_bdew_profile() # Calculate hourly difference in demand between space heating and space heating with warm water demand_ww_calc[ "h0_diff"] = demand_ww_calc["h0_ww"] - demand_ww_calc["h0"] # for space heating *only* adjust the heat demand so there is no demand if daily mean temperature # is above the heating limit temperature demand["h0"] = adjust_heat_demand(temp, heating_lim_temp, demand["h0"]) # Add the heat demand for warm water to the adjusted space heating demand demand["h0"] = demand["h0"] + demand_ww_calc["h0_diff"] else: # Adjust the heat demand so there is no demand if daily mean temperature # is above the heating limit temperature demand["h0"] = adjust_heat_demand(temp, heating_lim_temp, demand["h0"]) shifted_heat_demand = shift_working_hours(country=country, ts=demand) shifted_heat_demand.rename(columns={"h0": "kWh"}, inplace=True) if user_inputs_mvs_directory is None: user_inputs_mvs_directory = constants.DEFAULT_USER_INPUTS_MVS_DIRECTORY timeseries_directory = os.path.join(user_inputs_mvs_directory, "time_series/") logging.info("The electrical load profile is completely calculated and " "being saved under %s." % timeseries_directory) # define the name of the output file of the time series h_demand_csv = f"heat_load_{year}_{lat}_{lon}_{storeys}.csv" filename = os.path.join(timeseries_directory, h_demand_csv) shifted_heat_demand.to_csv(filename, index=False) # save the file name of the time series and the nominal value to # mvs_inputs/elements/csv/energyProduction.csv check_inputs.add_file_name_to_energy_consumption_file( column=column, ts_filename=h_demand_csv, user_inputs_mvs_directory=user_inputs_mvs_directory, ) return shifted_heat_demand
def heating_systems(esystem, dfull, add_elec, p): power_plants = prepare_data.chp_berlin(p) time_index = esystem.time_idx temperature_path = '/home/uwe/rli-lokal/git_home/demandlib/examples' temperature_file = temperature_path + '/example_data.csv' temperature = pd.read_csv(temperature_file)['temperature'] sli = pd.Series(list(temperature.loc[:23]), index=list(range(8760, 8784))) temperature = temperature.append(sli) temperature = temperature.iloc[0:len(time_index)] heatbus = dict() hd = dict() auxiliary_energy = 0 print(dfull) for h in dfull.keys(): hd.setdefault(h, 0) lsink = 'demand_{0}'.format(h) lbus = 'bus_{0}'.format(h) ltransf = '{0}'.format(h) lres_bus = 'bus_{0}'.format(p.heating2resource[h]) for b in dfull[h].keys(): if b.upper() in p.bdew_types: bc = 0 if b.upper() in ['EFH', 'MFH']: bc = 1 hd[h] += bdew.HeatBuilding(time_index, temperature=temperature, shlp_type=b, building_class=bc, wind_class=1, annual_heat_demand=dfull[h][b], name=h).get_bdew_profile() if b.upper() in ['EFH', 'MFH']: print(h, 'in') auxiliary_energy += bdew.HeatBuilding( time_index, temperature=temperature, shlp_type=b, building_class=bc, wind_class=1, annual_heat_demand=add_elec[h][b], name=h).get_bdew_profile() elif b in [ 'i', ]: hd[h] += pprofiles.IndustrialLoadProfile( time_index).simple_profile(annual_demand=dfull[h][b]) else: logging.error('Demandlib typ "{0}" not found.'.format(b)) heatbus[h] = solph.Bus(label=lbus) solph.Sink(label=lsink, inputs={ heatbus[h]: solph.Flow(actual_value=hd[h].div(hd[h].max()), fixed=True, nominal_value=hd[h].max()) }) if 'district' not in h: if lres_bus not in esystem.groups: solph.Bus(label=lres_bus) solph.LinearTransformer( label=ltransf, inputs={esystem.groups[lres_bus]: solph.Flow()}, outputs={ heatbus[h]: solph.Flow(nominal_value=hd[h].max(), variable_costs=0) }, conversion_factors={heatbus[h]: 1}) else: for pp in power_plants[h].index: lres_bus = 'bus_' + pp if lres_bus not in esystem.groups: solph.Bus(label=lres_bus) solph.LinearTransformer( label='pp_chp_{0}_{1}'.format(h, pp), inputs={esystem.groups[lres_bus]: solph.Flow()}, outputs={ esystem.groups['bus_el']: solph.Flow( nominal_value=power_plants[h]['power_el'][pp]), heatbus[h]: solph.Flow( nominal_value=power_plants[h]['power_th'][pp]) }, conversion_factors={ esystem.groups['bus_el']: 0.3, heatbus[h]: 0.4 }) from matplotlib import pyplot as plt hd_df = pd.DataFrame(hd) print(hd_df.sum().sum()) print('z_max:', hd_df['district_z'].max()) print('dz_max:', hd_df['district_dz'].max()) print('z_sum:', hd_df['district_z'].sum()) print('dz_sum:', hd_df['district_dz'].sum()) hd_df.plot(colormap='Spectral') hd_df.to_csv('/home/uwe/hd.csv') plt.show() solph.Sink(label='auxiliary_energy', inputs={ esystem.groups['bus_el']: solph.Flow(actual_value=auxiliary_energy.div( auxiliary_energy.max()), fixed=True, nominal_value=auxiliary_energy.max()) }) # Create sinks # Get normalise demand and maximum value of electricity usage electricity_usage = electricity.DemandElec(time_index) normalised_demand, max_demand = electricity_usage.solph_sink( resample='H', reduce=auxiliary_energy) sum_demand = normalised_demand.sum() * max_demand print("delec:", "{:.2E}".format(sum_demand)) solph.Sink(label='elec_demand', inputs={ esystem.groups['bus_el']: solph.Flow(actual_value=normalised_demand, fixed=True, nominal_value=max_demand) })
try_weather = pd.read_csv(datapath, skiprows=34, sep='\t', header=None, decimal=',') temperature = try_weather[5] cal = Germany() holidays = dict(cal.holidays(2010)) # Create DataFrame for 2010 demand = pd.DataFrame( index=pd.date_range(pd.datetime(2010, 1, 1, 0), periods=8760, freq='H')) # Single family house (efh: Einfamilienhaus) demand['efh'] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type='EFH', building_class=1, wind_class=1, annual_heat_demand=25000, name='EFH').get_bdew_profile() # Multi family house (mfh: Mehrfamilienhaus) demand['mfh'] = bdew.HeatBuilding( demand.index, holidays=holidays, temperature=temperature, shlp_type='MFH', building_class=2, wind_class=0, annual_heat_demand=80000, name='MFH').get_bdew_profile() # Industry, trade, service (ghd: Gewerbe, Handel, Dienstleistung) # Valid values for slp_types are: # GMK, GPD, GHA, GBD, GKO, GBH, GGA, GBA, GWA, GGB, GMF, GHD # https://demandlib.readthedocs.io/en/latest/description.html#heat-profiles demand['ghd'] = bdew.HeatBuilding(