diff --git a/setup.py b/setup.py index 5f59add4..f5715376 100644 --- a/setup.py +++ b/setup.py @@ -70,6 +70,7 @@ def read(*names, **kwargs): # "oemof.solph>=0.5.1", "oemof.solph==0.5.2dev0", "pandas>=0.22", + "oemof.network==0.5.0a4", # Temporal fix due to braking changes in 0.5.1 "paramiko", "toml", ], diff --git a/src/oemof/tabular/__main__.py b/src/oemof/tabular/__main__.py index c8442ddb..b8f821d1 100644 --- a/src/oemof/tabular/__main__.py +++ b/src/oemof/tabular/__main__.py @@ -8,6 +8,7 @@ - https://docs.python.org/2/using/cmdline.html#cmdoption-m - https://docs.python.org/3/using/cmdline.html#cmdoption-m """ + from tabular.cli import main if __name__ == "__main__": diff --git a/src/oemof/tabular/cli.py b/src/oemof/tabular/cli.py index 452ed8ae..2a44522b 100644 --- a/src/oemof/tabular/cli.py +++ b/src/oemof/tabular/cli.py @@ -2,6 +2,7 @@ Module that contains the command line app. """ + import collections import copy diff --git a/src/oemof/tabular/datapackage/aggregation.py b/src/oemof/tabular/datapackage/aggregation.py index 464d446f..0b51b3ce 100644 --- a/src/oemof/tabular/datapackage/aggregation.py +++ b/src/oemof/tabular/datapackage/aggregation.py @@ -88,9 +88,9 @@ def temporal_skip(datapackage, n, path="/tmp", name=None, *args): r = Resource({"path": "data/temporal.csv"}) r.infer() - r.descriptor[ - "description" - ] = "Temporal selection based on skipped timesteps. Skipped n={}".format(n) + r.descriptor["description"] = ( + "Temporal selection based on skipped timesteps. Skipped n={}".format(n) + ) # Update meta-data of copied package cp = Package("datapackage.json") @@ -212,9 +212,9 @@ def temporal_clustering(datapackage, n, path="/tmp", how="daily"): r = Resource({"path": "data/temporal.csv"}) r.infer() # TODO: Add meta-data description - r.descriptor[ - "description" - ] = "Temporal selection based on hierachical clustering..." + r.descriptor["description"] = ( + "Temporal selection based on hierachical clustering..." + ) # Update meta-data of copied package cp = Package("datapackage.json") diff --git a/src/oemof/tabular/datapackage/reading.py b/src/oemof/tabular/datapackage/reading.py index fac4ed7d..157758fe 100644 --- a/src/oemof/tabular/datapackage/reading.py +++ b/src/oemof/tabular/datapackage/reading.py @@ -13,6 +13,7 @@ import collections.abc as cabc import json import re +import typing import warnings from decimal import Decimal from itertools import chain, groupby, repeat @@ -117,14 +118,14 @@ def deserialize_energy_system(cls, path, typemap={}, attributemap={}): FLOW_TYPE: HSN, } - for k, v in default_typemap.items(): - typemap[k] = typemap.get(k, v) + for k, value in default_typemap.items(): + typemap[k] = typemap.get(k, value) if attributemap.get(object) is None: attributemap[object] = {"name": "label"} - for k, v in attributemap.items(): - if v.get("name") is None: + for k, value in attributemap.items(): + if value.get("name") is None: attributemap[k]["name"] = "label" package = dp.Package(path) @@ -309,13 +310,15 @@ def create(cls, init, attributes): data["buses"] = { name: create( - mapping - if mapping - else raisestatement( - ValueError, - "Typemap is missing a mapping for '{}'.".format( - bus.get("type", "bus") - ), + ( + mapping + if mapping + else raisestatement( + ValueError, + "Typemap is missing a mapping for '{}'.".format( + bus.get("type", "bus") + ), + ) ), {"label": name}, bus["parameters"], @@ -433,15 +436,108 @@ def create_periodic_values(values, periods_index): return periodic_values.tolist() - def create_yearly_values(values, years): + def create_yearly_values( + values: typing.Iterable[float], period_years: typing.Iterable[int] + ): + """ + Creates a value for every year (between two periods) + Value of period is continued until next period + Parameters + ---------- + values values to be interpolated + years years of periods + + Returns list + ------- + + """ results = pd.Series() - for i in range(len(years) - 1): - diff = years[i + 1] - years[i] + for i in range(len(period_years) - 1): + diff = period_years[i + 1] - period_years[i] period_results = pd.Series(repeat(values[i], diff)) results = pd.concat([results, period_results]) results = pd.concat([results, pd.Series(values[-1])]) return results.tolist() + def unpack_sequences(facade, period_data): + """ + Depending on dtype and content: + Periodically changing values [given as array] are either unpacked into + - full periods + - yearly values (between periods) + - kept as periodical values + + Decision happens based on + - value + - name + - entry in yearly/periodical values list. + + Parameters + ---------- + facade + period_data + + Returns + ------- + facade + """ + + yearly_values = ["fixed_costs", "marginal_costs"] + periodical_values = [ + "capacity", + "capacity_cost", + "capacity_potential", + "storage_capacity", + ] + + for value_name, value in facade.items(): + if isinstance(value, Decimal): + facade[value_name] = float(value) + # check if multi-period and value is list + if period_data and isinstance(value, list): + # check if length of list equals number of periods + if len(value) == len(period_data["periods"]): + if value_name in periodical_values: + # special period parameters don't need to be + # converted into timeseries + facade[value_name] = [ + float(vv) if isinstance(vv, Decimal) else vv + for vv in value + ] + continue + elif value_name in yearly_values: + # special period parameter need to be + # converted into timeseries with value for each + # year + facade[value_name] = create_yearly_values( + value, period_data["years"] + ) + msg = ( + f"\nThe parameter '{value_name}' of a " + f"'{facade['type']}' facade is converted " + "into a yearly list. This might not be " + "possible for every parameter and lead to " + "ambiguous error messages.\nPlease be " + "aware, when using this feature!" + ) + warnings.warn(msg, UserWarning) + + else: + # create timeseries with periodic values + facade[value_name] = create_periodic_values( + value, period_data["periods"] + ) + msg = ( + f"\nThe parameter '{value_name}' of a " + f"'{facade['type']}' facade is converted " + "into a periodic timeseries. This might " + "not be possible for every parameter and " + "lead to ambiguous error messages.\nPlease" + " be aware, when using this feature!" + ) + warnings.warn(msg, UserWarning) + return facade + facades = {} for r in package.resources: if all( @@ -465,58 +561,12 @@ def create_yearly_values(values, years): fk["fields"]: fk["reference"] for fk in r.descriptor["schema"].get("foreignKeys", ()) } + for facade in facade_data: # convert decimal to float - for f, v in facade.items(): - if isinstance(v, Decimal): - facade[f] = float(v) - # check if multi-period and value is list - if period_data and isinstance(v, list): - # check if length of list equals number of periods - if len(v) == len(period_data["periods"]): - if f in ["capacity_costs"]: - # special period parameters don't need to be - # converted into timeseries - facade[f] = [ - float(vv) - if isinstance(vv, Decimal) - else vv - for vv in v - ] - continue - elif f in ["fixed_costs"]: - # special period parameter need to be - # converted into timeseries with value for each - # year - facade[f] = create_yearly_values( - v, period_data["years"] - ) - msg = ( - f"\nThe parameter '{f}' of a " - f"'{facade['type']}' facade is converted " - "into a yearly list. This might not be " - "possible for every parameter and lead to " - "ambiguous error messages.\nPlease be " - "aware, when using this feature!" - ) - warnings.warn(msg, UserWarning) - - else: - # create timeseries with periodic values - facade[f] = create_periodic_values( - v, period_data["periods"] - ) - msg = ( - f"\nThe parameter '{f}' of a " - f"'{facade['type']}' facade is converted " - "into a periodic timeseries. This might " - "not be possible for every parameter and " - "lead to ambiguous error messages.\nPlease" - " be aware, when using this feature!" - ) - warnings.warn(msg, UserWarning) + read_facade( - facade, + unpack_sequences(facade=facade, period_data=period_data), facades, create, typemap, diff --git a/src/oemof/tabular/examples/datapackages/dispatch/scripts/infer.py b/src/oemof/tabular/examples/datapackages/dispatch/scripts/infer.py index f14f7f67..f156383c 100644 --- a/src/oemof/tabular/examples/datapackages/dispatch/scripts/infer.py +++ b/src/oemof/tabular/examples/datapackages/dispatch/scripts/infer.py @@ -2,6 +2,7 @@ Run this script from the root directory of the datapackage to update or create meta data. """ + from oemof.tabular.datapackage import building # This part is for testing only: It allows to pass diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period/scripts/infer.py b/src/oemof/tabular/examples/datapackages/dispatch_multi_period/scripts/infer.py index f14f7f67..f156383c 100644 --- a/src/oemof/tabular/examples/datapackages/dispatch_multi_period/scripts/infer.py +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period/scripts/infer.py @@ -2,6 +2,7 @@ Run this script from the root directory of the datapackage to update or create meta data. """ + from oemof.tabular.datapackage import building # This part is for testing only: It allows to pass diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/README.md b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/README.md new file mode 100644 index 00000000..be203d7c --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/README.md @@ -0,0 +1,5 @@ +# Dispatch 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. diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/bus.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/bus.csv new file mode 100644 index 00000000..56beebcf --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/bus.csv @@ -0,0 +1,5 @@ +name;type;balanced +bus0;bus;true +bus1;bus;true +heat-bus;bus;false +gas-bus;bus;false diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/dispatchable.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/dispatchable.csv new file mode 100644 index 00000000..bac86320 --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/dispatchable.csv @@ -0,0 +1,4 @@ +name;type;carrier;tech;capacity;bus;marginal_cost;profile;output_parameters +gas;dispatchable;gas;gt;100;bus1;40;1;{"full_load_time_max": 2000} +coal;dispatchable;coal;st;100;bus0;40;1;{} +lignite;dispatchable;lignite;st;50;bus0;20;1;{} diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/link.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/link.csv new file mode 100644 index 00000000..ed193f5b --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/link.csv @@ -0,0 +1,3 @@ +name;type;capacity;capacity_cost;loss;from_bus;to_bus +conn1;link;100;[10, 9, 8];0.05;bus0;bus1 +conn2;link;10;[0, 0, 0];0.05;heat-bus;gas-bus diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/load.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/load.csv new file mode 100644 index 00000000..5a3b43d3 --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/load.csv @@ -0,0 +1,3 @@ +name;amount;profile;type;bus +demand0;5000;electricity-load-profile;load;bus0 +demand1;1000;electricity-load-profile;load;bus1 diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/storage.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/storage.csv new file mode 100644 index 00000000..5065d0cc --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/storage.csv @@ -0,0 +1,3 @@ +name;carrier;tech;storage_capacity;capacity;capacity_cost;storage_capacity_initial;type;bus +el-storage1;lithium;battery;100;[10,12,13];[10,12,13];0.5;storage;bus0 +el-storage2;lithium;battery;200;[10,12,13];[16,13,14];0.2;storage;bus0 diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/volatile.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/volatile.csv new file mode 100644 index 00000000..9e3ac10a --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/elements/volatile.csv @@ -0,0 +1,3 @@ +name;type;carrier;tech;capacity;capacity_cost;bus;marginal_cost;profile;output_parameters +wind;volatile;wind;onshore;50;;bus0;[2, 1, 0];wind-profile;{} +pv;volatile;solar;pv;20;;bus1;[2, 1, 0];pv-profile;{} diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/periods/periods.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/periods/periods.csv new file mode 100644 index 00000000..88fbb8f1 --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/periods/periods.csv @@ -0,0 +1,10 @@ +timeindex;periods; timeincrement +2011-01-01T00:00:00Z;0;1 +2011-01-01T01:00:00Z;0;1 +2011-01-01T02:00:00Z;0;1 +2035-01-01T00:00:00Z;1;1 +2035-01-01T01:00:00Z;1;1 +2035-01-01T02:00:00Z;1;1 +2050-01-01T00:00:00Z;2;1 +2050-01-01T01:00:00Z;2;1 +2050-01-01T02:00:00Z;2;1 diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/sequences/load_profile.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/sequences/load_profile.csv new file mode 100644 index 00000000..7ff8e14c --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/sequences/load_profile.csv @@ -0,0 +1,10 @@ +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 +2035-01-01T00:00:00Z;0.000745659236 +2035-01-01T01:00:00Z;0.000709651546 +2035-01-01T02:00:00Z;0.00068564642 +2050-01-01T00:00:00Z;0.000745659236 +2050-01-01T01:00:00Z;0.000709651546 +2050-01-01T02:00:00Z;0.00068564642 diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/sequences/volatile_profile.csv b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/sequences/volatile_profile.csv new file mode 100644 index 00000000..1e871c95 --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/data/sequences/volatile_profile.csv @@ -0,0 +1,10 @@ +timeindex;wind-profile;pv-profile +2011-01-01T00:00:00Z;0.147532;0 +2011-01-01T01:00:00Z;0.184181;0 +2011-01-01T02:00:00Z;0.223937;0 +2035-01-01T00:00:00Z;0.147532;0 +2035-01-01T01:00:00Z;0.184181;0 +2035-01-01T02:00:00Z;0.223937;0 +2050-01-01T00:00:00Z;0.147532;0 +2050-01-01T01:00:00Z;0.184181;0 +2050-01-01T02:00:00Z;0.223937;0 diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/datapackage.json b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/datapackage.json new file mode 100644 index 00000000..b6a9349c --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/datapackage.json @@ -0,0 +1,468 @@ +{ + "profile": "tabular-data-package", + "name": "oemof-tabular-dispatch-example", + "oemof_tabular_version": "0.0.5dev", + "resources": [ + { + "path": "data/elements/bus.csv", + "profile": "tabular-data-resource", + "name": "bus", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "name", + "type": "string", + "format": "default" + }, + { + "name": "type", + "type": "string", + "format": "default" + }, + { + "name": "balanced", + "type": "boolean", + "format": "default" + } + ], + "missingValues": [ + "" + ], + "primaryKey": "name", + "foreignKeys": [] + } + }, + { + "path": "data/elements/dispatchable.csv", + "profile": "tabular-data-resource", + "name": "dispatchable", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "name", + "type": "string", + "format": "default" + }, + { + "name": "type", + "type": "string", + "format": "default" + }, + { + "name": "carrier", + "type": "string", + "format": "default" + }, + { + "name": "tech", + "type": "string", + "format": "default" + }, + { + "name": "capacity", + "type": "integer", + "format": "default" + }, + { + "name": "bus", + "type": "string", + "format": "default" + }, + { + "name": "marginal_cost", + "type": "integer", + "format": "default" + }, + { + "name": "profile", + "type": "integer", + "format": "default" + }, + { + "name": "output_parameters", + "type": "object", + "format": "default" + } + ], + "missingValues": [ + "" + ], + "primaryKey": "name", + "foreignKeys": [ + { + "fields": "bus", + "reference": { + "resource": "bus", + "fields": "name" + } + } + ] + } + }, + { + "path": "data/elements/link.csv", + "profile": "tabular-data-resource", + "name": "link", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "name", + "type": "string", + "format": "default" + }, + { + "name": "type", + "type": "string", + "format": "default" + }, + { + "name": "capacity", + "type": "integer", + "format": "default" + }, + { + "name": "capacity_cost", + "type": "array", + "format": "default" + }, + { + "name": "loss", + "type": "number", + "format": "default" + }, + { + "name": "from_bus", + "type": "string", + "format": "default" + }, + { + "name": "to_bus", + "type": "string", + "format": "default" + } + ], + "missingValues": [ + "" + ], + "primaryKey": "name", + "foreignKeys": [ + { + "fields": "from_bus", + "reference": { + "resource": "bus", + "fields": "name" + } + }, + { + "fields": "to_bus", + "reference": { + "resource": "bus", + "fields": "name" + } + } + ] + } + }, + { + "path": "data/elements/load.csv", + "profile": "tabular-data-resource", + "name": "load", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "name", + "type": "string", + "format": "default" + }, + { + "name": "amount", + "type": "integer", + "format": "default" + }, + { + "name": "profile", + "type": "string", + "format": "default" + }, + { + "name": "type", + "type": "string", + "format": "default" + }, + { + "name": "bus", + "type": "string", + "format": "default" + } + ], + "missingValues": [ + "" + ], + "primaryKey": "name", + "foreignKeys": [ + { + "fields": "bus", + "reference": { + "resource": "bus", + "fields": "name" + } + }, + { + "fields": "profile", + "reference": { + "resource": "load_profile" + } + } + ] + } + }, + { + "path": "data/elements/storage.csv", + "profile": "tabular-data-resource", + "name": "storage", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "name", + "type": "string", + "format": "default" + }, + { + "name": "carrier", + "type": "string", + "format": "default" + }, + { + "name": "tech", + "type": "string", + "format": "default" + }, + { + "name": "storage_capacity", + "type": "integer", + "format": "default" + }, + { + "name": "capacity", + "type": "array", + "format": "default" + }, + { + "name": "capacity_cost", + "type": "array", + "format": "default" + }, + { + "name": "storage_capacity_initial", + "type": "number", + "format": "default" + }, + { + "name": "type", + "type": "string", + "format": "default" + }, + { + "name": "bus", + "type": "string", + "format": "default" + } + ], + "missingValues": [ + "" + ], + "primaryKey": "name", + "foreignKeys": [ + { + "fields": "bus", + "reference": { + "resource": "bus", + "fields": "name" + } + } + ] + } + }, + { + "path": "data/elements/volatile.csv", + "profile": "tabular-data-resource", + "name": "volatile", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "name", + "type": "string", + "format": "default" + }, + { + "name": "type", + "type": "string", + "format": "default" + }, + { + "name": "carrier", + "type": "string", + "format": "default" + }, + { + "name": "tech", + "type": "string", + "format": "default" + }, + { + "name": "capacity", + "type": "integer", + "format": "default" + }, + { + "name": "capacity_cost", + "type": "string", + "format": "default" + }, + { + "name": "bus", + "type": "string", + "format": "default" + }, + { + "name": "marginal_cost", + "type": "array", + "format": "default" + }, + { + "name": "profile", + "type": "string", + "format": "default" + }, + { + "name": "output_parameters", + "type": "object", + "format": "default" + } + ], + "missingValues": [ + "" + ], + "primaryKey": "name", + "foreignKeys": [ + { + "fields": "bus", + "reference": { + "resource": "bus", + "fields": "name" + } + }, + { + "fields": "profile", + "reference": { + "resource": "volatile_profile" + } + } + ] + } + }, + { + "path": "data/sequences/load_profile.csv", + "profile": "tabular-data-resource", + "name": "load_profile", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "timeindex", + "type": "datetime", + "format": "default" + }, + { + "name": "electricity-load-profile", + "type": "number", + "format": "default" + } + ], + "missingValues": [ + "" + ] + } + }, + { + "path": "data/sequences/volatile_profile.csv", + "profile": "tabular-data-resource", + "name": "volatile_profile", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "timeindex", + "type": "datetime", + "format": "default" + }, + { + "name": "wind-profile", + "type": "number", + "format": "default" + }, + { + "name": "pv-profile", + "type": "integer", + "format": "default" + } + ], + "missingValues": [ + "" + ] + } + }, + { + "path": "data/periods/periods.csv", + "profile": "tabular-data-resource", + "name": "periods", + "format": "csv", + "mediatype": "text/csv", + "encoding": "utf-8", + "schema": { + "fields": [ + { + "name": "timeindex", + "type": "datetime", + "format": "default" + }, + { + "name": "periods", + "type": "integer", + "format": "default" + }, + { + "name": "timeincrement", + "type": "integer", + "format": "default" + } + ], + "missingValues": [ + "" + ] + } + } + ] +} diff --git a/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/scripts/infer.py b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/scripts/infer.py new file mode 100644 index 00000000..f156383c --- /dev/null +++ b/src/oemof/tabular/examples/datapackages/dispatch_multi_period_periodic_values/scripts/infer.py @@ -0,0 +1,22 @@ +""" +Run this script from the root directory of the datapackage to update +or create meta data. +""" + +from oemof.tabular.datapackage import building + +# This part is for testing only: It allows to pass +# the filename of inferred metadata other than the default. +if "kwargs" not in locals(): + kwargs = {} + +building.infer_metadata( + package_name="oemof-tabular-dispatch-example", + foreign_keys={ + "bus": ["volatile", "dispatchable", "storage", "load"], + "profile": ["load", "volatile"], + "from_to_bus": ["link"], + "chp": [], + }, + **kwargs, +) diff --git a/src/oemof/tabular/examples/datapackages/emission_constraint/scripts/infer.py b/src/oemof/tabular/examples/datapackages/emission_constraint/scripts/infer.py index 58321e9a..35967473 100644 --- a/src/oemof/tabular/examples/datapackages/emission_constraint/scripts/infer.py +++ b/src/oemof/tabular/examples/datapackages/emission_constraint/scripts/infer.py @@ -2,6 +2,7 @@ Run this script from the root directory of the datapackage to update or create meta data. """ + from oemof.tabular.datapackage import building # This part is for testing only: It allows to pass diff --git a/src/oemof/tabular/examples/datapackages/foreignkeys/scripts/infer.py b/src/oemof/tabular/examples/datapackages/foreignkeys/scripts/infer.py index 0303a86e..41b4cd11 100644 --- a/src/oemof/tabular/examples/datapackages/foreignkeys/scripts/infer.py +++ b/src/oemof/tabular/examples/datapackages/foreignkeys/scripts/infer.py @@ -2,6 +2,7 @@ Note: This script allow does not create meta data that are valid, you will need to set the foreign keys for the marginal_cost yourself. """ + from oemof.tabular.datapackage import building # This part is for testing only: It allows to pass diff --git a/src/oemof/tabular/examples/scripting/compute.py b/src/oemof/tabular/examples/scripting/compute.py index 09a737df..18f1303b 100644 --- a/src/oemof/tabular/examples/scripting/compute.py +++ b/src/oemof/tabular/examples/scripting/compute.py @@ -1,5 +1,6 @@ """ """ + import importlib.resources import os diff --git a/src/oemof/tabular/facades/backpressure_turbine.py b/src/oemof/tabular/facades/backpressure_turbine.py index eda89bd9..66599778 100644 --- a/src/oemof/tabular/facades/backpressure_turbine.py +++ b/src/oemof/tabular/facades/backpressure_turbine.py @@ -104,6 +104,7 @@ class BackpressureTurbine(Converter, Facade): """ + fuel_bus: Bus heat_bus: Bus diff --git a/src/oemof/tabular/facades/commodity.py b/src/oemof/tabular/facades/commodity.py index e568a214..0659ee10 100644 --- a/src/oemof/tabular/facades/commodity.py +++ b/src/oemof/tabular/facades/commodity.py @@ -47,6 +47,7 @@ class Commodity(Source, Facade): ... 'max': [0.9, 0.5, 0.4]}) """ + bus: Bus carrier: str diff --git a/src/oemof/tabular/facades/conversion.py b/src/oemof/tabular/facades/conversion.py index c4d5681e..133e5560 100644 --- a/src/oemof/tabular/facades/conversion.py +++ b/src/oemof/tabular/facades/conversion.py @@ -76,6 +76,7 @@ class Conversion(Converter, Facade): ... efficiency=0.4) """ + from_bus: Bus to_bus: Bus diff --git a/src/oemof/tabular/facades/dispatchable.py b/src/oemof/tabular/facades/dispatchable.py index 237f1e72..a7a5b1a7 100644 --- a/src/oemof/tabular/facades/dispatchable.py +++ b/src/oemof/tabular/facades/dispatchable.py @@ -105,6 +105,7 @@ class Dispatchable(Source, Facade): ... 'min': 0.2}) """ + bus: Bus carrier: str diff --git a/src/oemof/tabular/facades/extraction_turbine.py b/src/oemof/tabular/facades/extraction_turbine.py index 73779114..45a31576 100644 --- a/src/oemof/tabular/facades/extraction_turbine.py +++ b/src/oemof/tabular/facades/extraction_turbine.py @@ -112,6 +112,7 @@ class ExtractionTurbine(ExtractionTurbineCHP, Facade): ... thermal_efficiency=0.35) """ + carrier: str tech: str diff --git a/src/oemof/tabular/facades/heatpump.py b/src/oemof/tabular/facades/heatpump.py index 78ec19e6..40872768 100644 --- a/src/oemof/tabular/facades/heatpump.py +++ b/src/oemof/tabular/facades/heatpump.py @@ -94,6 +94,7 @@ class HeatPump(Converter, Facade): ... low_temperature_bus=heat_bus_low) """ + electricity_bus: Bus high_temperature_bus: Bus diff --git a/src/oemof/tabular/facades/load.py b/src/oemof/tabular/facades/load.py index cc1d8cf5..ffccb57f 100644 --- a/src/oemof/tabular/facades/load.py +++ b/src/oemof/tabular/facades/load.py @@ -44,6 +44,7 @@ class Load(Sink, Facade): ... amount=100, ... profile=[0.3, 0.2, 0.5]) """ + bus: Bus amount: float diff --git a/src/oemof/tabular/facades/reservoir.py b/src/oemof/tabular/facades/reservoir.py index 84676beb..25aada25 100644 --- a/src/oemof/tabular/facades/reservoir.py +++ b/src/oemof/tabular/facades/reservoir.py @@ -86,6 +86,7 @@ class Reservoir(GenericStorage, Facade): ... efficiency=0.93) """ + bus: Bus carrier: str diff --git a/src/oemof/tabular/facades/storage.py b/src/oemof/tabular/facades/storage.py index d677a27f..14116706 100644 --- a/src/oemof/tabular/facades/storage.py +++ b/src/oemof/tabular/facades/storage.py @@ -97,6 +97,7 @@ class Storage(GenericStorage, Facade): ... max_storage_level=[0.9, 0.95, 0.8])) # oemof.solph argument """ + bus: Bus carrier: str diff --git a/src/oemof/tabular/facades/volatile.py b/src/oemof/tabular/facades/volatile.py index e1586c1a..c3ff35f6 100644 --- a/src/oemof/tabular/facades/volatile.py +++ b/src/oemof/tabular/facades/volatile.py @@ -100,6 +100,7 @@ class Volatile(Source, Facade): ... profile=[0.25, 0.1, 0.3]) """ + bus: Bus carrier: str diff --git a/tests/test_constraints.py b/tests/test_constraints.py index 29534254..6111e93d 100644 --- a/tests/test_constraints.py +++ b/tests/test_constraints.py @@ -47,9 +47,7 @@ def normalize_to_positive_results(lines): lines[n] = ( "-" if lines[n] and lines[n][0] == "+" - else "+" - if lines[n] - else lines[n] + else "+" if lines[n] else lines[n] ) + lines[n][1:] lines[end] = "= " + lines[end][3:] return lines diff --git a/tests/test_multi_period_constraints.py b/tests/test_multi_period_constraints.py index 50f07b55..735785d7 100644 --- a/tests/test_multi_period_constraints.py +++ b/tests/test_multi_period_constraints.py @@ -47,9 +47,7 @@ def normalize_to_positive_results(lines): lines[n] = ( "-" if lines[n] and lines[n][0] == "+" - else "+" - if lines[n] - else lines[n] + else "+" if lines[n] else lines[n] ) + lines[n][1:] lines[end] = "= " + lines[end][3:] return lines