--- license: mit --- # Quakeflow_NC ## Introduction This dataset is part of the data 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: (File [ncedc_event_dataset_000.h5.txt](./ncedc_event_dataset_000.h5.txt) shows the structure of the firsr shard of the dataset, and you can find more information about the format at [AI4EPS](https://ai4eps.github.io/homepage/ml4earth/seismic_event_format1/)) Cite the NCEDC: "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:10000 |- Group: /nc100012 len:5 | |-* begin_time = 1987-05-08T00:15:48.890 | |-* depth_km = 7.04 | |-* end_time = 1987-05-08T00:17:48.890 | |-* event_id = nc100012 | |-* event_time = 1987-05-08T00:16:14.700 | |-* event_time_index = 2581 | |-* latitude = 37.5423 | |-* longitude = -118.4412 | |-* magnitude = 1.1 | |-* magnitude_type = D | |-* num_stations = 5 | |- Dataset: /nc100012/NC.MRS..EH (shape:(3, 12000)) | | |- (dtype=float32) | | | |-* azimuth = 265.0 | | | |-* component = ['Z'] | | | |-* distance_km = 39.1 | | | |-* dt_s = 0.01 | | | |-* elevation_m = 3680.0 | | | |-* emergence_angle = 93.0 | | | |-* event_id = ['nc100012' 'nc100012'] | | | |-* latitude = 37.5107 | | | |-* location = | | | |-* longitude = -118.8822 | | | |-* network = NC | | | |-* phase_index = [3274 3802] | | | |-* phase_polarity = ['U' 'N'] | | | |-* phase_remark = ['IP' 'S'] | | | |-* phase_score = [1 1] | | | |-* phase_time = ['1987-05-08T00:16:21.630' '1987-05-08T00:16:26.920'] | | | |-* phase_type = ['P' 'S'] | | | |-* snr = [0. 0. 1.98844361] | | | |-* station = MRS | | | |-* unit = 1e-6m/s | |- Dataset: /nc100012/NN.BEN.N1.EH (shape:(3, 12000)) | | |- (dtype=float32) | | | |-* azimuth = 329.0 | | | |-* component = ['Z'] | | | |-* distance_km = 22.5 | | | |-* dt_s = 0.01 | | | |-* elevation_m = 2476.0 | | | |-* emergence_angle = 102.0 | | | |-* event_id = ['nc100012' 'nc100012'] | | | |-* latitude = 37.7154 | | | |-* location = N1 | | | |-* longitude = -118.5741 | | | |-* network = NN | | | |-* phase_index = [3010 3330] | | | |-* phase_polarity = ['U' 'N'] | | | |-* phase_remark = ['IP' 'S'] | | | |-* phase_score = [0 0] | | | |-* phase_time = ['1987-05-08T00:16:18.990' '1987-05-08T00:16:22.190'] | | | |-* phase_type = ['P' 'S'] | | | |-* snr = [0. 0. 7.31356192] | | | |-* station = BEN | | | |-* unit = 1e-6m/s ...... ``` ## How to use ### Requirements - datasets - h5py - torch (for PyTorch) ### Usage ```python import h5py import numpy as np import torch from torch.utils.data import Dataset, IterableDataset, DataLoader from datasets import load_dataset # 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 quakeflow_nc = datasets.load_dataset("AI4EPS/quakeflow_nc", split="train") quakeflow_nc ``` If you want to use the first several shards of the dataset, you can download the script `quakeflow_nc.py` and change the code below: ```python # change the 37 to the number of shards you want _URLS = { "NCEDC": [f"{_REPO}/ncedc_event_dataset_{i:03d}.h5" for i in range(37)] } ``` Then you can use the dataset like this: ```python quakeflow_nc = datasets.load_dataset("./quakeflow_nc.py", split="train") quakeflow_nc ``` Then you can change the dataset into PyTorch format iterable dataset, and view the first sample: ```python quakeflow_nc = quakeflow_nc.to_iterable_dataset() quakeflow_nc = quakeflow_nc.with_format("torch") # because add examples formatting to get tensors when using the "torch" format # has not been implemented yet, we need to manually add the formatting 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=4) 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 ```