Skip to content

Commit

Permalink
WIP zu reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Bachibouzouk committed Oct 14, 2024
1 parent 1e2b690 commit f10d1d5
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 67 deletions.
2 changes: 1 addition & 1 deletion examples/scenarios/test_mimo_crop/datapackage.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profile": "tabular-data-package",
"name": "test_mimo_crop",
"oemof_tabular_version": "0.0.5",
"oemof_tabular_version": "0.0.6dev",
"resources": [
{
"path": "data/elements/bus.csv",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name;type;carrier;tech;capacity;capacity_cost;bus;marginal_cost;carrier_cost;profile;output_parameters;expandable
solar-radiation;volatile;solar-energy;source;0;0;solar-energy-bus;0.0;0.0;ghi;{};True
solar-radiation;volatile;solar-energy;source;0;0;solar-energy-bus;0.0;0.0;ghi;{};False
back-up-elec;dispatchable;electricity;source;0;10;elec-bus;10.0;0.3;1.0;{};True
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name;type;carrier;tech;capacity;capacity_cost;marginal_cost;carrier_cost;capacity_potential;from_bus;to_bus;t_air;ghi;p_rpv;r_ref;n_t;t_c_ref;noct;expandable
pv-panel;pv-panel;solar-energy;pv;0;0;0;-0.1;100;solar-energy-bus;elec-bus;t-air;ghi;270;1000;-0.0037;25;48;True
pv-panel;pv-panel;solar-energy;pv;0;0;0;0;100;solar-energy-bus;elec-bus;t-air;ghi;270;1000;-0.0037;25;48;True
2 changes: 1 addition & 1 deletion examples/scenarios/wefe_pv_panel/datapackage.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
},
{
"name": "carrier_cost",
"type": "number",
"type": "integer",
"format": "default"
},
{
Expand Down
3 changes: 2 additions & 1 deletion examples/scripts/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"water_footprint_factor",
]
# set whether the multi-objective optimization should be performed
moo = True
moo = False

# -------------- RUNNING THE SCENARIOS --------------
for scenario in scenarios:
Expand All @@ -86,6 +86,7 @@
moo=moo,
dash_app=True,
parameters_units=parameters_units,
infer_bus_carrier=False,
)
df = calculator.df_results
print(df)
Expand Down
1 change: 1 addition & 0 deletions examples/scripts/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# -------------- USER INPUTS --------------
# list of scenarios to be evaluated
scenarios = [
"test_mimo_crop",
# "general_add_cost_inputs",
# "general_basic",
# "general_constraints",
Expand Down
3 changes: 2 additions & 1 deletion src/oemof_tabular_plugins/datapackage/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ def construct_dataframe_from_results(
]
# lookup bus-carrier mapping in the dp_path, if existing
p = Package(dp_path)
bus_carrier = infer_busses_carrier(p, infer_from_component=False)
# bus_carrier = infer_busses_carrier(p, infer_from_component=False)
bus_carrier = None

if bus_carrier is None:
if infer_bus_carrier is True:
Expand Down
120 changes: 60 additions & 60 deletions src/oemof_tabular_plugins/general/post_processing/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@ def set_unit(carrier, facade_type):
if kpis is not None:
kpis.to_csv(results_path + "/kpis.csv", index=True)

if "mimo" in results_by_flow.index.get_level_values("asset"):
kpis.loc["total_water_produced"] = results_by_flow.loc[
"permeate-bus", "in"
]["aggregated_flow"].sum()
kpis.loc["total_brine_produced"] = results_by_flow.loc["brine-bus", "in"][
"aggregated_flow"
].sum()
kpis.loc["total_electricity_produced"] = results_by_flow.loc[
"ac-elec-bus", "in"
]["aggregated_flow"].sum()
# if "mimo" in results_by_flow.index.get_level_values("asset"):
# kpis.loc["total_water_produced"] = results_by_flow.loc[
# "permeate-bus", "in"
# ]["aggregated_flow"].sum()
# kpis.loc["total_brine_produced"] = results_by_flow.loc["brine-bus", "in"][
# "aggregated_flow"
# ].sum()
# kpis.loc["total_electricity_produced"] = results_by_flow.loc[
# "ac-elec-bus", "in"
# ]["aggregated_flow"].sum()

result_tables.update({"kpis": kpis})

Expand All @@ -314,55 +314,55 @@ def set_unit(carrier, facade_type):
demo_app.run_server(debug=False, port=8060)

# ----- OLD POST-PROCESSING - TO BE DELETED ONCE CERTAIN -----
if hasattr(calculator, "scalar_params"):
# calculate scalars using functions from clc module
aggregated_flows = clc.AggregatedFlows(calculator).result
storage_losses = clc.StorageLosses(calculator).result
transmission_losses = clc.TransmissionLosses(calculator).result
invested_capacity = clc.InvestedCapacity(calculator).result
invested_storage_capacity = clc.InvestedStorageCapacity(calculator).result
invested_capacity_costs = clc.InvestedCapacityCosts(calculator).result
invested_storage_capacity_costs = clc.InvestedStorageCapacityCosts(
calculator
).result
summed_carrier_costs = clc.SummedCarrierCosts(calculator).result
summed_marginal_costs = clc.SummedMarginalCosts(calculator).result
total_system_costs = clc.TotalSystemCosts(calculator).result

# combine all results into a single dataframe
all_scalars = [
aggregated_flows,
storage_losses,
transmission_losses,
invested_capacity,
invested_storage_capacity,
invested_capacity_costs,
invested_storage_capacity_costs,
summed_carrier_costs,
summed_marginal_costs,
]
# map variable names and add component information
all_scalars = pd.concat(all_scalars, axis=0)
all_scalars = naming.map_var_names(
all_scalars,
calculator.scalar_params,
calculator.busses,
calculator.links,
)
all_scalars = naming.add_component_info(all_scalars, calculator.scalar_params)
print("Total System Cost", total_system_costs)
total_system_costs.index.names = ("name", "var_name")
all_scalars = pd.concat([all_scalars, total_system_costs], axis=0)
all_scalars = all_scalars.sort_values(by=["carrier", "tech", "var_name"])
# save all scalar results to a csv file
filepath_name_all_scalars = os.path.join(results_path, "all_scalars.csv")
all_scalars.to_csv(filepath_name_all_scalars)

# saves all hourly timeseries as a dataframe (see test_postprocessing.py in oemof-tabular/tests
# for example if wanting to filter particular nodes)
all_sequences = clc.AggregatedFlows(calculator, resample_mode="H")
# save all timeseries (sequence) results to a csv file
filepath_name_all_sequences = os.path.join(results_path, "all_sequences.csv")
all_sequences.sequences.to_csv(filepath_name_all_sequences)
# if hasattr(calculator, "scalar_params"):
# # calculate scalars using functions from clc module
# aggregated_flows = clc.AggregatedFlows(calculator).result
# storage_losses = clc.StorageLosses(calculator).result
# transmission_losses = clc.TransmissionLosses(calculator).result
# invested_capacity = clc.InvestedCapacity(calculator).result
# invested_storage_capacity = clc.InvestedStorageCapacity(calculator).result
# invested_capacity_costs = clc.InvestedCapacityCosts(calculator).result
# invested_storage_capacity_costs = clc.InvestedStorageCapacityCosts(
# calculator
# ).result
# summed_carrier_costs = clc.SummedCarrierCosts(calculator).result
# summed_marginal_costs = clc.SummedMarginalCosts(calculator).result
# total_system_costs = clc.TotalSystemCosts(calculator).result
#
# # combine all results into a single dataframe
# all_scalars = [
# aggregated_flows,
# storage_losses,
# transmission_losses,
# invested_capacity,
# invested_storage_capacity,
# invested_capacity_costs,
# invested_storage_capacity_costs,
# summed_carrier_costs,
# summed_marginal_costs,
# ]
# # map variable names and add component information
# all_scalars = pd.concat(all_scalars, axis=0)
# all_scalars = naming.map_var_names(
# all_scalars,
# calculator.scalar_params,
# calculator.busses,
# calculator.links,
# )
# all_scalars = naming.add_component_info(all_scalars, calculator.scalar_params)
# print("Total System Cost", total_system_costs)
# total_system_costs.index.names = ("name", "var_name")
# all_scalars = pd.concat([all_scalars, total_system_costs], axis=0)
# all_scalars = all_scalars.sort_values(by=["carrier", "tech", "var_name"])
# # save all scalar results to a csv file
# filepath_name_all_scalars = os.path.join(results_path, "all_scalars.csv")
# all_scalars.to_csv(filepath_name_all_scalars)
#
# # saves all hourly timeseries as a dataframe (see test_postprocessing.py in oemof-tabular/tests
# # for example if wanting to filter particular nodes)
# all_sequences = clc.AggregatedFlows(calculator, resample_mode="H")
# # save all timeseries (sequence) results to a csv file
# filepath_name_all_sequences = os.path.join(results_path, "all_sequences.csv")
# all_sequences.sequences.to_csv(filepath_name_all_sequences)

return calculator
20 changes: 20 additions & 0 deletions src/oemof_tabular_plugins/script/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,29 @@ def compute_scenario(

logger.info("Energy system created from datapackage")

from oemof_visio import ESGraphRenderer

gr = ESGraphRenderer(
energy_system=es, filepath=os.path.join(results_path, scenario_name)
)
gr.render()

# create model from energy system (this is just oemof.solph)
m = Model(es)
logger.info("Model created from energy system")
# mimo = [n for n in es.nodes if "mimo" in n.label]
# print([l.label for l in mimo])
#
# crop = mimo[0]
# print("Investments on inputs")
# print([f"{i.label}({str(f.investment)})" for i,f in crop.inputs.items()])
# print("Nominal values on inputs")
# print([f"{i.label}({str(f.nominal_value)})" for i,f in crop.inputs.items()])
#
# print("Investments on outputs")
# print([f"{i.label}({str(f.investment)})" for i,f in crop.outputs.items()])
# print("Nominal values on outputs")
# print([f"{i.label}({str(f.nominal_value)})" for i,f in crop.outputs.items()])

# add constraints from datapackage to the model
m.add_constraints_from_datapackage(
Expand Down
158 changes: 157 additions & 1 deletion src/oemof_tabular_plugins/wefe/facades/water.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import field
from dataclasses import field, dataclass

from typing import Sequence, Union

from oemof.solph._plumbing import sequence
Expand All @@ -8,6 +9,8 @@

from oemof.tabular._facade import dataclass_facade, Facade

from oemof_tabular_plugins.wefe.facades import MIMO


@dataclass_facade
class WaterFiltration(Converter, Facade):
Expand Down Expand Up @@ -225,3 +228,156 @@ def build_solph_components(self):
)
}
)


