DarthReca commited on
Commit
bc6ce92
1 Parent(s): 6ec70af

:new: Added working script and README draft

Browse files
Files changed (2) hide show
  1. README.md +11 -69
  2. quakeset.py +181 -0
README.md CHANGED
@@ -9,11 +9,11 @@ pretty_name: QuakeSet
9
  size_categories:
10
  - 1K<n<10K
11
  ---
12
- # Dataset Card for Dataset Name
13
 
14
- <!-- Provide a quick summary of the dataset. -->
15
 
16
- This dataset card aims to be a base template for new datasets. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/datasetcard_template.md?plain=1).
17
 
18
  ## Dataset Details
19
 
@@ -24,10 +24,7 @@ This dataset card aims to be a base template for new datasets. It has been gener
24
 
25
 
26
  - **Curated by:** [More Information Needed]
27
- - **Funded by [optional]:** [More Information Needed]
28
- - **Shared by [optional]:** [More Information Needed]
29
- - **Language(s) (NLP):** [More Information Needed]
30
- - **License:** [More Information Needed]
31
 
32
  ### Dataset Sources [optional]
33
 
@@ -35,7 +32,6 @@ This dataset card aims to be a base template for new datasets. It has been gener
35
 
36
  - **Repository:** [More Information Needed]
37
  - **Paper [optional]:** [More Information Needed]
38
- - **Demo [optional]:** [More Information Needed]
39
 
40
  ## Uses
41
 
@@ -47,12 +43,6 @@ This dataset card aims to be a base template for new datasets. It has been gener
47
 
48
  [More Information Needed]
49
 
50
- ### Out-of-Scope Use
51
-
52
- <!-- This section addresses misuse, malicious use, and uses that the dataset will not work well for. -->
53
-
54
- [More Information Needed]
55
-
56
  ## Dataset Structure
57
 
58
  <!-- This section provides a description of the dataset fields, and additional information about the dataset structure such as criteria used to create the splits, relationships between data points, etc. -->
@@ -83,66 +73,18 @@ This dataset card aims to be a base template for new datasets. It has been gener
83
 
84
  [More Information Needed]
85
 
86
- ### Annotations [optional]
87
 
88
  <!-- If the dataset contains annotations which are not part of the initial data collection, use this section to describe them. -->
89
 
90
- #### Annotation process
91
-
92
- <!-- This section describes the annotation process such as annotation tools used in the process, the amount of data annotated, annotation guidelines provided to the annotators, interannotator statistics, annotation validation, etc. -->
93
-
94
- [More Information Needed]
95
-
96
- #### Who are the annotators?
97
-
98
- <!-- This section describes the people or systems who created the annotations. -->
99
-
100
- [More Information Needed]
101
-
102
- #### Personal and Sensitive Information
103
-
104
- <!-- State whether the dataset contains data that might be considered personal, sensitive, or private (e.g., data that reveals addresses, uniquely identifiable names or aliases, racial or ethnic origins, sexual orientations, religious beliefs, political opinions, financial or health data, etc.). If efforts were made to anonymize the data, describe the anonymization process. -->
105
-
106
- [More Information Needed]
107
-
108
- ## Bias, Risks, and Limitations
109
-
110
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
111
-
112
- [More Information Needed]
113
-
114
- ### Recommendations
115
 
116
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
117
-
118
- Users should be made aware of the risks, biases and limitations of the dataset. More information needed for further recommendations.
119
-
120
- ## Citation [optional]
121
 
122
  <!-- If there is a paper or blog post introducing the dataset, the APA and Bibtex information for that should go in this section. -->
123
 
124
  **BibTeX:**
125
-
126
- [More Information Needed]
127
-
128
- **APA:**
129
-
130
- [More Information Needed]
131
-
132
- ## Glossary [optional]
133
-
134
- <!-- If relevant, include terms and calculations in this section that can help readers understand the dataset or dataset card. -->
135
-
136
- [More Information Needed]
137
-
138
- ## More Information [optional]
139
-
140
- [More Information Needed]
141
-
142
- ## Dataset Card Authors [optional]
143
-
144
- [More Information Needed]
145
-
146
- ## Dataset Card Contact
147
-
148
- [More Information Needed]
 
