09: Fix resizing of dataset

This commit is contained in:
2022-11-24 11:34:21 +01:00
parent 2fb37002cb
commit 991fe4912d
4 changed files with 98 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@ -100,8 +100,8 @@ def main():
# Prepare file
with h5py.File(output_filename,'a') as f:
if not "mean-magn" in f:
dataset = f.create_dataset("magnetizations", (0,), maxshape=(None,), chunks=True)
if not "magnetizations" in f:
dataset = f.create_dataset("magnetizations", (0,), maxshape=(None,), dtype='f', chunks=True, compression="gzip")
# store some information as metadata for the data set
dataset.attrs["lamb"] = lamb
dataset.attrs["kappa"] = kappa
@ -112,7 +112,9 @@ def main():
dataset.attrs["measure_sweeps"] = measure_sweeps
dataset.attrs["measurements"] = measurements
dataset.attrs["start time"] = starttime
else:
# continue taking measurements (e.g. when previous run was interrupted)
measurements_done = len(f["magnetizations"])
# Measure
# TODO: Does mean_magn need to be a list?
@ -126,10 +128,10 @@ def main():
with h5py.File(output_filename,'a') as f:
# enlarge the data set
dataset = f["magnetizations"]
dataset.resize(measurements, axis=0)
dataset.resize(len(dataset) + len(magnetizations), axis=0)
# copy the data to the new space at the end of the dataset
dataset[-len(magnetizations):] = magnetizations
dataset.attrs["current_time"] = time.asctime()
dataset.attrs["current_time"] = time.time()
magnetizations.clear()
if measurements_done == measurements:
break

Binary file not shown.