Aaaapril commited on
Commit
e64d915
·
verified ·
1 Parent(s): e68420b

Update PS_Alaska.py

Browse files

Update urls and script

Files changed (1) hide show
  1. PS_Alaska.py +38 -61
PS_Alaska.py CHANGED
@@ -17,26 +17,16 @@
17
  import h5py
18
  import csv
19
  import os
 
20
 
21
  import datasets
22
 
23
- _PSAlaska_DESCRIPTION = """
24
- This dataset combines waveforms and phases from
25
- """
26
- _ManualPick_ai4eps_CITATION = """\
27
- @InProceedings{huggingface:dataset,
28
- title = {A great new dataset},
29
- author={huggingface, Inc.
30
- },
31
- year={2020}
32
- }
33
- """
34
 
35
- _ManualPick_ai4eps_DESCRIPTION = """\
36
- This dataset includes P and S phases recorded by the broadband stations in the Alaska Peninsula
37
- """
38
 
39
- _ManualPick_CITATION = """\
40
  @InProceedings{huggingface:dataset,
41
  title = {A great new dataset},
42
  author={huggingface, Inc.
@@ -46,24 +36,32 @@ year={2020}
46
  """
47
 
48
  _ManualPick_DESCRIPTION = """\
49
- This dataset includes P and S phases recorded by the broadband stations in the Alaska Peninsula
50
  """
51
 
52
- _PNTFIter1_CITATION = """
 
53
  """
54
 
55
  _PNTFIter1_DESCRIPTION = """
56
  This dataset includes P and S phases predicted by the PhaseNet-TF using model trained by the manualpick dataset
57
  """
58
 
59
- _PNTFIter1Combined_CITATION = """
60
- """
61
-
62
  _PNTFIter1Combined_DESCRIPTION = """
63
- This dataset includes all P and S phases from PNTFiter1 dataset and all false negative arrivals of manualpick dataset
64
  """
65
 
66
- _Data_URL = "https://huggingface.co/datasets/Aaaapril/PS_Alaska/resolve/main"
 
 
 
 
 
 
 
 
 
 
67
 
68
 
69
  class PSAlaskaConfig(datasets.BuilderConfig):
@@ -75,7 +73,7 @@ class PSAlaskaConfig(datasets.BuilderConfig):
75
  feature dict. Should not include "label".
76
  data_url: `string`, url to download the zip file from.
77
  citation: `string`, citation for the data set.
78
- url: `string`, url for information about the data set.
79
  label_classes: `list[string]`, the list of classes for the label if the
80
  label is present as a string. Non-string labels will be cast to either
81
  'False' or 'True'.
@@ -98,26 +96,26 @@ class PSAlaskaDataset(datasets.GeneratorBasedBuilder):
98
  PSAlaskaConfig(
99
  name="ManualPick",
100
  description=_ManualPick_DESCRIPTION,
101
- data_url=_Data_URL+"/ManualPick",
102
- citation=_ManualPick_CITATION,
103
  ),
104
  PSAlaskaConfig(
105
  name="ManualPick_ai4eps",
106
  description=_ManualPick_ai4eps_DESCRIPTION,
107
- data_url=_Data_URL+"/ManualPick_ai4eps",
108
- citation=_ManualPick_ai4eps_CITATION,
109
  ),
110
  PSAlaskaConfig(
111
  name="PNTFIter1",
112
  description=_PNTFIter1_DESCRIPTION,
113
- data_url=_Data_URL+"/PNTFIter1",
114
- citation=_PNTFIter1_CITATION,
115
  ),
116
  PSAlaskaConfig(
117
  name="PNTFIter1_combined",
118
  description=_PNTFIter1Combined_DESCRIPTION,
119
- data_url=_Data_URL+"/PNTFIter1_combined",
120
- citation=_PNTFIter1Combined_CITATION,
121
  ),
122
  ]
123
 
@@ -127,7 +125,7 @@ class PSAlaskaDataset(datasets.GeneratorBasedBuilder):
127
  def _info(self):
128
 
