Spaces:
Runtime error
Runtime error
Added explanations
Browse files- Gradio_app.ipynb +20 -13
- app.py +16 -9
Gradio_app.ipynb
CHANGED
@@ -17,14 +17,14 @@
|
|
17 |
},
|
18 |
{
|
19 |
"cell_type": "code",
|
20 |
-
"execution_count":
|
21 |
"metadata": {},
|
22 |
"outputs": [
|
23 |
{
|
24 |
"name": "stdout",
|
25 |
"output_type": "stream",
|
26 |
"text": [
|
27 |
-
"Running on local URL: http://127.0.0.1:
|
28 |
"\n",
|
29 |
"To create a public link, set `share=True` in `launch()`.\n"
|
30 |
]
|
@@ -32,7 +32,7 @@
|
|
32 |
{
|
33 |
"data": {
|
34 |
"text/html": [
|
35 |
-
"<div><iframe src=\"http://127.0.0.1:
|
36 |
],
|
37 |
"text/plain": [
|
38 |
"<IPython.core.display.HTML object>"
|
@@ -45,7 +45,7 @@
|
|
45 |
"data": {
|
46 |
"text/plain": []
|
47 |
},
|
48 |
-
"execution_count":
|
49 |
"metadata": {},
|
50 |
"output_type": "execute_result"
|
51 |
}
|
@@ -130,7 +130,7 @@
|
|
130 |
" a.axvline(s_phase.mean()*processed_input.shape[-1], color='b', linestyle='--', label='S')\n",
|
131 |
"\n",
|
132 |
" ax[-1].set_xlabel('Time, samples')\n",
|
133 |
-
" ax[-1].set_ylabel('Uncert
|
134 |
" ax[-1].legend()\n",
|
135 |
"\n",
|
136 |
" plt.subplots_adjust(hspace=0., wspace=0.)\n",
|
@@ -319,8 +319,9 @@
|
|
319 |
" ax[1].imshow(hillshade, cmap=\"Greys\", alpha=0.5)\n",
|
320 |
"\n",
|
321 |
" output_picks = pd.DataFrame({'station_name' : [], 'starttime' : [], \n",
|
322 |
-
" 'p_phase' : [], 'p_uncertainty
|
323 |
-
" '
|
|
|
324 |
" \n",
|
325 |
" \n",
|
326 |
" for i in range(len(waveforms)):\n",
|
@@ -352,9 +353,9 @@
|
|
352 |
" print(f\"Station {st_lats[i]}, {st_lons[i]} has P velocity {velocity_p} and S velocity {velocity_s}\")\n",
|
353 |
"\n",
|
354 |
" output_picks = output_picks.append(pd.DataFrame({'station_name': [names[i]], 'starttime' : [str(t0s[i])], \n",
|
355 |
-
" 'p_phase' : [(delta_t+current_P.mean()*60).item()], 'p_uncertainty' : [current_P.std().item()*60], \n",
|
356 |
-
" 's_phase' : [(delta_t+current_S.mean()*60).item()], 's_uncertainty' : [current_S.std().item()*60],\n",
|
357 |
-
" 'velocity_p' : [velocity_p], 'velocity_s' : [velocity_s]}))\n",
|
358 |
" \n",
|
359 |
" # Generate an array from st_lat to eq_lat and from st_lon to eq_lon\n",
|
360 |
" x = np.linspace(st_lons[i], eq_lon, 50)\n",
|
@@ -445,8 +446,12 @@
|
|
445 |
" button.click(mark_phases, inputs=[inputs, upload], outputs=outputs)\n",
|
446 |
" \n",
|
447 |
" with gr.Tab(\"Select earthquake from catalogue\"):\n",
|
448 |
-
" gr.Markdown(\"\"\"
|
449 |
-
"
|
|
|
|
|
|
|
|
|
450 |
" with gr.Row(): \n",
|
451 |
" client_inputs = gr.Dropdown(\n",
|
452 |
" choices = list(URL_MAPPINGS.keys()), \n",
|
@@ -513,7 +518,9 @@
|
|
513 |
" \n",
|
514 |
" button = gr.Button(\"Predict phases\")\n",
|
515 |
" output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n",
|
516 |
-
" output_picks = gr.Dataframe(label='
|
|
|
|
|
517 |
"\n",
|
518 |
" button.click(predict_on_section, \n",
|
519 |
" inputs=[client_inputs, timestamp_inputs, \n",
|
|
|
17 |
},
|
18 |
{
|
19 |
"cell_type": "code",
|
20 |
+
"execution_count": 29,
|
21 |
"metadata": {},
|
22 |
"outputs": [
|
23 |
{
|
24 |
"name": "stdout",
|
25 |
"output_type": "stream",
|
26 |
"text": [
|
27 |
+
"Running on local URL: http://127.0.0.1:7875\n",
|
28 |
"\n",
|
29 |
"To create a public link, set `share=True` in `launch()`.\n"
|
30 |
]
|
|
|
32 |
{
|
33 |
"data": {
|
34 |
"text/html": [
|
35 |
+
"<div><iframe src=\"http://127.0.0.1:7875/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
36 |
],
|
37 |
"text/plain": [
|
38 |
"<IPython.core.display.HTML object>"
|
|
|
45 |
"data": {
|
46 |
"text/plain": []
|
47 |
},
|
48 |
+
"execution_count": 29,
|
49 |
"metadata": {},
|
50 |
"output_type": "execute_result"
|
51 |
}
|
|
|
130 |
" a.axvline(s_phase.mean()*processed_input.shape[-1], color='b', linestyle='--', label='S')\n",
|
131 |
"\n",
|
132 |
" ax[-1].set_xlabel('Time, samples')\n",
|
133 |
+
" ax[-1].set_ylabel('Uncert., samples')\n",
|
134 |
" ax[-1].legend()\n",
|
135 |
"\n",
|
136 |
" plt.subplots_adjust(hspace=0., wspace=0.)\n",
|
|
|
319 |
" ax[1].imshow(hillshade, cmap=\"Greys\", alpha=0.5)\n",
|
320 |
"\n",
|
321 |
" output_picks = pd.DataFrame({'station_name' : [], 'starttime' : [], \n",
|
322 |
+
" 'p_phase, s' : [], 'p_uncertainty, s' : [], \n",
|
323 |
+
" 's_phase, s' : [], 's_uncertainty, s' : [],\n",
|
324 |
+
" 'velocity_p, km/s' : [], 'velocity_s, km/s' : []})\n",
|
325 |
" \n",
|
326 |
" \n",
|
327 |
" for i in range(len(waveforms)):\n",
|
|
|
353 |
" print(f\"Station {st_lats[i]}, {st_lons[i]} has P velocity {velocity_p} and S velocity {velocity_s}\")\n",
|
354 |
"\n",
|
355 |
" output_picks = output_picks.append(pd.DataFrame({'station_name': [names[i]], 'starttime' : [str(t0s[i])], \n",
|
356 |
+
" 'p_phase, s' : [(delta_t+current_P.mean()*60).item()], 'p_uncertainty, s' : [current_P.std().item()*60], \n",
|
357 |
+
" 's_phase, s' : [(delta_t+current_S.mean()*60).item()], 's_uncertainty, s' : [current_S.std().item()*60],\n",
|
358 |
+
" 'velocity_p, km/s' : [velocity_p], 'velocity_s, km/s' : [velocity_s]}))\n",
|
359 |
" \n",
|
360 |
" # Generate an array from st_lat to eq_lat and from st_lon to eq_lon\n",
|
361 |
" x = np.linspace(st_lons[i], eq_lon, 50)\n",
|
|
|
446 |
" button.click(mark_phases, inputs=[inputs, upload], outputs=outputs)\n",
|
447 |
" \n",
|
448 |
" with gr.Tab(\"Select earthquake from catalogue\"):\n",
|
449 |
+
" gr.Markdown(\"\"\"\n",
|
450 |
+
" Select an earthquake from the global earthquake catalogue and the app will download the waveform from the FDSN client of your choice.\n",
|
451 |
+
" Pick data for each waveform is reported in seconds from the start of the waveform.\n",
|
452 |
+
" Velocities are derived from distance and travel time determined by PhaseHunter picks ($v = \\mathrm{distance}/\\mathrm{predicted_pick_time}$).\n",
|
453 |
+
" Backround of velocity plot is colored by DEM.\n",
|
454 |
+
" \"\"\")\n",
|
455 |
" with gr.Row(): \n",
|
456 |
" client_inputs = gr.Dropdown(\n",
|
457 |
" choices = list(URL_MAPPINGS.keys()), \n",
|
|
|
518 |
" \n",
|
519 |
" button = gr.Button(\"Predict phases\")\n",
|
520 |
" output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n",
|
521 |
+
" output_picks = gr.Dataframe(label='Pick data', \n",
|
522 |
+
" type='pandas', \n",
|
523 |
+
" interactive=False)\n",
|
524 |
"\n",
|
525 |
" button.click(predict_on_section, \n",
|
526 |
" inputs=[client_inputs, timestamp_inputs, \n",
|
app.py
CHANGED
@@ -77,7 +77,7 @@ def mark_phases(waveform, uploaded_file):
|
|
77 |
a.axvline(s_phase.mean()*processed_input.shape[-1], color='b', linestyle='--', label='S')
|
78 |
|
79 |
ax[-1].set_xlabel('Time, samples')
|
80 |
-
ax[-1].set_ylabel('Uncert
|
81 |
ax[-1].legend()
|
82 |
|
83 |
plt.subplots_adjust(hspace=0., wspace=0.)
|
@@ -266,8 +266,9 @@ def predict_on_section(client_name, timestamp, eq_lat, eq_lon, radius_km, source
|
|
266 |
ax[1].imshow(hillshade, cmap="Greys", alpha=0.5)
|
267 |
|
268 |
output_picks = pd.DataFrame({'station_name' : [], 'starttime' : [],
|
269 |
-
'p_phase' : [], 'p_uncertainty
|
270 |
-
'
|
|
|
271 |
|
272 |
|
273 |
for i in range(len(waveforms)):
|
@@ -299,9 +300,9 @@ def predict_on_section(client_name, timestamp, eq_lat, eq_lon, radius_km, source
|
|
299 |
print(f"Station {st_lats[i]}, {st_lons[i]} has P velocity {velocity_p} and S velocity {velocity_s}")
|
300 |
|
301 |
output_picks = output_picks.append(pd.DataFrame({'station_name': [names[i]], 'starttime' : [str(t0s[i])],
|
302 |
-
'p_phase' : [(delta_t+current_P.mean()*60).item()], 'p_uncertainty' : [current_P.std().item()*60],
|
303 |
-
's_phase' : [(delta_t+current_S.mean()*60).item()], 's_uncertainty' : [current_S.std().item()*60],
|
304 |
-
'velocity_p' : [velocity_p], 'velocity_s' : [velocity_s]}))
|
305 |
|
306 |
# Generate an array from st_lat to eq_lat and from st_lon to eq_lon
|
307 |
x = np.linspace(st_lons[i], eq_lon, 50)
|
@@ -392,8 +393,12 @@ with gr.Blocks() as demo:
|
|
392 |
button.click(mark_phases, inputs=[inputs, upload], outputs=outputs)
|
393 |
|
394 |
with gr.Tab("Select earthquake from catalogue"):
|
395 |
-
gr.Markdown("""
|
396 |
-
|
|
|
|
|
|
|
|
|
397 |
with gr.Row():
|
398 |
client_inputs = gr.Dropdown(
|
399 |
choices = list(URL_MAPPINGS.keys()),
|
@@ -460,7 +465,9 @@ with gr.Blocks() as demo:
|
|
460 |
|
461 |
button = gr.Button("Predict phases")
|
462 |
output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)
|
463 |
-
output_picks = gr.Dataframe(label='
|
|
|
|
|
464 |
|
465 |
button.click(predict_on_section,
|
466 |
inputs=[client_inputs, timestamp_inputs,
|
|
|
77 |
a.axvline(s_phase.mean()*processed_input.shape[-1], color='b', linestyle='--', label='S')
|
78 |
|
79 |
ax[-1].set_xlabel('Time, samples')
|
80 |
+
ax[-1].set_ylabel('Uncert., samples')
|
81 |
ax[-1].legend()
|
82 |
|
83 |
plt.subplots_adjust(hspace=0., wspace=0.)
|
|
|
266 |
ax[1].imshow(hillshade, cmap="Greys", alpha=0.5)
|
267 |
|
268 |
output_picks = pd.DataFrame({'station_name' : [], 'starttime' : [],
|
269 |
+
'p_phase, s' : [], 'p_uncertainty, s' : [],
|
270 |
+
's_phase, s' : [], 's_uncertainty, s' : [],
|
271 |
+
'velocity_p, km/s' : [], 'velocity_s, km/s' : []})
|
272 |
|
273 |
|
274 |
for i in range(len(waveforms)):
|
|
|
300 |
print(f"Station {st_lats[i]}, {st_lons[i]} has P velocity {velocity_p} and S velocity {velocity_s}")
|
301 |
|
302 |
output_picks = output_picks.append(pd.DataFrame({'station_name': [names[i]], 'starttime' : [str(t0s[i])],
|
303 |
+
'p_phase, s' : [(delta_t+current_P.mean()*60).item()], 'p_uncertainty, s' : [current_P.std().item()*60],
|
304 |
+
's_phase, s' : [(delta_t+current_S.mean()*60).item()], 's_uncertainty, s' : [current_S.std().item()*60],
|
305 |
+
'velocity_p, km/s' : [velocity_p], 'velocity_s, km/s' : [velocity_s]}))
|
306 |
|
307 |
# Generate an array from st_lat to eq_lat and from st_lon to eq_lon
|
308 |
x = np.linspace(st_lons[i], eq_lon, 50)
|
|
|
393 |
button.click(mark_phases, inputs=[inputs, upload], outputs=outputs)
|
394 |
|
395 |
with gr.Tab("Select earthquake from catalogue"):
|
396 |
+
gr.Markdown("""
|
397 |
+
Select an earthquake from the global earthquake catalogue and the app will download the waveform from the FDSN client of your choice.
|
398 |
+
Pick data for each waveform is reported in seconds from the start of the waveform.
|
399 |
+
Velocities are derived from distance and travel time determined by PhaseHunter picks ($v = \mathrm{distance}/\mathrm{predicted_pick_time}$).
|
400 |
+
Backround of velocity plot is colored by DEM.
|
401 |
+
""")
|
402 |
with gr.Row():
|
403 |
client_inputs = gr.Dropdown(
|
404 |
choices = list(URL_MAPPINGS.keys()),
|
|
|
465 |
|
466 |
button = gr.Button("Predict phases")
|
467 |
output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)
|
468 |
+
output_picks = gr.Dataframe(label='Pick data',
|
469 |
+
type='pandas',
|
470 |
+
interactive=False)
|
471 |
|
472 |
button.click(predict_on_section,
|
473 |
inputs=[client_inputs, timestamp_inputs,
|