-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from oemof/feature/constraint-facade
Load constraints from datapackage
- Loading branch information
Showing
20 changed files
with
701 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import abc | ||
from dataclasses import dataclass | ||
|
||
from oemof.solph.constraints.integral_limit import generic_integral_limit | ||
|
||
|
||
class ConstraintFacade(abc.ABC): | ||
def build_constraint(self): | ||
pass | ||
|
||
|
||
@dataclass | ||
class GenericIntegralLimit(ConstraintFacade): | ||
name: str | ||
type: str | ||
limit: float | ||
keyword: str = "emission_factor" | ||
|
||
def build_constraint(self, model): | ||
# to use the constraints in oemof.solph, we need to pass the model. | ||
|
||
# check if there are flows with key | ||
flows = {} | ||
for (i, o) in model.flows: | ||
if hasattr(model.flows[i, o], self.keyword): | ||
flows[(i, o)] = model.flows[i, o] | ||
|
||
if not flows: | ||
raise Warning(f"No flows with keyword {self.keyword}") | ||
else: | ||
print( | ||
f"These flows will contribute to the " | ||
f"emission constraint {flows.keys()}" | ||
) | ||
|
||
# add constraint to the model | ||
generic_integral_limit( | ||
model, keyword=self.keyword, flows=flows, limit=self.limit | ||
) | ||
|
||
|
||
CONSTRAINT_TYPE_MAP = {"generic_integral_limit": GenericIntegralLimit} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from oemof.network.energy_system import EnergySystem | ||
from oemof.solph import Model | ||
|
||
from . import building # noqa F401 | ||
from .reading import deserialize_energy_system | ||
from .reading import deserialize_constraints, deserialize_energy_system | ||
|
||
EnergySystem.from_datapackage = classmethod(deserialize_energy_system) | ||
|
||
Model.add_constraints_from_datapackage = deserialize_constraints |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/oemof/tabular/examples/datapackages/emission_constraint/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Emission constraint example for oemof-tabular | ||
|
||
Run `scripts/infer.py` from the datapackage root directory to add the | ||
meta data file `datapackage.json` after updating the resources of the | ||
datapackage. |
2 changes: 2 additions & 0 deletions
2
...abular/examples/datapackages/emission_constraint/data/constraints/emission_constraint.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name;type;limit;keyword | ||
constraint0;generic_integral_limit;1000;emission_factor |
2 changes: 2 additions & 0 deletions
2
src/oemof/tabular/examples/datapackages/emission_constraint/data/elements/bus.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name;type;balanced | ||
bus-electricity;bus;true |
4 changes: 4 additions & 0 deletions
4
src/oemof/tabular/examples/datapackages/emission_constraint/data/elements/dispatchable.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name;type;carrier;tech;capacity;bus;marginal_cost;profile;output_parameters | ||
gas;dispatchable;gas;gt;1000;bus-electricity;40;1;{"emission_factor": 10} | ||
coal;dispatchable;coal;st;1000;bus-electricity;40;1;{"emission_factor": 20} | ||
lignite;dispatchable;lignite;st;500;bus-electricity;20;1;{"emission_factor": 30} |
2 changes: 2 additions & 0 deletions
2
src/oemof/tabular/examples/datapackages/emission_constraint/data/elements/excess.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name;type;bus | ||
electricity-excess;excess;bus-electricity |
2 changes: 2 additions & 0 deletions
2
src/oemof/tabular/examples/datapackages/emission_constraint/data/elements/load.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name;amount;profile;type;bus | ||
electricity-demand;5000;electricity-load-profile;load;bus-electricity |
2 changes: 2 additions & 0 deletions
2
src/oemof/tabular/examples/datapackages/emission_constraint/data/elements/storage.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name,carrier,tech,storage_capacity,capacity,capacity_cost,storage_capacity_initial,type,bus | ||
el-storage,lithium,battery,100,10,10,0.5,storage,bus-electricity |
2 changes: 2 additions & 0 deletions
2
src/oemof/tabular/examples/datapackages/emission_constraint/data/elements/volatile.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name;type;carrier;tech;capacity;capacity_cost;bus;marginal_cost;profile;output_parameters | ||
wind;volatile;wind;onshore;50;;bus-electricity;0;wind-profile;{} |
4 changes: 4 additions & 0 deletions
4
src/oemof/tabular/examples/datapackages/emission_constraint/data/sequences/load_profile.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
timeindex,electricity-load-profile | ||
2011-01-01T00:00:00Z,0.000745659236 | ||
2011-01-01T01:00:00Z,0.000709651546 | ||
2011-01-01T02:00:00Z,0.00068564642 |
4 changes: 4 additions & 0 deletions
4
...mof/tabular/examples/datapackages/emission_constraint/data/sequences/volatile_profile.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
timeindex,wind-profile | ||
2011-01-01T00:00:00Z,0.147532 | ||
2011-01-01T01:00:00Z,0.184181 | ||
2011-01-01T02:00:00Z,0.223937 |
Oops, something went wrong.