diff --git a/.gitattributes b/.gitattributes index 9d690c210691ee1386f740bebcbc6b41802407c7..9a9a4a12e91cf39e24a14485b53e9879f3532bed 100644 --- a/.gitattributes +++ b/.gitattributes @@ -52,4 +52,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.jpg filter=lfs diff=lfs merge=lfs -text *.jpeg filter=lfs diff=lfs merge=lfs -text *.webp filter=lfs diff=lfs merge=lfs -text -*.csv filter=lfs diff=lfs merge=lfs -text +ncedc_eventid.h5 filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md index 037eb6eab84fdcf496c2649f69c62c5b2f4192cf..ec11e946b20e1a27860cec391663cc281703f38e 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Waveform data, metadata, or data products for this study were accessed through t - datasets - h5py - fsspec -- pytorch +- torch (for PyTorch) ### Usage Import the necessary packages: @@ -74,6 +74,7 @@ Import the necessary packages: import h5py import numpy as np import torch +from torch.utils.data import Dataset, IterableDataset, DataLoader from datasets import load_dataset ``` We have 6 configurations for the dataset: @@ -88,28 +89,16 @@ We have 6 configurations for the dataset: The sample of `station` is a dictionary with the following keys: - `data`: the waveform with shape `(3, nt)`, the default time length is 8192 -- `begin_time`: the begin time of the waveform data -- `end_time`: the end time of the waveform data -- `phase_time`: the phase arrival time -- `phase_index`: the time point index of the phase arrival time -- `phase_type`: the phase type -- `phase_polarity`: the phase polarity in ('U', 'D', 'N') -- `event_time`: the event time -- `event_time_index`: the time point index of the event time -- `event_location`: the event location with shape `(3,)`, including latitude, longitude, depth +- `phase_pick`: the probability of the phase pick with shape `(3, nt)`, the first dimension is noise, P and S +- `event_location`: the event location with shape `(4,)`, including latitude, longitude, depth and time - `station_location`: the station location with shape `(3,)`, including latitude, longitude and depth The sample of `event` is a dictionary with the following keys: - `data`: the waveform with shape `(n_station, 3, nt)`, the default time length is 8192 -- `begin_time`: the begin time of the waveform data -- `end_time`: the end time of the waveform data -- `phase_time`: the phase arrival time with shape `(n_station,)` -- `phase_index`: the time point index of the phase arrival time with shape `(n_station,)` -- `phase_type`: the phase type with shape `(n_station,)` -- `phase_polarity`: the phase polarity in ('U', 'D', 'N') with shape `(n_station,)` -- `event_time`: the event time -- `event_time_index`: the time point index of the event time -- `event_location`: the space-time coordinates of the event with shape `(n_staion, 3)` +- `phase_pick`: the probability of the phase pick with shape `(n_station, 3, nt)`, the first dimension is noise, P and S +- `event_center`: the probability of the event time with shape `(n_station, feature_nt)`, default feature time length is 512 +- `event_location`: the space-time coordinates of the event with shape `(n_staion, 4, feature_nt)` +- `event_location_mask`: the probability mask of the event time with shape `(n_station, feature_nt)` - `station_location`: the space coordinates of the station with shape `(n_station, 3)`, including latitude, longitude and depth The default configuration is `station_test`. You can specify the configuration by argument `name`. For example: @@ -128,33 +117,70 @@ quakeflow_nc = load_dataset("AI4EPS/quakeflow_nc", name="station_test", split="t quakeflow_nc = load_dataset("AI4EPS/quakeflow_nc", name="event", split="train") ``` -#### Example loading the dataset +#### Usage for `station` +Then you can change the dataset into PyTorch format iterable dataset, and view the first sample: ```python quakeflow_nc = load_dataset("AI4EPS/quakeflow_nc", name="station_test", split="test") +# for PyTorch DataLoader, we need to divide the dataset into several shards +num_workers=4 +quakeflow_nc = quakeflow_nc.to_iterable_dataset(num_shards=num_workers) +# because add examples formatting to get tensors when using the "torch" format +# has not been implemented yet, we need to manually add the formatting when using iterable dataset +# if you want to use dataset directly, just use +# quakeflow_nc.with_format("torch") +quakeflow_nc = quakeflow_nc.map(lambda x: {key: torch.from_numpy(np.array(value, dtype=np.float32)) for key, value in x.items()}) +try: + isinstance(quakeflow_nc, torch.utils.data.IterableDataset) +except: + raise Exception("quakeflow_nc is not an IterableDataset") # print the first sample of the iterable dataset for example in quakeflow_nc: print("\nIterable test\n") print(example.keys()) for key in example.keys(): - if key == "data": - print(key, np.array(example[key]).shape) - else: - print(key, example[key]) + print(key, example[key].shape, example[key].dtype) break -# %% -quakeflow_nc = quakeflow_nc.with_format("torch") -dataloader = DataLoader(quakeflow_nc, batch_size=8, num_workers=0, collate_fn=lambda x: x) +dataloader = DataLoader(quakeflow_nc, batch_size=4, num_workers=num_workers) for batch in dataloader: print("\nDataloader test\n") - print(f"Batch size: {len(batch)}") - print(batch[0].keys()) - for key in batch[0].keys(): - if key == "data": - print(key, np.array(batch[0][key]).shape) - else: - print(key, batch[0][key]) + print(batch.keys()) + for key in batch.keys(): + print(key, batch[key].shape, batch[key].dtype) + break +``` + +#### Usage for `event` + +Then you can change the dataset into PyTorch format dataset, and view the first sample (Don't forget to reorder the keys): +```python +quakeflow_nc = datasets.load_dataset("AI4EPS/quakeflow_nc", split="test", name="event_test") + +# for PyTorch DataLoader, we need to divide the dataset into several shards +num_workers=4 +quakeflow_nc = quakeflow_nc.to_iterable_dataset(num_shards=num_workers) +quakeflow_nc = quakeflow_nc.map(lambda x: {key: torch.from_numpy(np.array(value, dtype=np.float32)) for key, value in x.items()}) +try: + isinstance(quakeflow_nc, torch.utils.data.IterableDataset) +except: + raise Exception("quakeflow_nc is not an IterableDataset") + +# print the first sample of the iterable dataset +for example in quakeflow_nc: + print("\nIterable test\n") + print(example.keys()) + for key in example.keys(): + print(key, example[key].shape, example[key].dtype) + break + +dataloader = DataLoader(quakeflow_nc, batch_size=1, num_workers=num_workers) + +for batch in dataloader: + print("\nDataloader test\n") + print(batch.keys()) + for key in batch.keys(): + print(key, batch[key].shape, batch[key].dtype) break ``` \ No newline at end of file diff --git a/events.csv b/events.csv deleted file mode 100644 index 4f0010ec3004aaa104f532f229efbd5bc0704911..0000000000000000000000000000000000000000 --- a/events.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:84166f6a0be6a02caeb8d11ed3495e5256db698c795dbb3db4d45d8b863313d8 -size 46863258 diff --git a/events_test.csv b/events_test.csv deleted file mode 100644 index 6dd7f244a40ad0ebf4d832cb0ff7f590d9018c3c..0000000000000000000000000000000000000000 --- a/events_test.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:74b5bf132e23763f851035717a1baa92ab8fb73253138b640103390dce33e154 -size 1602217 diff --git a/events_train.csv b/events_train.csv deleted file mode 100644 index ea35c5a0b9d34a8bc2d6e1dfdbee744603fc3a8d..0000000000000000000000000000000000000000 --- a/events_train.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ef579400d9354ecaf142bdc7023291c952dbfc20d6bafab4715dff1774b3f7a5 -size 45261178 diff --git a/example.py b/example.py deleted file mode 100644 index 31e2ca98dee3d1cafd16bd6d5944dd38238e2316..0000000000000000000000000000000000000000 --- a/example.py +++ /dev/null @@ -1,54 +0,0 @@ -# %% -import datasets -import numpy as np -from torch.utils.data import DataLoader - -quakeflow_nc = datasets.load_dataset( - "AI4EPS/quakeflow_nc", - name="station", - split="train", - # name="station_test", - # split="test", - # download_mode="force_redownload", - trust_remote_code=True, - num_proc=36, -) -# quakeflow_nc = datasets.load_dataset( -# "./quakeflow_nc.py", -# name="station", -# split="train", -# # name="statoin_test", -# # split="test", -# num_proc=36, -# ) - -print(quakeflow_nc) - -# print the first sample of the iterable dataset -for example in quakeflow_nc: - print("\nIterable dataset\n") - print(example) - print(example.keys()) - for key in example.keys(): - if key == "waveform": - print(key, np.array(example[key]).shape) - else: - print(key, example[key]) - break - -# %% -quakeflow_nc = quakeflow_nc.with_format("torch") -dataloader = DataLoader(quakeflow_nc, batch_size=8, num_workers=0, collate_fn=lambda x: x) - -for batch in dataloader: - print("\nDataloader dataset\n") - print(f"Batch size: {len(batch)}") - print(batch[0].keys()) - for key in batch[0].keys(): - if key == "waveform": - print(key, np.array(batch[0][key]).shape) - else: - print(key, batch[0][key]) - break - -# %% diff --git a/merge_hdf5.py b/merge_hdf5.py index acf4dfdffe060a44bd8c90b8f67b86f42cafdcd3..7f0fc899280c6dae193ce77405991a17edfd3bcb 100644 --- a/merge_hdf5.py +++ b/merge_hdf5.py @@ -11,18 +11,9 @@ h5_out = "waveform.h5" h5_train = "waveform_train.h5" h5_test = "waveform_test.h5" -# # %% -# 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:] -# train_files = h5_files -# train_files = [x for x in train_files if (x != "2014.h5") and (x not in [])] -# test_files = [] print(f"train files: {train_files}") print(f"test files: {test_files}") diff --git a/models/phasenet_picks.csv b/models/phasenet_picks.csv deleted file mode 100644 index ca5343692ccf490e8cbac0264571e9494c7b6034..0000000000000000000000000000000000000000 --- a/models/phasenet_picks.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b51df5987a2a05e44e0949b42d00a28692109da521911c55d2692ebfad0c54d7 -size 9355127 diff --git a/models/phasenet_plus_events.csv b/models/phasenet_plus_events.csv deleted file mode 100644 index 308fc9ef433d9415b76acc4000aae80a0e913cff..0000000000000000000000000000000000000000 --- a/models/phasenet_plus_events.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f686ebf8da632b71a947e4ee884c76f30a313ae0e9d6e32d1f675828884a95f7 -size 7381331 diff --git a/models/phasenet_plus_picks.csv b/models/phasenet_plus_picks.csv deleted file mode 100644 index ff567bb43d44912659e5f703007cea3f3ce82795..0000000000000000000000000000000000000000 --- a/models/phasenet_plus_picks.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:83d241a54477f722cd032efe8368a653bba170e1abebf3d9097d7756cfd54b23 -size 9987053 diff --git a/models/phasenet_pt_picks.csv b/models/phasenet_pt_picks.csv deleted file mode 100644 index bbac4709de81fed932527cf0e9c299943f8309bc..0000000000000000000000000000000000000000 --- a/models/phasenet_pt_picks.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bb7ea98484b5e6e1c4c79ea5eb1e38bce43e87b546fc6d29c72d187a6d8b1d00 -size 8715799 diff --git a/picks.csv b/picks.csv deleted file mode 100644 index 56f90699b043dec4f5a5847cdb493d48414ca255..0000000000000000000000000000000000000000 --- a/picks.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:52f077ae9f94481d4b80f37c9f15038ee1e3636d5da2da3b1d4aaa2991879cc3 -size 422247029 diff --git a/picks_test.csv b/picks_test.csv deleted file mode 100644 index b703c6df4a1a06811b5e931ca0b08f256cbe6adc..0000000000000000000000000000000000000000 --- a/picks_test.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bb09f0ac169bf451cfcfb4547359756cb1a53828bf4074971d9160a3aa171f38 -size 21850235 diff --git a/picks_train.csv b/picks_train.csv deleted file mode 100644 index c4c2ef6d1db2946f34296241686015a2c2f1adee..0000000000000000000000000000000000000000 --- a/picks_train.csv +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d22c5d5eb1c27a723525c657c1308a3b643d6f3e716eb1c43e064b7a87bb0819 -size 400397230 diff --git a/quakeflow_nc.py b/quakeflow_nc.py index 569a90d65b17b53f262ea43ef51aa74c164f3f33..550d2a8fa45f1a6d025ff87482a7a08246df9a75 100644 --- a/quakeflow_nc.py +++ b/quakeflow_nc.py @@ -104,10 +104,14 @@ class BatchBuilderConfig(datasets.BuilderConfig): """ yield a batch of event-based sample, so the number of sample stations can vary among batches Batch Config for QuakeFlow_NC + :param batch_size: number of samples in a batch + :param num_stations_list: possible number of stations in a batch """ - def __init__(self, **kwargs): + def __init__(self, batch_size: int, num_stations_list: List, **kwargs): super().__init__(**kwargs) + self.batch_size = batch_size + self.num_stations_list = num_stations_list # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case @@ -116,7 +120,11 @@ class QuakeFlow_NC(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("1.1.0") + degree2km = 111.32 nt = 8192 + feature_nt = 512 + feature_scale = int(nt / feature_nt) + sampling_rate = 100.0 # This is an example of a dataset with multiple configurations. # If you don't want/need to define several sub-sets in your dataset, @@ -165,44 +173,30 @@ class QuakeFlow_NC(datasets.GeneratorBasedBuilder): or (self.config.name == "station_train") or (self.config.name == "station_test") ): - features = datasets.Features( + features=datasets.Features( { - "id": datasets.Value("string"), - "event_id": datasets.Value("string"), - "station_id": datasets.Value("string"), - "waveform": datasets.Array2D(shape=(3, self.nt), dtype="float32"), - "phase_time": datasets.Sequence(datasets.Value("string")), - "phase_index": datasets.Sequence(datasets.Value("int32")), - "phase_type": datasets.Sequence(datasets.Value("string")), - "phase_polarity": datasets.Sequence(datasets.Value("string")), - "begin_time": datasets.Value("string"), - "end_time": datasets.Value("string"), - "event_time": datasets.Value("string"), - "event_time_index": datasets.Value("int32"), + "data": datasets.Array2D(shape=(3, self.nt), dtype='float32'), + "phase_pick": datasets.Array2D(shape=(3, self.nt), dtype='float32'), "event_location": datasets.Sequence(datasets.Value("float32")), "station_location": datasets.Sequence(datasets.Value("float32")), - }, - ) - elif (self.config.name == "event") or (self.config.name == "event_train") or (self.config.name == "event_test"): - features = datasets.Features( + }) + + elif ( + (self.config.name == "event") + or (self.config.name == "event_train") + or (self.config.name == "event_test") + ): + features=datasets.Features( { - "event_id": datasets.Value("string"), - "waveform": datasets.Array3D(shape=(None, 3, self.nt), dtype="float32"), - "phase_time": datasets.Sequence(datasets.Sequence(datasets.Value("string"))), - "phase_index": datasets.Sequence(datasets.Sequence(datasets.Value("int32"))), - "phase_type": datasets.Sequence(datasets.Sequence(datasets.Value("string"))), - "phase_polarity": datasets.Sequence(datasets.Sequence(datasets.Value("string"))), - "begin_time": datasets.Value("string"), - "end_time": datasets.Value("string"), - "event_time": datasets.Value("string"), - "event_time_index": datasets.Value("int32"), - "event_location": datasets.Sequence(datasets.Value("float32")), - "station_location": datasets.Sequence(datasets.Sequence(datasets.Value("float32"))), - }, + "data": datasets.Array3D(shape=(None, 3, self.nt), dtype='float32'), + "phase_pick": datasets.Array3D(shape=(None, 3, self.nt), dtype='float32'), + "event_center" : datasets.Array2D(shape=(None, self.feature_nt), dtype='float32'), + "event_location": datasets.Array3D(shape=(None, 4, self.feature_nt), dtype='float32'), + "event_location_mask": datasets.Array2D(shape=(None, self.feature_nt), dtype='float32'), + "station_location": datasets.Array2D(shape=(None, 3), dtype="float32"), + } ) - else: - raise ValueError(f"config.name = {self.config.name} is not in BUILDER_CONFIGS") - + return datasets.DatasetInfo( # This is the description that will appear on the datasets page. description=_DESCRIPTION, @@ -228,20 +222,18 @@ class QuakeFlow_NC(datasets.GeneratorBasedBuilder): # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive urls = _URLS[self.config.name] # files = dl_manager.download(urls) - if "bucket" not in self.storage_options: - files = dl_manager.download_and_extract(urls) - else: - files = [f"{self.storage_options['bucket']}/{x}" for x in _FILES] - # files = [f"/nfs/quakeflow_dataset/NC/quakeflow_nc/waveform_h5/{x}" for x in _FILES][-3:] - print("Files:\n", "\n".join(sorted(files))) - print(self.storage_options) + files = dl_manager.download_and_extract(urls) + print(files) if self.config.name == "station" or self.config.name == "event": return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples - gen_kwargs={"filepath": files[:-1], "split": "train"}, + gen_kwargs={ + "filepath": files[:-1], + "split": "train", + }, ), datasets.SplitGenerator( name=datasets.Split.TEST, @@ -252,7 +244,10 @@ class QuakeFlow_NC(datasets.GeneratorBasedBuilder): return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, - gen_kwargs={"filepath": files, "split": "train"}, + gen_kwargs={ + "filepath": files, + "split": "train", + }, ), ] elif self.config.name == "station_test" or self.config.name == "event_test": @@ -271,92 +266,156 @@ class QuakeFlow_NC(datasets.GeneratorBasedBuilder): # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example. for file in filepath: - print(f"\nReading {file}") with fsspec.open(file, "rb") as fs: with h5py.File(fs, "r") as fp: + # for event_id in sorted(list(fp.keys())): event_ids = list(fp.keys()) for event_id in event_ids: event = fp[event_id] - event_attrs = event.attrs - begin_time = event_attrs["begin_time"] - end_time = event_attrs["end_time"] - event_location = [ - event_attrs["longitude"], - event_attrs["latitude"], - event_attrs["depth_km"], - ] - event_time = event_attrs["event_time"] - event_time_index = event_attrs["event_time_index"] station_ids = list(event.keys()) - if len(station_ids) == 0: - continue if ( (self.config.name == "station") or (self.config.name == "station_train") or (self.config.name == "station_test") ): - waveform = np.zeros([3, self.nt], dtype="float32") - - for i, station_id in enumerate(station_ids): - waveform[:, : self.nt] = event[station_id][:, : self.nt] - attrs = event[station_id].attrs - phase_type = attrs["phase_type"] - phase_time = attrs["phase_time"] - phase_index = attrs["phase_index"] - phase_polarity = attrs["phase_polarity"] + waveforms = np.zeros([3, self.nt], dtype="float32") + phase_pick = np.zeros_like(waveforms) + attrs = event.attrs + event_location = [ + attrs["longitude"], + attrs["latitude"], + attrs["depth_km"], + attrs["event_time_index"], + ] + + for i, sta_id in enumerate(station_ids): + waveforms[:, : self.nt] = event[sta_id][:, :self.nt] + # waveforms[:, : self.nt] = event[sta_id][: self.nt, :].T + attrs = event[sta_id].attrs + p_picks = attrs["phase_index"][attrs["phase_type"] == "P"] + s_picks = attrs["phase_index"][attrs["phase_type"] == "S"] + phase_pick[:, :self.nt] = generate_label([p_picks, s_picks], nt=self.nt) station_location = [attrs["longitude"], attrs["latitude"], -attrs["elevation_m"] / 1e3] - yield f"{event_id}/{station_id}", { - "id": f"{event_id}/{station_id}", - "event_id": event_id, - "station_id": station_id, - "waveform": waveform, - "phase_time": phase_time, - "phase_index": phase_index, - "phase_type": phase_type, - "phase_polarity": phase_polarity, - "begin_time": begin_time, - "end_time": end_time, - "event_time": event_time, - "event_time_index": event_time_index, - "event_location": event_location, - "station_location": station_location, + yield f"{event_id}/{sta_id}", { + "data": torch.from_numpy(waveforms).float(), + "phase_pick": torch.from_numpy(phase_pick).float(), + "event_location": torch.from_numpy(np.array(event_location)).float(), + "station_location": torch.from_numpy(np.array(station_location)).float(), } + elif ( (self.config.name == "event") or (self.config.name == "event_train") or (self.config.name == "event_test") ): + event_attrs = event.attrs + + # avoid stations with P arrival equals S arrival + is_sick = False + for sta_id in station_ids: + attrs = event[sta_id].attrs + if not np.intersect1d(attrs["phase_index"][attrs["phase_type"] == "P"], attrs["phase_index"][attrs["phase_type"] == "S"]): + is_sick = True + break + if is_sick: + continue + + waveforms = np.zeros([len(station_ids), 3, self.nt], dtype="float32") + phase_pick = np.zeros_like(waveforms) + event_center = np.zeros([len(station_ids), self.nt]) + event_location = np.zeros([len(station_ids), 4, self.nt]) + event_location_mask = np.zeros([len(station_ids), self.nt]) + station_location = np.zeros([len(station_ids), 3]) + + for i, sta_id in enumerate(station_ids): + # trace_id = event_id + "/" + sta_id + waveforms[i, :, :] = event[sta_id][:, :self.nt] + attrs = event[sta_id].attrs + p_picks = attrs["phase_index"][attrs["phase_type"] == "P"] + s_picks = attrs["phase_index"][attrs["phase_type"] == "S"] + phase_pick[i, :, :] = generate_label([p_picks, s_picks], nt=self.nt) + + ## TODO: how to deal with multiple phases + # center = (attrs["phase_index"][::2] + attrs["phase_index"][1::2])/2.0 + ## assuming only one event with both P and S picks + c0 = ((p_picks) + (s_picks)) / 2.0 # phase center + c0_width = ((s_picks - p_picks) * self.sampling_rate / 200.0).max() if p_picks!=s_picks else 50 + dx = round( + (event_attrs["longitude"] - attrs["longitude"]) + * np.cos(np.radians(event_attrs["latitude"])) + * self.degree2km, + 2, + ) + dy = round( + (event_attrs["latitude"] - attrs["latitude"]) + * self.degree2km, + 2, + ) + dz = round( + event_attrs["depth_km"] + attrs["elevation_m"] / 1e3, + 2, + ) - waveform = np.zeros([len(station_ids), 3, self.nt], dtype="float32") - phase_type = [] - phase_time = [] - phase_index = [] - phase_polarity = [] - station_location = [] - - for i, station_id in enumerate(station_ids): - waveform[i, :, : self.nt] = event[station_id][:, : self.nt] - attrs = event[station_id].attrs - phase_type.append(list(attrs["phase_type"])) - phase_time.append(list(attrs["phase_time"])) - phase_index.append(list(attrs["phase_index"])) - phase_polarity.append(list(attrs["phase_polarity"])) - station_location.append( - [attrs["longitude"], attrs["latitude"], -attrs["elevation_m"] / 1e3] + event_center[i, :] = generate_label( + [ + # [c0 / self.feature_scale], + c0, + ], + label_width=[ + c0_width, + ], + # label_width=[ + # 10, + # ], + # nt=self.feature_nt, + nt=self.nt, + )[1, :] + mask = event_center[i, :] >= 0.5 + event_location[i, 0, :] = ( + np.arange(self.nt) - event_attrs["event_time_index"] + ) / self.sampling_rate + # event_location[0, :, i] = (np.arange(self.feature_nt) - 3000 / self.feature_scale) / self.sampling_rate + # print(event_location[i, 1:, mask].shape, event_location.shape, event_location[i][1:, mask].shape) + event_location[i][1:, mask] = np.array([dx, dy, dz])[:, np.newaxis] + event_location_mask[i, :] = mask + + ## station location + station_location[i, 0] = round( + attrs["longitude"] + * np.cos(np.radians(attrs["latitude"])) + * self.degree2km, + 2, ) + station_location[i, 1] = round(attrs["latitude"] * self.degree2km, 2) + station_location[i, 2] = round(-attrs["elevation_m"]/1e3, 2) + + std = np.std(waveforms, axis=1, keepdims=True) + std[std == 0] = 1.0 + waveforms = (waveforms - np.mean(waveforms, axis=1, keepdims=True)) / std + waveforms = waveforms.astype(np.float32) + yield event_id, { - "event_id": event_id, - "waveform": waveform, - "phase_time": phase_time, - "phase_index": phase_index, - "phase_type": phase_type, - "phase_polarity": phase_polarity, - "begin_time": begin_time, - "end_time": end_time, - "event_time": event_time, - "event_time_index": event_time_index, - "event_location": event_location, - "station_location": station_location, + "data": torch.from_numpy(waveforms).float(), + "phase_pick": torch.from_numpy(phase_pick).float(), + "event_center": torch.from_numpy(event_center[:, ::self.feature_scale]).float(), + "event_location": torch.from_numpy(event_location[:, :, ::self.feature_scale]).float(), + "event_location_mask": torch.from_numpy(event_location_mask[:, ::self.feature_scale]).float(), + "station_location": torch.from_numpy(station_location).float(), } + + +def generate_label(phase_list, label_width=[150, 150], nt=8192): + target = np.zeros([len(phase_list) + 1, nt], dtype=np.float32) + + for i, (picks, w) in enumerate(zip(phase_list, label_width)): + for phase_time in picks: + t = np.arange(nt) - phase_time + gaussian = np.exp(-(t**2) / (2 * (w / 6) ** 2)) + gaussian[gaussian < 0.1] = 0.0 + target[i + 1, :] += gaussian + + target[0:1, :] = np.maximum(0, 1 - np.sum(target[1:, :], axis=0, keepdims=True)) + + return target diff --git a/waveform.h5 b/waveform.h5 deleted file mode 100644 index 68882b505bef6c2ee76e6c1a0a138526a4944b15..0000000000000000000000000000000000000000 --- a/waveform.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:77fb8b0bb040e1412a183a217dcbc1aa03ceb86b42db39ac62afe922a1673889 -size 20016390 diff --git a/waveform_h5/1987.h5 b/waveform_h5/1987.h5 deleted file mode 100644 index 07668f24139a48d629594b037b4cb970fed88130..0000000000000000000000000000000000000000 --- a/waveform_h5/1987.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8afb94aafbf79db2848ae9c2006385c782493a97e6c71c1b8abf97c5d53bfc9d -size 7744528 diff --git a/waveform_h5/1988.h5 b/waveform_h5/1988.h5 deleted file mode 100644 index 513cab71b72cf473c844e189b1c7a074eb081c13..0000000000000000000000000000000000000000 --- a/waveform_h5/1988.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c1398baca3f539e52744f83625b1dbb6f117a32b8d7e97f6af02a1f452f0dedd -size 46126800 diff --git a/waveform_h5/1989.h5 b/waveform_h5/1989.h5 deleted file mode 100644 index 89ba384abbe224be945899870a51779c2a8a1606..0000000000000000000000000000000000000000 --- a/waveform_h5/1989.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:533cd50fe365de8c050f0ffd4a90b697dc6b90cb86c8199ec0172316eab2ddaa -size 48255208 diff --git a/waveform_h5/1990.h5 b/waveform_h5/1990.h5 deleted file mode 100644 index 0498df584514024eab7455938f6fc0451cc433e2..0000000000000000000000000000000000000000 --- a/waveform_h5/1990.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f5a282a9a8c47cf65d144368085470940660faeb0e77cea59fff16af68020d26 -size 60092656 diff --git a/waveform_h5/1991.h5 b/waveform_h5/1991.h5 deleted file mode 100644 index 98124f1858b142d47f38824f8d3e700ff3197d77..0000000000000000000000000000000000000000 --- a/waveform_h5/1991.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5ba897d96eb92e8684b52a206e94a500abfe0192930f971ce7b1319c0638d452 -size 62332336 diff --git a/waveform_h5/1992.h5 b/waveform_h5/1992.h5 deleted file mode 100644 index ad22f7fd4c03fa45d146ba948d39e082fb5fb58e..0000000000000000000000000000000000000000 --- a/waveform_h5/1992.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d00021f46956bf43192f8c59405e203f823f1f4202c720efa52c5029e8e880b8 -size 67360896 diff --git a/waveform_h5/1993.h5 b/waveform_h5/1993.h5 deleted file mode 100644 index 08259128beeb6ca5be12406d6c5797126842b987..0000000000000000000000000000000000000000 --- a/waveform_h5/1993.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:eec41dd0aa7b88c81fa9f9b5dbcaab80e1c7bc8f6c144bd81761941278c57b4f -size 706087936 diff --git a/waveform_h5/1994.h5 b/waveform_h5/1994.h5 deleted file mode 100644 index 28751e418848cd2020bad602982494e32aac7768..0000000000000000000000000000000000000000 --- a/waveform_h5/1994.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b1cd002f20573636eaf101a30c5bac477edda201aba3af68be358756543ed48a -size 609524864 diff --git a/waveform_h5/1995.h5 b/waveform_h5/1995.h5 deleted file mode 100644 index 4ed4c1bfff4b873555c865ec824d35a42439d088..0000000000000000000000000000000000000000 --- a/waveform_h5/1995.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:948f19d71520a0dd25574be300f70e62c383e319b07a7d7182fca1dcfa9d61ee -size 1728452872 diff --git a/waveform_h5/1996.h5 b/waveform_h5/1996.h5 deleted file mode 100644 index 8f911973f8274dba91f9c994547e69865e918233..0000000000000000000000000000000000000000 --- a/waveform_h5/1996.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:23654b6f9c3a4c5a0aa56ed13ba04e943a94b458a51ac80ec1d418e9aa132840 -size 1752242680 diff --git a/waveform_h5/1997.h5 b/waveform_h5/1997.h5 deleted file mode 100644 index ac6b68037806e12ef4f8bbbb60ab6b9362a26b0b..0000000000000000000000000000000000000000 --- a/waveform_h5/1997.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d1c0f4c8146fc8ff27c8a47a942b967a97bd2835346203e6de74ca55dd522616 -size 2661543208 diff --git a/waveform_h5/1998.h5 b/waveform_h5/1998.h5 deleted file mode 100644 index 29c713a00cba720e768a6bc523ffb4aad41b58bf..0000000000000000000000000000000000000000 --- a/waveform_h5/1998.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1afac9c1a33424b739d26261ac2e9a4520be9c86c57bae4c8fe1a7a422356e45 -size 2070489120 diff --git a/waveform_h5/1999.h5 b/waveform_h5/1999.h5 deleted file mode 100644 index 1ef248f279f2168bab28ea9b2ce7f863a95ca257..0000000000000000000000000000000000000000 --- a/waveform_h5/1999.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2f2595a1919a5435148cdcf2cfa1501ce5edb53878d471500b13936f0f6f558c -size 2300297608 diff --git a/waveform_h5/2000.h5 b/waveform_h5/2000.h5 deleted file mode 100644 index 2c088cb44fd6826f2030d940287b6630fb89662a..0000000000000000000000000000000000000000 --- a/waveform_h5/2000.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:250fd52d9f8dd17a8bfb58a3ecfef25d62b0a1adf67f6fe6f2b446e9f72caf7a -size 434865160 diff --git a/waveform_h5/2001.h5 b/waveform_h5/2001.h5 deleted file mode 100644 index bbf39abd08e0fe09912126c5ce05406ccbea3bdb..0000000000000000000000000000000000000000 --- a/waveform_h5/2001.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d70dea6156b32057760f91742f7a05a336e4f63b1f793408b5e7aad6a15551e5 -size 919203704 diff --git a/waveform_h5/2002.h5 b/waveform_h5/2002.h5 deleted file mode 100644 index 76fb93897b9d94ef3e5f9b1d91e9850880cd4415..0000000000000000000000000000000000000000 --- a/waveform_h5/2002.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f88c4c5960741a8d354db4a7324d56ef8750ab93aa1d9b11fc80d0c497d8d6ae -size 2445812792 diff --git a/waveform_h5/2003.h5 b/waveform_h5/2003.h5 deleted file mode 100644 index 11a95b638c0c8a2101af4ff2244b0e70475366d4..0000000000000000000000000000000000000000 --- a/waveform_h5/2003.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:943d649f1a8a0e3989d2458be68fbf041058a581c4c73f8de39f1d50d3e7b35c -size 3618485352 diff --git a/waveform_h5/2004.h5 b/waveform_h5/2004.h5 deleted file mode 100644 index 69b990cca13edb58f1857585abeb2b2e9aaef4fc..0000000000000000000000000000000000000000 --- a/waveform_h5/2004.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ed1ba66e10ba5c165568ac13950a1728927ba49b33903a0df42c3d9965a16807 -size 6158740712 diff --git a/waveform_h5/2005.h5 b/waveform_h5/2005.h5 deleted file mode 100644 index ff6db36cba3743bf05b50910917934fd856a3c8b..0000000000000000000000000000000000000000 --- a/waveform_h5/2005.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c816d75b172148763b19e60c1469c106c1af1f906843c3d6d94e603e02c2b6cb -size 2994468240 diff --git a/waveform_h5/2006.h5 b/waveform_h5/2006.h5 deleted file mode 100644 index da042eba8b60c0346992c5108230cd747db304b8..0000000000000000000000000000000000000000 --- a/waveform_h5/2006.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:521e6b0ce262461f87b4b0a78ac6403cfbb597d6ace36e17f92354c456a30447 -size 2189511664 diff --git a/waveform_h5/2007.h5 b/waveform_h5/2007.h5 deleted file mode 100644 index 9678c39ab40c938ccb9c6842a26931738d54218e..0000000000000000000000000000000000000000 --- a/waveform_h5/2007.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ae6654c213fb4838d6a732b2c8d936bd799005b2a189d64f2d74e3767c0c503a -size 4393926088 diff --git a/waveform_h5/2008.h5 b/waveform_h5/2008.h5 deleted file mode 100644 index 5a5778354acd20652a086c3e902892e808ba1504..0000000000000000000000000000000000000000 --- a/waveform_h5/2008.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d8163aee689448c260032df9b0ab9132a5b46f0fee88a4c1ca8f4492ec5534d6 -size 3964283536 diff --git a/waveform_h5/2009.h5 b/waveform_h5/2009.h5 deleted file mode 100644 index 83c493a52086454f8dcc29c8dfb775c1ece86257..0000000000000000000000000000000000000000 --- a/waveform_h5/2009.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6702c2d3951ddf1034f1886a79e8c5a00dfa47c88c84048edc528f047a2337b5 -size 4162296168 diff --git a/waveform_h5/2010.h5 b/waveform_h5/2010.h5 deleted file mode 100644 index 40558b648e41d3ccf40280396b6021ec00cf53ad..0000000000000000000000000000000000000000 --- a/waveform_h5/2010.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2f2de7c07f088a32ea7ae71c2107dfd121780a47d3e3f23e5c98ddb482c6ce71 -size 4547184704 diff --git a/waveform_h5/2011.h5 b/waveform_h5/2011.h5 deleted file mode 100644 index ef67d39a31c1a234596c1e3b34fb50ff08dbe370..0000000000000000000000000000000000000000 --- a/waveform_h5/2011.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:520d62f3a94f1b4889f583196676fe2eccb6452807461afc93432dca930d6052 -size 5633641952 diff --git a/waveform_h5/2012.h5 b/waveform_h5/2012.h5 deleted file mode 100644 index efdb6143c6ecef81ccf2ab8c874078ad7a73b6aa..0000000000000000000000000000000000000000 --- a/waveform_h5/2012.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:98b90529df4cbff7f21cd233d482454eaeac77b81117720ca7fe6c2697819071 -size 9520058832 diff --git a/waveform_h5/2013.h5 b/waveform_h5/2013.h5 deleted file mode 100644 index b79fe550e2a5e1b89a34367724719f985ac6f47e..0000000000000000000000000000000000000000 --- a/waveform_h5/2013.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e6f1030ff4ebe488ef9072ec984c91024a8be4ecdbe7e9af47c6e65de942c2fe -size 8380878704 diff --git a/waveform_h5/2014.h5 b/waveform_h5/2014.h5 deleted file mode 100644 index 9fb1172801cb11294a9d970761162f1a472bf840..0000000000000000000000000000000000000000 --- a/waveform_h5/2014.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a63f5e6d7d5bca552dcc99053753603dfa3109a6a080f8402f843ef688927d4c -size 12088815344 diff --git a/waveform_h5/2015.h5 b/waveform_h5/2015.h5 deleted file mode 100644 index 59e75b017c5dd25720f0dca6c673f84914a048a5..0000000000000000000000000000000000000000 --- a/waveform_h5/2015.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:42be6994ad27eb8aee241f5edfb4ed0ee69aa3460397325cc858224ba9dd9721 -size 8536767520 diff --git a/waveform_h5/2016.h5 b/waveform_h5/2016.h5 deleted file mode 100644 index 5d896e656c300684d28111f4814f751cf2283d21..0000000000000000000000000000000000000000 --- a/waveform_h5/2016.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6e706aefd38170da41196974fc92e457d0dc56948a63640a37cea4a86a297843 -size 9287201016 diff --git a/waveform_h5/2017.h5 b/waveform_h5/2017.h5 deleted file mode 100644 index e34661a8e07f61aa2345e3f7936b57d8a7043d87..0000000000000000000000000000000000000000 --- a/waveform_h5/2017.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e20f8e5a3f5ec8927e5d44e722987461ef08c9ceb33ab982038528e9000d5323 -size 8627205152 diff --git a/waveform_h5/2018.h5 b/waveform_h5/2018.h5 deleted file mode 100644 index d08517a7f4196a05249aa452273952a8eda73afc..0000000000000000000000000000000000000000 --- a/waveform_h5/2018.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ad6e83734ff1e24ad91b17cb6656766861ae9fb30413948579d762acc092e66a -size 7158598240 diff --git a/waveform_h5/2019.h5 b/waveform_h5/2019.h5 deleted file mode 100644 index 2745da173a8fc5bcb99b3efd7b34af2ee02ebc90..0000000000000000000000000000000000000000 --- a/waveform_h5/2019.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6bda0b414a7a7726aebf89a51d3629ae350ffc4da797c548172a74dfbb723b05 -size 8614182952 diff --git a/waveform_h5/2020.h5 b/waveform_h5/2020.h5 deleted file mode 100644 index 8fbd0e1ed3b4ec9e31717fa2201ede54e7f7d331..0000000000000000000000000000000000000000 --- a/waveform_h5/2020.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1c064183f40d8081b3ab835871a69a58ed4584bb0bfe950cca8cacf77a312b8e -size 9519933120 diff --git a/waveform_h5/2021.h5 b/waveform_h5/2021.h5 deleted file mode 100644 index 66e6a0bfe59aec13b18c33c7e9499d00afd604d3..0000000000000000000000000000000000000000 --- a/waveform_h5/2021.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8393ce458c5731d15773dffa199eaee495f32c719cf5c60701c8c17ea3bc8c89 -size 10863499296 diff --git a/waveform_h5/2022.h5 b/waveform_h5/2022.h5 deleted file mode 100644 index 0ff7a7674f461c8bbc72e9f65c76f1906bb77371..0000000000000000000000000000000000000000 --- a/waveform_h5/2022.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9dd61cbe98098c55d0d668b0fcdd1422833d80e0b2444a8dfb6470e1e51bceee -size 7912114912 diff --git a/waveform_h5/2023.h5 b/waveform_h5/2023.h5 deleted file mode 100644 index 8adfd4d7bd3e7eafff55dcbcc18c80af35b205a5..0000000000000000000000000000000000000000 --- a/waveform_h5/2023.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:97dd942bf4faf3360df457d5a28ca16462c3e42859fd6a8d2aa09c7c85b0d1a0 -size 8424253768 diff --git a/waveform_test.h5 b/waveform_test.h5 deleted file mode 100644 index 3510b4b6be9341a317376931b79c2fc40495f255..0000000000000000000000000000000000000000 --- a/waveform_test.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8fef227fb8851e6b17c50abe2e9ce25b3378ed1f767ae475962dc350b6cec7e4 -size 686651 diff --git a/waveform_train.h5 b/waveform_train.h5 deleted file mode 100644 index af5a671b84bd7dfecf91694776322791bdf23c86..0000000000000000000000000000000000000000 --- a/waveform_train.h5 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:170810f17d65e06f99934f26eaeafd3dc1cb45dfc723b063ceba29c34c02f701 -size 19360027