crimeacs commited on
Commit
d5f505f
1 Parent(s): 545314e

Fixed button bug and added contacts

Browse files
.vscode/settings.json CHANGED
@@ -1,3 +1,6 @@
1
  {
2
- "python.formatting.provider": "black"
 
 
 
3
  }
 
1
  {
2
+ "python.formatting.provider": "none",
3
+ "[python]": {
4
+ "editor.defaultFormatter": "ms-python.black-formatter"
5
+ }
6
  }
Gradio_app.ipynb CHANGED
@@ -2,14 +2,14 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 1,
6
  "metadata": {},
7
  "outputs": [
8
  {
9
  "name": "stdout",
10
  "output_type": "stream",
11
  "text": [
12
- "Running on local URL: http://127.0.0.1:7860\n",
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:7860/\" 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,7 +30,7 @@
30
  "data": {
31
  "text/plain": []
32
  },
33
- "execution_count": 1,
34
  "metadata": {},
35
  "output_type": "execute_result"
36
  }
@@ -667,6 +667,7 @@
667
  " <li>Select an earthquake from the global earthquake catalogue and PhaseHunter will analyze seismic stations in the given radius.</li>\n",
668
  " <li>Waveforms should be sampled at 100 samples/sec and have 3 (Z, N, E) or 1 (Z) channels. PhaseHunter analyzes the first 6000 samples of your file.</li>\n",
669
  " </ul>\n",
 
670
  "</div>\n",
671
  "\"\"\")\n",
672
  " with gr.Tab(\"Try on a single station\"):\n",
@@ -810,7 +811,7 @@
810
  " interactive=True,\n",
811
  " )\n",
812
  " \n",
813
- " button = gr.Button(\"Predict phases\")\n",
814
  " output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n",
815
  " \n",
816
  " with gr.Row():\n",
@@ -839,7 +840,7 @@
839
  " interactive=False)\n",
840
  " output_csv = gr.File(label=\"Output File\", file_types=[\".csv\"])\n",
841
  "\n",
842
- " button.click(predict_on_section, \n",
843
  " inputs=[client_inputs, timestamp_inputs, \n",
844
  " eq_lat_inputs, eq_lon_inputs, \n",
845
  " radius_inputs, source_depth_inputs, \n",
@@ -1465,7 +1466,7 @@
1465
  "name": "python",
1466
  "nbconvert_exporter": "python",
1467
  "pygments_lexer": "ipython3",
1468
- "version": "3.11.2"
1469
  },
1470
  "orig_nbformat": 4
1471
  },
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 5,
6
  "metadata": {},
7
  "outputs": [
8
  {
9
  "name": "stdout",
10
  "output_type": "stream",
11
  "text": [
12
+ "Running on local URL: http://127.0.0.1:7862\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:7862/\" 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": 5,
34
  "metadata": {},
35
  "output_type": "execute_result"
36
  }
 
667
  " <li>Select an earthquake from the global earthquake catalogue and PhaseHunter will analyze seismic stations in the given radius.</li>\n",
668
  " <li>Waveforms should be sampled at 100 samples/sec and have 3 (Z, N, E) or 1 (Z) channels. PhaseHunter analyzes the first 6000 samples of your file.</li>\n",
669
  " </ul>\n",
670
+ " <p style=\"font-size: 16px; margin-bottom: 20px;\">Please contact me at anovosel@stanford.edu with questions and feedback</p>\n",
671
  "</div>\n",
672
  "\"\"\")\n",
673
  " with gr.Tab(\"Try on a single station\"):\n",
 
811
  " interactive=True,\n",
812
  " )\n",
813
  " \n",
814
+ " button_phases = gr.Button(\"Predict phases\")\n",
815
  " output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n",
816
  " \n",
817
  " with gr.Row():\n",
 
840
  " interactive=False)\n",
841
  " output_csv = gr.File(label=\"Output File\", file_types=[\".csv\"])\n",
842
  "\n",
843
+ " button_phases.click(predict_on_section, \n",
844
  " inputs=[client_inputs, timestamp_inputs, \n",
845
  " eq_lat_inputs, eq_lon_inputs, \n",
846
  " radius_inputs, source_depth_inputs, \n",
 
1466
  "name": "python",
1467
  "nbconvert_exporter": "python",
1468
  "pygments_lexer": "ipython3",
1469
+ "version": "3.9.8"
1470
  },
1471
  "orig_nbformat": 4
1472
  },
