Skip to content

Commit

Permalink
test with h5 copies
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenMeinecke committed May 24, 2024
1 parent f7d7e5c commit d0ca497
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions SimBench_EHV_HV_excerpt/toolbox/h5_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def add_profiles_from_h5_to_net(net:pp.pandapowerNet,

elif time_steps is True:
check_file_existence(h5_file)
with pd.HDFStore(h5_file) as hdf:
temp = tempfile.mktemp()
shutil.copyfile(h5_file, temp)
with pd.HDFStore(temp) as hdf:
net.profiles = {slash_to_dot(key): hdf.get(key) for key in hdf.keys()}

if always_set_time_step:
Expand All @@ -52,9 +54,11 @@ def add_profiles_from_h5_to_net(net:pp.pandapowerNet,
"time_steps are not sorted.")
time_steps = sorted(time_steps)

check_file_existence(h5_file)
check_file_existence(temp)
temp = tempfile.mktemp()
shutil.copyfile(h5_file, temp)

with pd.HDFStore(h5_file) as hdf:
with pd.HDFStore(temp) as hdf:
keys = hdf.keys()
profiles = dict()
for key in keys:
Expand Down Expand Up @@ -93,7 +97,9 @@ def store_profiles_to_hdf5_file(
columns. Applicable only to format='table'; by default None
"""

with pd.HDFStore(file, mode=mode) as store:
temp = tempfile.mktemp()
shutil.copyfile(file, temp)
with pd.HDFStore(temp, mode=mode) as store:
for key in profiles.keys():
d_c = data_columns if not isinstance(data_columns, dict) else data_columns.get(key, None)
store.put(key.replace(".", "/"), profiles[key], format=format, data_columns=d_c, **kwargs)
Expand Down

0 comments on commit d0ca497

Please # to comment.