change name
Browse files- dataset_script.py +0 -161
- QuakeFlow_NC.py → quakeflow_nc.py +0 -0
dataset_script.py
DELETED
@@ -1,161 +0,0 @@
|
|
1 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
-
#
|
3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
# you may not use this file except in compliance with the License.
|
5 |
-
# You may obtain a copy of the License at
|
6 |
-
#
|
7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
-
#
|
9 |
-
# Unless required by applicable law or agreed to in writing, software
|
10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
-
# See the License for the specific language governing permissions and
|
13 |
-
# limitations under the License.
|
14 |
-
# TODO: Address all TODOs and remove all explanatory comments
|
15 |
-
"""TODO: Add a description here."""
|
16 |
-
|
17 |
-
|
18 |
-
import csv
|
19 |
-
import json
|
20 |
-
import os
|
21 |
-
import h5py
|
22 |
-
from glob import glob
|
23 |
-
|
24 |
-
import datasets
|
25 |
-
|
26 |
-
|
27 |
-
# TODO: Add BibTeX citation
|
28 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
29 |
-
_CITATION = """\
|
30 |
-
@InProceedings{huggingface:dataset,
|
31 |
-
title = {A great new dataset},
|
32 |
-
author={huggingface, Inc.
|
33 |
-
},
|
34 |
-
year={2020}
|
35 |
-
}
|
36 |
-
"""
|
37 |
-
|
38 |
-
# TODO: Add description of the dataset here
|
39 |
-
# You can copy an official description
|
40 |
-
_DESCRIPTION = """\
|
41 |
-
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
|
42 |
-
"""
|
43 |
-
|
44 |
-
# TODO: Add a link to an official homepage for the dataset here
|
45 |
-
_HOMEPAGE = ""
|
46 |
-
|
47 |
-
# TODO: Add the licence for the dataset here if you can find it
|
48 |
-
_LICENSE = ""
|
49 |
-
|
50 |
-
# TODO: Add link to the official dataset URLs here
|
51 |
-
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
52 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
53 |
-
_REPO = "https://huggingface.co/datasets/AI4EPS/QuakeFlow_NC/resolve/main/data"
|
54 |
-
_URLS = {
|
55 |
-
"NCEDC": [f"{_REPO}/ncedc_event_dataset_{i:03d}.h5" for i in range(36)]
|
56 |
-
}
|
57 |
-
|
58 |
-
|
59 |
-
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
60 |
-
class NewDataset(datasets.GeneratorBasedBuilder):
|
61 |
-
"""TODO: Short description of my dataset."""
|
62 |
-
|
63 |
-
VERSION = datasets.Version("1.1.0")
|
64 |
-
|
65 |
-
# This is an example of a dataset with multiple configurations.
|
66 |
-
# If you don't want/need to define several sub-sets in your dataset,
|
67 |
-
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
68 |
-
|
69 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
70 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
71 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
72 |
-
|
73 |
-
# You will be able to load one or the other configurations in the following list with
|
74 |
-
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
75 |
-
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
76 |
-
BUILDER_CONFIGS = [
|
77 |
-
datasets.BuilderConfig(name="NCEDC", version=VERSION, description="This part of my dataset covers a first domain"),
|
78 |
-
]
|
79 |
-
|
80 |
-
DEFAULT_CONFIG_NAME = "NCEDC" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
81 |
-
|
82 |
-
def _info(self):
|
83 |
-
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
84 |
-
features=datasets.Features(
|
85 |
-
{
|
86 |
-
"event_id": datasets.Value("string"),
|
87 |
-
"station_id": datasets.Value("string"),
|
88 |
-
"waveform": datasets.Array2D(shape=(3, 1200), dtype="float32"),
|
89 |
-
}
|
90 |
-
)
|
91 |
-
return datasets.DatasetInfo(
|
92 |
-
# This is the description that will appear on the datasets page.
|
93 |
-
description=_DESCRIPTION,
|
94 |
-
# This defines the different columns of the dataset and their types
|
95 |
-
features=features, # Here we define them above because they are different between the two configurations
|
96 |
-
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
97 |
-
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
98 |
-
# supervised_keys=("sentence", "label"),
|
99 |
-
# Homepage of the dataset for documentation
|
100 |
-
homepage=_HOMEPAGE,
|
101 |
-
# License for the dataset if available
|
102 |
-
license=_LICENSE,
|
103 |
-
# Citation for the dataset
|
104 |
-
citation=_CITATION,
|
105 |
-
)
|
106 |
-
|
107 |
-
def _split_generators(self, dl_manager):
|
108 |
-
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
109 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
110 |
-
|
111 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
112 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
113 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
114 |
-
urls = _URLS[self.config.name]
|
115 |
-
# files = dl_manager.download(urls)
|
116 |
-
files = dl_manager.download_and_extract(urls)
|
117 |
-
|
118 |
-
return [
|
119 |
-
datasets.SplitGenerator(
|
120 |
-
name=datasets.Split.TRAIN,
|
121 |
-
# These kwargs will be passed to _generate_examples
|
122 |
-
gen_kwargs={
|
123 |
-
"filepath": files,
|
124 |
-
"split": "train",
|
125 |
-
},
|
126 |
-
),
|
127 |
-
# datasets.SplitGenerator(
|
128 |
-
# name=datasets.Split.VALIDATION,
|
129 |
-
# # These kwargs will be passed to _generate_examples
|
130 |
-
# gen_kwargs={
|
131 |
-
# "filepath": os.path.join(data_dir, "dev.jsonl"),
|
132 |
-
# "split": "dev",
|
133 |
-
# },
|
134 |
-
# ),
|
135 |
-
# datasets.SplitGenerator(
|
136 |
-
# name=datasets.Split.TEST,
|
137 |
-
# # These kwargs will be passed to _generate_examples
|
138 |
-
# gen_kwargs={
|
139 |
-
# "filepath": os.path.join(data_dir, "test.jsonl"),
|
140 |
-
# "split": "test"
|
141 |
-
# },
|
142 |
-
# ),
|
143 |
-
]
|
144 |
-
|
145 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
146 |
-
def _generate_examples(self, filepath, split):
|
147 |
-
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
148 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
149 |
-
|
150 |
-
for file in filepath:
|
151 |
-
with h5py.File(file, "r") as fp:
|
152 |
-
for event_id in sorted(list(fp.keys())):
|
153 |
-
event = fp[event_id]
|
154 |
-
for station_id in sorted(list(event.keys())):
|
155 |
-
station = event[station_id]
|
156 |
-
# print(f"{event_id = } {station_id = }")
|
157 |
-
yield event_id + "_" + station_id, {
|
158 |
-
"event_id": event_id,
|
159 |
-
"station_id": station_id,
|
160 |
-
"waveform": station[:],
|
161 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuakeFlow_NC.py → quakeflow_nc.py
RENAMED
File without changes
|