@dataclass(unsafe_hash=False, frozen=False, eq=False)
class ReverseOsmosis(MIMO):
r"""
Crop Model Converter with 3 inputs (irradiation, precipitation, irrigation)
and 2 outputs (crop harvest, remaining biomass), based on MultipleInputMultipleOutputConverter.
Functions designed according to 3 publications, please note the abbreviations in the function descriptions:
FAO56 ISBN: 978-92-5-104219-9
SIMPLE https://doi.org/10.1016/j.eja.2019.01.009
ARID https://doi.org/10.2134/agronj2011.0286
Parameters
----------
type: str
will link MimoCrop to TYPEMAP, currently named 'mimo-crop'
name: str
a remarkable name for your component
tech: str
whatever, I just specified it as 'mimo'
carrier: str
carrier of the primary bus, should be overwritten by carriers directly assigned to buses
primary: str
primary bus object to which investments etc. are assigned
expandable: boolean or numeric (binary)
True, if capacity can be expanded within optimization. Default: False.
capacity: numeric
The capacity of crop. It is expressed in cultivated area [m²]
capacity_minimum: numeric
Minimum invest capacity in unit of output capacity.
capacity_potential: numeric (seems not to work as it should)
Maximum invest capacity in unit of output capacity.
capacity_cost: numeric
Investment costs per unit of output capacity. If capacity is not set,
this value will be used for optimizing the conversion output capacity.
crop_type: str
the name of crop as defined in global_specs/crop_specs.py
solar_energy_bus: oemof.solph.Bus
An oemof bus instance where the MimoCrop unit is connected to with
its input, it is expected to provide W/m² irradiance.
precipitation_bus: oemof.solph.Bus
An oemof bus instance where the MimoCrop unit is connected to with
its input, it is expected to provide mm precipitation.
irrigation_bus: oemof.solph.Bus
An oemof bus instance where the MimoCrop unit is connected to with
its input, it is expected to provide mm irrigation.
crop_bus: oemof.solph.Bus
An oemof bus instance where the MimoCrop unit is connected to with
its crop-harvest output. The unit is kg.
biomass_bus: oemof.solph.Bus
An oemof bus instance where the MimoCrop is connected with its
non-edible, remaining (residual) biomass output. The unit is kg.
time_profile: time series
time profile separate from time index
ghi_profile: time series
global horizontal solar irradiance in W/m²
tp_profile: time series
total precipitation in mm
t_air_profile: time series
ambient air tempearture in °C
t_dp_profile: time series
dew point temperature in °C
windspeed_profile: time series
windspeed in m/s
elevation: float
elevation above sea level of the location
crop_type: str
the name of crop as defined in global_specs/crop_specs.py
sowing_date: str
date when cultivation period starts, MM-DD format
harvest_date:
date when cultivation period ends, MM-DD format
has_irrigation: bool
if set to False, irrigation profile will be set to 0
Other optional parameters that could be added:
---------------------------------------------
marginal_cost: numeric
Marginal cost for one unit of produced output. Default: 0
carrier_cost: numeric
Carrier cost for one unit of used input. Default: 0
input_parameters: dict (optional)
Set parameters on the input edge of the conversion unit
(see oemof.solph for more information on possible parameters)
output_parameters: dict (optional)
Set parameters on the output edge of the conversion unit
(see oemof.solph for more information on possible parameters)
Notes:
---------------------------------------------
One input (eg. ghi) has to be volatile with a fixed capacity, other 2 dispatchable.
MimoCrop capacity_potential seems to not work correctly.
Two options to successfully run MimoCrop:
1) Expandable = True and ignore capacity, use capacity of volatile source instead.
2) Expandable = False, set capacity equal to that of the volatile source.
In case you experience a weird error, for example "TypeError: can't multiply sequence by non-int of type 'float'",
this is likely due to empty rows at the end of your input csv files.
Please remove them and try again.
"""

type: str = "mimo-crop"

name: str = ""

tech: str = "mimo"

carrier: str = ""

primary: str = ""

expandable: bool = False

capacity: float = 0

capacity_minimum: float = None

capacity_potential: float = None

capacity_cost: float = 0

solar_energy_bus: Bus = None

precipitation_bus: Bus = None

irrigation_bus: Bus = None

crop_bus: Bus = None

biomass_bus: Bus = None

time_profile: Union[float, Sequence[float]] = None

ghi_profile: Union[float, Sequence[float]] = None

tp_profile: Union[float, Sequence[float]] = None

t_air_profile: Union[float, Sequence[float]] = None

t_dp_profile: Union[float, Sequence[float]] = None

windspeed_profile: Union[float, Sequence[float]] = None

elevation: float = 0

crop_type: str = "" # according to crop_dict

sowing_date: str = "" # MM-DD format

harvest_date: str = "" # MM-DD format

has_irrigation: bool = False

0 comments on commit f10d1d5

Please sign in to comment.