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

Add tsam to datapackage #141

Draft
wants to merge 24 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
856a126
Merge branch 'dev' into features/add-tsam-to-datapackage
nailend Nov 10, 2023
a6481b9
Add tsam to reading module
nailend Nov 10, 2023
dc78863
Add tsam multi-period example
nailend Nov 10, 2023
bb0a97a
Remove timesteps from tsa_parameters
nailend Dec 4, 2023
268f940
Adjust timeseries data for tsam example
nailend Dec 4, 2023
8b16116
Remove timeindex.csv
nailend Dec 4, 2023
5fc423e
Add changelog entry
nailend Dec 4, 2023
ae5f159
Remove timeindex.csv from datapackage.json
nailend Dec 4, 2023
21b0159
Add tsam resource to infer_metadata
nailend Dec 4, 2023
5567933
Merge branch 'dev' into features/add-tsam-to-datapackage
nailend Dec 4, 2023
054ade0
Merge branch 'dev' into features/add-tsam-to-datapackage
nailend Dec 5, 2023
87afb28
Add further exceptions for not converted periodic values
nailend Dec 11, 2023
447546f
Make lifetime parameter a constant value
nailend Dec 11, 2023
32dc918
Raise error if length mismatches periods or index
nailend Dec 11, 2023
c6fddca
Merge branch 'features/add-tsam-to-datapackage' of github.com:oemof/o…
nailend Dec 11, 2023
1345f7b
tsam period order 2-0
FelixMau Jan 23, 2024
d84168b
Solph dependency
FelixMau Jan 23, 2024
cb8d058
Sepcify oemof.solph and oemof.network
FelixMau Jan 23, 2024
4bcbfb0
Solph dependency
FelixMau Jan 23, 2024
a7e9548
Merge remote-tracking branch 'origin/features/add-tsam-to-datapackage…
FelixMau Jan 31, 2024
7034337
Merge branch 'dev' into features/add-tsam-to-datapackage
FelixMau Feb 7, 2024
11c432c
Linting
FelixMau Feb 7, 2024
99681e4
Add option to set up TSAM Model without multi period mode
henhuy Apr 15, 2024
8c9fcc0
Read TSAM parameters for all timeindex options
henhuy Apr 16, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Features

* Improve reading error message `#134 <https://github.com/oemof/oemof-tabular/pull/134>`_
* Remove facade relicts `#135 <https://github.com/oemof/oemof-tabular/pull/135>`_
* Add tsam to datapackge `#141 <https://github.com/oemof/oemof-tabular/pull/141>`_
* Add dev install version `#147 <https://github.com/oemof/oemof-tabular/pull/147>`_

Fixes
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ def read(*names, **kwargs):
"datapackage==1.5.1",
"tableschema==1.7.4", # newer versions (v1.8.0 and up) fail!
# "oemof.solph>=0.5.1",
# Upcomming upgrade to solph 0.5.2 postponed due to many changes necessary for implementing
# explicit arguments and upgrade to network 0.5.1
"oemof.solph==0.5.2dev1",
# Fixing solph version. Might Upgrade later but depends on explicit arguments
"oemof.solph @ git+https://github.com/oemof/oemof-solph.git@feature/integrate_tsam",
"oemof.network==0.5.0.a5",
"pandas>=0.22",
"oemof.network==0.5.0a4", # Temporal fix due to braking changes in 0.5.1
"paramiko",
"toml",
],
Expand Down
19 changes: 19 additions & 0 deletions src/oemof/tabular/datapackage/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ def infer_metadata(
)
p.add_resource(r.descriptor)

# create meta data resources tsam
if not os.path.exists("data/tsam"):
print(
"No periods path found in directory {}. Skipping...".format(
os.getcwd()
)
)
else:
for f in os.listdir("data/tsam"):
r = Resource(
{"path": str(pathlib.PurePosixPath("data", "tsam", f))}
)
r.infer()
r.commit()
r.save(
pathlib.PurePosixPath("resources", f.replace(".csv", ".json"))
)
p.add_resource(r.descriptor)

p.commit()
p.save(metadata_filename)

Expand Down
30 changes: 21 additions & 9 deletions src/oemof/tabular/datapackage/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ def unpack_sequences(facade, period_data):
resource,
)

def get_tsam_parameters():
"""Extract TSAM parameters from pacakge if given."""
if package.get_resource("tsa_parameters"):
df_tsa_parameters = pd.DataFrame.from_dict(
package.get_resource("tsa_parameters").read(keyed=True)
).set_index("period", drop=True)
return df_tsa_parameters.sort_index().to_dict(
"records"
)
return None

