Skip to content

Commit 419c486

Browse files
committed
add das event dataset
1 parent e402f5e commit 419c486

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

phasenet/data_reader.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,13 @@ def __init__(
269269
self.data_dir = kwargs["data_dir"]
270270
elif format == "das":
271271
with open(kwargs["data_list"], "r") as fp:
272-
self.data_list = fp.readlines()
272+
self.data_list = [line.rstrip("\n") for line in fp.readlines()]
273+
274+
self.num_data = len(self.data_list)
275+
self.data_dir = kwargs["data_dir"]
276+
elif format == "das_event":
277+
with open(kwargs["data_list"], "r") as fp:
278+
self.data_list = [line.rstrip("\n") for line in fp.readlines()]
273279
self.num_data = len(self.data_list)
274280
self.data_dir = kwargs["data_dir"]
275281
else:
@@ -553,6 +559,24 @@ def read_das(self, fname, sampling_rate=100, highpass_filter=0.0):
553559
}
554560
return meta
555561

562+
def read_das_event(self, fname):
563+
with fsspec.open(fname, "rb", anon=True) as fp:
564+
with h5py.File(fp, "r") as f:
565+
data = f["data"][:]
566+
begin_time = f["data"].attrs["begin_time"]
567+
568+
data = np.array(data).T # nt, nx
569+
nt, nx = data.shape
570+
# tmp = np.zeros([nt, nx, 3], dtype=np.float32)
571+
# tmp[:, :, -1] = data
572+
tmp = np.repeat(data[:, :, np.newaxis], 3, axis=-1)
573+
meta = {
574+
"data": tmp,
575+
"t0": begin_time,
576+
"station_id": [f"{x}" for x in range(nx)],
577+
}
578+
return meta
579+
556580
def read_sac(self, fname):
557581
mseed = obspy.read(fname)
558582
mseed = mseed.detrend("spline", order=2, dspline=5 * mseed[0].stats.sampling_rate)
@@ -960,6 +984,8 @@ def __getitem__(self, i):
960984
base_name = ""
961985
elif self.format == "das":
962986
meta = self.read_das(base_name, sampling_rate=self.sampling_rate, highpass_filter=self.highpass_filter)
987+
elif self.format == "das_event":
988+
meta = self.read_das_event(base_name)
963989
else:
964990
raise (f"{self.format} does not support!")
965991

phasenet/predict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def pred_fn(args, data_reader, figure_dir=None, prob_dir=None, log_dir=None):
162162
tmp = fname_batch[0].decode().split(",")[0].split("/")
163163
# subdir = "/".join(tmp[-1 - 3 : -1])
164164
subdir = "/".join(tmp[-1 - args.subdir_level : -1])
165-
fname = tmp[-1].rstrip("\n").rstrip(".mseed").rstrip(".ms") + ".csv"
165+
fname = tmp[-1].rstrip("\n").rstrip(".mseed").rstrip(".ms").rstrip(".h5") + ".csv"
166166
# csv_name = f"quakeflow_catalog/NC/phasenet/{subdir}/{fname}"
167167
# csv_name = f"quakeflow_catalog/SC/phasenet/{subdir}/{fname}"
168168
if not os.path.exists(os.path.join(args.result_dir, "picks", subdir)):

0 commit comments

Comments
 (0)