9
  size_categories:
10
  - 1K<n<10K
11
  ---
12
+ # Dataset Card for QuakeSet
13
 
14
+ QuakeSet is a dataset to analyze different attributes of earthquakes. It contains bi-temporal timeseries of images and ground truth annotations for magnitudes, hypocenters and affected areas.
15
 
16
+ The dataset is divided in three folds with equal distribution of magnitudes and balanced in positive and negative examples.
17
 
18
  ## Dataset Details
19
 
 
24
 
25
 
26
  - **Curated by:** [More Information Needed]
27
+ - **License:** OPENRAIL
 
 
 
28
 
29
  ### Dataset Sources [optional]
30
 
 
32
 
33
  - **Repository:** [More Information Needed]
34
  - **Paper [optional]:** [More Information Needed]
 
35
 
36
  ## Uses
37
 
 
43
 
44
  [More Information Needed]
45
 
 
 
 
 
 
 
46
  ## Dataset Structure
47
 
48
  <!-- This section provides a description of the dataset fields, and additional information about the dataset structure such as criteria used to create the splits, relationships between data points, etc. -->
 
73
 
74
  [More Information Needed]
75
 
76
+ ### Annotations
77
 
78
  <!-- If the dataset contains annotations which are not part of the initial data collection, use this section to describe them. -->
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
+ ## Citation
 
 
 
 
82
 
83
  <!-- If there is a paper or blog post introducing the dataset, the APA and Bibtex information for that should go in this section. -->
84
 
85
  **BibTeX:**