# TODO: Find concept how to deal with timeindices and clean up based on
# concept
lst = [idx for idx in timeindices.values()]
Expand All @@ -597,19 +608,20 @@ def unpack_sequences(facade, period_data):
name="timeindex",
)
timeindex = temporal.index
es = cls(timeindex=timeindex, temporal=temporal)
es = cls(timeindex=timeindex, temporal=temporal, tsa_parameters=get_tsam_parameters())

# if no temporal provided as resource, take the first timeindex
# from dict
else:
# look for periods resource and if present, take periods from it
if package.get_resource("periods"):
es = cls(
timeindex=period_data["timeindex"],
timeincrement=period_data["timeincrement"],
periods=period_data["periods"],
infer_last_interval=False,
)
es = cls(
timeindex=period_data["timeindex"],
timeincrement=period_data["timeincrement"],
periods=period_data["periods"],
tsam_parameters=get_tsam_parameters(),
infer_last_interval=False,
)

# if lst is not empty
elif lst:
Expand All @@ -618,7 +630,7 @@ def unpack_sequences(facade, period_data):
idx.values, freq=idx.inferred_freq, name="timeindex"
)
temporal = None
es = cls(timeindex=timeindex, temporal=temporal)
es = cls(timeindex=timeindex, temporal=temporal, tsa_parameters=get_tsam_parameters())
# if for any reason lst of datetimeindices is empty
# (i.e. no sequences) have been provided, set datetime to one time
# step of today (same as in the EnergySystem __init__ if no
Expand All @@ -627,7 +639,7 @@ def unpack_sequences(facade, period_data):
timeindex = pd.date_range(
start=pd.to_datetime("today"), periods=1, freq="H"
)
es = cls(timeindex=timeindex)
es = cls(timeindex=timeindex, tsa_parameters=get_tsam_parameters())

es.add(
*chain(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name;type;balanced
bus0;bus;true
bus1;bus;true
heat-bus;bus;false
gas-bus;bus;false
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;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;{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name;type;capacity;capacity_cost;loss;from_bus;to_bus
conn1;link;100;10;0.05;bus0;bus1
conn2;link;10;0;0.05;heat-bus;gas-bus
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name;amount;profile;type;bus
demand0;5000;electricity-load-profile;load;bus0
demand1;1000;electricity-load-profile;load;bus1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,carrier,tech,storage_capacity,capacity,capacity_cost,storage_capacity_initial,type,bus
el-storage1,lithium,battery,100,10,10,0.5,storage,bus0
el-storage2,lithium,battery,200,20,15,0.2,storage,bus0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name;type;carrier;tech;capacity;capacity_cost;bus;marginal_cost;profile;output_parameters
wind;volatile;wind;onshore;50;;bus0;0;wind-profile;{}
pv;volatile;solar;pv;50;;bus1;0;pv-profile;{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
timeindex;periods;timeincrement
2011-01-01T00:00:00Z;0;1
2011-01-01T01:00:00Z;0;1
2011-01-01T02:00:00Z;0;1
2011-01-01T03: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
2035-01-01T03: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
2050-01-01T03:00:00Z;2;1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
timeindex;electricity-load-profile
2011-01-01T00:00:00Z;0.00074565923
2011-01-01T01:00:00Z;0.00070965154
2011-01-01T02:00:00Z;0.00068564642
2011-01-01T03:00:00Z;0.00074565923
2035-01-01T00:00:00Z;0.00074565923
2035-01-01T01:00:00Z;0.00070965154
2035-01-01T02:00:00Z;0.00068564642
2035-01-01T03:00:00Z;0.00074565923
2050-01-01T00:00:00Z;0.00074565923
2050-01-01T01:00:00Z;0.00070965154
2050-01-01T02:00:00Z;0.00068564642
2050-01-01T03:00:00Z;0.00074565923
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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
2011-01-01T03:00:00Z;0.147532;0
2035-01-01T00:00:00Z;0;0.147532
2035-01-01T01:00:00Z;0;0.184181
2035-01-01T02:00:00Z;0;0.223937
2035-01-01T03:00:00Z;0;0.147532
2050-01-01T00:00:00Z;0.147532;0
2050-01-01T01:00:00Z;0.184181;0
2050-01-01T02:00:00Z;0.223937;0
2050-01-01T03:00:00Z;0.147532;0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
period;timesteps_per_period;order
0;2;[0, 1, 1, 0]
1;2;[0, 1, 1, 1]
2;2;[0, 0, 1, 0]
Loading