Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and extend tests #48

Merged
merged 50 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d332e47
Fix Gas generator
FelixMau Aug 10, 2023
4581a23
Add in some more data into mocks
FelixMau Aug 10, 2023
a5111a8
Included in `test_data_adapter`
FelixMau Aug 16, 2023
664dec8
Update __init__.py
FelixMau Aug 16, 2023
4d2f0f5
Mapping test adjustments
FelixMau Aug 16, 2023
babd2f5
Mapping test adjustments
FelixMau Aug 16, 2023
459fe4b
Pre-commit
FelixMau Aug 16, 2023
32afe2c
Merge remote-tracking branch 'origin/fix-and-extend-tests' into fix-a…
FelixMau Aug 16, 2023
66cee65
pre-commit
FelixMau Aug 16, 2023
2bb4cc6
Pre-comm
FelixMau Aug 16, 2023
68a1377
test_build_datapackage.py
FelixMau Aug 16, 2023
727812f
Adapter is tested in `data_adapter`
FelixMau Aug 16, 2023
fbab594
Example is tested when full example is ready
FelixMau Aug 16, 2023
661bf3f
Adding FIXME statements to functionality that is on hold
FelixMau Aug 16, 2023
4d3466f
Fix Gas generator
FelixMau Aug 10, 2023
7e81602
Add in some more data into mocks
FelixMau Aug 10, 2023
fb10c1f
Included in `test_data_adapter`
FelixMau Aug 16, 2023
469dc28
Mapping test adjustments
FelixMau Aug 16, 2023
f63c251
Mapping test adjustments
FelixMau Aug 16, 2023
5de6b23
Pre-commit
FelixMau Aug 16, 2023
a1eb0d2
Update __init__.py
FelixMau Aug 16, 2023
eedaac9
pre-commit
FelixMau Aug 16, 2023
76736ec
test_build_datapackage.py
FelixMau Aug 16, 2023
f07a1bb
Adapter is tested in `data_adapter`
FelixMau Aug 16, 2023
5c3fceb
Example is tested when full example is ready
FelixMau Aug 16, 2023
a0bf5a1
Adding FIXME statements to functionality that is on hold
FelixMau Aug 16, 2023
8b4b1fb
Black&Isort
nailend Aug 16, 2023
0d90d96
Add skip test
nailend Aug 16, 2023
13ae5cd
Adjust collections dir
nailend Aug 16, 2023
7e76ac0
Fix typo
nailend Aug 16, 2023
a24aa93
Load test environment variables via conftest.py
henhuy Aug 17, 2023
aa05500
Update fixed data adapter
henhuy Aug 17, 2023
6725515
Make linter happy
henhuy Aug 17, 2023
332b7ba
Update data adapter
henhuy Aug 17, 2023
24c1250
Make linter happy
henhuy Aug 17, 2023
7aa38dc
Fix isort
henhuy Aug 17, 2023
a7b7303
Fix collections and structures dir defaults
henhuy Aug 17, 2023
5663f45
Update data adapter
henhuy Aug 17, 2023
b98db82
Remove support for python v3.8
henhuy Aug 17, 2023
a7bac18
Merge remote-tracking branch 'origin/fix-and-extend-tests' into fix-a…
FelixMau Aug 28, 2023
524ab1b
make linter happy
FelixMau Aug 28, 2023
a283b57
Check on files in github checks
FelixMau Aug 28, 2023
e4e503d
gitkeep filestructure
FelixMau Aug 28, 2023
6bfa77f
further test for utils
FelixMau Aug 28, 2023
4f5c753
Further test on utils
FelixMau Aug 28, 2023
e356fd6
fix tests pathing
FelixMau Aug 28, 2023
73951fb
Finally Fixed Pathing
FelixMau Aug 28, 2023
4346896
Linter shall be happy
FelixMau Aug 28, 2023
4ffd485
Add todo
FelixMau Aug 28, 2023
400c000
Improve comments and add ToDo
FelixMau Aug 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10' ]
python-version: [ '3.9', '3.10' ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea/
collections/
collections/*
__pycache__/
/structures/
#/structures/
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@ repos:
entry: black
language: python
types: [ python ]
- id: isort
name: isort
entry: isort
language: python
types: [ python ]
- id: flake8
name: flake8
entry: flake8
language: python
types: [python]
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
]
6 changes: 6 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pathlib

import dotenv

TEST_ENV_FILE = pathlib.Path(__file__).parent / "tests" / ".env"
dotenv.load_dotenv(TEST_ENV_FILE)
2 changes: 0 additions & 2 deletions data_adapter_oemof/adapters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import dataclasses
import logging

import oemof.solph
import pandas
from oemof.solph import Bus
from oemof.tabular import facades

Expand Down
37 changes: 23 additions & 14 deletions data_adapter_oemof/build_datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def refactor_timeseries(timeseries: pd.DataFrame):
Parameters
----------
timeseries: pd.DataFrame
timeseries in parameter-model format (https://github.com/sedos-project/oedatamodel#oedatamodel-parameter)
timeseries in parameter-model format
(https://github.com/sedos-project/oedatamodel#oedatamodel-parameter)

Returns
pd.DataFrame Tabular form of timeseries for multiple periods of similar
Expand All @@ -31,7 +32,6 @@ def refactor_timeseries(timeseries: pd.DataFrame):
"""
# Combine all time series into one DataFrame
df_timeseries = pd.DataFrame()
timeseries_timesteps = []
if timeseries.empty:
return df_timeseries
# Iterate over different time periods/years
Expand Down Expand Up @@ -107,14 +107,16 @@ def get_foreign_keys(struct: list, mapper: Mapper, components: list) -> list:
struct: list
Energy System structure defining input/outputs for Processes
mapper: Mapper
for one element of the Process (foreign keys have to be equal for all components of a Process)
for one element of the Process
(foreign keys have to be equal for all components of a Process)
components: list
all components as of a Process as dicts. Helps to check what columns that could be pointing to sequences
are found in Sequences.
all components as of a Process as dicts. Helps to check what columns
that could be pointing to sequences are found in Sequences.

Returns
-------
list of foreignKeys for Process including bus references and pointers to files containing `profiles`
list of foreignKeys for Process including bus references and pointers to files
containing `profiles`
"""
new_foreign_keys = []
components = pd.DataFrame(components)
Expand All @@ -139,9 +141,13 @@ def get_foreign_keys(struct: list, mapper: Mapper, components: list) -> list:
}
)
elif any(components[field.name].isin(mapper.timeseries.columns)):
# Todo clean up on examples:
# -remove DE from hackerthon or
# -create propper example with realistic project data
warnings.warn(
"Not all profile columns are set within the given profiles."
f" Please check if there is a timeseries for every Component in {mapper.process_name}"
f" Please check if there is a timeseries for every Component in "
f"{mapper.process_name}"
)
new_foreign_keys.append(
{
Expand All @@ -152,7 +158,9 @@ def get_foreign_keys(struct: list, mapper: Mapper, components: list) -> list:
}
)
else:
# Most likely the field may be a Timeseries in this case, but it is a scalar or unused.
# The Field is allowed to be a timeseries
# -> and likely is a supposed to be a timeseries
# but a scalar or `unused` is found.
pass
return new_foreign_keys

Expand All @@ -165,8 +173,9 @@ def save_datapackage_to_csv(self, destination: str) -> None:
self: DataPackage
DataPackage to save
destination: str
String to where the datapackage save to. More convenient to use os.path. If last level of folder stucture
does not exist, it will be created (as well as /elements and /sequences)
String to where the datapackage save to. More convenient to use os.path.
If last level of folder stucture does not exist, it will be created
(as well as /elements and /sequences)

Returns
-------
Expand Down Expand Up @@ -228,8 +237,8 @@ def build_datapackage(cls, adapter: Adapter):
Parameters
----------
adapter: Adapter
Adapter from oemof_data_adapter that is able to handle parameter model data from Databus.
Adapter needs to be initialized with `structure_name`. Use `links_
Adapter from oemof_data_adapter that is able to handle parameter model data
from Databus. Adapter needs to be initialized with `structure_name`. Use `links_

Returns
-------
Expand Down Expand Up @@ -267,8 +276,8 @@ def build_datapackage(cls, adapter: Adapter):
parametrized_elements["bus"] += process_busses

# getting foreign keys with last component
# foreign keys have to be equal for every component within a Process as foreign key columns cannot
# have mixed meaning
# foreign keys have to be equal for every component within a Process
# as foreign key columns cannot have mixed meaning
foreign_keys[process_name] = cls.get_foreign_keys(
struct, component_mapper, components
)
Expand Down
14 changes: 7 additions & 7 deletions data_adapter_oemof/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ def get_busses(self, struct):
If found, search for similarities in the structure CSV.
If not, search for name similarities:
Between the structure CSV and the adapter's buses take name from the structure.
Note: If passed class has more than two busses or different names for busses fields it is highly recommended
to provide BUS_NAME_MAP entry for this class. If multiple instances of the same facade
shall be having different inputs/outputs a facade Adapter has to be added for each.
Note: If passed class has more than two busses or different names for busses fields it
is highly recommended to provide BUS_NAME_MAP entry for this class.
If multiple instances of the same facade shall be having different inputs/outputs
a facade Adapter has to be added for each.
:param struct: dict
:return: dictionary with tabular like Busses
"""
Expand All @@ -153,7 +154,6 @@ def get_busses(self, struct):

bus_dict = {}
for bus in bus_occurrences_in_fields: # emission_bus

# 1. Check for existing mappings
try:
bus_dict[bus] = self.bus_map[self.adapter.__name__][bus]
Expand All @@ -169,8 +169,8 @@ def get_busses(self, struct):
struct = struct["default"]
else:
warnings.warn(
"Please check structure and provide either one set of inputs/outputs or specify as default"
"Parameter specific busses not implemented yet"
"Please check structure and provide either one set of inputs/outputs "
"or specify as default Parameter specific busses not implemented yet"
)

# 2. Check for default busses
Expand All @@ -183,7 +183,7 @@ def get_busses(self, struct):
busses = struct["outputs"]
if len(busses) != 1:
raise MappingError(
f"Could not map {bus=} to default bus - too many options"
f"Could not map {bus} to default bus - too many options"
)
bus_dict[bus] = busses[0]
continue
Expand Down
4 changes: 2 additions & 2 deletions data_adapter_oemof/mappings/BUS_NAME_MAP.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ VolatileAdapter:
bus: electricity

ConversionAdapter:
from_bus: auto
to_bus: auto
from_bus: ch4
to_bus: electricity
2 changes: 1 addition & 1 deletion data_adapter_oemof/mappings/PROCESS_TYPE_MAP.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a mapping file to map the various processes to the oemof tabular facades.
modex_tech_wind_turbine_onshore: VolatileAdapter
modex_tech_storage_battery: StorageAdapter
modex_tech_generator_gas: ExtractionTurbineAdapter
modex_tech_generator_gas: ConversionAdapter
27 changes: 25 additions & 2 deletions data_adapter_oemof/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
import os
import pathlib

ROOT_DIR = pathlib.Path(__file__).parent.parent
COLLECTIONS_DIR = ROOT_DIR / "collections"
ROOT_DIR = pathlib.Path(__file__).parent

COLLECTIONS_DIR = (
pathlib.Path(os.environ["COLLECTIONS_DIR"])
if "COLLECTIONS_DIR" in os.environ
else pathlib.Path.cwd() / "collections"
)
if not COLLECTIONS_DIR.exists():
raise FileNotFoundError(
f"Could not find collections directory '{COLLECTIONS_DIR}'. "
"You should either create the collections folder or "
"change path to collection folder by changing environment variable 'COLLECTIONS_DIR'.",
)
STRUCTURES_DIR = (
pathlib.Path(os.environ["STRUCTURES_DIR"])
if "STRUCTURES_DIR" in os.environ
else pathlib.Path.cwd() / "structures"
)
if not STRUCTURES_DIR.exists():
raise FileNotFoundError(
f"Could not find structure directory '{STRUCTURES_DIR}'. "
"You should either create the structure folder or "
"change path to structure folder by changing environment variable 'STRUCTURES_DIR'.",
)
33 changes: 25 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "data_adapter_oemof"
name = "data_adapter_oemof_tests"
version = "0.0.1dev"
description = "Data adapter from oedatamodel to oemof.tabular datapackages"
authors = [
Expand All @@ -8,16 +8,19 @@ authors = [
"Julian Endres <[email protected]>",
]

[tool.poetry.group.dev.dependencies]
isort = "^5.12.0"

[build-system]
requires = ["poetry_core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python = ">=3.8.1,<3.11"
data_adapter = { git = "https://[email protected]/sedos-project/data_adapter", branch = "dev"}
data_adapter = { git = "https://[email protected]/sedos-project/data_adapter", branch = "main"}
oemof-tabular = { git = "https://[email protected]/oemof/oemof-tabular", tag = "v0.0.4.dev0"}
# fix boto3 to fasten up dependency resolution
boto3 = "1.26.125"
boto3 = "1.26.125" # fix boto3 to fasten up dependency resolution
python-dotenv = "^0.21.0"

[tool.poetry.dev-dependencies]
black = "20.8b1"
Expand All @@ -43,3 +46,6 @@ exclude = '''
)/
'''
max-line-length=100

[tool.isort]
profile = "black"
3 changes: 3 additions & 0 deletions tests/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

COLLECTIONS_DIR=tests/collections
STRUCTURES_DIR=tests/structures
3 changes: 3 additions & 0 deletions tests/_files/build_datapackage_goal/data/elements/bus.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name;type;balanced
electricity;bus;True
ch4;bus;True
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from_bus;to_bus;carrier;tech;capacity;efficiency;marginal_cost;carrier_cost;capacity_cost;expandable;capacity_potential;capacity_minimum;input_parameters;output_parameters;name;type
ch4;electricity;gas;generator_gas;;1;0;0;;False;inf;;{};{};BB-2016-generator_gas;conversion
ch4;electricity;gas;generator_gas;;1;0;0;;False;inf;;{};{};BB-2030-generator_gas;conversion
ch4;electricity;gas;generator_gas;;1;0;0;;False;inf;;{};{};BB-2050-generator_gas;conversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bus;carrier;tech;storage_capacity;capacity;capacity_cost;storage_capacity_cost;storage_capacity_potential;capacity_potential;expandable;lifetime;age;fixed_costs;marginal_cost;efficiency;input_parameters;output_parameters;name;type
electricity;Lithium;storage_battery;0;17.8;0;;inf;inf;False;;0;[];0;1;{};{};BB-2016-storage_battery;storage
electricity;Lithium;storage_battery;0;17.8;0;;inf;inf;False;;0;[];0;1;{};{};BB-2030-storage_battery;storage
electricity;Lithium;storage_battery;0;17.8;0;;inf;inf;False;;0;[];0;1;{};{};BB-2050-storage_battery;storage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bus;carrier;tech;profile;capacity;capacity_potential;capacity_minimum;expandable;marginal_cost;capacity_cost;lifetime;age;fixed_costs;output_parameters;name;type
electricity;wind;wind_turbine_onshore;onshore_BB;5700.03;inf;;False;0;;25.4;0;23280.0;{};BB-2016-wind_turbine_onshore;volatile
electricity;wind;wind_turbine_onshore;onshore_BB;5700.03375;inf;;False;0;;30.0;0;12600.0;{};BB-2030-wind_turbine_onshore;volatile
electricity;wind;wind_turbine_onshore;onshore_BB;5700.03375;inf;;False;0;;30.0;0;11340.0;{};BB-2050-wind_turbine_onshore;volatile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
timeindex;onshore_BB
2016-01-01T00:00:00;0.0516
2016-01-01T01:00:00;0.051
2016-01-01T02:00:00;0.0444
2030-01-01T00:00:00;0.0526
2030-01-01T01:00:00;0.051
2030-01-01T02:00:00;0.0444
2050-01-01T00:00:00;0.0536
2050-01-01T01:00:00;0.051
2050-01-01T02:00:00;0.0444
Loading
Loading