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..32897cd3e640101ba184f8c4ccd896981de3804a 100644 --- a/README.md +++ b/README.md @@ -1,160 +1,3 @@ --- license: mit --- - -# Quakeflow_NC - -## Introduction -This dataset is part of the data (1970-2020) from [NCEDC (Northern California Earthquake Data Center)](https://ncedc.org/index.html) and is organized as several HDF5 files. The dataset structure is shown below, and you can find more information about the format at [AI4EPS](https://ai4eps.github.io/homepage/ml4earth/seismic_event_format1/)) - -Cite the NCEDC and PhaseNet: - -Zhu, W., & Beroza, G. C. (2018). PhaseNet: A Deep-Neural-Network-Based Seismic Arrival Time Picking Method. arXiv preprint arXiv:1803.03211. - -NCEDC (2014), Northern California Earthquake Data Center. UC Berkeley Seismological Laboratory. Dataset. doi:10.7932/NCEDC. - -Acknowledge the NCEDC: - -Waveform data, metadata, or data products for this study were accessed through the Northern California Earthquake Data Center (NCEDC), doi:10.7932/NCEDC. - -``` - Group: / len:16227 - |- Group: /nc71111584 len:2 - | |-* begin_time = 2020-01-02T07:01:19.620 - | |-* depth_km = 3.69 - | |-* end_time = 2020-01-02T07:03:19.620 - | |-* event_id = nc71111584 - | |-* event_time = 2020-01-02T07:01:48.240 - | |-* event_time_index = 2862 - | |-* latitude = 37.6545 - | |-* longitude = -118.8798 - | |-* magnitude = -0.15 - | |-* magnitude_type = D - | |-* num_stations = 2 - | |- Dataset: /nc71111584/NC.MCB..HH (shape:(3, 12000)) - | | |- (dtype=float32) - | | | |-* azimuth = 233.0 - | | | |-* component = ['E' 'N' 'Z'] - | | | |-* distance_km = 1.9 - | | | |-* dt_s = 0.01 - | | | |-* elevation_m = 2391.0 - | | | |-* emergence_angle = 159.0 - | | | |-* event_id = ['nc71111584' 'nc71111584'] - | | | |-* latitude = 37.6444 - | | | |-* location = - | | | |-* longitude = -118.8968 - | | | |-* network = NC - | | | |-* phase_index = [3000 3101] - | | | |-* phase_polarity = ['U' 'N'] - | | | |-* phase_remark = ['IP' 'ES'] - | | | |-* phase_score = [1 2] - | | | |-* phase_time = ['2020-01-02T07:01:49.620' '2020-01-02T07:01:50.630'] - | | | |-* phase_type = ['P' 'S'] - | | | |-* snr = [2.82143 3.055604 1.8412642] - | | | |-* station = MCB - | | | |-* unit = 1e-6m/s - | |- Dataset: /nc71111584/NC.MCB..HN (shape:(3, 12000)) - | | |- (dtype=float32) - | | | |-* azimuth = 233.0 - | | | |-* component = ['E' 'N' 'Z'] - ...... - ``` - -## How to use - -### Requirements -- datasets -- h5py -- fsspec -- pytorch - -### Usage -Import the necessary packages: -```python -import h5py -import numpy as np -import torch -from datasets import load_dataset -``` -We have 6 configurations for the dataset: -- "station" -- "event" -- "station_train" -- "event_train" -- "station_test" -- "event_test" - -"station" yields station-based samples one by one, while "event" yields event-based samples one by one. The configurations with no suffix are the full dataset, while the configurations with suffix "_train" and "_test" only have corresponding split of the full dataset. Train split contains data from 1970 to 2019, while test split contains data in 2020. - -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 -- `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)` -- `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: -```python -# load dataset -# ATTENTION: Streaming(Iterable Dataset) is difficult to support because of the feature of HDF5 -# So we recommend to directly load the dataset and convert it into iterable later -# The dataset is very large, so you need to wait for some time at the first time - -# to load "station_test" with test split -quakeflow_nc = load_dataset("AI4EPS/quakeflow_nc", split="test") -# or -quakeflow_nc = load_dataset("AI4EPS/quakeflow_nc", name="station_test", split="test") - -# to load "event" with train split -quakeflow_nc = load_dataset("AI4EPS/quakeflow_nc", name="event", split="train") -``` - -#### Example loading the dataset -```python -quakeflow_nc = load_dataset("AI4EPS/quakeflow_nc", name="station_test", split="test") - -# 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]) - 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 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]) - 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 deleted file mode 100644 index acf4dfdffe060a44bd8c90b8f67b86f42cafdcd3..0000000000000000000000000000000000000000 --- a/merge_hdf5.py +++ /dev/null @@ -1,65 +0,0 @@ -# %% -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_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}") - -# %% -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 - -# %% 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..97614da39e34122708051d99f156e795ddcf074e 100644 --- a/quakeflow_nc.py +++ b/quakeflow_nc.py @@ -17,21 +17,23 @@ """QuakeFlow_NC: A dataset of earthquake waveforms organized by earthquake events and based on the HDF5 format.""" -from typing import Dict, List, Optional, Tuple, Union +import csv +import json +import os +import h5py +from glob import glob import datasets -import fsspec -import h5py -import numpy as np -import torch + # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @InProceedings{huggingface:dataset, -title = {NCEDC dataset for QuakeFlow}, -author={Zhu et al.}, -year={2023} +title = {A great new dataset}, +author={huggingface, Inc. +}, +year={2020} } """ @@ -50,74 +52,18 @@ _LICENSE = "" # TODO: Add link to the official dataset URLs here # The HuggingFace Datasets library doesn't host the datasets but only points to the original files. # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method) -_REPO = "https://huggingface.co/datasets/AI4EPS/quakeflow_nc/resolve/main/waveform_h5" -_FILES = [ - "1987.h5", - "1988.h5", - "1989.h5", - "1990.h5", - "1991.h5", - "1992.h5", - "1993.h5", - "1994.h5", - "1995.h5", - "1996.h5", - "1997.h5", - "1998.h5", - "1999.h5", - "2000.h5", - "2001.h5", - "2002.h5", - "2003.h5", - "2004.h5", - "2005.h5", - "2006.h5", - "2007.h5", - "2008.h5", - "2009.h5", - "2010.h5", - "2011.h5", - "2012.h5", - "2013.h5", - "2014.h5", - "2015.h5", - "2016.h5", - "2017.h5", - "2018.h5", - "2019.h5", - "2020.h5", - "2021.h5", - "2022.h5", - "2023.h5", -] +_REPO = "https://huggingface.co/datasets/AI4EPS/QuakeFlow_NC/resolve/main/data" _URLS = { - "station": [f"{_REPO}/{x}" for x in _FILES], - "event": [f"{_REPO}/{x}" for x in _FILES], - "station_train": [f"{_REPO}/{x}" for x in _FILES[:-1]], - "event_train": [f"{_REPO}/{x}" for x in _FILES[:-1]], - "station_test": [f"{_REPO}/{x}" for x in _FILES[-1:]], - "event_test": [f"{_REPO}/{x}" for x in _FILES[-1:]], + "NCEDC": [f"{_REPO}/ncedc_event_dataset_{i:03d}.h5" for i in range(37)] } -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 - """ - - def __init__(self, **kwargs): - super().__init__(**kwargs) - - # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case class QuakeFlow_NC(datasets.GeneratorBasedBuilder): """QuakeFlow_NC: A dataset of earthquake waveforms organized by earthquake events and based on the HDF5 format.""" VERSION = datasets.Version("1.1.0") - nt = 8192 - # This is an example of a dataset with multiple configurations. # If you don't want/need to define several sub-sets in your dataset, # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes. @@ -129,80 +75,21 @@ class QuakeFlow_NC(datasets.GeneratorBasedBuilder): # You will be able to load one or the other configurations in the following list with # data = datasets.load_dataset('my_dataset', 'first_domain') # data = datasets.load_dataset('my_dataset', 'second_domain') - - # default config, you can change batch_size and num_stations_list when use `datasets.load_dataset` BUILDER_CONFIGS = [ - datasets.BuilderConfig( - name="station", version=VERSION, description="yield station-based samples one by one of whole dataset" - ), - datasets.BuilderConfig( - name="event", version=VERSION, description="yield event-based samples one by one of whole dataset" - ), - datasets.BuilderConfig( - name="station_train", - version=VERSION, - description="yield station-based samples one by one of training dataset", - ), - datasets.BuilderConfig( - name="event_train", version=VERSION, description="yield event-based samples one by one of training dataset" - ), - datasets.BuilderConfig( - name="station_test", version=VERSION, description="yield station-based samples one by one of test dataset" - ), - datasets.BuilderConfig( - name="event_test", version=VERSION, description="yield event-based samples one by one of test dataset" - ), + datasets.BuilderConfig(name="NCEDC", version=VERSION, description="This part of my dataset covers a first domain"), ] - DEFAULT_CONFIG_NAME = ( - "station_test" # It's not mandatory to have a default configuration. Just use one if it make sense. - ) + DEFAULT_CONFIG_NAME = "NCEDC" # It's not mandatory to have a default configuration. Just use one if it make sense. def _info(self): # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset - if ( - (self.config.name == "station") - or (self.config.name == "station_train") - or (self.config.name == "station_test") - ): - 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"), - "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( - { - "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"))), - }, - ) - else: - raise ValueError(f"config.name = {self.config.name} is not in BUILDER_CONFIGS") - + features=datasets.Features( + { + "event_id": datasets.Value("string"), + "station_id": datasets.Value("string"), + "waveform": datasets.Array2D(shape=(3, 12000), dtype="float32"), + } + ) return datasets.DatasetInfo( # This is the description that will appear on the datasets page. description=_DESCRIPTION, @@ -228,42 +115,35 @@ 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) - - 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"}, - ), - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepath": files[-1:], "split": "test"}, - ), - ] - elif self.config.name == "station_train" or self.config.name == "event_train": - return [ - datasets.SplitGenerator( - name=datasets.Split.TRAIN, - gen_kwargs={"filepath": files, "split": "train"}, - ), - ] - elif self.config.name == "station_test" or self.config.name == "event_test": - return [ - datasets.SplitGenerator( - name=datasets.Split.TEST, - gen_kwargs={"filepath": files, "split": "test"}, - ), - ] - else: - raise ValueError("config.name is not in BUILDER_CONFIGS") + files = dl_manager.download_and_extract(urls) + # files = ["./data/ncedc_event_dataset_000.h5"] + + return [ + datasets.SplitGenerator( + name=datasets.Split.TRAIN, + # These kwargs will be passed to _generate_examples + gen_kwargs={ + "filepath": files, + "split": "train", + }, + ), + # datasets.SplitGenerator( + # name=datasets.Split.VALIDATION, + # # These kwargs will be passed to _generate_examples + # gen_kwargs={ + # "filepath": os.path.join(data_dir, "dev.jsonl"), + # "split": "dev", + # }, + # ), + # datasets.SplitGenerator( + # name=datasets.Split.TEST, + # # These kwargs will be passed to _generate_examples + # gen_kwargs={ + # "filepath": os.path.join(data_dir, "test.jsonl"), + # "split": "test" + # }, + # ), + ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, filepath, split): @@ -271,92 +151,14 @@ 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: - 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"] - 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, - } - - elif ( - (self.config.name == "event") - or (self.config.name == "event_train") - or (self.config.name == "event_test") - ): - - 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] - ) - 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, - } + with h5py.File(file, "r") as fp: + for event_id in sorted(list(fp.keys())): + event = fp[event_id] + for station_id in sorted(list(event.keys())): + station = event[station_id] + # print(f"{event_id = } {station_id = }") + yield event_id + "_" + station_id, { + "event_id": event_id, + "station_id": station_id, + "waveform": station[:], + } diff --git a/upload.py b/upload.py deleted file mode 100644 index f41256a103521dc13b095224e248bb189bafe07d..0000000000000000000000000000000000000000 --- a/upload.py +++ /dev/null @@ -1,11 +0,0 @@ -from huggingface_hub import HfApi - -api = HfApi() - -# Upload all the content from the local folder to your remote Space. -# By default, files are uploaded at the root of the repo -api.upload_folder( - folder_path="./", - repo_id="AI4EPS/quakeflow_nc", - repo_type="space", -) \ No newline at end of file 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