Skip to content

Commit

Permalink
Merge branch 'feature/extend_steel_example' into feature/EmissionCons…
Browse files Browse the repository at this point in the history
…traintAdapter
  • Loading branch information
SabineHaas committed Dec 2, 2024
2 parents 6ca11c2 + 28999d7 commit 5664f50
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
28 changes: 17 additions & 11 deletions data_adapter_oemof/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Adapter:
Field(name="name", type=str),
Field(name="region", type=str),
Field(name="year", type=int),
Field(name="full_load_time_max", type=float),
)
output_parameters = (Field(name="max", type=float), Field(name="min", type=float))
input_parameters = ()
Expand Down Expand Up @@ -79,7 +80,6 @@ def get_default_parameters(self) -> dict:

defaults = self.default_post_mapping_calculations(defaults)
if "max_profile" in defaults:
self.timeseries = defaults["max_profile"]
defaults["profile"] = defaults["max_profile"].columns[0]
if not defaults["input_parameters"]:
defaults.pop("input_parameters")
Expand Down Expand Up @@ -339,12 +339,14 @@ def default_pre_mapping_calculations(self):
"""
calculations.normalize_activity_bonds(self)
calculations.process_availability_constant_to_full_load_time_max(self)

def default_post_mapping_calculations(self, mapped_defaults):
"""
Does default calculations#
I. Decommissioning of existing Capacities
I. Decommissioning of existing Capacities (processes _0) and add
`expandable = True` if process is expandable (_1, _2, not _0)
II. Reformatting of amount in case amount is not a number
a) Multiply timeseries by the repeoctiv yearly amount
b) Analogous to decommissioning of capacities
Expand All @@ -361,6 +363,15 @@ def default_post_mapping_calculations(self, mapped_defaults):
adapter_dict=mapped_defaults,
column="capacity",
)
elif self.process_name[-1] == "1" or self.process_name[-1] == "2":
mapped_defaults["expandable"] = True
elif "x2x_other_biogas_treatment" in self.process_name:
mapped_defaults["expandable"] = True
logging.warning(
"Setting capacity cost of x2x_other_biogas_treatment to 0 and "
"life time to 20 as this is missing in the data.")
mapped_defaults["capacity_cost"] = 0
mapped_defaults["lifetime"] = 20

# II:
if "amount" in mapped_defaults.keys():
Expand Down Expand Up @@ -620,6 +631,7 @@ class MIMOAdapter(Adapter):
Field(name="name", type=str),
Field(name="region", type=str),
Field(name="year", type=int),
Field(name="full_load_time_max", type=float),
Field(name="groups", type=dict),
Field(name="lifetime", type=float),
Field(name="capacity_cost", type=float),
Expand All @@ -628,18 +640,10 @@ class MIMOAdapter(Adapter):
Field(name="activity_bound_min", type=float),
Field(name="activity_bound_max", type=float),
Field(name="activity_bound_fix", type=float),
Field(name="primary", type=str),
)
output_parameters = ()

def default_pre_mapping_calculations(self):
"""
Mimo adapter specific pre calculations
Returns
-------
"""
pass

def get_default_parameters(self) -> dict:
defaults = super().get_default_parameters()
defaults["groups"] = self.get_groups()
Expand All @@ -663,6 +667,8 @@ def get_bus_from_struct(bus_list: list, prefix: str) -> dict:
buses = {}
counter = 0
for bus_group in bus_list:
if prefix == "to_bus_" and counter == 0:
buses["primary"] = bus_group
if isinstance(bus_group, str):
buses[f"{prefix}{counter}"] = bus_group
counter += 1
Expand Down
6 changes: 6 additions & 0 deletions data_adapter_oemof/build_datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ def save_datapackage_to_csv(
field_names = [field["name"] for field in resource["schema"]["fields"]]
resource["dialect"] = {"delimiter": ";"}
if resource["name"] in self.foreign_keys.keys():
# drop "primary", see mimo converter of oemof.industry for more information
self.foreign_keys[resource["name"]] = [
item for item in self.foreign_keys[resource["name"]] if
item["fields"] != "primary"
]
# update schema
resource["schema"].update(
{"foreignKeys": self.foreign_keys[resource["name"]]}
)
Expand Down
9 changes: 9 additions & 0 deletions data_adapter_oemof/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def normalize_activity_bonds(adapter):
return adapter


def process_availability_constant_to_full_load_time_max(adapter):
""" Calculate full load time max from availability constant."""
if "availability_constant" in adapter.data.keys():
availability_constant = adapter.data["availability_constant"]
if availability_constant > 1: # assumption: then the unit is %
availability_constant = availability_constant / 100
adapter.data["full_load_time_max"] = 8760 * availability_constant


def floor_lifetime(mapped_defaults):
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/industry/data_adapter_industry.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

logger.info("Building Adapter Map")

# create dicitonary with all found in and outputs
# create dictionary with all found in- and outputs
process_adapter_map = pd.concat(
[
pd.read_excel(
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ authors = [
"Sarah Berendes <Sarah.Berendes@rl-institut.de>",
"Julian Endres <Julian.Endres@rl-institut.de>",
"Felix Maurer <Felix.Maurer@rl-institut.de>",
"Hendrik Huyskens <Hendrik.Huyskens@rl-institut.de>"
"Hendrik Huyskens <Hendrik.Huyskens@rl-institut.de>",
"Sabine Haas <Sabine.Haas@rl-institut.de>"
]

[tool.poetry.group.dev.dependencies]
Expand All @@ -19,8 +20,8 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python = ">=3.10,<3.11"
data_adapter = { git = "https://git@github.com/sedos-project/data_adapter", branch = "bug_fix/drop_comment_column"}
oemof-tabular = { git = "https://git@github.com/oemof/oemof-tabular", branch = "dev"}
data_adapter = { git = "https://git@github.com/sedos-project/data_adapter", branch = "main"}
oemof-tabular = { git = "https://git@github.com/oemof/oemof-tabular", branch = "feature/multi-period-results"}
oemof-industry = { git = "https://github.com/sedos-project/oemof.industry.git", branch = "main"}
boto3 = "1.26.125" # fix boto3 to fasten up dependency resolution
python-dotenv = "^0.21.0"
Expand Down

0 comments on commit 5664f50

Please sign in to comment.