app.py CHANGED
@@ -629,6 +629,7 @@ with gr.Blocks() as demo:
629
  <li>Select an earthquake from the global earthquake catalogue and PhaseHunter will analyze seismic stations in the given radius.</li>
630
  <li>Waveforms should be sampled at 100 samples/sec and have 3 (Z, N, E) or 1 (Z) channels. PhaseHunter analyzes the first 6000 samples of your file.</li>
631
  </ul>
 
632
  </div>
633
  """)
634
  with gr.Tab("Try on a single station"):
@@ -772,7 +773,7 @@ with gr.Blocks() as demo:
772
  interactive=True,
773
  )
774
 
775
- button = gr.Button("Predict phases")
776
  output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)
777
 
778
  with gr.Row():
@@ -801,7 +802,7 @@ with gr.Blocks() as demo:
801
  interactive=False)
802
  output_csv = gr.File(label="Output File", file_types=[".csv"])
803
 
804
- button.click(predict_on_section,
805
  inputs=[client_inputs, timestamp_inputs,
806
  eq_lat_inputs, eq_lon_inputs,
807
  radius_inputs, source_depth_inputs,
 
629
  <li>Select an earthquake from the global earthquake catalogue and PhaseHunter will analyze seismic stations in the given radius.</li>
630
  <li>Waveforms should be sampled at 100 samples/sec and have 3 (Z, N, E) or 1 (Z) channels. PhaseHunter analyzes the first 6000 samples of your file.</li>
631
  </ul>
632
+ <p style="font-size: 16px; margin-bottom: 20px;">Please contact me at anovosel@stanford.edu with questions and feedback</p>
633
  </div>
634
  """)
635
  with gr.Tab("Try on a single station"):
 
773
  interactive=True,
774
  )
775
 
776
+ button_phases = gr.Button("Predict phases")
777
  output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)
778
 
779
  with gr.Row():
 
802
  interactive=False)
803
  output_csv = gr.File(label="Output File", file_types=[".csv"])
804
 
