geofwi 0.0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
geofwi-0.0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 aaspip
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.1
2
+ Name: geofwi
3
+ Version: 0.0.0.1
4
+ Summary: GeoFWI: A lightweight velocity model dataset for benchmarking full waveform inversion using deep learning
5
+ Home-page: https://github.com/aaspip/geofwi
6
+ Author: geofwi developing team
7
+ Author-email: chenyk2016@gmail.com
8
+ License: MIT License
9
+ Keywords: seismology,seismic imaging,computational seismology,AI for science
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: Unix
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Scientific/Engineering :: Physics
21
+ Classifier: License :: OSI Approved :: MIT License
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy
24
+ Requires-Dist: scipy
25
+ Requires-Dist: matplotlib
26
+ Provides-Extra: docs
27
+ Requires-Dist: sphinx; extra == "docs"
28
+ Requires-Dist: ipython; extra == "docs"
29
+ Requires-Dist: runipy; extra == "docs"
30
+
31
+ Source code: https://github.com/aaspip/geofwi
@@ -0,0 +1,269 @@
1
+ # GeoFWI
2
+
3
+ ## Description
4
+
5
+ **GeoFWI** is a lightweight velocity model dataset for deep-learning-based FWI benchmarking. This project is inspired by the OpenFWI project (https://sites.google.com/site/youzuolin044/openfwi) but includes more realistic geological models (e.g., folding layers, faults, and salt bodies).
6
+
7
+ Currently, we call it lightweight because this is the first step toward an eventually "heavyweight," very realistic, highly generalizable 3D velocity model dataset for unprecedented high-efficacy deep-learning-empowered FWI studies.
8
+
9
+ -----------
10
+ ## Download GeoFWI.npy from
11
+ https://utexas.box.com/s/scbh25utyy5jz3mq7b0hp3wyluka7gaq
12
+
13
+ ## Reference
14
+ Li et al., 2025, GeoFWI: A lightweight velocity model dataset for benchmarking full waveform inversion using deep learning - upcoming, TBD.
15
+
16
+ BibTeX:
17
+
18
+ @Article{geofwi,
19
+ author={Chao Li and Liuqing Yang and Sergey Fomel and Andrey Bakulin and Yiran Shen and Shuang Gao and Umair Bin Waheed and Alexandros Savvaidis and Yangkang Chen},
20
+ title = {GeoFWI: A lightweight velocity model dataset for benchmarking full waveform inversion using deep learning},
21
+ journal={TBD},
22
+ year=2025,
23
+ volume=TBD,
24
+ number=TBD,
25
+ issue=TBD,
26
+ pages={TBD},
27
+ doi={TBD},
28
+ }
29
+
30
+ -----------
31
+ ## Copyright
32
+ GEOFWI developing team, 2024-present
33
+
34
+ -----------
35
+ ## License
36
+ MIT License
37
+
38
+ -----------
39
+ ## Install
40
+ Using the latest version
41
+
42
+ git clone https://github.com/aaspip/geofwi
43
+ cd geofwi
44
+ pip install -v -e .
45
+
46
+ or using Pypi
47
+
48
+ pip install geofwi
49
+
50
+ or (recommended, because we update very fast)
51
+
52
+ pip install git+https://github.com/aaspip/geofwi
53
+
54
+ -----------
55
+ ## Verified runnable OS
56
+ Mac OS, Linux, Windows (need Microsoft C++ Build Tools)
57
+
58
+ -----------
59
+ ## Examples
60
+
61
+ Here is a sneak peek of some of the structures and initial results of the GeoFWI project.
62
+
63
+ <p align="center">
64
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/geofwi-seisinvnet.png' alt='comp' width=960/>
65
+ </p>
66
+
67
+ Figure below shows a few good/bad predictions using the data-driven DL-based method (SeisInvNet) detailed in Li et al., 2020, Deep learning Inversion of Seismic Data, IEEE TGRS.
68
+
69
+ <p align="center">
70
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/geofwi-types.png' alt='comp' width=960/>
71
+ </p>
72
+
73
+ -----------
74
+ ## Play with GeoFWI
75
+
76
+ Read the GeoFWI data and check its dimension
77
+
78
+ import numpy as np
79
+ sizes=np.load("data/geofwi-size-layer-fault-salt-1-10.npy")
80
+ GeoFWI_path='data/geofwi.npy' #suppose you put geofwi.npy in "./data/" directory
81
+ geofwi=np.load(GeoFWI_path)
82
+ print('geofwi.shape',geofwi.shape)
83
+ print('NO of samples in GeoFWI is ',geofwi.shape[0])
84
+ print('Each sample has a dimension of %d * %d '%(geofwi.shape[1],geofwi.shape[2]))
85
+
86
+ *The output will be like*
87
+
88
+ > geofwi.shape (49476, 100, 100)
89
+
90
+ > NO of samples in GeoFWI is 49476
91
+
92
+ > Each sample has a dimension of 100 * 100
93
+
94
+ Get some statistics from GeoFWI
95
+
96
+ import numpy as np
97
+ sizes=np.load("data/geofwi-size-layer-fault-salt-1-10.npy")
98
+ print('length of sizes:',len(sizes))
99
+
100
+ print('Two-layer folding model: %d samples'%sizes[0])
101
+ print('Two-layer fault model: %d samples'%sizes[1])
102
+ print('Two-layer salt model: %d samples'%sizes[2])
103
+ print('Three-layer folding model: %d samples'%sizes[3])
104
+ print('Three-layer fault model: %d samples'%sizes[4])
105
+ print('Three-layer salt model: %d samples'%sizes[5])
106
+ print('Four-layer folding model: %d samples'%sizes[6])
107
+ print('Four-layer fault model: %d samples'%sizes[7])
108
+ print('Four-layer salt model: %d samples'%sizes[8])
109
+ print('Five-layer folding model: %d samples'%sizes[9])
110
+ print('Five-layer fault model: %d samples'%sizes[10])
111
+ print('Five-layer salt model: %d samples'%sizes[11])
112
+ print('Six-layer folding model: %d samples'%sizes[12])
113
+ print('Six-layer fault model: %d samples'%sizes[13])
114
+ print('Six-layer salt model: %d samples'%sizes[14])
115
+ print('Seven-layer folding model: %d samples'%sizes[15])
116
+ print('Seven-layer fault model: %d samples'%sizes[16])
117
+ print('Seven-layer salt model: %d samples'%sizes[17])
118
+ print('Eight-layer folding model: %d samples'%sizes[18])
119
+ print('Eight-layer fault model: %d samples'%sizes[19])
120
+ print('Eight-layer salt model: %d samples'%sizes[20])
121
+ print('Nine-layer folding model: %d samples'%sizes[21])
122
+ print('Nine-layer fault model: %d samples'%sizes[22])
123
+ print('Nine-layer salt model: %d samples'%sizes[23])
124
+ print('Ten-layer folding model: %d samples'%sizes[24])
125
+ print('Ten-layer fault model: %d samples'%sizes[25])
126
+ print('Ten-layer salt model: %d samples'%sizes[26])
127
+ print('Eleven-layer folding model: %d samples'%sizes[27])
128
+ print('Eleven-layer fault model: %d samples'%sizes[28])
129
+ print('Eleven-layer salt model: %d samples'%sizes[29])
130
+
131
+ *The output will be like*
132
+
133
+ > Two-layer folding model: 2826 samples
134
+
135
+ > Two-layer fault model: 2754 samples
136
+
137
+ > Two-layer salt model: 1888 samples
138
+
139
+ > Three-layer folding model: 2649 samples
140
+
141
+ > Three-layer fault model: 2473 samples
142
+
143
+ > Three-layer salt model: 1758 samples
144
+
145
+ > Four-layer folding model: 2491 samples
146
+
147
+ > Four-layer fault model: 2161 samples
148
+
149
+ > Four-layer salt model: 1674 samples
150
+
151
+ > Five-layer folding model: 2245 samples
152
+
153
+ > Five-layer fault model: 1948 samples
154
+
155
+ > Five-layer salt model: 1508 samples
156
+
157
+ > Six-layer folding model: 1974 samples
158
+
159
+ > Six-layer fault model: 1653 samples
160
+
161
+ > Six-layer salt model: 1340 samples
162
+
163
+ > Seven-layer folding model: 1797 samples
164
+
165
+ > Seven-layer fault model: 1478 samples
166
+
167
+ > Seven-layer salt model: 1226 samples
168
+
169
+ > Eight-layer folding model: 1635 samples
170
+
171
+ > Eight-layer fault model: 1325 samples
172
+
173
+ > Eight-layer salt model: 1076 samples
174
+
175
+ > Nine-layer folding model: 1453 samples
176
+
177
+ > Nine-layer fault model: 1117 samples
178
+
179
+ > Nine-layer salt model: 976 samples
180
+
181
+ > Ten-layer folding model: 1309 samples
182
+
183
+ > Ten-layer fault model: 1000 samples
184
+
185
+ > Ten-layer salt model: 881 samples
186
+
187
+ > Eleven-layer folding model: 1200 samples
188
+
189
+ > Eleven-layer fault model: 829 samples
190
+
191
+ > Eleven-layer salt model: 832 samples
192
+
193
+
194
+ Extract a few five-layer fault models from GeoFWI
195
+
196
+ import numpy as np
197
+ sizes=np.load("data/geofwi-size-layer-fault-salt-1-10.npy")
198
+ GeoFWI_path='data/geofwi.npy' #suppose you put geofwi.npy in "./data/" directory
199
+ geofwi=np.load(GeoFWI_path)
200
+
201
+ #first index for five-layer fault models,
202
+ ind=sum(sizes[0:10])+1 #refer to last example for checking the index for each type of model
203
+
204
+ no=8 #make it 4,8,16
205
+ import matplotlib.pyplot as plt
206
+ fig=plt.figure(figsize=(16, 8))
207
+ for ii in range(no):
208
+ plt.subplot(2,int(no/2),ii+1)
209
+ plt.imshow(geofwi[ind+ii,:,:],clim=[1500,4000]);
210
+ plt.colorbar(orientation='horizontal',cax=fig.add_axes([0.37,0.07,0.3,0.01]),shrink=1,label='Velocity (m/s)');
211
+ plt.show()
212
+
213
+ *The output will be like*
214
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/hands-example-5layer-fault.png' alt='comp' width=960/>
215
+
216
+ Extract a few five-layer salt models from GeoFWI
217
+
218
+ import numpy as np
219
+ sizes=np.load("data/geofwi-size-layer-fault-salt-1-10.npy")
220
+ GeoFWI_path='data/geofwi.npy' #suppose you put geofwi.npy in "./data/" directory
221
+ geofwi=np.load(GeoFWI_path)
222
+
223
+ #first index for five-layer salt models,
224
+ ind=sum(sizes[0:11])+1 #refer to last example for checking the index for each type of model
225
+
226
+ no=8 #make it 4,8,16
227
+ import matplotlib.pyplot as plt
228
+ fig=plt.figure(figsize=(16, 8))
229
+ for ii in range(no):
230
+ plt.subplot(2,int(no/2),ii+1)
231
+ plt.imshow(geofwi[ind+ii,:,:],clim=[1500,4000]);
232
+ plt.colorbar(orientation='horizontal',cax=fig.add_axes([0.37,0.07,0.3,0.01]),shrink=1,label='Velocity (m/s)');
233
+ plt.show()
234
+
235
+ *The output will be like*
236
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/hands-example-5layer-salt.png' alt='comp' width=960/>
237
+
238
+ -----------
239
+ ## Development
240
+ The development team welcomes voluntary contributions from any open-source enthusiast.
241
+ If you want to make contribution to this project, feel free to contact the development team.
242
+
243
+ -----------
244
+ ## Contact
245
+ Regarding any questions, bugs, developments, collaborations, please contact
246
+ Yangkang Chen
247
+ chenyk2016@gmail.com
248
+
249
+
250
+ -----------
251
+ ## Gallery
252
+ The gallery figures of the geofwi project can be found at
253
+ https://github.com/aaspip/gallery/tree/main/geofwi
254
+ All figures in the gallery directory can be reproduced by their corresponding DEMO scripts in the "demo" directory. These gallery figures are also presented below.
255
+
256
+ # Below is an example for quickly visualizing a few samples from GeoFWI.npy in different scenarios
257
+ Generated by [demos/test_quick_visualize.py](https://github.com/aaspip/geofwi/tree/main/demos/test_quick_visualize.py)
258
+
259
+ First scenario: randomly chosen 25 samples from the whole GeoFWI dataset
260
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/geofwi-samples-random.png' alt='comp' width=960/>
261
+
262
+ Second scenario: the first 25 samples from the whole GeoFWI dataset
263
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/geofwi-samples-increasing.png' alt='comp' width=960/>
264
+
265
+ Third scenario: the last 25 samples from the whole GeoFWI dataset
266
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/geofwi-samples-increasing.png' alt='comp' width=960/>
267
+
268
+ Fourth scenario: the last 25 samples in the "11-layer fault category" (e.g., sizes=np.load('data/geofwi-size-layer-fault-salt-1-10.npy'); index is chosen from 49476-sizes[-1]-1 to sizes[-1]-25) from the whole GeoFWI dataset
269
+ <img src='https://github.com/aaspip/gallery/blob/main/geofwi/geofwi-samples-faults.png' alt='comp' width=960/>
File without changes
@@ -0,0 +1,54 @@
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ import os
4
+
5
+ ## Define GeoFWI datapath
6
+ GeoFWI_path=os.getenv('HOME')+'/DATALIB/GeoFWI/geofwi.npy' #define your own path
7
+ #GeoFWI_path = './geofwi.npy' #for example
8
+
9
+ sizes=np.load('../data/geofwi-size-layer-fault-salt-1-10.npy') #if you run this script in demos/
10
+
11
+ geofwi=np.load(GeoFWI_path)
12
+ nsample=geofwi.shape[0]
13
+
14
+ np.random.seed(20232425)
15
+ inds=np.arange(49500)
16
+ np.random.shuffle(inds)
17
+
18
+ fig=plt.figure(figsize=(16, 16))
19
+ for ii in range(25):
20
+ plt.subplot(5,5,ii+1)
21
+ plt.imshow(geofwi[inds[ii],:,:],clim=[1500,4000]);
22
+ plt.colorbar(orientation='horizontal',cax=fig.add_axes([0.37,0.07,0.3,0.01]),shrink=1,label='Velocity (m/s)');
23
+ plt.savefig('geofwi-samples-random.png',dpi=300)
24
+ plt.show()
25
+
26
+ fig=plt.figure(figsize=(16, 16))
27
+ for ii in range(25):
28
+ plt.subplot(5,5,ii+1)
29
+ plt.imshow(geofwi[ii,:,:],clim=[1500,4000]);
30
+ plt.colorbar(orientation='horizontal',cax=fig.add_axes([0.37,0.07,0.3,0.01]),shrink=1,label='Velocity (m/s)');
31
+ plt.savefig('geofwi-samples-increasing.png',dpi=300)
32
+ plt.show()
33
+
34
+
35
+
36
+ fig=plt.figure(figsize=(16, 16))
37
+ for ii in range(25):
38
+ plt.subplot(5,5,ii+1)
39
+ plt.imshow(geofwi[nsample-ii-1,:,:],clim=[1500,4000]);
40
+ plt.colorbar(orientation='horizontal',cax=fig.add_axes([0.37,0.07,0.3,0.01]),shrink=1,label='Velocity (m/s)');
41
+ plt.savefig('geofwi-samples-decreasing.png',dpi=300)
42
+ plt.show()
43
+
44
+
45
+ fig=plt.figure(figsize=(16, 16))
46
+ for ii in range(25):
47
+ plt.subplot(5,5,ii+1)
48
+ plt.imshow(geofwi[nsample-sizes[-1]-1-ii,:,:],clim=[1500,4000]);
49
+ plt.colorbar(orientation='horizontal',cax=fig.add_axes([0.37,0.07,0.3,0.01]),shrink=1,label='Velocity (m/s)');
50
+ plt.savefig('geofwi-samples-faults.png',dpi=300)
51
+
52
+ plt.show()
53
+
54
+
@@ -0,0 +1,3 @@
1
+ from .plot import *
2
+ from .utils import *
3
+ from .acc import *
@@ -0,0 +1,145 @@
1
+ # import os
2
+
3
+ def acc_occurence(yesno,geofwipath='./'):
4
+ '''
5
+ acc_occurence: calculate occurence accuracy
6
+
7
+ EXAMPLE
8
+
9
+ from pylib.io import asciiread
10
+
11
+ yesnoall=asciiread('yesnoall_cyk_new.txt');
12
+ yesnoall=[float(ii) for ii in yesnoall]
13
+
14
+ locall=asciiread('locall_cyk_new.txt')
15
+ magall=asciiread('magall_cyk_new.txt')
16
+
17
+ from geofwi import acc_occurence
18
+ import os
19
+ geofwipath=os.getenv('HOME')+"/DATALIB/geofwi.h5"
20
+ pre,rec,acc,f1=acc_occurence(yesnoall,geofwipath)
21
+
22
+ '''
23
+
24
+ #one way to get label
25
+ # import h5py
26
+ # aetalab=[]
27
+ # f = h5py.File(geofwipath, 'r')
28
+ # for WKNO in range(1,31,1):
29
+ # idx='WK_%02d'%(WKNO)
30
+ # g=f.get(idx)
31
+ #
32
+ # if g.get('Label_EV').attrs['yesno'] == 'yes':
33
+ # aetalab.append(1)
34
+ # else:
35
+ # aetalab.append(0)
36
+
37
+ #an easier way to get label
38
+ from geofwi import get_testlabel
39
+ aetalab=get_testlabel(geofwipath,mode='occurence')
40
+
41
+ print('aetalab size is',len(aetalab))
42
+ print('yesno size is',len(yesno))
43
+
44
+ from sklearn.metrics import f1_score, precision_score, recall_score, accuracy_score
45
+
46
+ accuracy=accuracy_score(aetalab,yesno)
47
+ f1=f1_score(aetalab,yesno)
48
+ precision=precision_score(aetalab,yesno)
49
+ recall=recall_score(aetalab,yesno)
50
+
51
+ print("Precision=",precision)
52
+ print("Recall=",recall)
53
+ print("Accuracy=",accuracy)
54
+ print("F1-score=",f1)
55
+
56
+ return precision,recall,accuracy,f1
57
+
58
+
59
+ def acc_mag(mags,geofwipath='./'):
60
+ '''
61
+ acc_mag: calculate magnitude accuracy
62
+
63
+ EXAMPLE
64
+
65
+ from pylib.io import asciiread
66
+ import numpy as np
67
+
68
+ yesnoall=asciiread('yesnoall_cyk_new.txt');
69
+ yesnoall=[float(ii) for ii in yesnoall]
70
+
71
+ locall=asciiread('locall_cyk_new.txt')
72
+ magall=asciiread('magall_cyk_new.txt')
73
+ magall=[float(ii.split(" ")[0].split("]")[0].split("[")[-1]) for ii in magall] #choose the first one
74
+
75
+ from geofwi import acc_mag
76
+ import os
77
+ geofwipath=os.getenv('HOME')+"/DATALIB/geofwi.h5"
78
+ mae=acc_mag(magall,geofwipath)
79
+
80
+ '''
81
+ import numpy as np
82
+ from geofwi import get_testlabel
83
+ aetalab=get_testlabel(geofwipath,mode='occurence')
84
+ aetalabmag=get_testlabel(geofwipath,mode='magnitude')
85
+
86
+ print('aetalab size is',len(aetalab))
87
+
88
+ ssum=[]
89
+ for ii in range(len(aetalab)):
90
+ if mags[ii]>0 and aetalab[ii]==1:
91
+ print(mags[ii],aetalabmag[ii])
92
+ ssum.append(np.abs(mags[ii]-aetalabmag[ii]))
93
+ MAE=np.mean(ssum)
94
+
95
+ print('MAE of magnitude=',MAE)
96
+
97
+ return MAE
98
+
99
+
100
+ def acc_loc(locs,geofwipath='./'):
101
+ '''
102
+ acc_loc: calculate location accuracy
103
+
104
+ EXAMPLE
105
+
106
+ from pylib.io import asciiread
107
+ import numpy as np
108
+
109
+ yesnoall=asciiread('yesnoall_cyk_new.txt');
110
+ yesnoall=[float(ii) for ii in yesnoall]
111
+
112
+ locall=asciiread('locall_cyk_new.txt')
113
+ locall=[ii.split("]")[0].split("[")[-1] for ii in locall]
114
+
115
+ magall=asciiread('magall_cyk_new.txt')
116
+ magall=[float(ii.split(" ")[0].split("]")[0].split("[")[-1]) for ii in magall] #choose the first one
117
+
118
+ from geofwi import acc_loc
119
+ import os
120
+ geofwipath=os.getenv('HOME')+"/DATALIB/geofwi.h5"
121
+ mde=acc_loc(locall,geofwipath)
122
+
123
+ '''
124
+ import numpy as np
125
+ from geofwi import get_testlabel
126
+ aetalab=get_testlabel(geofwipath,mode='occurence')
127
+ aetalabmag=get_testlabel(geofwipath,mode='magnitude')
128
+ aetalabloc=get_testlabel(geofwipath,mode='location')
129
+
130
+ print('aetalab size is',len(aetalab))
131
+
132
+ ssum=[]
133
+ for ii in range(len(aetalab)):
134
+ if locs[ii]!='0' and aetalab[ii]==1:
135
+ print(locs[ii],aetalabloc[ii])
136
+ loc=locs[ii].split()
137
+ loc=[float(ii) for ii in loc]
138
+ ssum.append(np.hypot(loc[0]-aetalabloc[ii][0],loc[1]-aetalabloc[ii][1])*111.0)
139
+ MDE=np.mean(ssum)
140
+
141
+ print('MDE of location=',MDE)
142
+
143
+ return MDE
144
+
145
+
@@ -0,0 +1,127 @@
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+
4
+ def plot_traces(st,axoff=1,ayoff=1,titleoff=1,picks=None,eid=None,mag=None,ifmap=0,staloc=None,evloc=None,staname=None,ptime=None,stime=None,figname=None,showf=True,**kwargs):
5
+ """
6
+ plot_traces: plot all traces in a stream quickly side-by-side from top to bottom
7
+
8
+ INPUT
9
+ st: Stream
10
+ axoff: axes X off
11
+ ayoff: axes Y off
12
+ title: title off
13
+ picks: P/S picks object
14
+ in this subroutine, picks is a list of two-entries Dict
15
+ initialized by {'P':None,'S':None}
16
+ (compared with obspy pick object obspy.core.event.origin.Pick)
17
+ showf: if show figure interatively
18
+
19
+ EXAMPLES
20
+ from geofwi import plot_traces
21
+ plot_traces(st);
22
+
23
+ from geofwi import plot_traces
24
+ plot_traces(st,axoff=0,ayoff=0,titleoff=0);
25
+
26
+ from geofwi plot_traces;
27
+ plot_traces(obspy.read("newwaveforms/texnet2022ugad.mseed")[0:10]);
28
+
29
+ demos/test_event.py
30
+ """
31
+ ntr=len(st)
32
+ if ifmap == 0:
33
+ fig = plt.figure(figsize=(6, 8))
34
+ else:
35
+ fig = plt.figure(figsize=(12, 8))
36
+
37
+ for ii in range(ntr):
38
+ if ifmap==0:
39
+ ax = plt.subplot(ntr,1,ii+1)
40
+ else:
41
+ ax = plt.subplot(ntr,2,2*ii+1)
42
+ nt=len(st[ii].data);
43
+ twin=(nt-1)*1.0/st[ii].stats.sampling_rate;
44
+ # print('twin=',twin,'nt=',nt,'dt',1.0/st[ii].stats.sampling_rate)
45
+ # staname=st[ii].stats.network+'.'+st[ii].stats.station
46
+ t=np.linspace(0,twin,nt)
47
+ plt.plot(t,st[ii].data,color='k',label = st[ii].stats.station, linewidth = 1, markersize=1)
48
+
49
+ if ii==0 and titleoff != 1:
50
+ if eid is None and mag is None:
51
+ plt.title(st[ii].stats.starttime,fontsize='large', fontweight='normal')
52
+ else:
53
+ plt.title(eid+' (M=%.3g)'%(mag)+' '+str(st[ii].stats.starttime),fontsize=10, fontweight='normal')
54
+
55
+ ax.legend(loc='lower right', fontsize = 10/(ntr/4))
56
+ if ii==ntr-1:
57
+ if axoff == 1:
58
+ plt.setp(ax.get_xticklabels(), visible=False)
59
+ else:
60
+ plt.setp(ax.get_xticklabels(), visible=True)
61
+ ax.set_xlabel("Time (s)",fontsize='large', fontweight='normal')
62
+ else:
63
+ plt.setp(ax.get_xticklabels(), visible=False)
64
+ ax.set_xlim(xmin=0)
65
+ ax.set_xlim(xmax=t[-1])
66
+ ymin, ymax = ax.get_ylim()
67
+
68
+ if ayoff:
69
+ plt.setp(ax.get_yticklabels(), visible=False)
70
+
71
+ if picks is not None:
72
+ if picks[ii]['P'] is not None:
73
+ tp=picks[ii]['P']-st[ii].stats.starttime
74
+ plt.vlines(tp, ymin, ymax, color = 'r', linewidth = 1) #for P
75
+
76
+ if picks[ii]['S'] is not None:
77
+ ts=picks[ii]['S']-st[ii].stats.starttime
78
+ plt.vlines(ts, ymin, ymax, color = 'g', linewidth = 1) #for S
79
+ # plt.text(2.5,(ymin+ymax)/2,staname)
80
+
81
+ if ptime is not None:
82
+ tp=ptime[ii]-st[ii].stats.starttime
83
+ plt.vlines(tp, ymin, ymax, color = 'r', linewidth = 1) #for P
84
+
85
+ if stime is not None:
86
+ ts=stime[ii]-st[ii].stats.starttime
87
+ plt.vlines(ts, ymin, ymax, color = 'g', linewidth = 1) #for P
88
+
89
+ if ifmap==1:
90
+ ax = plt.subplot(2,2,2)
91
+ plt.plot(staloc[:,0],staloc[:,1],'v',color='b')
92
+ plt.plot(evloc[0],evloc[1],'*',color='r')
93
+ addcounty_tx();
94
+
95
+ plt.ylabel('Latitude (deg)')
96
+ plt.gca().set_xlim(evloc[0]-3,evloc[0]+3)
97
+ plt.gca().set_ylim(evloc[1]-3,evloc[1]+3)
98
+ [x1,x2]=plt.gca().get_xlim()
99
+
100
+ if len(staname) == staloc.shape[0]:
101
+ for ii in range(len(staname)):
102
+ plt.text(staloc[ii,0],staloc[ii,1],staname[ii][:],color='k',fontsize=6)
103
+
104
+ ax = plt.subplot(2,2,4)
105
+ plt.plot(evloc[0],evloc[2],'*',color='r',label='TexNet event')
106
+
107
+ plt.gca().set_ylim(-2, 25);plt.gca().set_xlim(x1, x2)
108
+ plt.gca().invert_yaxis()
109
+ plt.xlabel('Longitude (deg)');plt.ylabel('Depth (km)')
110
+
111
+ plt.plot(staloc[:,0],-staloc[:,2]/1000.0,'v',color='b',label='Station')
112
+ plt.plot(0, 0, color = 'k', linestyle='solid', linewidth = 1, label="Waveform") #for S
113
+
114
+ ## add picks legend
115
+ plt.vlines(0, 100, 120, color = 'r', linestyle='solid', linewidth = 1, label="TexNet P") #for P
116
+ plt.vlines(0, 100, 120, color = 'g', linestyle='solid', linewidth = 1, label="TexNet S") #for S
117
+
118
+ ax.legend(loc='lower right', fontsize = 8)
119
+
120
+
121
+ if figname is not None:
122
+ plt.savefig(figname,**kwargs)
123
+
124
+ if showf:
125
+ plt.show()
126
+ else:
127
+ plt.close() #or plt.clear() ?
@@ -0,0 +1,572 @@
1
+ import numpy as np
2
+ def shift3c(data,tshift):
3
+ '''
4
+ shift3c: shift a 3C numpy array according to the tshift (scalar)
5
+
6
+ INPUT
7
+ data: nsample x 3 array
8
+ tshift: shift in samples (>0 -> right shift; <0 -> left shift)
9
+
10
+ OUTPUT
11
+ data2: shifted array
12
+ '''
13
+
14
+ # return np.roll(data, tshift, axis=0) #not best
15
+ data2=np.zeros(data.shape)
16
+ if tshift>0:
17
+ data2[tshift:,:] = data[0:-tshift,:]
18
+ else:
19
+ data2[0:tshift,:]=data[-tshift:,:]
20
+
21
+ return data2
22
+
23
+ def asciiread(fname):
24
+ '''
25
+ fname: file name
26
+ din: a list of lines
27
+ withnewline: if with the newline symbol '\n': True: with; False: without
28
+
29
+ EXAMPLE
30
+
31
+ from geofwi import asciiread
32
+ import os
33
+
34
+ lines=asciiread(os.getenv('HOME')+'/chenyk.data2/various/cyksmall/texnet_stations_2022_1019.csv');
35
+ '''
36
+
37
+ f=open(fname,'r')
38
+ lines=f.readlines()
39
+ lines=[ii.strip() for ii in lines]
40
+
41
+ return lines
42
+
43
+ def asciiwrite(fname,din,withnewline=False):
44
+ '''
45
+ fname: file name
46
+ din: a list of lines
47
+ withnewline: if with the newline symbol '\n': True: with; False: without
48
+
49
+ EXAMPLE
50
+
51
+ from geofwi import asciiwrite
52
+ import os
53
+
54
+ f=open(os.getenv('HOME')+'/chenyk.data2/various/cyksmall/texnet_stations_2022_1019.csv')
55
+ lines=f.readlines();
56
+
57
+ asciiwrite('stations.txt',lines,withnewline=True);
58
+ '''
59
+
60
+ f=open(fname,'w')
61
+ if withnewline:
62
+ for ii in range(len(din)):
63
+ f.write(str(din[ii]))
64
+ else:
65
+ for ii in range(len(din)):
66
+ f.write(str(din[ii])+"\n")
67
+
68
+ def get_week():
69
+ '''
70
+ get_week: get week interval
71
+
72
+ three columns in each list entry are weekNO,starting time (local),ending time (local)
73
+
74
+ EXAMPLE
75
+ from geofwi import get_week
76
+ import os
77
+ weeks=get_week()
78
+
79
+ '''
80
+ from obspy.core.utcdatetime import UTCDateTime
81
+ import h5py
82
+ import numpy as np
83
+
84
+ ##########################################################################################
85
+ contime= 8 * 60 *60
86
+ t0 = UTCDateTime(1483200000+contime) #begin time: 2017-01-01T00:00:00.000000Z
87
+ tend = UTCDateTime(1606751400+contime) #end time: 2020-11-30T23:50:00.000000Z
88
+ print('Starting and Ending time of testing data are', t0, tend)
89
+
90
+ v = int(tend-t0)/(7*24*60*60) #number of weeks
91
+ tweek=[]
92
+ c=0
93
+ for cv in range(0,int(v)):
94
+ c =t0 + (cv*7*24*60*60)
95
+ tweek.append(c)
96
+ tweek.append(c+7*24*60*60) #making it 205 weeks (actually there are only 204 complete weeks)
97
+
98
+ weeks=[str(ii+1)+" "+str(tweek[ii])+" "+str(tweek[ii+1]) for ii in range(len(tweek)-1)]
99
+ return weeks
100
+
101
+ def get_week_test():
102
+ '''
103
+ get_week_test: get week interval in the testing data
104
+
105
+ three columns in each list entry are weekNO,starting time (local),ending time (local)
106
+
107
+ EXAMPLE
108
+ from geofwi import get_week_test
109
+ import os
110
+ weeks=get_week_test()
111
+
112
+ '''
113
+ from obspy.core.utcdatetime import UTCDateTime
114
+ import h5py
115
+ import numpy as np
116
+
117
+ ##########################################################################################
118
+ t0 = UTCDateTime(2021,3,28) #begin time: 2021-03-28T00:00:00.000000Z
119
+ tend = UTCDateTime(2021,10,24) #end time: 2021-10-23T23:50:00.000000Z
120
+ print('Starting and Ending time of testing data are', t0, tend)
121
+
122
+ v = int(tend-t0)/(7*24*60*60) #number of weeks
123
+ tweek=[]
124
+ c=0
125
+ for cv in range(0,int(v)):
126
+ c =t0 + (cv*7*24*60*60)
127
+ tweek.append(c)
128
+ tweek.append(c+7*24*60*60) #making it 205 weeks (actually there are only 204 complete weeks)
129
+
130
+ weeks=[str(ii+1)+" "+str(tweek[ii])+" "+str(tweek[ii+1]) for ii in range(len(tweek)-1)]
131
+ return weeks
132
+
133
+ def get_traindata(station='EM_101',geofwipath='./'):
134
+ '''
135
+ get_traindata: get station-wise training data (for 203 weeks, no first week)
136
+
137
+ EXAMPLE
138
+ from geofwi import get_traindata
139
+ import os
140
+ data=get_traindata('EM_101',os.getenv('HOME')+"/DATALIB/geofwi.h5")
141
+
142
+ '''
143
+ from obspy.core.utcdatetime import UTCDateTime
144
+ import h5py
145
+ import numpy as np
146
+
147
+ ##########################################################################################
148
+ contime= 8 * 60 *60
149
+ t0 = UTCDateTime(1483200000+contime) #begin time: 2017-01-01T00:00:00.000000Z
150
+ tend = UTCDateTime(1606751400+contime) #end time: 2020-11-30T23:50:00.000000Z
151
+ t0, tend
152
+
153
+ v = int(tend-t0)/(10*60)
154
+ t10min=[]
155
+ c=0
156
+ for cv in range(0,int(v)):
157
+ c =t0 + (cv*10*60)
158
+ t10min.append(c)
159
+
160
+ v = int(tend-t0)/(7*24*60*60)
161
+ tweek=[]
162
+ c=0
163
+ for cv in range(0,int(v)):
164
+ c =t0 + (cv*7*24*60*60)
165
+ tweek.append(c)
166
+ tweek.append(c+7*24*60*60) #making it 205 weeks (actually there are only 204 complete weeks)
167
+ f = h5py.File(geofwipath, 'r')
168
+
169
+ # keys=list(f.keys())
170
+ # # id=2 #event NO
171
+ # keys=[ii for ii in keys if ii[0:2]=='EV']
172
+ #
173
+ # #sort
174
+ # def myFunc(e):
175
+ # return int(e[3:])
176
+ # keys.sort(key=myFunc)
177
+ #
178
+ # ##########################################################################################
179
+ # ##extract event info (longitude,latitude,magnitude)
180
+ # ##########################################################################################
181
+ # tweek_lab=np.zeros_like(tweek)
182
+ # Longall=[]
183
+ # Latall=[]
184
+ # magall=[]
185
+ # for s in range(3,len(keys)):
186
+ # dataset = f.get(keys[s])
187
+ # mag=[]
188
+ # Lat=[]
189
+ # Long=[]
190
+ # b = 0
191
+ # ind=[]
192
+ # for q in tweek:
193
+ # d = UTCDateTime(q)-UTCDateTime(dataset.attrs['ev_time'])
194
+ # if d>=0:
195
+ # ind=b-1
196
+ # tweek_lab[ind]=tweek_lab[ind]+1
197
+
198
+ dataset = f.get('%s'%station)
199
+ data=np.array(dataset['data'])
200
+ data19=[]
201
+ for i in range(1,205):
202
+
203
+ a = int(tweek[i-1]-t0)/(10*60)
204
+ b = int(tweek[i]-t0)/(10*60)
205
+
206
+ dataE = data[int(a):int(b)]
207
+ dataE = np.reshape(dataE,(dataE.shape[0]*dataE.shape[1]))
208
+
209
+ data19.append(dataE)
210
+ data19=np.array(data19)
211
+ if True in np.isnan(np.isnan(data19)):
212
+ print('Running nan check')
213
+ data19=np.nan_to_num(data19, nan=0, posinf=33333333, neginf=33333333)
214
+ data19=np.nan_to_num(data19, nan=0, posinf=33333333, neginf=33333333)
215
+
216
+ return data19
217
+
218
+ def get_label(geofwipath='./',mode='occurence',ifmag='True'):
219
+ '''
220
+ get_label: get earthquake occurence label of geofwi
221
+
222
+ NOTE:
223
+ Actual EQ label week is one week after the ML label in a forecasting-classification problem
224
+
225
+ For instance
226
+ If the data from Week2-203 is selected for training
227
+ Correspondingly, the label for EQ occurence is Week3-204
228
+
229
+ The first EQ earthquake in the 204-week training data occurred in the third week
230
+ but for forecasting it, the label in the second week should be set as 1 (one week before)
231
+
232
+ EXAMPLE 1
233
+ from geofwi import get_label
234
+ import os
235
+ label=get_label(os.getenv('HOME')+"/DATALIB/geofwi.h5")
236
+
237
+ EXAMPLE 2
238
+ from geofwi import get_label
239
+ import os
240
+ geofwipath=os.getenv('HOME')+"/DATALIB/geofwi.h5"
241
+ labelmag=get_label(geofwipath,mode='magnitude')
242
+
243
+ EXAMPLE 3
244
+ from geofwi import get_label
245
+ import os
246
+ geofwipath=os.getenv('HOME')+"/DATALIB/geofwi.h5"
247
+ labelloc=get_label(geofwipath,mode='location')
248
+ '''
249
+
250
+ if ifmag==True:
251
+ mode='magnitude' #for compatible with old version
252
+
253
+ from obspy.core.utcdatetime import UTCDateTime
254
+
255
+ ##########################################################################################
256
+ ## Set up week
257
+ ##########################################################################################
258
+ contime= 8 * 60 *60
259
+ t0 = UTCDateTime(1483200000+contime) #begin time: 2017-01-01T00:00:00.000000Z
260
+ tend = UTCDateTime(1606751400+contime) #end time: 2020-11-30T23:50:00.000000Z
261
+ t0, tend
262
+
263
+ v = int(tend-t0)/(10*60)
264
+ t10min=[]
265
+ c=0
266
+ for cv in range(0,int(v)):
267
+ c =t0 + (cv*10*60)
268
+ t10min.append(c)
269
+
270
+ v = int(tend-t0)/(7*24*60*60)
271
+ tweek=[]
272
+ c=0
273
+ for cv in range(0,int(v)):
274
+ c =t0 + (cv*7*24*60*60)
275
+ tweek.append(c)
276
+
277
+ import h5py
278
+ f = h5py.File(geofwipath, 'r')
279
+ keys=list(f.keys())
280
+ # id=2 #event NO
281
+ keys=[ii for ii in keys if ii[0:2]=='EV']
282
+
283
+ #sort
284
+ def myFunc(e):
285
+ return int(e[3:])
286
+ keys.sort(key=myFunc)
287
+
288
+ ##########################################################################################
289
+ ##extract event info (longitude,latitude,magnitude)
290
+ ##########################################################################################
291
+ tweek_lab=np.zeros_like(tweek)
292
+ Longall=[]
293
+ Latall=[]
294
+ magall=[]
295
+ for s in range(0,len(keys)):
296
+ dataset = f.get(keys[s])
297
+ mag=[]
298
+ Lat=[]
299
+ Long=[]
300
+ b = 0
301
+ ind=[]
302
+ for q in tweek:
303
+ d = UTCDateTime(q)-UTCDateTime(dataset.attrs['ev_time'])
304
+ if d>=0:
305
+ ind=b-1
306
+ tweek_lab[ind]=tweek_lab[ind]+1 #This is the actual EQ week (one week after the label week)
307
+ mag.append(dataset.attrs['ev_magnitude'])
308
+ Lat.append(dataset.attrs['ev_latitude'])
309
+ Long.append(dataset.attrs['ev_longitude'])
310
+ break
311
+ b = b+1
312
+ magall.append(mag)
313
+ Longall.append(Long)
314
+ Latall.append(Lat)
315
+
316
+ magweek = np.zeros_like(tweek_lab)
317
+ latweek = np.zeros_like(tweek_lab)
318
+ lonweek = np.zeros_like(tweek_lab)
319
+
320
+ v = 0
321
+ c = 0
322
+ for i in tweek_lab:
323
+ if i>0:
324
+ magweek[v] = magall[c:c+i]
325
+ latweek[v] = Latall[c:c+i]
326
+ lonweek[v] = Longall[c:c+i]
327
+ c = c +i
328
+ else:
329
+ magweek[v]=0
330
+ latweek[v]=[[0]]
331
+ lonweek[v]=[[0]]
332
+ v = v+1
333
+
334
+ len(tweek_lab), int(tweek[2]-t0)/(10*60), int(tweek[3]-t0)/(10*60)
335
+
336
+ lab=tweek_lab
337
+ labclass = np.zeros((len(lab)))
338
+ cc=0
339
+ for i in lab:
340
+ if i>0:
341
+ labclass[cc]=1
342
+ cc = cc+1
343
+ labclass = np.array(labclass)
344
+
345
+ if mode=='occurence':
346
+ return labclass
347
+ elif mode=='magnitude':
348
+ mags = np.array([np.round(np.array(ii).max()) for ii in magweek])
349
+ return mags
350
+ elif mode=='location':
351
+ inds=np.array([np.array(ii).argmax() for ii in magweek],dtype='int')
352
+ lons=np.array([lonweek[ii][inds[ii]] for ii in range(len(lonweek))]).flatten()
353
+ lats=np.array([latweek[ii][inds[ii]] for ii in range(len(latweek))]).flatten()
354
+ return [(lons[ii],lats[ii]) for ii in range(len(inds))]
355
+ else:
356
+ return labclass
357
+
358
+
359
+
360
+ def get_time():
361
+ '''
362
+ get_time: get the time axis for geofwi
363
+
364
+ The length of the time vector is 205920
365
+ The format of time is UTC time format but in local time (CST = UTC + 8 hours)
366
+
367
+ Written by Yangkang Chen
368
+ Aug, 21, 2024
369
+
370
+ EXAMPLE
371
+ from geofwi import get_time
372
+ times=get_time()
373
+ print(times[0],times[-1])
374
+
375
+ '''
376
+ from obspy.core.utcdatetime import UTCDateTime
377
+ import numpy as np
378
+
379
+ ##########################################################################################
380
+ ## Set up week
381
+ ##########################################################################################
382
+ contime= 8 * 60 *60
383
+ t0 = UTCDateTime(1483200000+contime) #begin time: 2017-01-01T00:00:00.000000Z
384
+ tend = UTCDateTime(1606751400+contime) #end time: 2020-11-30T23:50:00.000000Z
385
+ t0, tend
386
+
387
+ nsample=204*7*24*6+2*24*6; #205920
388
+
389
+ timestamps=np.linspace(1483200000+contime,1606751400+contime,nsample);
390
+
391
+ times=[UTCDateTime(ii) for ii in timestamps]
392
+
393
+ return times
394
+
395
+
396
+ def get_testdata(week=1,station='EM_101',geofwipath='./'):
397
+ '''
398
+ get_testdata: get station-wise training data (for 203 weeks, no first week)
399
+
400
+ EXAMPLE:
401
+
402
+ exe1
403
+ from geofwi import get_testdata
404
+ import os
405
+ data=get_testdata(1,'EM_101',os.getenv('HOME')+"/DATALIB/geofwi.h5")
406
+
407
+ exe2
408
+ from geofwi import get_testdata
409
+ import os
410
+ data=get_testdata(1,'GA_101',os.getenv('HOME')+"/DATALIB/geofwi.h5")
411
+
412
+ '''
413
+ import h5py
414
+ f = h5py.File(geofwipath, 'r')
415
+ idx="WK_%02d"%week
416
+ dataset = f.get(idx)
417
+ print('idx:',idx)
418
+
419
+ keywords=list(f.get(idx).keys())
420
+
421
+ ems=[ii for ii in keywords if ii[0:2]=='EM']
422
+ gas=[ii for ii in keywords if ii[0:2]=='GA']
423
+
424
+ ems=ems+gas
425
+
426
+ # wkno='WK_01'
427
+ allstas=[station]
428
+ for ista in range(len(allstas)):
429
+ print(idx,ista,len(allstas))
430
+
431
+ emname=[ii for ii in ems if ii.split("_")[0]+'_'+ii.split("_")[-1]==allstas[ista] ]
432
+
433
+ if len(emname) > 0:
434
+ print(idx,emname)
435
+ data_em=np.array(f.get(idx).get(emname[0])['data'])
436
+ data_em=np.nan_to_num(data_em, nan=0, posinf=33333333, neginf=33333333)
437
+
438
+ # ganame=[ii for ii in gas if ii.split("_")[-1]==allstas[ista] ]
439
+ #
440
+ # if len(ganame) > 0:
441
+ # data_ga=np.array(f.get(idx).get(ganame[0])['data'])
442
+ # print('Max/Min GA values: ',data_ga.max(),data_ga.min())
443
+
444
+ return data_em
445
+
446
+
447
+ def get_testlabel(geofwipath='./',mode='occurence'):
448
+ '''
449
+ get_testlabel: get earthquake occurence label of geofwi for the testing data (30 weeks)
450
+
451
+
452
+ mode: occurence, magnitude, location
453
+
454
+ EXAMPLE:
455
+ from geofwi import get_testlabel
456
+ import os
457
+ label=get_testlabel(os.getenv('HOME')+"/DATALIB/geofwi.h5")
458
+ labelmag=get_testlabel(os.getenv('HOME')+"/DATALIB/geofwi.h5",mode='magnitude')
459
+ labelloc=get_testlabel(os.getenv('HOME')+"/DATALIB/geofwi.h5",mode='location')
460
+
461
+ '''
462
+ import os,h5py
463
+
464
+ geofwipath=os.getenv('HOME')+'/DATALIB/geofwi.h5'
465
+
466
+ f = h5py.File(geofwipath, 'r')
467
+ keys=list(f.keys())
468
+ keys=[ii for ii in keys if ii[0:2]=='WK']
469
+
470
+
471
+ labclass=[]
472
+ mags=[]
473
+ lons=[]
474
+ lats=[]
475
+ for ii in range(len(keys)):
476
+ idx=keys[ii]
477
+ keywords=list(f.get(idx).keys())
478
+ # print(keywords[-1])
479
+ yesno=f.get(idx).get('Label_EV').attrs['yesno']
480
+
481
+ if yesno=='yes':
482
+ labclass.append(1)
483
+ mags.append(f.get(idx).get('Label_EV').attrs['ev_magnitude'])
484
+ lons.append(f.get(idx).get('Label_EV').attrs['ev_longitude'])
485
+ lats.append(f.get(idx).get('Label_EV').attrs['ev_latitude'])
486
+ else:
487
+ labclass.append(0)
488
+ mags.append(0)
489
+ lons.append(0)
490
+ lats.append(0)
491
+
492
+
493
+ if mode=='occurence':
494
+ return labclass
495
+ elif mode=='magnitude':
496
+ return mags
497
+ elif mode=='location':
498
+ return [(lons[ii],lats[ii]) for ii in range(len(lons))]
499
+ else:
500
+ return labclass
501
+
502
+
503
+ def get_testlabelaeta(geofwipath='./',mode='occurence'):
504
+ '''
505
+ get_testlabelaeta: get earthquake occurence label of geofwi for the testing data (30 weeks)
506
+
507
+ NOTE: The difference between get_testlabel and get_testlabelaeta is that the latter
508
+ removes the events that are far away from AETA stations. The AETA competition is
509
+ based on the labels from the latter (get_testlabelaeta).
510
+
511
+ For keep a record of all event information, we preserve both label functions.
512
+
513
+ mode: occurence, magnitude, location
514
+
515
+ EXAMPLE:
516
+ from geofwi import get_testlabelaeta
517
+ import os
518
+ label=get_testlabelaeta(os.getenv('HOME')+"/DATALIB/geofwi.h5")
519
+ labelmag=get_testlabelaeta(os.getenv('HOME')+"/DATALIB/geofwi.h5",mode='magnitude')
520
+ labelloc=get_testlabelaeta(os.getenv('HOME')+"/DATALIB/geofwi.h5",mode='location')
521
+
522
+ '''
523
+ import os,h5py
524
+
525
+ geofwipath=os.getenv('HOME')+'/DATALIB/geofwi.h5'
526
+
527
+ f = h5py.File(geofwipath, 'r')
528
+ keys=list(f.keys())
529
+ keys=[ii for ii in keys if ii[0:2]=='WK']
530
+
531
+
532
+ labclass=[]
533
+ mags=[]
534
+ lons=[]
535
+ lats=[]
536
+ for ii in range(len(keys)):
537
+ idx=keys[ii]
538
+ keywords=list(f.get(idx).keys())
539
+ # print(keywords[-1])
540
+ yesno=f.get(idx).get('Label_EV').attrs['yesno']
541
+
542
+ if yesno=='yes':
543
+ labclass.append(1)
544
+ mags.append(f.get(idx).get('Label_EV').attrs['ev_magnitude'])
545
+ lons.append(f.get(idx).get('Label_EV').attrs['ev_longitude'])
546
+ lats.append(f.get(idx).get('Label_EV').attrs['ev_latitude'])
547
+ else:
548
+ labclass.append(0)
549
+ mags.append(0)
550
+ lons.append(0)
551
+ lats.append(0)
552
+
553
+ weeks=[17,18,20,23]
554
+ #In these weeks, event from China's catalog is removed due to the remoteness from nearest AETA stations
555
+ for iweek in weeks:
556
+ labclass[iweek-1]=0
557
+ mags[iweek-1]=0
558
+ lons[iweek-1]=0
559
+ lats[iweek-1]=0
560
+
561
+ if mode=='occurence':
562
+ return labclass
563
+ elif mode=='magnitude':
564
+ return mags
565
+ elif mode=='location':
566
+ return [(lons[ii],lats[ii]) for ii in range(len(lons))]
567
+ else:
568
+ return labclass
569
+
570
+
571
+
572
+
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.1
2
+ Name: geofwi
3
+ Version: 0.0.0.1
4
+ Summary: GeoFWI: A lightweight velocity model dataset for benchmarking full waveform inversion using deep learning
5
+ Home-page: https://github.com/aaspip/geofwi
6
+ Author: geofwi developing team
7
+ Author-email: chenyk2016@gmail.com
8
+ License: MIT License
9
+ Keywords: seismology,seismic imaging,computational seismology,AI for science
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: Unix
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Scientific/Engineering :: Physics
21
+ Classifier: License :: OSI Approved :: MIT License
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy
24
+ Requires-Dist: scipy
25
+ Requires-Dist: matplotlib
26
+ Provides-Extra: docs
27
+ Requires-Dist: sphinx; extra == "docs"
28
+ Requires-Dist: ipython; extra == "docs"
29
+ Requires-Dist: runipy; extra == "docs"
30
+
31
+ Source code: https://github.com/aaspip/geofwi
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ data/data.jsonl
5
+ data/geofwi-size-layer-fault-salt-1-10.npy
6
+ demos/test_quick_visualize.py
7
+ geofwi/__init__.py
8
+ geofwi/acc.py
9
+ geofwi/plot.py
10
+ geofwi/utils.py
11
+ geofwi.egg-info/PKG-INFO
12
+ geofwi.egg-info/SOURCES.txt
13
+ geofwi.egg-info/dependency_links.txt
14
+ geofwi.egg-info/not-zip-safe
15
+ geofwi.egg-info/requires.txt
16
+ geofwi.egg-info/top_level.txt
17
+ notebooks/README.md
@@ -0,0 +1,8 @@
1
+ numpy
2
+ scipy
3
+ matplotlib
4
+
5
+ [docs]
6
+ sphinx
7
+ ipython
8
+ runipy
@@ -0,0 +1 @@
1
+ geofwi
File without changes
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env python
2
+ # -*- encoding: utf8 -*-
3
+ # import glob
4
+ # import inspect
5
+ # import io
6
+ # import os
7
+
8
+ from setuptools import setup
9
+ import numpy
10
+ long_description = """
11
+ Source code: https://github.com/aaspip/geofwi""".strip()
12
+
13
+
14
+ def read(*names, **kwargs):
15
+ return io.open(
16
+ os.path.join(os.path.dirname(__file__), *names),
17
+ encoding=kwargs.get("encoding", "utf8")).read()
18
+
19
+ # from numpy.distutils.core import setup
20
+ setup(
21
+ name="geofwi",
22
+ version="0.0.0.1",
23
+ license='MIT License',
24
+ description="GeoFWI: A lightweight velocity model dataset for benchmarking full waveform inversion using deep learning",
25
+ long_description=long_description,
26
+ author="geofwi developing team",
27
+ author_email="chenyk2016@gmail.com",
28
+ url="https://github.com/aaspip/geofwi",
29
+ packages=['geofwi'],
30
+ include_package_data=True,
31
+ zip_safe=False,
32
+ classifiers=[
33
+ # complete classifier list:
34
+ # http://pypi.python.org/pypi?%3Aaction=list_classifiers
35
+ "Development Status :: 4 - Beta",
36
+ "Intended Audience :: Developers",
37
+ "Intended Audience :: Science/Research",
38
+ "Operating System :: Unix",
39
+ "Operating System :: POSIX",
40
+ "Operating System :: Microsoft :: Windows",
41
+ "Programming Language :: Python",
42
+ "Programming Language :: Python :: 3.11",
43
+ "Programming Language :: Python :: Implementation :: CPython",
44
+ "Topic :: Scientific/Engineering",
45
+ "Topic :: Scientific/Engineering :: Physics",
46
+ "License :: OSI Approved :: MIT License"
47
+ ],
48
+ keywords=[
49
+ "seismology", "seismic imaging", "computational seismology", "AI for science"
50
+ ],
51
+ install_requires=[
52
+ "numpy", "scipy", "matplotlib"
53
+ ],
54
+ extras_require={
55
+ "docs": ["sphinx", "ipython", "runipy"]
56
+ }
57
+ )