Datasets:
ArXiv:
DOI:
License:
File size: 1,772 Bytes
f5fc79f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# %%
import os
import h5py
import matplotlib.pyplot as plt
from tqdm import tqdm
# %%
h5_dir = "waveform_h5"
h5_out = "waveform.h5"
h5_train = "waveform_train.h5"
h5_test = "waveform_test.h5"
h5_files = sorted(os.listdir(h5_dir))
train_files = h5_files[:-1]
test_files = h5_files[-1:]
print(f"train files: {train_files}")
print(f"test files: {test_files}")
# %%
with h5py.File(h5_out, "w") as fp:
# external linked file
for h5_file in h5_files:
with h5py.File(os.path.join(h5_dir, h5_file), "r") as f:
for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())):
if event not in fp:
fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event)
else:
print(f"{event} already exists")
continue
# %%
with h5py.File(h5_train, "w") as fp:
# external linked file
for h5_file in train_files:
with h5py.File(os.path.join(h5_dir, h5_file), "r") as f:
for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())):
if event not in fp:
fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event)
else:
print(f"{event} already exists")
continue
# %%
with h5py.File(h5_test, "w") as fp:
# external linked file
for h5_file in test_files:
with h5py.File(os.path.join(h5_dir, h5_file), "r") as f:
for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())):
if event not in fp:
fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event)
else:
print(f"{event} already exists")
continue
# %%
|