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 multi period deserialization #112

Merged
merged 7 commits into from Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/oemof/tabular/datapackage/building.py
Expand Up @@ -212,6 +212,25 @@ def infer_metadata(
)
p.add_resource(r.descriptor)

# create meta data resources periods
if not os.path.exists("data/periods"):
print(
"No periods path found in directory {}. Skipping...".format(
os.getcwd()
)
)
else:
for f in os.listdir("data/periods"):
r = Resource(
{"path": str(pathlib.PurePosixPath("data", "periods", 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
32 changes: 29 additions & 3 deletions src/oemof/tabular/datapackage/reading.py
Expand Up @@ -437,17 +437,44 @@ def find(n, d):
name="timeindex",
)
timeindex = temporal.index
es = cls(timeindex=timeindex, temporal=temporal)

# if no temporal provided as resource, take the first timeindex
# from dict
else:
# look for periods resource and if present, take as periods from it
if package.get_resource("periods"):
df_periods = pd.DataFrame.from_dict(
package.get_resource("periods").read(keyed=True)
)
timeincrement = df_periods["increment"].values
timeindex = pd.DatetimeIndex(df_periods["timeindex"])
periods = [
pd.DatetimeIndex(df["timeindex"])
for period, df in df_periods.groupby("periods")
]
periods = [
pd.DatetimeIndex(
i.values, freq=i.inferred_freq, name="timeindex"
)
for i in periods
]

es = cls(
timeindex=timeindex,
timeincrement=timeincrement,
periods=periods,
infer_last_interval=False,
)

# if lst is not empty
if lst:
elif lst:
idx = pd.DatetimeIndex(lst[0])
timeindex = pd.DatetimeIndex(
idx.values, freq=idx.inferred_freq, name="timeindex"
)
temporal = None
es = cls(timeindex=timeindex, temporal=temporal)
# 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 @@ -456,8 +483,7 @@ def find(n, d):
timeindex = pd.date_range(
start=pd.to_datetime("today"), periods=1, freq="H"
)

es = cls(timeindex=timeindex, temporal=temporal) if lst else cls()
es = cls()

es.add(
*chain(
Expand Down
@@ -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.
@@ -0,0 +1,5 @@
name;type;balanced
bus0;bus;true
bus1;bus;true
heat-bus;bus;false
gas-bus;bus;false
@@ -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;{}
@@ -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
@@ -0,0 +1,3 @@
name;amount;profile;type;bus
demand0;5000;electricity-load-profile;load;bus0
demand1;1000;electricity-load-profile;load;bus1
@@ -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
@@ -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;20;;bus1;0;pv-profile;{}
@@ -0,0 +1,10 @@
timeindex,periods, increment
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
@@ -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
@@ -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