Skip to content

Commit

Permalink
Merge pull request #48 from rl-institut/feature/developp-for-uscases
Browse files Browse the repository at this point in the history
Feature/developp for uscases
  • Loading branch information
Bachibouzouk authored Oct 24, 2024
2 parents 12d0c74 + 432e0b6 commit d3eefbe
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- pre-commit configuration (lint files with black)
- general_custom_attributes example
- tests for pre-rpocessing of custom attributes
- tests for pre-processing of custom attributes
- layout for multi-objective optimization (MOO)
- a new workflow for automated tests
- new function for adding additional foreign keys to datapackage.json in src/oemof_tabular_plugins/datapackage/building.py
- new Facade for APV (Agriphotovolatic) based on oemof.industry MIMO class
- function `infer_busses_carrier` to get the carriers assigned to each bus either explicitly (ie directly defined in `bus.csv` resource) or implicitly (ie via the carriers assigned to components connected to busses). The explicit method can lead to logical errors such as two carriers assigned to a single bus which is then raised as an error.
- Facade SimpleCrop in wefe subpackage to simulate a crop growth without accounting for water in (following this reference https://doi.org/10.1016/j.eja.2019.01.009), a test model is provided in `examples/scenarios/test_crop`.
- new Facade for Water Pump

### Changed
- structure of the general package and the wefe package
- pre-processing.py to include the option for adding custom attributes e.g. renewable factor, emission factor, land requirement
- scripts/infer.py files and included foreign keys function where necessary
- grouped common fonctions for different wefe facade in one module
- Now `validate_datapackage` of facades must return the resource (modified or not)

### Removed
- the hydrogen package
Expand Down
14 changes: 14 additions & 0 deletions src/oemof_tabular_plugins/datapackage/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def compute_capacity_total(results_df):
return results_df.capacity + investments


def compute_capacity_added(results_df):
"""Calculates duplicate optimized capacity (investments) into a column with a better name"""
investments = results_df.investments
if investments is None:
investments = 0
return investments


def compute_annuity_total(results_df):
"""Calculates total annuity by multiplying the annuity by the optimized capacity"""
# ToDo: now storage_capacity_cost is used for the annuity if the component is storage.
Expand Down Expand Up @@ -369,6 +377,12 @@ def _check_arguments(df, column_names, col_name):
"to the existing capacity (capacity)",
"argument_names": ["investments", "capacity"],
},
{
"column_name": "capacity_added",
"operation": compute_capacity_added,
"description": "The optimized capacity column is duplicated with a better name than 'investments'",
"argument_names": ["investments"],
},
{
"column_name": "annuity_total",
"operation": compute_annuity_total,
Expand Down
12 changes: 11 additions & 1 deletion src/oemof_tabular_plugins/wefe/facades/mimo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
from oemof_industry.mimo_converter import MIMO
import logging

try:
from oemof_industry.mimo_converter import MIMO
except ModuleNotFoundError:
logging.error(
"oemof industry is not installed, install it with 'pip install oemof.industry'"
)
from oemof.tabular.facades import Conversion

MIMO = Conversion


def validate_mimo_datapackage(cls, resource):
Expand Down
47 changes: 41 additions & 6 deletions src/oemof_tabular_plugins/wefe/facades/water.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import field
from typing import Sequence, Union

import numpy as np
from oemof.solph._plumbing import sequence
from oemof.solph.buses import Bus
from oemof.solph.components import Converter
Expand Down Expand Up @@ -133,11 +134,15 @@ class WaterPump(Converter, Facade):
water_out_bus: oemof.solph.Bus
An oemof bus instance where the unit is connected to with
its water output.
capacity: numeric
pump_height: numeric
The height in meters the pump must overcome.
efficiency: numeric (iterable or scalar) (optional)
The efficiency of the pump
capacity: numeric (optional)
The thermal capacity (high temperature output side) of the unit.
carrier_cost: numeric
carrier_cost: numeric (optional)
Carrier cost for one unit of used input. Default: 0
capacity_cost: numeric
capacity_cost: numeric (optional)
Investment costs per unit of output capacity.
If capacity is not set, this value will be used for optimizing the
conversion output capacity.
Expand Down Expand Up @@ -173,8 +178,12 @@ class WaterPump(Converter, Facade):

tech: str

pump_height: float

carrier: str = ""

efficiency: Union[float, Sequence[float]] = 1

capacity: float = None

marginal_cost: float = 0
Expand All @@ -197,13 +206,39 @@ class WaterPump(Converter, Facade):

output_parameters: dict = field(default_factory=dict)

@property
def g(self):
"""Gravitational acceleration"""
return 9.81 # m²/s

@property
def rho_w(self):
"""Water density"""
return 1000 # kg/m³

def build_solph_components(self):
"""TODO change efficiencies here"""
# TODO ask vivek for references for water pumps
conversion_W_to_kW = 1e-3
conversion_m3_per_hour_to_m3_per_s = 1.0 / 3600

if isinstance(self.efficiency, list):
eta = np.array(self.efficiency)
else:
eta = self.efficiency

self.conversion_factors.update(
{
self.electricity_bus: sequence(1),
self.water_in_bus: sequence(1),
self.water_out_bus: sequence(1),
self.electricity_bus: sequence(
self.g
* self.rho_w
* conversion_W_to_kW
* self.pump_height
* conversion_m3_per_hour_to_m3_per_s
/ eta
), # in kWh
self.water_in_bus: sequence(1), # in m³/h
self.water_out_bus: sequence(1), # in m³/h
}
)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_inputs/water_components/data/elements/water.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
type;name;carrier;tech;expandable;capacity;capacity_cost;marginal_cost;electricity_bus;water_in_bus;water_out_bus;capex;opex_fix;age;lifetime;carrier_cost;resource_cost;land_requirement_factor;ghg_emission_factor;water_footprint_factor;land_requirement;ghg_emissions;water_footprint;output_parameters
water-filtration;water filter;water;filtration;True;0;0;0;ac-elec-bus;service-water-bus;drinking-water-bus;;;0;10;0;0;0;0;0;0;0;0;"{""custom_attributes"": {""ghg_emission_factor"": 0, ""land_requirement_factor"": 0, ""water_footprint_factor"": 0, ""land_requirement"": 0, ""water_footprint"": 0, ""ghg_emissions"": 0, ""resource_cost"": 0}}"
water-pump;water pump;water;pumping;True;0;0;0;ac-elec-bus;groundwater-bus;service-water-bus;;;0;10;0;0;0;0;0;0;0;0;"{""custom_attributes"": {""ghg_emission_factor"": 0, ""land_requirement_factor"": 0, ""water_footprint_factor"": 0, ""land_requirement"": 0, ""water_footprint"": 0, ""ghg_emissions"": 0, ""resource_cost"": 0}}"
type;name;carrier;tech;expandable;pump_height;capacity;capacity_cost;marginal_cost;electricity_bus;water_in_bus;water_out_bus;capex;opex_fix;age;lifetime;carrier_cost;resource_cost;land_requirement_factor;ghg_emission_factor;water_footprint_factor;land_requirement;ghg_emissions;water_footprint;output_parameters
water-pump;water pump;water;pumping;True;2.3;0;0;0;ac-elec-bus;groundwater-bus;service-water-bus;;;0;10;0;0;0;0;0;0;0;0;"{""custom_attributes"": {""ghg_emission_factor"": 0, ""land_requirement_factor"": 0, ""water_footprint_factor"": 0, ""land_requirement"": 0, ""water_footprint"": 0, ""ghg_emissions"": 0, ""resource_cost"": 0}}"
water-filtration;water filter;water;filtration;True;;0;0;0;ac-elec-bus;service-water-bus;drinking-water-bus;;;0;10;0;0;0;0;0;0;0;0;"{""custom_attributes"": {""ghg_emission_factor"": 0, ""land_requirement_factor"": 0, ""water_footprint_factor"": 0, ""land_requirement"": 0, ""water_footprint"": 0, ""ghg_emissions"": 0, ""resource_cost"": 0}}"
5 changes: 5 additions & 0 deletions tests/test_inputs/water_components/datapackage.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@
"type": "boolean",
"format": "default"
},
{
"name": "pump_height",
"type": "number",
"format": "default"
},
{
"name": "capacity",
"type": "integer",
Expand Down
1 change: 0 additions & 1 deletion tests/test_pre_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pandas as pd
import pytest
from oemof_tabular_plugins.general import pre_processing, calculate_annuity
from unittest.mock import patch
import json


Expand Down

0 comments on commit d3eefbe

Please sign in to comment.