Spaces:
Runtime error
Runtime error
Added download for data
Browse files- Gradio_app.ipynb +22 -185
- app.py +18 -5
- data/picks.csv +4 -0
Gradio_app.ipynb
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stdout",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
-
"Running on local URL: http://127.0.0.1:
|
13 |
"\n",
|
14 |
"To create a public link, set `share=True` in `launch()`.\n"
|
15 |
]
|
@@ -17,7 +17,7 @@
|
|
17 |
{
|
18 |
"data": {
|
19 |
"text/html": [
|
20 |
-
"<div><iframe src=\"http://127.0.0.1:
|
21 |
],
|
22 |
"text/plain": [
|
23 |
"<IPython.core.display.HTML object>"
|
@@ -30,140 +30,9 @@
|
|
30 |
"data": {
|
31 |
"text/plain": []
|
32 |
},
|
33 |
-
"execution_count":
|
34 |
"metadata": {},
|
35 |
"output_type": "execute_result"
|
36 |
-
},
|
37 |
-
{
|
38 |
-
"name": "stdout",
|
39 |
-
"output_type": "stream",
|
40 |
-
"text": [
|
41 |
-
"Starting to download inventory\n",
|
42 |
-
"Finished downloading inventory\n",
|
43 |
-
"Processing CI.CCC...\n",
|
44 |
-
"Downloading waveform\n",
|
45 |
-
"Skipping CI_CCC_2019-07-04T17:33:40.494920Z\n",
|
46 |
-
"Processing CI.CLC...\n",
|
47 |
-
"Processing CI.JRC2...\n",
|
48 |
-
"Reading cached waveform\n",
|
49 |
-
"Added CI.JRC2 to the list of waveforms\n",
|
50 |
-
"Processing CI.LRL...\n",
|
51 |
-
"Reading cached waveform\n",
|
52 |
-
"Added CI.LRL to the list of waveforms\n",
|
53 |
-
"Processing CI.MPM...\n",
|
54 |
-
"Reading cached waveform\n",
|
55 |
-
"Processing CI.Q0072...\n",
|
56 |
-
"Reading cached waveform\n",
|
57 |
-
"Processing CI.SLA...\n",
|
58 |
-
"Reading cached waveform\n",
|
59 |
-
"Added CI.SLA to the list of waveforms\n",
|
60 |
-
"Processing CI.SRT...\n",
|
61 |
-
"Reading cached waveform\n",
|
62 |
-
"Added CI.SRT to the list of waveforms\n",
|
63 |
-
"Processing CI.TOW2...\n",
|
64 |
-
"Reading cached waveform\n",
|
65 |
-
"Added CI.TOW2 to the list of waveforms\n",
|
66 |
-
"Processing CI.WBM...\n",
|
67 |
-
"Downloading waveform\n",
|
68 |
-
"Skipping CI_WBM_2019-07-04T17:33:40.063616Z\n",
|
69 |
-
"Processing CI.WCS2...\n",
|
70 |
-
"Downloading waveform\n",
|
71 |
-
"Skipping CI_WCS2_2019-07-04T17:33:40.200958Z\n",
|
72 |
-
"Processing CI.WMF...\n",
|
73 |
-
"Reading cached waveform\n",
|
74 |
-
"Added CI.WMF to the list of waveforms\n",
|
75 |
-
"Processing CI.WNM...\n",
|
76 |
-
"Reading cached waveform\n",
|
77 |
-
"Processing CI.WRC2...\n",
|
78 |
-
"Downloading waveform\n",
|
79 |
-
"Skipping CI_WRC2_2019-07-04T17:33:38.698099Z\n",
|
80 |
-
"Processing CI.WRV2...\n",
|
81 |
-
"Reading cached waveform\n",
|
82 |
-
"Processing CI.WVP2...\n",
|
83 |
-
"Downloading waveform\n",
|
84 |
-
"Skipping CI_WVP2_2019-07-04T17:33:39.650402Z\n",
|
85 |
-
"Processing NP.1809...\n",
|
86 |
-
"Reading cached waveform\n",
|
87 |
-
"Processing NP.5419...\n",
|
88 |
-
"Reading cached waveform\n",
|
89 |
-
"Processing PB.B916...\n",
|
90 |
-
"Reading cached waveform\n",
|
91 |
-
"Processing PB.B917...\n",
|
92 |
-
"Reading cached waveform\n",
|
93 |
-
"Processing PB.B918...\n",
|
94 |
-
"Reading cached waveform\n",
|
95 |
-
"Processing PB.B921...\n",
|
96 |
-
"Reading cached waveform\n",
|
97 |
-
"Starting to run predictions\n"
|
98 |
-
]
|
99 |
-
},
|
100 |
-
{
|
101 |
-
"name": "stderr",
|
102 |
-
"output_type": "stream",
|
103 |
-
"text": [
|
104 |
-
"/var/folders/_g/3q5q8_dj0ydcpktxlwxb5vrh0000gq/T/ipykernel_27324/1938231065.py:224: FutureWarning: The input object of type 'Tensor' is an array-like implementing one of the corresponding protocols (`__array__`, `__array_interface__` or `__array_struct__`); but not a sequence (or 0-D). In the future, this object will be coerced as if it was first converted using `np.array(obj)`. To retain the old behaviour, you have to either modify the type 'Tensor', or assign to an empty array created with `np.empty(correct_shape, dtype=object)`.\n",
|
105 |
-
" waveforms = np.array(waveforms)[selection_indexes]\n",
|
106 |
-
"/var/folders/_g/3q5q8_dj0ydcpktxlwxb5vrh0000gq/T/ipykernel_27324/1938231065.py:224: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
|
107 |
-
" waveforms = np.array(waveforms)[selection_indexes]\n",
|
108 |
-
"/var/folders/_g/3q5q8_dj0ydcpktxlwxb5vrh0000gq/T/ipykernel_27324/1938231065.py:231: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).\n",
|
109 |
-
" waveforms = [torch.tensor(waveform) for waveform in waveforms]\n"
|
110 |
-
]
|
111 |
-
},
|
112 |
-
{
|
113 |
-
"name": "stdout",
|
114 |
-
"output_type": "stream",
|
115 |
-
"text": [
|
116 |
-
"Starting plotting 3 waveforms\n",
|
117 |
-
"Fetching topography\n",
|
118 |
-
"Plotting topo\n"
|
119 |
-
]
|
120 |
-
},
|
121 |
-
{
|
122 |
-
"name": "stderr",
|
123 |
-
"output_type": "stream",
|
124 |
-
"text": [
|
125 |
-
"/Users/anovosel/miniconda3/envs/phasehunter/lib/python3.11/site-packages/bmi_topography/api_key.py:49: UserWarning: You are using a demo key to fetch data from OpenTopography, functionality will be limited. See https://bmi-topography.readthedocs.io/en/latest/#api-key for more information.\n",
|
126 |
-
" warnings.warn(\n"
|
127 |
-
]
|
128 |
-
},
|
129 |
-
{
|
130 |
-
"name": "stdout",
|
131 |
-
"output_type": "stream",
|
132 |
-
"text": [
|
133 |
-
"Plotting waveform 1/3\n",
|
134 |
-
"Station 36.11758, -117.85486 has P velocity 4.987805380766392 and S velocity 2.9782985042350987\n",
|
135 |
-
"Plotting waveform 2/3\n"
|
136 |
-
]
|
137 |
-
},
|
138 |
-
{
|
139 |
-
"name": "stderr",
|
140 |
-
"output_type": "stream",
|
141 |
-
"text": [
|
142 |
-
"/var/folders/_g/3q5q8_dj0ydcpktxlwxb5vrh0000gq/T/ipykernel_27324/1938231065.py:299: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.\n",
|
143 |
-
" output_picks = output_picks.append(pd.DataFrame({'station_name': [names[i]], 'starttime' : [str(t0s[i])],\n",
|
144 |
-
"/var/folders/_g/3q5q8_dj0ydcpktxlwxb5vrh0000gq/T/ipykernel_27324/1938231065.py:299: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.\n",
|
145 |
-
" output_picks = output_picks.append(pd.DataFrame({'station_name': [names[i]], 'starttime' : [str(t0s[i])],\n"
|
146 |
-
]
|
147 |
-
},
|
148 |
-
{
|
149 |
-
"name": "stdout",
|
150 |
-
"output_type": "stream",
|
151 |
-
"text": [
|
152 |
-
"Station 35.98249, -117.80885 has P velocity 4.255522557803516 and S velocity 2.2929437916670583\n",
|
153 |
-
"Plotting waveform 3/3\n",
|
154 |
-
"Station 35.69235, -117.75051 has P velocity 2.979034174961547 and S velocity 1.3728192788753049\n",
|
155 |
-
"Plotting stations\n"
|
156 |
-
]
|
157 |
-
},
|
158 |
-
{
|
159 |
-
"name": "stderr",
|
160 |
-
"output_type": "stream",
|
161 |
-
"text": [
|
162 |
-
"/var/folders/_g/3q5q8_dj0ydcpktxlwxb5vrh0000gq/T/ipykernel_27324/1938231065.py:299: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.\n",
|
163 |
-
" output_picks = output_picks.append(pd.DataFrame({'station_name': [names[i]], 'starttime' : [str(t0s[i])],\n",
|
164 |
-
"/var/folders/_g/3q5q8_dj0ydcpktxlwxb5vrh0000gq/T/ipykernel_27324/1938231065.py:324: UserWarning: FixedFormatter should only be used together with FixedLocator\n",
|
165 |
-
" ax[i].set_xticklabels(ax[i].get_xticks(), rotation = 50)\n"
|
166 |
-
]
|
167 |
}
|
168 |
],
|
169 |
"source": [
|
@@ -174,6 +43,7 @@
|
|
174 |
"import pandas as pd\n",
|
175 |
"from phasehunter.data_preparation import prepare_waveform\n",
|
176 |
"import torch\n",
|
|
|
177 |
"\n",
|
178 |
"from scipy.stats import gaussian_kde\n",
|
179 |
"from bmi_topography import Topography\n",
|
@@ -510,7 +380,16 @@
|
|
510 |
" image = np.array(fig.canvas.renderer.buffer_rgba())\n",
|
511 |
" plt.close(fig)\n",
|
512 |
"\n",
|
513 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
514 |
"\n",
|
515 |
"model = torch.jit.load(\"model.pt\")\n",
|
516 |
"\n",
|
@@ -638,65 +517,23 @@
|
|
638 |
" \n",
|
639 |
" button = gr.Button(\"Predict phases\")\n",
|
640 |
" output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n",
|
641 |
-
"
|
642 |
-
"
|
643 |
-
"
|
|
|
|
|
|
|
644 |
"\n",
|
645 |
" button.click(predict_on_section, \n",
|
646 |
" inputs=[client_inputs, timestamp_inputs, \n",
|
647 |
" eq_lat_inputs, eq_lon_inputs, \n",
|
648 |
" radius_inputs, source_depth_inputs, \n",
|
649 |
" velocity_inputs, max_waveforms_inputs],\n",
|
650 |
-
" outputs=[output_image, output_picks])\n",
|
651 |
"\n",
|
652 |
"demo.launch()"
|
653 |
]
|
654 |
},
|
655 |
-
{
|
656 |
-
"cell_type": "code",
|
657 |
-
"execution_count": 24,
|
658 |
-
"metadata": {},
|
659 |
-
"outputs": [
|
660 |
-
{
|
661 |
-
"data": {
|
662 |
-
"text/html": [
|
663 |
-
"\n",
|
664 |
-
"<span style=\"animation: arrow-anim 10s linear infinite; display: inline-block; transform: rotate(45deg) translateX(-20px);\">🏹</span>\n",
|
665 |
-
"\n",
|
666 |
-
"<style>\n",
|
667 |
-
" @keyframes arrow-anim {\n",
|
668 |
-
" 0% { transform: translateX(-20px); }\n",
|
669 |
-
" 50% { transform: translateX(20px); }\n",
|
670 |
-
" 100% { transform: translateX(-20px); }\n",
|
671 |
-
" }\n",
|
672 |
-
"</style>\n",
|
673 |
-
"\n",
|
674 |
-
"\n"
|
675 |
-
],
|
676 |
-
"text/plain": [
|
677 |
-
"<IPython.core.display.HTML object>"
|
678 |
-
]
|
679 |
-
},
|
680 |
-
"metadata": {},
|
681 |
-
"output_type": "display_data"
|
682 |
-
}
|
683 |
-
],
|
684 |
-
"source": [
|
685 |
-
"%%html\n",
|
686 |
-
"\n",
|
687 |
-
"<span style=\"animation: arrow-anim 10s linear infinite; display: inline-block; transform: rotate(45deg) translateX(-20px);\">🏹</span>\n",
|
688 |
-
"\n",
|
689 |
-
"<style>\n",
|
690 |
-
" @keyframes arrow-anim {\n",
|
691 |
-
" 0% { transform: translateX(-20px); }\n",
|
692 |
-
" 50% { transform: translateX(20px); }\n",
|
693 |
-
" 100% { transform: translateX(-20px); }\n",
|
694 |
-
" }\n",
|
695 |
-
"</style>\n",
|
696 |
-
"\n",
|
697 |
-
"\n"
|
698 |
-
]
|
699 |
-
},
|
700 |
{
|
701 |
"cell_type": "code",
|
702 |
"execution_count": null,
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 55,
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
9 |
"name": "stdout",
|
10 |
"output_type": "stream",
|
11 |
"text": [
|
12 |
+
"Running on local URL: http://127.0.0.1:7901\n",
|
13 |
"\n",
|
14 |
"To create a public link, set `share=True` in `launch()`.\n"
|
15 |
]
|
|
|
17 |
{
|
18 |
"data": {
|
19 |
"text/html": [
|
20 |
+
"<div><iframe src=\"http://127.0.0.1:7901/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
21 |
],
|
22 |
"text/plain": [
|
23 |
"<IPython.core.display.HTML object>"
|
|
|
30 |
"data": {
|
31 |
"text/plain": []
|
32 |
},
|
33 |
+
"execution_count": 55,
|
34 |
"metadata": {},
|
35 |
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
],
|
38 |
"source": [
|
|
|
43 |
"import pandas as pd\n",
|
44 |
"from phasehunter.data_preparation import prepare_waveform\n",
|
45 |
"import torch\n",
|
46 |
+
"import io\n",
|
47 |
"\n",
|
48 |
"from scipy.stats import gaussian_kde\n",
|
49 |
"from bmi_topography import Topography\n",
|
|
|
380 |
" image = np.array(fig.canvas.renderer.buffer_rgba())\n",
|
381 |
" plt.close(fig)\n",
|
382 |
"\n",
|
383 |
+
" output_picks.to_csv('data/picks.csv', index=False)\n",
|
384 |
+
" output_csv = 'data/picks.csv'\n",
|
385 |
+
"\n",
|
386 |
+
" return image, output_picks, output_csv\n",
|
387 |
+
"\n",
|
388 |
+
"def download_picks(output_picks):\n",
|
389 |
+
" output_csv = io.BytesIO()\n",
|
390 |
+
" output_picks.to_csv(output_csv, index=False)\n",
|
391 |
+
" output_csv.seek(0)\n",
|
392 |
+
" return output_csv\n",
|
393 |
"\n",
|
394 |
"model = torch.jit.load(\"model.pt\")\n",
|
395 |
"\n",
|
|
|
517 |
" \n",
|
518 |
" button = gr.Button(\"Predict phases\")\n",
|
519 |
" output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n",
|
520 |
+
"\n",
|
521 |
+
" with gr.Row():\n",
|
522 |
+
" output_picks = gr.Dataframe(label='Pick data', \n",
|
523 |
+
" type='pandas', \n",
|
524 |
+
" interactive=False)\n",
|
525 |
+
" output_csv = gr.File(label=\"Output File\", file_types=[\".csv\"])\n",
|
526 |
"\n",
|
527 |
" button.click(predict_on_section, \n",
|
528 |
" inputs=[client_inputs, timestamp_inputs, \n",
|
529 |
" eq_lat_inputs, eq_lon_inputs, \n",
|
530 |
" radius_inputs, source_depth_inputs, \n",
|
531 |
" velocity_inputs, max_waveforms_inputs],\n",
|
532 |
+
" outputs=[output_image, output_picks, output_csv])\n",
|
533 |
"\n",
|
534 |
"demo.launch()"
|
535 |
]
|
536 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
{
|
538 |
"cell_type": "code",
|
539 |
"execution_count": null,
|
app.py
CHANGED
@@ -5,6 +5,7 @@ import numpy as np
|
|
5 |
import pandas as pd
|
6 |
from phasehunter.data_preparation import prepare_waveform
|
7 |
import torch
|
|
|
8 |
|
9 |
from scipy.stats import gaussian_kde
|
10 |
from bmi_topography import Topography
|
@@ -341,7 +342,16 @@ def predict_on_section(client_name, timestamp, eq_lat, eq_lon, radius_km, source
|
|
341 |
image = np.array(fig.canvas.renderer.buffer_rgba())
|
342 |
plt.close(fig)
|
343 |
|
344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
|
346 |
model = torch.jit.load("model.pt")
|
347 |
|
@@ -469,15 +479,18 @@ with gr.Blocks() as demo:
|
|
469 |
|
470 |
button = gr.Button("Predict phases")
|
471 |
output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)
|
472 |
-
|
473 |
-
|
474 |
-
|
|
|
|
|
|
|
475 |
|
476 |
button.click(predict_on_section,
|
477 |
inputs=[client_inputs, timestamp_inputs,
|
478 |
eq_lat_inputs, eq_lon_inputs,
|
479 |
radius_inputs, source_depth_inputs,
|
480 |
velocity_inputs, max_waveforms_inputs],
|
481 |
-
outputs=[output_image, output_picks])
|
482 |
|
483 |
demo.launch()
|
|
|
5 |
import pandas as pd
|
6 |
from phasehunter.data_preparation import prepare_waveform
|
7 |
import torch
|
8 |
+
import io
|
9 |
|
10 |
from scipy.stats import gaussian_kde
|
11 |
from bmi_topography import Topography
|
|
|
342 |
image = np.array(fig.canvas.renderer.buffer_rgba())
|
343 |
plt.close(fig)
|
344 |
|
345 |
+
output_picks.to_csv('data/picks.csv', index=False)
|
346 |
+
output_csv = 'data/picks.csv'
|
347 |
+
|
348 |
+
return image, output_picks, output_csv
|
349 |
+
|
350 |
+
def download_picks(output_picks):
|
351 |
+
output_csv = io.BytesIO()
|
352 |
+
output_picks.to_csv(output_csv, index=False)
|
353 |
+
output_csv.seek(0)
|
354 |
+
return output_csv
|
355 |
|
356 |
model = torch.jit.load("model.pt")
|
357 |
|
|
|
479 |
|
480 |
button = gr.Button("Predict phases")
|
481 |
output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)
|
482 |
+
|
483 |
+
with gr.Row():
|
484 |
+
output_picks = gr.Dataframe(label='Pick data',
|
485 |
+
type='pandas',
|
486 |
+
interactive=False)
|
487 |
+
output_csv = gr.File(label="Output File", file_types=[".csv"])
|
488 |
|
489 |
button.click(predict_on_section,
|
490 |
inputs=[client_inputs, timestamp_inputs,
|
491 |
eq_lat_inputs, eq_lon_inputs,
|
492 |
radius_inputs, source_depth_inputs,
|
493 |
velocity_inputs, max_waveforms_inputs],
|
494 |
+
outputs=[output_image, output_picks, output_csv])
|
495 |
|
496 |
demo.launch()
|
data/picks.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
station_name,starttime,"p_phase, s","p_uncertainty, s","s_phase, s","s_uncertainty, s","velocity_p, km/s","velocity_s, km/s"
|
2 |
+
CI.SRT,2019-07-04T17:33:38.029990Z,5.195954322814941,0.4883878491818905,11.277575492858887,1.6350263357162476,2.9791118172972846,1.3725759526093728
|
3 |
+
CI.JRC2,2019-07-04T17:33:39.947494Z,7.11562442779541,0.4898720048367977,13.208794593811035,1.644418090581894,4.255539668245224,2.29247429065224
|
4 |
+
CI.WMF,2019-07-04T17:33:41.867962Z,9.043024063110352,0.4864034615457058,15.146604537963867,1.6339519992470741,4.987844305676596,2.9779080827144124
|