Spaces:
Runtime error
Runtime error
section plot updated
Browse files- .DS_Store +0 -0
- Gradio_app.ipynb +64 -218
- data/.DS_Store +0 -0
- data/cached/CI_CCC_2019-07-04T17:33:40.494912Z.mseed +0 -0
- data/cached/CI_WCS2_2019-07-04T17:33:40.200950Z.mseed +0 -0
- data/cached/CI_WNM_2019-07-04T17:33:39.710492Z.mseed +0 -0
- data/cached/NP_1809_2019-07-04T17:33:42.451267Z.mseed +0 -0
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
Gradio_app.ipynb
CHANGED
|
@@ -2,178 +2,27 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
-
"execution_count":
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [
|
| 8 |
{
|
| 9 |
-
"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"\t\tNetworks (7):\n",
|
| 18 |
-
"\t\t\t8P, CI, LB, NN, NP, PB, SY\n",
|
| 19 |
-
"\t\tStations (85):\n",
|
| 20 |
-
"\t\t\t8P.CAU08 (Monache Meadows, CA, USA)\n",
|
| 21 |
-
"\t\t\tCI.APL (Apollo)\n",
|
| 22 |
-
"\t\t\tCI.CCA (California City Airport)\n",
|
| 23 |
-
"\t\t\tCI.CCC (Christmas Canyon China Lake)\n",
|
| 24 |
-
"\t\t\tCI.CGO (Cerro Gordo)\n",
|
| 25 |
-
"\t\t\tCI.CLC (China Lake)\n",
|
| 26 |
-
"\t\t\tCI.CWC (Cottonwood Creek)\n",
|
| 27 |
-
"\t\t\tCI.DAW (Darwin)\n",
|
| 28 |
-
"\t\t\tCI.DTP (Desert Tortoise Park)\n",
|
| 29 |
-
"\t\t\tCI.GSC (Goldstone)\n",
|
| 30 |
-
"\t\t\tCI.HAR (Harper Dry Lake bed)\n",
|
| 31 |
-
"\t\t\tCI.ISA (Isabella)\n",
|
| 32 |
-
"\t\t\tCI.JRC2 (Joshua Ridge: China Lake)\n",
|
| 33 |
-
"\t\t\tCI.LMR2 (Leuhmann Ridge Extension)\n",
|
| 34 |
-
"\t\t\tCI.LRL (Laurel Mtn)\n",
|
| 35 |
-
"\t\t\tCI.MPM (Manuel Prospect Mine)\n",
|
| 36 |
-
"\t\t\tCI.MRS (Mars)\n",
|
| 37 |
-
"\t\t\tCI.Q0068 (Redwood Blvd, California City CA)\n",
|
| 38 |
-
"\t\t\tCI.Q0072 (Lakeland Street, Ridgecrest CA)\n",
|
| 39 |
-
"\t\t\tCI.SLA (Slate Mountain)\n",
|
| 40 |
-
"\t\t\tCI.SRT (Snort)\n",
|
| 41 |
-
"\t\t\tCI.TEH (Cattani Ranch)\n",
|
| 42 |
-
"\t\t\tCI.TOW2 (Tower 2)\n",
|
| 43 |
-
"\t\t\tCI.WAS2 (Alta Sierra 2)\n",
|
| 44 |
-
"\t\t\tCI.WBM (Bowman Road)\n",
|
| 45 |
-
"\t\t\tCI.WBS (Bird Springs)\n",
|
| 46 |
-
"\t\t\tCI.WCS2 (Coso Hot Springs 2)\n",
|
| 47 |
-
"\t\t\tCI.WHF (Hanning Flat)\n",
|
| 48 |
-
"\t\t\tCI.WLH2 (Little Horse 2)\n",
|
| 49 |
-
"\t\t\tCI.WMF (Mccloud Flat)\n",
|
| 50 |
-
"\t\t\tCI.WNM (Nine Mile Canyon)\n",
|
| 51 |
-
"\t\t\tCI.WOR (Onyx Ranch)\n",
|
| 52 |
-
"\t\t\tCI.WRC2 (Renegade Canyon)\n",
|
| 53 |
-
"\t\t\tCI.WRV2 (Rose Valley Canyon 2)\n",
|
| 54 |
-
"\t\t\tCI.WVP2 (Volcano Peak 2)\n",
|
| 55 |
-
"\t\t\tLB.DAC (Inyo County, Darwin, CA, USA)\n",
|
| 56 |
-
"\t\t\tNN.GWY (Greenwater Valley, CA. (GPS 12/06/2000) w84gm)\n",
|
| 57 |
-
"\t\t\tNN.PAN (Panamint Range. (GPS 12/06/2000) w84gm)\n",
|
| 58 |
-
"\t\t\tNN.QSM (Queen of Sheba Mine, CA. (GPS 01/17/2001) w84gm)\n",
|
| 59 |
-
"\t\t\tNP.1035 (CA:Lake Isabella Dam)\n",
|
| 60 |
-
"\t\t\tNP.1809 (CA:Haiwee Rsvr;Pump Pl)\n",
|
| 61 |
-
"\t\t\tNP.5419 (CA:China Lake;Nav Weapon Ctr)\n",
|
| 62 |
-
"\t\t\tPB.B916 (marips916bcs2008, China Lake, CA, USA)\n",
|
| 63 |
-
"\t\t\tPB.B917 (tonyso917bcs2008, China Lake, CA, USA)\n",
|
| 64 |
-
"\t\t\tPB.B918 (mtsprn918bcs2008, China Lake, CA, USA)\n",
|
| 65 |
-
"\t\t\tPB.B921 (randsb921bcs2008, China Lake, CA, USA)\n",
|
| 66 |
-
"\t\t\tSY.CCA (CCA synthetic)\n",
|
| 67 |
-
"\t\t\tSY.CCC (CCC synthetic)\n",
|
| 68 |
-
"\t\t\tSY.CGO (CGO synthetic)\n",
|
| 69 |
-
"\t\t\tSY.CLC (CLC synthetic)\n",
|
| 70 |
-
"\t\t\tSY.CWC (CWC synthetic)\n",
|
| 71 |
-
"\t\t\tSY.DAC (DAC synthetic)\n",
|
| 72 |
-
"\t\t\tSY.DAW (DAW synthetic)\n",
|
| 73 |
-
"\t\t\tSY.DTP (DTP synthetic)\n",
|
| 74 |
-
"\t\t\tSY.FPC (FPC synthetic)\n",
|
| 75 |
-
"\t\t\tSY.FSR (FSR synthetic)\n",
|
| 76 |
-
"\t\t\tSY.GPO (GPO synthetic)\n",
|
| 77 |
-
"\t\t\tSY.GSC (GSC synthetic)\n",
|
| 78 |
-
"\t\t\tSY.HAR (HAR synthetic)\n",
|
| 79 |
-
"\t\t\tSY.ISA (ISA synthetic)\n",
|
| 80 |
-
"\t\t\tSY.JRC (JRC synthetic)\n",
|
| 81 |
-
"\t\t\tSY.JRC2 (JRC2 synthetic)\n",
|
| 82 |
-
"\t\t\tSY.KRV3 (KRV3 synthetic)\n",
|
| 83 |
-
"\t\t\tSY.LMR (LMR synthetic)\n",
|
| 84 |
-
"\t\t\tSY.LMR2 (LMR2 synthetic)\n",
|
| 85 |
-
"\t\t\tSY.LRL (LRL synthetic)\n",
|
| 86 |
-
"\t\t\tSY.MPM (MPM synthetic)\n",
|
| 87 |
-
"\t\t\tSY.OVRO (OVRO synthetic)\n",
|
| 88 |
-
"\t\t\tSY.RRC (RRC synthetic)\n",
|
| 89 |
-
"\t\t\tSY.SEV (SEV synthetic)\n",
|
| 90 |
-
"\t\t\tSY.SLA (SLA synthetic)\n",
|
| 91 |
-
"\t\t\tSY.SRT (SRT synthetic)\n",
|
| 92 |
-
"\t\t\tSY.TEH (TEH synthetic)\n",
|
| 93 |
-
"\t\t\tSY.TOW2 (TOW2 synthetic)\n",
|
| 94 |
-
"\t\t\tSY.WAS2 (WAS2 synthetic)\n",
|
| 95 |
-
"\t\t\tSY.WBM (WBM synthetic)\n",
|
| 96 |
-
"\t\t\tSY.WBP (WBP synthetic)\n",
|
| 97 |
-
"\t\t\tSY.WBS (WBS synthetic)\n",
|
| 98 |
-
"\t\t\tSY.WCS2 (WCS2 synthetic)\n",
|
| 99 |
-
"\t\t\tSY.WHF (WHF synthetic)\n",
|
| 100 |
-
"\t\t\tSY.WLH2 (WLH2 synthetic)\n",
|
| 101 |
-
"\t\t\tSY.WMF (WMF synthetic)\n",
|
| 102 |
-
"\t\t\tSY.WNM (WNM synthetic)\n",
|
| 103 |
-
"\t\t\tSY.WOR (WOR synthetic)\n",
|
| 104 |
-
"\t\t\tSY.WRC2 (WRC2 synthetic)\n",
|
| 105 |
-
"\t\tChannels (0):\n",
|
| 106 |
-
"\n"
|
| 107 |
-
]
|
| 108 |
-
}
|
| 109 |
-
],
|
| 110 |
-
"source": [
|
| 111 |
-
"import obspy\n",
|
| 112 |
-
"from obspy.clients.fdsn import Client\n",
|
| 113 |
-
"\n",
|
| 114 |
-
"client_name = 'SCEDC'\n",
|
| 115 |
-
"radius_km = 100\n",
|
| 116 |
-
"timestamp = '2019-07-04 17:33:49'\n",
|
| 117 |
-
"eq_lat = 35.766\n",
|
| 118 |
-
"eq_lon = -117.605\n",
|
| 119 |
-
"\n",
|
| 120 |
-
"origin_time = obspy.UTCDateTime(timestamp)\n",
|
| 121 |
-
"\n",
|
| 122 |
-
"client = Client(\"IRIS\")\n",
|
| 123 |
-
"inventory = client.get_stations(network=\"*\", station=\"*\", channel=\"*\",\n",
|
| 124 |
-
" starttime=origin_time, endtime=origin_time + 120,\n",
|
| 125 |
-
" latitude=eq_lat, longitude=eq_lon, maxradius=radius_km/111.2)\n",
|
| 126 |
-
"print(inventory)\n"
|
| 127 |
-
]
|
| 128 |
-
},
|
| 129 |
-
{
|
| 130 |
-
"cell_type": "code",
|
| 131 |
-
"execution_count": null,
|
| 132 |
-
"metadata": {},
|
| 133 |
-
"outputs": [],
|
| 134 |
-
"source": [
|
| 135 |
-
"\n",
|
| 136 |
-
"\n",
|
| 137 |
-
"client = Client(client_name)\n",
|
| 138 |
-
"window = radius_km / 111.2\n",
|
| 139 |
-
"\n",
|
| 140 |
-
"assert eq_lat - window > -90 and eq_lat + window < 90, \"Latitude out of bounds\"\n",
|
| 141 |
-
"assert eq_lon - window > -180 and eq_lon + window < 180, \"Longitude out of bounds\"\n",
|
| 142 |
-
"\n",
|
| 143 |
-
"starttime = obspy.UTCDateTime(timestamp)\n",
|
| 144 |
-
"endtime = starttime + 120\n",
|
| 145 |
-
"\n",
|
| 146 |
-
"inv = client.get_stations(network=\"*\", station=\"*\", location=\"*\", channel=\"*H*\", \n",
|
| 147 |
-
" starttime=starttime, endtime=endtime, \n",
|
| 148 |
-
" minlatitude=(eq_lat-window), maxlatitude=(eq_lat+window),\n",
|
| 149 |
-
" minlongitude=(eq_lon-window), maxlongitude=(eq_lon+window), \n",
|
| 150 |
-
" level='station')"
|
| 151 |
-
]
|
| 152 |
-
},
|
| 153 |
-
{
|
| 154 |
-
"cell_type": "code",
|
| 155 |
-
"execution_count": 75,
|
| 156 |
-
"metadata": {},
|
| 157 |
-
"outputs": [
|
| 158 |
-
{
|
| 159 |
-
"ename": "NameError",
|
| 160 |
-
"evalue": "name 't0s' is not defined",
|
| 161 |
-
"output_type": "error",
|
| 162 |
-
"traceback": [
|
| 163 |
-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
| 164 |
-
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
| 165 |
-
"Cell \u001b[0;32mIn[75], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mpandas\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mpd\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m pd\u001b[39m.\u001b[39mdate_range(start\u001b[39m=\u001b[39mt0s[i], periods\u001b[39m=\u001b[39mwaveforms[i][\u001b[39m0\u001b[39m]\u001b[39m.\u001b[39mshape[\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m], freq\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39m1s\u001b[39m\u001b[39m'\u001b[39m)\n",
|
| 166 |
-
"\u001b[0;31mNameError\u001b[0m: name 't0s' is not defined"
|
| 167 |
-
]
|
| 168 |
}
|
| 169 |
],
|
| 170 |
"source": [
|
| 171 |
-
"
|
| 172 |
]
|
| 173 |
},
|
| 174 |
{
|
| 175 |
"cell_type": "code",
|
| 176 |
-
"execution_count":
|
| 177 |
"metadata": {},
|
| 178 |
"outputs": [
|
| 179 |
{
|
|
@@ -188,7 +37,7 @@
|
|
| 188 |
"name": "stdout",
|
| 189 |
"output_type": "stream",
|
| 190 |
"text": [
|
| 191 |
-
"Running on local URL: http://127.0.0.1:
|
| 192 |
"\n",
|
| 193 |
"To create a public link, set `share=True` in `launch()`.\n"
|
| 194 |
]
|
|
@@ -196,7 +45,7 @@
|
|
| 196 |
{
|
| 197 |
"data": {
|
| 198 |
"text/html": [
|
| 199 |
-
"<div><iframe src=\"http://127.0.0.1:
|
| 200 |
],
|
| 201 |
"text/plain": [
|
| 202 |
"<IPython.core.display.HTML object>"
|
|
@@ -209,7 +58,7 @@
|
|
| 209 |
"data": {
|
| 210 |
"text/plain": []
|
| 211 |
},
|
| 212 |
-
"execution_count":
|
| 213 |
"metadata": {},
|
| 214 |
"output_type": "execute_result"
|
| 215 |
}
|
|
@@ -238,6 +87,8 @@
|
|
| 238 |
"import matplotlib.pyplot as plt\n",
|
| 239 |
"import matplotlib.dates as mdates\n",
|
| 240 |
"\n",
|
|
|
|
|
|
|
| 241 |
"def make_prediction(waveform):\n",
|
| 242 |
" waveform = np.load(waveform)\n",
|
| 243 |
" processed_input = prepare_waveform(waveform)\n",
|
|
@@ -297,6 +148,15 @@
|
|
| 297 |
" plt.close(fig)\n",
|
| 298 |
" return image\n",
|
| 299 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
"def predict_on_section(client_name, timestamp, eq_lat, eq_lon, radius_km, source_depth_km, velocity_model):\n",
|
| 301 |
" distances, t0s, st_lats, st_lons, waveforms = [], [], [], [], []\n",
|
| 302 |
" \n",
|
|
@@ -318,6 +178,8 @@
|
|
| 318 |
" level='station')\n",
|
| 319 |
" \n",
|
| 320 |
" waveforms = []\n",
|
|
|
|
|
|
|
| 321 |
" for network in inv:\n",
|
| 322 |
" for station in network:\n",
|
| 323 |
" try:\n",
|
|
@@ -332,8 +194,12 @@
|
|
| 332 |
" starttime = obspy.UTCDateTime(timestamp) + arrivals[0].time - 15\n",
|
| 333 |
" endtime = starttime + 60\n",
|
| 334 |
"\n",
|
| 335 |
-
"
|
| 336 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
" \n",
|
| 338 |
" waveform = waveform.select(channel=\"H[BH][ZNE]\")\n",
|
| 339 |
" waveform = waveform.merge(fill_value=0)\n",
|
|
@@ -365,29 +231,39 @@
|
|
| 365 |
" p_phases = output[:, 0]\n",
|
| 366 |
" s_phases = output[:, 1]\n",
|
| 367 |
"\n",
|
| 368 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
" for i in range(len(waveforms)):\n",
|
| 370 |
" current_P = p_phases[i::len(waveforms)]\n",
|
| 371 |
" current_S = s_phases[i::len(waveforms)]\n",
|
|
|
|
| 372 |
" x = [t0s[i] + pd.Timedelta(seconds=k/100) for k in np.linspace(0,6000,6000)]\n",
|
| 373 |
" x = mdates.date2num(x)\n",
|
| 374 |
-
" ax.plot(x, waveforms[i][0, 0]+distances[i]*111.2, color='black', alpha=0.5)\n",
|
| 375 |
-
" ax.scatter(x[int(current_P.mean()*waveforms[i][0].shape[-1])], waveforms[i][0, 0].mean()+distances[i]*111.2, color='r')\n",
|
| 376 |
-
" ax.scatter(x[int(current_S.mean()*waveforms[i][0].shape[-1])], waveforms[i][0, 0].mean()+distances[i]*111.2, color='b')\n",
|
| 377 |
-
" ax.set_ylabel('Z')\n",
|
| 378 |
"\n",
|
| 379 |
-
"
|
| 380 |
-
"
|
|
|
|
| 381 |
"\n",
|
| 382 |
-
"
|
| 383 |
-
" # a.axvline(current_P.mean()*waveforms[i][0].shape[-1], color='r', linestyle='--', label='P')\n",
|
| 384 |
-
" # a.axvline(current_S.mean()*waveforms[i][0].shape[-1], color='b', linestyle='--', label='S')\n",
|
| 385 |
"\n",
|
| 386 |
-
"
|
| 387 |
-
"
|
| 388 |
-
"
|
| 389 |
"\n",
|
| 390 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
" \n",
|
| 392 |
" fig.canvas.draw();\n",
|
| 393 |
" image = np.array(fig.canvas.renderer.buffer_rgba())\n",
|
|
@@ -401,12 +277,6 @@
|
|
| 401 |
" learning_rate=3e-4)\n",
|
| 402 |
"model.eval()\n",
|
| 403 |
"\n",
|
| 404 |
-
"\n",
|
| 405 |
-
"\n",
|
| 406 |
-
"# # Create the Gradio interface\n",
|
| 407 |
-
"# gr.Interface(mark_phases, inputs, outputs, title='PhaseHunter').launch()\n",
|
| 408 |
-
"\n",
|
| 409 |
-
"\n",
|
| 410 |
"with gr.Blocks() as demo:\n",
|
| 411 |
" gr.Markdown(\"# PhaseHunter\")\n",
|
| 412 |
" gr.Markdown(\"\"\"This app allows one to detect P and S seismic phases along with uncertainty of the detection. \n",
|
|
@@ -467,7 +337,9 @@
|
|
| 467 |
" radius_inputs = gr.Slider(minimum=1, \n",
|
| 468 |
" maximum=150, \n",
|
| 469 |
" value=50, label=\"Radius (km)\", \n",
|
| 470 |
-
"
|
|
|
|
|
|
|
| 471 |
" interactive=True)\n",
|
| 472 |
" \n",
|
| 473 |
" velocity_inputs = gr.Dropdown(\n",
|
|
@@ -480,7 +352,7 @@
|
|
| 480 |
" \n",
|
| 481 |
" \n",
|
| 482 |
" button = gr.Button(\"Predict phases\")\n",
|
| 483 |
-
" outputs_section = gr.
|
| 484 |
" \n",
|
| 485 |
" button.click(predict_on_section, \n",
|
| 486 |
" inputs=[client_inputs, timestamp_inputs, \n",
|
|
@@ -494,41 +366,15 @@
|
|
| 494 |
" Your waveform should be sampled at 100 sps and have 3 (Z, N, E) or 1 (Z) channels.\n",
|
| 495 |
" \"\"\")\n",
|
| 496 |
"\n",
|
| 497 |
-
"\n",
|
| 498 |
-
"\n",
|
| 499 |
"demo.launch()"
|
| 500 |
]
|
| 501 |
},
|
| 502 |
{
|
| 503 |
"cell_type": "code",
|
| 504 |
-
"execution_count":
|
| 505 |
"metadata": {},
|
| 506 |
-
"outputs": [
|
| 507 |
-
|
| 508 |
-
"data": {
|
| 509 |
-
"text/plain": [
|
| 510 |
-
"DatetimeIndex(['2019-07-04 17:33:49', '2019-07-04 17:33:50',\n",
|
| 511 |
-
" '2019-07-04 17:33:51', '2019-07-04 17:33:52',\n",
|
| 512 |
-
" '2019-07-04 17:33:53', '2019-07-04 17:33:54',\n",
|
| 513 |
-
" '2019-07-04 17:33:55', '2019-07-04 17:33:56',\n",
|
| 514 |
-
" '2019-07-04 17:33:57', '2019-07-04 17:33:58',\n",
|
| 515 |
-
" ...\n",
|
| 516 |
-
" '2019-07-04 19:13:39', '2019-07-04 19:13:40',\n",
|
| 517 |
-
" '2019-07-04 19:13:41', '2019-07-04 19:13:42',\n",
|
| 518 |
-
" '2019-07-04 19:13:43', '2019-07-04 19:13:44',\n",
|
| 519 |
-
" '2019-07-04 19:13:45', '2019-07-04 19:13:46',\n",
|
| 520 |
-
" '2019-07-04 19:13:47', '2019-07-04 19:13:48'],\n",
|
| 521 |
-
" dtype='datetime64[ns]', length=6000, freq='S')"
|
| 522 |
-
]
|
| 523 |
-
},
|
| 524 |
-
"execution_count": 105,
|
| 525 |
-
"metadata": {},
|
| 526 |
-
"output_type": "execute_result"
|
| 527 |
-
}
|
| 528 |
-
],
|
| 529 |
-
"source": [
|
| 530 |
-
"pd.date_range(start=obspy.UTCDateTime(\"2019-07-04 17:33:49\").timestamp*1e9, periods=6000, freq='s')"
|
| 531 |
-
]
|
| 532 |
}
|
| 533 |
],
|
| 534 |
"metadata": {
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [
|
| 8 |
{
|
| 9 |
+
"data": {
|
| 10 |
+
"text/plain": [
|
| 11 |
+
"'hi!'"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
"execution_count": 1,
|
| 15 |
+
"metadata": {},
|
| 16 |
+
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
],
|
| 19 |
"source": [
|
| 20 |
+
"'hi!'"
|
| 21 |
]
|
| 22 |
},
|
| 23 |
{
|
| 24 |
"cell_type": "code",
|
| 25 |
+
"execution_count": 4,
|
| 26 |
"metadata": {},
|
| 27 |
"outputs": [
|
| 28 |
{
|
|
|
|
| 37 |
"name": "stdout",
|
| 38 |
"output_type": "stream",
|
| 39 |
"text": [
|
| 40 |
+
"Running on local URL: http://127.0.0.1:7862\n",
|
| 41 |
"\n",
|
| 42 |
"To create a public link, set `share=True` in `launch()`.\n"
|
| 43 |
]
|
|
|
|
| 45 |
{
|
| 46 |
"data": {
|
| 47 |
"text/html": [
|
| 48 |
+
"<div><iframe src=\"http://127.0.0.1:7862/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 49 |
],
|
| 50 |
"text/plain": [
|
| 51 |
"<IPython.core.display.HTML object>"
|
|
|
|
| 58 |
"data": {
|
| 59 |
"text/plain": []
|
| 60 |
},
|
| 61 |
+
"execution_count": 4,
|
| 62 |
"metadata": {},
|
| 63 |
"output_type": "execute_result"
|
| 64 |
}
|
|
|
|
| 87 |
"import matplotlib.pyplot as plt\n",
|
| 88 |
"import matplotlib.dates as mdates\n",
|
| 89 |
"\n",
|
| 90 |
+
"from glob import glob\n",
|
| 91 |
+
"\n",
|
| 92 |
"def make_prediction(waveform):\n",
|
| 93 |
" waveform = np.load(waveform)\n",
|
| 94 |
" processed_input = prepare_waveform(waveform)\n",
|
|
|
|
| 148 |
" plt.close(fig)\n",
|
| 149 |
" return image\n",
|
| 150 |
"\n",
|
| 151 |
+
"def variance_coefficient(residuals):\n",
|
| 152 |
+
" # calculate the variance of the residuals\n",
|
| 153 |
+
" var = residuals.var()\n",
|
| 154 |
+
" \n",
|
| 155 |
+
" # scale the variance to a coefficient between 0 and 1\n",
|
| 156 |
+
" coeff = 1 - (var / (residuals.max() - residuals.min()))\n",
|
| 157 |
+
" \n",
|
| 158 |
+
" return coeff\n",
|
| 159 |
+
"\n",
|
| 160 |
"def predict_on_section(client_name, timestamp, eq_lat, eq_lon, radius_km, source_depth_km, velocity_model):\n",
|
| 161 |
" distances, t0s, st_lats, st_lons, waveforms = [], [], [], [], []\n",
|
| 162 |
" \n",
|
|
|
|
| 178 |
" level='station')\n",
|
| 179 |
" \n",
|
| 180 |
" waveforms = []\n",
|
| 181 |
+
" cached_waveforms = glob(\"data/cached/*.mseed\")\n",
|
| 182 |
+
"\n",
|
| 183 |
" for network in inv:\n",
|
| 184 |
" for station in network:\n",
|
| 185 |
" try:\n",
|
|
|
|
| 194 |
" starttime = obspy.UTCDateTime(timestamp) + arrivals[0].time - 15\n",
|
| 195 |
" endtime = starttime + 60\n",
|
| 196 |
"\n",
|
| 197 |
+
" if f\"data/cached/{network.code}_{station.code}_{starttime}.mseed\" not in cached_waveforms:\n",
|
| 198 |
+
" waveform = client.get_waveforms(network=network.code, station=station.code, location=\"*\", channel=\"*\", \n",
|
| 199 |
+
" starttime=starttime, endtime=endtime)\n",
|
| 200 |
+
" waveform.write(f\"data/cached/{network.code}_{station.code}_{starttime}.mseed\", format=\"MSEED\")\n",
|
| 201 |
+
" else:\n",
|
| 202 |
+
" waveform = obspy.read(f\"data/cached/{network.code}_{station.code}_{starttime}.mseed\")\n",
|
| 203 |
" \n",
|
| 204 |
" waveform = waveform.select(channel=\"H[BH][ZNE]\")\n",
|
| 205 |
" waveform = waveform.merge(fill_value=0)\n",
|
|
|
|
| 231 |
" p_phases = output[:, 0]\n",
|
| 232 |
" s_phases = output[:, 1]\n",
|
| 233 |
"\n",
|
| 234 |
+
" # Max confidence - min variance \n",
|
| 235 |
+
" p_max_confidence = np.min([p_phases[i::len(waveforms)].std() for i in range(len(waveforms))]) \n",
|
| 236 |
+
" s_max_confidence = np.min([s_phases[i::len(waveforms)].std() for i in range(len(waveforms))])\n",
|
| 237 |
+
"\n",
|
| 238 |
+
" fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(10, 3), sharex=True)\n",
|
| 239 |
" for i in range(len(waveforms)):\n",
|
| 240 |
" current_P = p_phases[i::len(waveforms)]\n",
|
| 241 |
" current_S = s_phases[i::len(waveforms)]\n",
|
| 242 |
+
"\n",
|
| 243 |
" x = [t0s[i] + pd.Timedelta(seconds=k/100) for k in np.linspace(0,6000,6000)]\n",
|
| 244 |
" x = mdates.date2num(x)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
"\n",
|
| 246 |
+
" # Normalize confidence for the plot\n",
|
| 247 |
+
" p_conf = 1/(current_P.std()/p_max_confidence).item()\n",
|
| 248 |
+
" s_conf = 1/(current_S.std()/s_max_confidence).item()\n",
|
| 249 |
"\n",
|
| 250 |
+
" ax[0].plot(x, waveforms[i][0, 0]*10+distances[i]*111.2, color='black', alpha=0.5, lw=1)\n",
|
|
|
|
|
|
|
| 251 |
"\n",
|
| 252 |
+
" ax[0].scatter(x[int(current_P.mean()*waveforms[i][0].shape[-1])], waveforms[i][0, 0].mean()+distances[i]*111.2, color='r', alpha=p_conf, marker='|')\n",
|
| 253 |
+
" ax[0].scatter(x[int(current_S.mean()*waveforms[i][0].shape[-1])], waveforms[i][0, 0].mean()+distances[i]*111.2, color='b', alpha=s_conf, marker='|')\n",
|
| 254 |
+
" ax[0].set_ylabel('Z')\n",
|
| 255 |
"\n",
|
| 256 |
+
" ax[0].xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))\n",
|
| 257 |
+
" ax[0].xaxis.set_major_locator(mdates.SecondLocator(interval=5))\n",
|
| 258 |
+
" \n",
|
| 259 |
+
" ax[0].scatter(None, None, color='r', marker='|', label='P')\n",
|
| 260 |
+
" ax[0].scatter(None, None, color='b', marker='|', label='S')\n",
|
| 261 |
+
" ax[0].legend()\n",
|
| 262 |
+
"\n",
|
| 263 |
+
" ax[1].scatter(st_lats, st_lons, color='b', marker='d', label='Stations')\n",
|
| 264 |
+
" ax[1].scatter(eq_lat, eq_lon, color='r', marker='*', label='Earthquake')\n",
|
| 265 |
+
" ax[1].legend()\n",
|
| 266 |
+
" plt.subplots_adjust(hspace=0., wspace=0.)\n",
|
| 267 |
" \n",
|
| 268 |
" fig.canvas.draw();\n",
|
| 269 |
" image = np.array(fig.canvas.renderer.buffer_rgba())\n",
|
|
|
|
| 277 |
" learning_rate=3e-4)\n",
|
| 278 |
"model.eval()\n",
|
| 279 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
"with gr.Blocks() as demo:\n",
|
| 281 |
" gr.Markdown(\"# PhaseHunter\")\n",
|
| 282 |
" gr.Markdown(\"\"\"This app allows one to detect P and S seismic phases along with uncertainty of the detection. \n",
|
|
|
|
| 337 |
" radius_inputs = gr.Slider(minimum=1, \n",
|
| 338 |
" maximum=150, \n",
|
| 339 |
" value=50, label=\"Radius (km)\", \n",
|
| 340 |
+
" step=10,\n",
|
| 341 |
+
" info=\"\"\"Select the radius around the earthquake to download data from.\\n \n",
|
| 342 |
+
" Note that the larger the radius, the longer the app will take to run.\"\"\",\n",
|
| 343 |
" interactive=True)\n",
|
| 344 |
" \n",
|
| 345 |
" velocity_inputs = gr.Dropdown(\n",
|
|
|
|
| 352 |
" \n",
|
| 353 |
" \n",
|
| 354 |
" button = gr.Button(\"Predict phases\")\n",
|
| 355 |
+
" outputs_section = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n",
|
| 356 |
" \n",
|
| 357 |
" button.click(predict_on_section, \n",
|
| 358 |
" inputs=[client_inputs, timestamp_inputs, \n",
|
|
|
|
| 366 |
" Your waveform should be sampled at 100 sps and have 3 (Z, N, E) or 1 (Z) channels.\n",
|
| 367 |
" \"\"\")\n",
|
| 368 |
"\n",
|
|
|
|
|
|
|
| 369 |
"demo.launch()"
|
| 370 |
]
|
| 371 |
},
|
| 372 |
{
|
| 373 |
"cell_type": "code",
|
| 374 |
+
"execution_count": null,
|
| 375 |
"metadata": {},
|
| 376 |
+
"outputs": [],
|
| 377 |
+
"source": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
}
|
| 379 |
],
|
| 380 |
"metadata": {
|
data/.DS_Store
CHANGED
|
Binary files a/data/.DS_Store and b/data/.DS_Store differ
|
|
|
data/cached/CI_CCC_2019-07-04T17:33:40.494912Z.mseed
ADDED
|
Binary file (123 kB). View file
|
|
|
data/cached/CI_WCS2_2019-07-04T17:33:40.200950Z.mseed
ADDED
|
Binary file (111 kB). View file
|
|
|
data/cached/CI_WNM_2019-07-04T17:33:39.710492Z.mseed
ADDED
|
Binary file (65.5 kB). View file
|
|
|
data/cached/NP_1809_2019-07-04T17:33:42.451267Z.mseed
ADDED
|
Binary file (86 kB). View file
|
|
|