129
  return datasets.DatasetInfo(
130
- description=_PSAlaska_DESCRIPTION + self.config.description,
131
  features=datasets.Features(
132
  {
133
  "begin_time": datasets.Value("string"),
@@ -152,44 +150,23 @@ class PSAlaskaDataset(datasets.GeneratorBasedBuilder):
152
 
153
  urls = self.config.data_url
154
  data_dir = dl_manager.download_and_extract(urls)
155
- stationf = dl_manager.download_and_extract(_Data_URL + '/stations.csv')
156
- stationl = []
157
- eventl = []
158
- waveform_files = {}
159
- with open(stationf, newline='') as csvfile:
160
- r = csv.reader(csvfile, delimiter=',')
161
- next(r)
162
- for row in r:
163
- stationl.append(row[-1])
164
-
165
- with open(os.path.join(data_dir, 'catalogs.csv'), newline='') as csvfile:
166
- r = csv.reader(csvfile, delimiter=',')
167
- next(r)
168
- for row in r:
169
- eventl.append(row[3])
170
-
171
- for e in eventl:
172
- waveform_files[e] = os.path.join(data_dir, 'waveform', f'{e}.h5')
173
 
174
  return [
175
  datasets.SplitGenerator(
176
  name="full",
177
  gen_kwargs={
178
- "stations": stationl,
179
- "events": eventl,
180
- "waveform_files": waveform_files
181
  },
182
  ),
183
  ]
184
 
185
 
186
- def _generate_examples(self, stations, events, waveform_files):
187
-
188
- for e in events:
189
- f = h5py.File(waveform_files[e], 'r')
190
- for sta in f[e].keys():
191
  key = f'{e}_{sta}'
192
- meta = f[e][sta].attrs
193
  yield key, {
194
  "begin_time": meta['begin_time'],
195
  "end_time": meta['end_time'],
@@ -201,6 +178,6 @@ class PSAlaskaDataset(datasets.GeneratorBasedBuilder):
201
  "phase_index": meta['phase_index'],
202
  "phase_time": meta['phase_time'],
203
  "phase_type": meta['phase_type'],
204
- "waveform": f[e][sta]
205
  }
206
- f.close()
 
17
  import h5py
18
  import csv
19
  import os
20
+ import logging
21
 
22
  import datasets
23
 
24
+ # Set up logging for debugging download issues
25
+ logging.basicConfig(level=logging.INFO)
26
+ logger = logging.getLogger(__name__)
 
 
 
 
 
 
 
 
27
 
 
 
 
28
 
29
+ _CITATION = """\
30
  @InProceedings{huggingface:dataset,
31
  title = {A great new dataset},
32
  author={huggingface, Inc.
 
36
  """
37
 
38
  _ManualPick_DESCRIPTION = """\
39
+ This dataset includes P and S phases from AACSE catalog recorded by the broadband stations in the Alaska Peninsula
40
  """
41
 
42
+ _ManualPick_ai4eps_DESCRIPTION = """\
43
+ This dataset includes P and S phases from AACSE catalog recorded by the broadband stations in the Alaska Peninsula in ai4eps format
44
  """
45
 
46
  _PNTFIter1_DESCRIPTION = """
47
  This dataset includes P and S phases predicted by the PhaseNet-TF using model trained by the manualpick dataset
48
  """
49
 
 
 
 
50
  _PNTFIter1Combined_DESCRIPTION = """
51
+ This dataset includes all P and S phases from PNTFiter1 dataset and all false negative arrivals of ManualPick dataset
52
  """
53
 
54
+ _Base_URL = "https://huggingface.co/datasets/Aaaapril/PS_Alaska/resolve/main"
55
+ def get_data_url(dataset, n):
56
+ return {
57
+ "catalogs": f"{_Base_URL}/{dataset}/catalogs.csv",
58
+ "phases": f"{_Base_URL}/{dataset}/phase_picks.csv",
59
+ "waveform": f"{_Base_URL}/{dataset}/waveform.h5",
60
+ "stations": f"{_Base_URL}/stations.json",
61
+ "waveforms": [
62
+ f"{_Base_URL}/{dataset}/waveform/{x:05d}-of-{n:05d}.zip" for x in range(n)
63
+ ]
64
+ }
65
 
66
 
67
  class PSAlaskaConfig(datasets.BuilderConfig):
 
73
  feature dict. Should not include "label".
74
  data_url: `string`, url to download the zip file from.
75
  citation: `string`, citation for the data set.
76
+ data_url: `string`, url for information about the data set.
77
  label_classes: `list[string]`, the list of classes for the label if the
78
  label is present as a string. Non-string labels will be cast to either
79
  'False' or 'True'.
 
96
  PSAlaskaConfig(
97
  name="ManualPick",
98
  description=_ManualPick_DESCRIPTION,
99
+ data_url=get_data_url("ManualPick", 4),
100
+ citation=_CITATION,
101
  ),
102
  PSAlaskaConfig(
103
  name="ManualPick_ai4eps",
104
  description=_ManualPick_ai4eps_DESCRIPTION,
105
+ data_url=get_data_url("ManualPick_ai4eps", 4),
106
+ citation=_CITATION,
107
  ),
108
  PSAlaskaConfig(
109
  name="PNTFIter1",
110
  description=_PNTFIter1_DESCRIPTION,
111
+ data_url=get_data_url("PNTFIter1", 19),
112
+ citation=_CITATION,
113
  ),
114
  PSAlaskaConfig(
115
  name="PNTFIter1_combined",
116
  description=_PNTFIter1Combined_DESCRIPTION,
117
+ data_url=get_data_url("PNTFIter1_combined", 20),
118
+ citation=_CITATION,
119
  ),
120
  ]
121
 
 
125
  def _info(self):
126
 
127
  return datasets.DatasetInfo(
128
+ description=self.config.description,
129
  features=datasets.Features(
130
  {
131
  "begin_time": datasets.Value("string"),
 
150
 
151
  urls = self.config.data_url
152
  data_dir = dl_manager.download_and_extract(urls)
153
+ handler = h5py.File(data_dir['waveform'], 'r')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  return [
156
  datasets.SplitGenerator(
157
  name="full",
158
  gen_kwargs={
159
+ "handler": handler
 
 
160
  },
161
  ),
162
  ]
163
 
164
 
165
+ def _generate_examples(self, handler):
166
+ for e in handler.keys():
167
+ for sta in handler[e].keys():
 
 
168
  key = f'{e}_{sta}'
169
+ meta = handler[e][sta].attrs
170
  yield key, {
171
  "begin_time": meta['begin_time'],
172
  "end_time": meta['end_time'],
 
178
  "phase_index": meta['phase_index'],
179
  "phase_time": meta['phase_time'],
180
  "phase_type": meta['phase_type'],
181
+ "waveform": handler[e][sta]
182
  }
183
+ handler.close()