Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into release/0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jnnr committed Nov 21, 2022
2 parents 6d6598f + b173f30 commit ff5cc20
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def read(*names, **kwargs):
],
install_requires=[
"datapackage==1.5.1",
"tableschema==1.3.0",
"tableschema==1.7.4", # newer versions (v1.8.0 and up) fail!
"oemof.solph @ git+https://git@github.com/oemof/oemof-solph@v0.4#egg=oemof.solph",
"pandas>=0.22",
"paramiko",
Expand Down
4 changes: 2 additions & 2 deletions src/oemof/tabular/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os
import pathlib

CONFIG_FOLDER = pathlib.PurePosixPath(__file__).parent
CONFIG_FOLDER = pathlib.PurePath(__file__).parent

FOREIGN_KEYS_FILE = os.environ.get(
"OEMOF_TABULAR_FOREIGN_KEYS_FILE",
CONFIG_FOLDER / "foreign_keys.json"
pathlib.Path(CONFIG_FOLDER, "foreign_keys.json")
)
with open(FOREIGN_KEYS_FILE, "r") as fk_file:
FOREIGN_KEYS = json.load(fk_file)
Expand Down
19 changes: 13 additions & 6 deletions src/oemof/tabular/datapackage/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urlparse
import errno
import os
import pathlib
import shutil
import sys
import tarfile
Expand Down Expand Up @@ -104,7 +105,8 @@ def infer_metadata(
)
else:
for f in os.listdir("data/elements"):
r = Resource({"path": os.path.join("data/elements", f)})
r = Resource({"path": str(pathlib.PurePosixPath(
"data", "elements", f))})
r.infer()
r.descriptor["schema"]["primaryKey"] = "name"

Expand Down Expand Up @@ -138,7 +140,8 @@ def infer_metadata(
)

r.commit()
r.save(os.path.join("resources", f.replace(".csv", ".json")))
r.save(pathlib.PurePosixPath("resources", f.replace(
".csv", ".json")))
p.add_resource(r.descriptor)

# create meta data resources sequences
Expand All @@ -150,10 +153,12 @@ def infer_metadata(
)
else:
for f in os.listdir("data/sequences"):
r = Resource({"path": os.path.join("data/sequences", f)})
r = Resource({"path": str(pathlib.PurePosixPath(
"data", "sequences", f))})
r.infer()
r.commit()
r.save(os.path.join("resources", f.replace(".csv", ".json")))
r.save(pathlib.PurePosixPath("resources", f.replace(
".csv", ".json")))
p.add_resource(r.descriptor)

if not os.path.exists("data/geometries"):
Expand All @@ -164,10 +169,12 @@ def infer_metadata(
)
else:
for f in os.listdir("data/geometries"):
r = Resource({"path": os.path.join("data/geometries", f)})
r = Resource({"path": str(pathlib.PurePosixPath(
"data", "geometries", f))})
r.infer()
r.commit()
r.save(os.path.join("resources", f.replace(".csv", ".json")))
r.save(pathlib.PurePosixPath("resources", f.replace(
".csv", ".json")))
p.add_resource(r.descriptor)

p.commit()
Expand Down
47 changes: 30 additions & 17 deletions tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import pandas as pd

from oemof.network.network import Node
from oemof.solph import helpers
import oemof.solph as solph

Expand Down Expand Up @@ -87,7 +86,6 @@ def setup(cls):
cls.energysystem = solph.EnergySystem(
groupings=solph.GROUPINGS, timeindex=cls.date_time_index
)
Node.registry = cls.energysystem

def get_om(self):
return solph.Model(
Expand Down Expand Up @@ -121,7 +119,7 @@ def test_storage_investment_green_field(self):
"""
el_bus = solph.Bus(label="electricity")

Storage(
storage = Storage(
label="storage",
carrier="electricity",
tech="storage",
Expand All @@ -135,6 +133,7 @@ def test_storage_investment_green_field(self):
capacity_cost=240,
capacity_potential=3,
)
self.energysystem.add(el_bus, storage)

self.compare_to_reference_lp("storage_investment_green_field.lp")

Expand All @@ -144,7 +143,7 @@ def test_storage_investment_brown_field(self):
"""
bus_el = solph.Bus(label="electricity")

Storage(
storage = Storage(
label="storage",
carrier="electricity",
tech="storage",
Expand All @@ -158,6 +157,7 @@ def test_storage_investment_brown_field(self):
capacity_cost=240,
capacity_potential=5,
)
self.energysystem.add(bus_el, storage)

self.compare_to_reference_lp("storage_investment_brown_field.lp")

Expand All @@ -168,7 +168,7 @@ def test_storage_investment_brown_field_no_storage_capacity_cost(self):
"""
bus_el = solph.Bus(label="electricity")

Storage(
storage = Storage(
label="storage",
carrier="electricity",
tech="storage",
Expand All @@ -181,6 +181,7 @@ def test_storage_investment_brown_field_no_storage_capacity_cost(self):
capacity_cost=240,
capacity_potential=5,
)
self.energysystem.add(bus_el, storage)

self.compare_to_reference_lp(
"storage_investment_brown_field_no_storage_capacity_cost.lp"
Expand All @@ -194,7 +195,7 @@ def test_backpressure_investment_green_field(self):
bus_el = solph.Bus(label="electricity")
bus_heat = solph.Bus(label="heat")

BackpressureTurbine(
bpchp = BackpressureTurbine(
label='backpressure',
carrier='gas',
tech='bp',
Expand All @@ -208,6 +209,7 @@ def test_backpressure_investment_green_field(self):
thermal_efficiency=0.35,
expandable=True,
)
self.energysystem.add(bus_el, bus_fuel, bus_heat, bpchp)

self.compare_to_reference_lp("backpressure_investment_green_field.lp")

Expand All @@ -219,7 +221,7 @@ def test_backpressure_investment_brown_field(self):
bus_el = solph.Bus(label="electricity")
bus_heat = solph.Bus(label="heat")

BackpressureTurbine(
bpchp = BackpressureTurbine(
label='backpressure',
carrier='gas',
tech='bp',
Expand All @@ -233,6 +235,7 @@ def test_backpressure_investment_brown_field(self):
thermal_efficiency=0.35,
expandable=True,
)
self.energysystem.add(bus_el, bus_fuel, bus_heat, bpchp)

self.compare_to_reference_lp("backpressure_investment_brown_field.lp")

Expand All @@ -244,7 +247,7 @@ def test_extraction_investment_green_field(self):
bus_el = solph.Bus(label="electricity")
bus_heat = solph.Bus(label="heat")

ExtractionTurbine(
extchp = ExtractionTurbine(
label='extraction',
carrier='gas',
tech="extraction",
Expand All @@ -259,6 +262,7 @@ def test_extraction_investment_green_field(self):
thermal_efficiency=0.35,
expandable=True,
)
self.energysystem.add(bus_el, bus_fuel, bus_heat, extchp)

self.compare_to_reference_lp("extraction_investment_green_field.lp")

Expand All @@ -270,7 +274,7 @@ def test_extraction_investment_brown_field(self):
bus_el = solph.Bus(label="electricity")
bus_heat = solph.Bus(label="heat")

ExtractionTurbine(
extchp = ExtractionTurbine(
label='extraction',
carrier='gas',
tech="extraction",
Expand All @@ -285,6 +289,7 @@ def test_extraction_investment_brown_field(self):
thermal_efficiency=0.35,
expandable=True,
)
self.energysystem.add(bus_el, bus_fuel, bus_heat, extchp)

self.compare_to_reference_lp("extraction_investment_brown_field.lp")

Expand All @@ -293,14 +298,15 @@ def test_commodity(self):
"""
bus_biomass = solph.Bus("biomass")

Commodity(
commodity = Commodity(
label='biomass-commodity',
bus=bus_biomass,
carrier='biomass',
amount=1000,
marginal_cost=10,
output_parameters={'max': [0.9, 0.5, 0.4]}
)
self.energysystem.add(bus_biomass, commodity)

self.compare_to_reference_lp("commodity.lp")

Expand All @@ -310,7 +316,7 @@ def test_conversion(self):
bus_biomass = solph.Bus("biomass")
bus_heat = solph.Bus("heat")

Conversion(
conversion = Conversion(
label='biomass_plant',
carrier='biomass',
tech='st',
Expand All @@ -319,13 +325,14 @@ def test_conversion(self):
capacity=100,
efficiency=0.4
)
self.energysystem.add(bus_heat, bus_biomass, conversion)

self.compare_to_reference_lp("conversion.lp")

def test_dispatchable(self):
bus = solph.Bus("electricity")

Dispatchable(
dispatchable = Dispatchable(
label='gt',
bus=bus,
carrier='gas',
Expand All @@ -334,6 +341,7 @@ def test_dispatchable(self):
marginal_cost=10,
output_parameters={'min': 0.2},
)
self.energysystem.add(bus, dispatchable)

self.compare_to_reference_lp("dispatchable.lp")

Expand All @@ -343,7 +351,7 @@ def test_link(self):
bus1 = solph.Bus("bus1")
bus2 = solph.Bus("bus2")

Link(
link = Link(
label='link',
carrier='electricity',
from_bus=bus1,
Expand All @@ -353,6 +361,7 @@ def test_link(self):
loss=0.25,
marginal_cost=4,
)
self.energysystem.add(bus1, bus2, link)

self.compare_to_reference_lp("link.lp")

Expand All @@ -361,13 +370,14 @@ def test_load(self):
"""
bus = solph.Bus("electricity")

Load(
load = Load(
label='load',
carrier='electricity',
bus=bus,
amount=100,
profile=[0.3, 0.2, 0.5]
)
self.energysystem.add(bus, load)

self.compare_to_reference_lp("load.lp")

Expand All @@ -376,7 +386,7 @@ def test_reservoir(self):
"""
bus = solph.Bus("electricity")

Reservoir(
reservoir = Reservoir(
label='reservoir',
bus=bus,
carrier='water',
Expand All @@ -389,6 +399,7 @@ def test_reservoir(self):
max_storage_level=0.75,
efficiency=0.8,
)
self.energysystem.add(bus, reservoir)

self.compare_to_reference_lp("reservoir.lp")

Expand All @@ -397,7 +408,7 @@ def test_storage(self):
"""
bus = solph.Bus("electricity")

Storage(
storage = Storage(
label="storage",
bus=bus,
carrier="lithium",
Expand All @@ -410,6 +421,7 @@ def test_storage(self):
max_storage_level=[0.75, 0.5, 0.25],
expandable=True,
)
self.energysystem.add(bus, storage)

self.compare_to_reference_lp("storage.lp")

Expand All @@ -418,7 +430,7 @@ def test_volatile(self):
"""
bus = solph.Bus("electricity")

Volatile(
volatile = Volatile(
label='wind',
bus=bus,
carrier='wind',
Expand All @@ -429,5 +441,6 @@ def test_volatile(self):
capacity_potential=100,
profile=[0.25, 0.1, 0.3],
)
self.energysystem.add(bus, volatile)

self.compare_to_reference_lp("volatile.lp")

0 comments on commit ff5cc20

Please sign in to comment.