Skip to content

Commit

Permalink
improve hdf5 cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuwq0 committed May 11, 2024
1 parent 43d156e commit bdc9edf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions eqnet/data/seismic_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,17 @@ def __init__(
self.rank = rank
self.world_size = world_size
if hdf5_file is not None:
tmp_hdf5_keys = f"/tmp/{hdf5_file.split('/')[-1]}.txt"
tmp_hdf5_keys = f"/tmp/{'_'.join(hdf5_file.split('/'))}.txt"
if not os.path.exists(tmp_hdf5_keys) and (rank == 0):
with h5py.File(hdf5_file, "r", libver="latest", swmr=True) as fp:
self.data_list = []
for event in tqdm(list(fp.keys()), desc="Caching HDF5 keys"):
for station in list(fp[event].keys()):
attrs = dict(fp[event][station].attrs)
if ("component" in attrs) and ("snr" in attrs):
if (attrs["component"] == "ENZ") and (max(attrs["snr"]) > 2.0): ## filtering
self.data_list.append(event + "/" + station)
if training:
attrs = dict(fp[event][station].attrs)
if ("component" in attrs) and ("snr" in attrs):
if (attrs["component"] == "ENZ") and (max(attrs["snr"]) > 2.0): ## filtering
self.data_list.append(event + "/" + station)
else:
self.data_list.append(event + "/" + station)
with open(tmp_hdf5_keys, "w") as f:
Expand Down

0 comments on commit bdc9edf

Please sign in to comment.