freq='H') energysystem = solph.EnergySystem(timeindex=date_time_index) ########################################################################## # Create oemof object ########################################################################## logging.info('Create oemof objects') # The bus objects were assigned to variables which makes it easier to connect # components to these buses (see below). ## create (commodity (fuels + electricity in OSeMOSYS) busses Brandenburg & Berlin # Brandenburg GAS = solph.Bus(label="GAS") ## adding the buses to the energy system #Brandenburg ELECTRICITY = solph.Bus(label="ELECTRICITY") energysystem.add(GAS, ELECTRICITY) ## create sources (fuel import technologies in OSeMOSYS) to represent the fuel input (annual limit) #Brandenburg energysystem.add(solph.Source(label='GAS_IMPORT', outputs={GAS: solph.Flow()})) ## create excess component for the electricity bus to allow overproduction #Brandenburg #energysystem.add(solph.Sink(label='excess_BBEL_FIN', inputs={BBEL_FIN: solph.Flow()}))
import pandas as pd from oemof import solph from oemof.solph import constraints try: import matplotlib.pyplot as plt except ImportError: plt = None # create energy system energysystem = solph.EnergySystem( timeindex=pd.date_range("1/1/2012", periods=3, freq="H")) # create gas bus bgas = solph.Bus(label="gas") # create electricity bus bel = solph.Bus(label="electricity") # adding the buses to the energy system energysystem.add(bel, bgas) # create fixed source object representing biomass plants energysystem.add( solph.Source( label="biomass", outputs={ bel: solph.Flow( nominal_value=100,
try: import matplotlib.pyplot as plt except ImportError: plt = None ########################################################################## # Initialize the energy system and calculate necessary parameters ########################################################################## periods = 365 time = pd.date_range('1/1/2018', periods=periods, freq='D') es = solph.EnergySystem(timeindex=time) b_heat = solph.Bus(label='b_heat') es.add(b_heat) def heat_demand(d): """basic model for heat demand, solely based on the day of the year""" return 0.6 + 0.4 * np.cos(2 * np.pi * d / 356) def solar_thermal(d): """ basic model for solar thermal yield, solely based on the day of the year """ return 0.5 - 0.5 * np.cos(2 * np.pi * d / 356)
# regular oemof_system # # parameters for energy system eta_losses = 0.8 elec_consumption = 0.05 backup_costs = 1000 cap_loss = 0.02 conversion_storage = 0.95 costs_storage = economics.annuity(20, 20, 0.06) costs_electricity = 1000 conversion_factor_turbine = 0.4 size_collector = 1000 # busses bth = solph.Bus(label='thermal', balanced=True) bel = solph.Bus(label='electricity') bcol = solph.Bus(label='solar') #sources and sinks col_heat = solph.Source(label='collector_heat', outputs={ bcol: solph.Flow( fixed=True, actual_value=data_precalc['collector_heat'], nominal_value=size_collector) }) el_grid = solph.Source( label='grid', outputs={bel: solph.Flow(variable_costs=costs_electricity)})
def storage_example(): # read time series timeseries = pd.read_csv(os.path.join(os.getcwd(), "storage_data.csv")) # create an energy system idx = pd.date_range("1/1/2017", periods=len(timeseries), freq="H") es = solph.EnergySystem(timeindex=idx) for data_set in DATA: name = data_set["name"] # power bus bel = solph.Bus(label="bel_{0}".format(name)) es.add(bel) es.add( solph.Source( label="source_el_{0}".format(name), outputs={ bel: solph.Flow(variable_costs=PARAMETER["el_price"]) }, )) es.add( solph.Source( label="pv_el_{0}".format(name), outputs={ bel: solph.Flow(fix=timeseries["pv_el"], nominal_value=1) }, )) es.add( solph.Sink( label="demand_el_{0}".format(name), inputs={ bel: solph.Flow(fix=timeseries["demand_el"], nominal_value=1) }, )) es.add( solph.Sink( label="shunt_el_{0}".format(name), inputs={bel: solph.Flow(variable_costs=PARAMETER["sh_price"])}, )) # Electric Storage es.add( solph.components.GenericStorage( label="storage_elec_{0}".format(name), nominal_storage_capacity=PARAMETER["nominal_storage_capacity"], inputs={bel: solph.Flow()}, outputs={bel: solph.Flow()}, initial_storage_level=data_set["initial_storage_level"], balanced=data_set["balanced"], )) # create an optimization problem and solve it om = solph.Model(es) # solve model om.solve(solver="cbc") # create result object results = solph.processing.results(om) flows = [x for x in results if x[1] is not None] components = [x for x in results if x[1] is None] storage_cap = pd.DataFrame() costs = pd.Series(dtype=float) balance = pd.Series(dtype=float) for flow in [x for x in flows if "source_el" in x[0].label]: name = "_".join(flow[0].label.split("_")[2:]) print(name, float(results[flow]["sequences"].sum())) costs[name] = float(results[flow]["sequences"].sum() * PARAMETER["el_price"]) for flow in [x for x in flows if "shunt_el" in x[1].label]: name = "_".join(flow[1].label.split("_")[2:]) costs[name] += float(results[flow]["sequences"].sum() * PARAMETER["sh_price"]) storages = [x[0] for x in components if "storage" in x[0].label] idx = results[storages[0], None]["sequences"]["storage_content"].index last = idx[-1] prev = idx[0] - 1 * idx.freq for s in storages: name = s.label storage_cap[name] = results[s, None]["sequences"]["storage_content"] storage_cap.loc[prev, name] = results[s, None]["scalars"]["init_content"] balance[name] = (storage_cap.loc[last][name] - storage_cap.loc[prev][name]) if plt is not None: storage_cap.plot(drawstyle="steps-mid", subplots=False, sharey=True) storage_cap.plot(drawstyle="steps-mid", subplots=True, sharey=True) costs.plot(kind="bar", ax=plt.subplots()[1], rot=0) balance.index = [ "balanced", "balanced_None", "unbalanced", "unbalanced_None", ] balance.plot( kind="bar", linewidth=1, edgecolor="#000000", rot=0, ax=plt.subplots()[1], ) plt.show() print(storage_cap) print(costs) print(balance)