805
+ button_phases.click(predict_on_section,
806
  inputs=[client_inputs, timestamp_inputs,
807
  eq_lat_inputs, eq_lon_inputs,
808
  radius_inputs, source_depth_inputs,
data/velocity/35.766_-117.605_10.0_2019-07-04T17:33:49-00_3.csv CHANGED
@@ -1,4 +1,4 @@
1
  station_name,st_lat,st_lon,starttime,"p_phase, s","p_uncertainty, s","s_phase, s","s_uncertainty, s","velocity_p, km/s","velocity_s, km/s"
2
- CI.WMF,36.11758,-117.85486,2019-07-04T17:33:41.867962Z,9.503650665283203,0.016685163136571646,17.022592544555664,0.04997979383915663,4.746091546067712,2.649725414106055
3
- CI.SRT,35.69235,-117.75051,2019-07-04T17:33:38.029990Z,4.53201961517334,0.01748959010001272,9.215676307678223,0.019567650742828846,3.4155476453388767,1.67967367867923
4
- CI.JRC2,35.98249,-117.80885,2019-07-04T17:33:39.947494Z,7.3213396072387695,0.014792646397836506,13.395279884338379,0.02523316943552345,4.135967410510336,2.2605591132307814
 
1
  station_name,st_lat,st_lon,starttime,"p_phase, s","p_uncertainty, s","s_phase, s","s_uncertainty, s","velocity_p, km/s","velocity_s, km/s"
2
+ CI.WMF,36.11758,-117.85486,2019-07-04T17:33:41.867962Z,9.503650665283203,0.0166851474205032,17.022594451904297,0.04997983225621283,4.746091546067712,2.6497251172094707
3
+ CI.SRT,35.69235,-117.75051,2019-07-04T17:33:38.029990Z,4.53201961517334,0.017489900928921998,9.215676307678223,0.019567753770388663,3.4155476453388767,1.67967367867923
4
+ CI.JRC2,35.98249,-117.80885,2019-07-04T17:33:39.947494Z,7.3213396072387695,0.014792497968301177,13.395279884338379,0.025232930202037096,4.135967410510336,2.2605591132307814
phasehunter/__pycache__/data_preparation.cpython-39.pyc CHANGED
Binary files a/phasehunter/__pycache__/data_preparation.cpython-39.pyc and b/phasehunter/__pycache__/data_preparation.cpython-39.pyc differ
 
phasehunter/__pycache__/utils.cpython-39.pyc ADDED
Binary file (1.73 kB). View file
 
phasehunter/utils.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from scipy.interpolate import griddata
3
+
4
+
5
+ def bin_distances(distances, bin_size=10):
6
+ # Bin the distances into groups of `bin_size` kilometers
7
+ binned_distances = {}
8
+ for i, distance in enumerate(distances):
9
+ bin_index = distance // bin_size
10
+ if bin_index not in binned_distances:
11
+ binned_distances[bin_index] = (distance, i)
12
+ elif i < binned_distances[bin_index][1]:
13
+ binned_distances[bin_index] = (distance, i)
14
+
15
+ # Select the first distance in each bin and its index
16
+ first_distances = []
17
+ for bin_index in binned_distances:
18
+ first_distance, first_distance_index = binned_distances[bin_index]
19
+ first_distances.append(first_distance_index)
20
+
21
+ return first_distances
22
+
23
+
24
+ def interpolate_vel_model(
25
+ velocity_model,
26
+ initial_velocity,
27
+ lat_values,
28
+ lon_values,
29
+ depth_values,
30
+ n_lat,
31
+ n_lon,
32
+ n_depth,
33
+ ):
34
+ # Create a mask for points with the initial velocity
35
+ initial_velocity_mask = velocity_model == initial_velocity
36
+
37
+ # Find the indices of points with non-initial velocities
38
+ non_initial_velocity_indices = np.argwhere(~initial_velocity_mask)
39
+
40
+ # Extract the coordinates and corresponding velocities of the known points
41
+ known_points = np.column_stack(
42
+ [
43
+ lat_values[non_initial_velocity_indices[:, 0]],
44
+ lon_values[non_initial_velocity_indices[:, 1]],
45
+ depth_values[non_initial_velocity_indices[:, 2]],
46
+ ]
47
+ )
48
+
49
+ # Find the maximum depth in the known_points
50
+ max_known_depth = np.max(known_points[:, 2])
51
+
52
+ known_velocities = velocity_model[~initial_velocity_mask]
53
+
54
+ # Create a grid of points for the entire volume
55
+ grid_points = (
56
+ np.array(np.meshgrid(lat_values, lon_values, depth_values, indexing="ij"))
57
+ .reshape(3, -1)
58
+ .T
59
+ )
60
+
61
+ # Create a mask for grid points that are deeper than the maximum known depth
62
+ depth_mask = grid_points[:, 2] <= max_known_depth
63
+
64
+ # Interpolate the velocities at the grid points
65
+ interpolated_velocities = griddata(
66
+ known_points, known_velocities, grid_points[depth_mask], method="linear"
67
+ )
68
+
69
+ # Fill nan values with the nearest known velocities
70
+ interpolated_velocities_filled = griddata(
71
+ known_points, known_velocities, grid_points[depth_mask], method="nearest"
72
+ )
73
+ interpolated_velocities[
74
+ np.isnan(interpolated_velocities)
75
+ ] = interpolated_velocities_filled[np.isnan(interpolated_velocities)]
76
+
77
+ # Initialize an array with the same length as grid_points and fill it with nan values
78
+ interpolated_velocities_with_depth_limit = np.full(grid_points.shape[0], np.nan)
79
+
80
+ # Update the array with the interpolated velocities for the masked grid points
81
+ interpolated_velocities_with_depth_limit[depth_mask] = interpolated_velocities
82
+
83
+ # Reshape the interpolated velocities to match the shape of the velocity_model
84
+ interpolated_velocity_model = interpolated_velocities_with_depth_limit.reshape(
85
+ n_lat, n_lon, n_depth
86
+ )
87
+
88
+ return interpolated_velocity_model
89
+
90
+
91
+ # Function to find the closest index for a given value in an array
92
+ def find_closest_index(array, value):
93
+ return np.argmin(np.abs(array - value))