86
+ ```
87
+ @article{
88
+
89
+ }
90
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
quakeset.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+
16
+ import json
17
+ import os
18
+
19
+ import datasets
20
+ import h5py
21
+ import numpy as np
22
+
23
+ # Find for instance the citation on arxiv or on the dataset repo/website
24
+ _CITATION = """\
25
+ WIP
26
+ """
27
+
28
+ # You can copy an official description
29
+ _DESCRIPTION = """\
30
+ QuakeSet is a dataset of earthquake images from the Copernicus Sentinel-1 satellites.
31
+ It contains images from before, after an earthquake, and a sample before the "before" sample.
32
+ Ground truth contains magnitudes and locations of earthquakes provided by ISC.
33
+ """
34
+
35
+ _HOMEPAGE = "https://huggingface.co/datasets/DarthReca/quakeset"
36
+
37
+ _LICENSE = "OPENRAIL"
38
+
39
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
40
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
41
+ _URLS = "earthquakes.h5"
42
+
43
+
44
+ class QuakeSet(datasets.GeneratorBasedBuilder):
45
+ """TODO: Short description of my dataset."""
46
+
47
+ VERSION = datasets.Version("1.0.0")
48
+
49
+ # This is an example of a dataset with multiple configurations.
50
+ # If you don't want/need to define several sub-sets in your dataset,
51
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
52
+
53
+ # If you need to make complex sub-parts in the datasets with configurable options
54
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
55
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
56
+
57
+ # You will be able to load one or the other configurations in the following list with
58
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
59
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
60
+ BUILDER_CONFIGS = [
61
+ datasets.BuilderConfig(
62
+ name="default",
63
+ version=VERSION,
64
+ description="Default configuration. No other configuration is available",
65
+ )
66
+ ]
67
+
68
+ DEFAULT_CONFIG_NAME = "default" # It's not mandatory to have a default configuration. Just use one if it make sense.
69
+
70
+ def _info(self):
71
+ features = datasets.Features(
72
+ {
73
+ "pre_post_image": datasets.Array3D(
74
+ shape=(512, 513, 2), dtype="float32"
75
+ ),
76
+ "affected": datasets.ClassLabel(num_classes=2),
77
+ "magnitude": datasets.Value("float32"),
78
+ "hypocenter": datasets.Sequence(datasets.Value("float32"), length=3),
79
+ "epsg": datasets.Value("int32"),
80
+ "x": datasets.Sequence(datasets.Value("float32"), length=512),
81
+ "y": datasets.Sequence(datasets.Value("float32"), length=512),
82
+ }
83
+ )
84
+
85
+ return datasets.DatasetInfo(
86
+ # This is the description that will appear on the datasets page.
87
+ description=_DESCRIPTION,
88
+ # This defines the different columns of the dataset and their types
89
+ features=features, # Here we define them above because they are different between the two configurations
90
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
91
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
92
+ # supervised_keys=("sentence", "label"),
93
+ # Homepage of the dataset for documentation
94
+ homepage=_HOMEPAGE,
95
+ # License for the dataset if available
96
+ license=_LICENSE,
97
+ # Citation for the dataset
98
+ citation=_CITATION,
99
+ )
100
+
101
+ def _split_generators(self, dl_manager):
102
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
103
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
104
+ # 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.
105
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
106
+ urls = _URLS
107
+ data_dir = dl_manager.download(urls)
108
+ return [
109
+ datasets.SplitGenerator(
110
+ name=datasets.Split.TRAIN,
111
+ # These kwargs will be passed to _generate_examples
112
+ gen_kwargs={
113
+ "filepath": os.path.join(data_dir, "earthquakes.h5"),
114
+ "split": "train",
115
+ },
116
+ ),
117
+ datasets.SplitGenerator(
118
+ name=datasets.Split.VALIDATION,
119
+ # These kwargs will be passed to _generate_examples
120
+ gen_kwargs={
121
+ "filepath": os.path.join(data_dir, "earthquakes.h5"),
122
+ "split": "validation",
123
+ },
124
+ ),
125
+ datasets.SplitGenerator(
126
+ name=datasets.Split.TEST,
127
+ # These kwargs will be passed to _generate_examples
128
+ gen_kwargs={
129
+ "filepath": os.path.join(data_dir, "earthquakes.h5"),
130
+ "split": "test",
131
+ },
132
+ ),
133
+ ]
134
+
135
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
136
+ def _generate_examples(self, filepath, split):
137
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
138
+ sample_ids = []
139
+ with h5py.File(filepath) as f:
140
+ for key, patches in f.items():
141
+ attributes = dict(f[key].attrs)
142
+ if attributes["split"] != split:
143
+ continue
144
+ sample_ids += [(f"{key}/{p}", 1, attributes) for p in patches.keys()]
145
+ sample_ids += [
146
+ (f"{key}/{p}", 0, attributes)
147
+ for p, v in patches.items()
148
+ if "before" in v
149
+ ]
150
+
151
+ for sample_id, label, attributes in sample_ids:
152
+ if "x" in sample_id or "y" in sample_id:
153
+ continue
154
+
155
+ resource_id, patch_id = sample_id.split("/")
156
+ x = f[resource_id]["x"][...]
157
+ y = f[resource_id]["y"][...]
158
+ x_start = int(patch_id.split("_")[1]) % (x.shape[0] // 512)
159
+ y_start = int(patch_id.split("_")[1]) // (x.shape[0] // 512)
160
+ x = x[x_start * 512 : (x_start + 1) * 512]
161
+ y = y[y_start * 512 : (y_start + 1) * 512]
162
+
163
+ pre_key = "pre" if label == 1 else "before"
164
+ post_key = "post" if label == 1 else "pre"
165
+ pre_sample = f[sample_id][pre_key][...]
166
+ post_sample = f[sample_id][post_key][...]
167
+ pre_sample = np.nan_to_num(pre_sample, nan=0).transpose(2, 0, 1)
168
+ post_sample = np.nan_to_num(post_sample, nan=0).transpose(2, 0, 1)
169
+ sample = np.concatenate(
170
+ [pre_sample, post_sample], axis=0, dtype=np.float32
171
+ )
172
+
173
+ yield f"{sample_id}/{post_key}", {
174
+ "pre_post_image": sample,
175
+ "affected": label,
176
+ "magnitude": np.float32(attributes["magnitude"]),
177
+ "hypocenter": attributes["hypocenter"],
178
+ "epsg": attributes["epsg"],
179
+ "x": x.flatten(),
180
+ "y": y.flatten(),
181
+ }