Spaces:
Runtime error
Runtime error
Removed 3D velocity, because I broke it somehow
Browse files
Gradio_app.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
app.py
CHANGED
@@ -29,6 +29,9 @@ from mpl_toolkits.axes_grid1 import ImageGrid
|
|
29 |
|
30 |
from glob import glob
|
31 |
|
|
|
|
|
|
|
32 |
|
33 |
def resample_waveform(waveform, original_freq, target_freq):
|
34 |
"""
|
@@ -435,10 +438,6 @@ def predict_on_section(client_name, timestamp, eq_lat, eq_lon, radius_km, source
|
|
435 |
|
436 |
return image, output_picks, output_csv
|
437 |
|
438 |
-
import numpy as np
|
439 |
-
from matplotlib import colors, cm
|
440 |
-
from scipy.interpolate import griddata
|
441 |
-
|
442 |
def interpolate_vel_model(velocity_model, initial_velocity, lat_values, lon_values, depth_values, n_lat, n_lon, n_depth):
|
443 |
# Create a mask for points with the initial velocity
|
444 |
initial_velocity_mask = (velocity_model == initial_velocity)
|
@@ -485,120 +484,123 @@ def interpolate_vel_model(velocity_model, initial_velocity, lat_values, lon_valu
|
|
485 |
def find_closest_index(array, value):
|
486 |
return np.argmin(np.abs(array - value))
|
487 |
|
488 |
-
|
489 |
-
|
|
|
490 |
|
491 |
-
|
492 |
-
|
493 |
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
|
|
|
|
|
|
544 |
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
|
583 |
-
|
584 |
|
585 |
-
|
586 |
-
|
587 |
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
|
597 |
-
|
598 |
|
599 |
# model = torch.jit.load("model.pt")
|
600 |
model = torch.jit.load("model.pt")
|
601 |
-
|
602 |
model.eval()
|
603 |
|
604 |
with gr.Blocks() as demo:
|
@@ -625,8 +627,8 @@ with gr.Blocks() as demo:
|
|
625 |
-webkit-text-fill-color: transparent;
|
626 |
background-clip: text;">uncertainty</span></p>
|
627 |
<ul style="font-size: 16px; margin-bottom: 40px;">
|
628 |
-
<li>Detect seismic phases by selecting a sample waveform or uploading your own waveform in <code>.npy</code> format.</li>
|
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>
|
@@ -776,25 +778,25 @@ with gr.Blocks() as demo:
|
|
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():
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
button.click(compute_velocity_model,
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
|
799 |
with gr.Row():
|
800 |
output_picks = gr.Dataframe(label='Pick data',
|
|
|
29 |
|
30 |
from glob import glob
|
31 |
|
32 |
+
import numpy as np
|
33 |
+
from matplotlib import colors, cm
|
34 |
+
from scipy.interpolate import griddata
|
35 |
|
36 |
def resample_waveform(waveform, original_freq, target_freq):
|
37 |
"""
|
|
|
438 |
|
439 |
return image, output_picks, output_csv
|
440 |
|
|
|
|
|
|
|
|
|
441 |
def interpolate_vel_model(velocity_model, initial_velocity, lat_values, lon_values, depth_values, n_lat, n_lon, n_depth):
|
442 |
# Create a mask for points with the initial velocity
|
443 |
initial_velocity_mask = (velocity_model == initial_velocity)
|
|
|
484 |
def find_closest_index(array, value):
|
485 |
return np.argmin(np.abs(array - value))
|
486 |
|
487 |
+
# FIX AFTER CONFERENCE
|
488 |
+
# def compute_velocity_model(azimuth, elevation, interpolate, n_lat, n_lon, n_depth):
|
489 |
+
# filename = list(output_csv.temp_files)[0]
|
490 |
|
491 |
+
# df = pd.read_csv(filename)
|
492 |
+
# filename = filename.split('/')[-1]
|
493 |
|
494 |
+
# # Current EQ location
|
495 |
+
# eq_lat = float(filename.split("_")[0])
|
496 |
+
# eq_lon = float(filename.split("_")[1])
|
497 |
+
# eq_depth = float(filename.split("_")[2])
|
498 |
+
|
499 |
+
# # Define the region of interest (latitude, longitude, and depth ranges)
|
500 |
+
# lat_range = (np.min([df.st_lat.min(), eq_lat]), np.max([df.st_lat.max(), eq_lat]))
|
501 |
+
# lon_range = (np.min([df.st_lon.min(), eq_lon]), np.max([df.st_lon.max(), eq_lon]))
|
502 |
+
# depth_range = (0, 50)
|
503 |
+
|
504 |
+
# # Define the number of nodes in each dimension
|
505 |
+
# num_points = 100
|
506 |
+
|
507 |
+
# taup_model = TauPyModel(model='1066a')
|
508 |
+
|
509 |
+
# # Create the grid
|
510 |
+
# lat_values = np.linspace(lat_range[0], lat_range[1], n_lat)
|
511 |
+
# lon_values = np.linspace(lon_range[0], lon_range[1], n_lon)
|
512 |
+
# depth_values = np.linspace(depth_range[0], depth_range[1], n_depth)
|
513 |
+
|
514 |
+
# # Initialize the velocity model with constant values
|
515 |
+
# initial_velocity = 0 # km/s, this can be P-wave or S-wave velocity
|
516 |
+
# velocity_model = np.full((n_lat, n_lon, n_depth), initial_velocity, dtype=float)
|
517 |
+
|
518 |
+
# # Loop through the stations and update the velocity model
|
519 |
+
# for i in range(len(df)):
|
520 |
+
# if ~np.isnan(df['velocity_p, km/s'].iloc[i]):
|
521 |
+
|
522 |
+
# ray_path = taup_model.get_ray_paths_geo(source_depth_in_km=eq_depth,
|
523 |
+
# source_latitude_in_deg=eq_lat,
|
524 |
+
# source_longitude_in_deg=eq_lon,
|
525 |
+
# receiver_latitude_in_deg=df.st_lat.iloc[i],
|
526 |
+
# receiver_longitude_in_deg=df.st_lon.iloc[i],
|
527 |
+
# phase_list=['P', 'S'])
|
528 |
+
|
529 |
+
# # THERE IS A PROBLEM WITH THE RAY PATHS. APPARENTLY LAT AND LON DON'T EXIST (HOW DID IT WORK BEFORE?)
|
530 |
+
# print(ray_path[0].path)
|
531 |
+
|
532 |
+
# # Create the interpolator objects for latitude, longitude, and depth
|
533 |
+
# interp_latitude = interp1d(np.linspace(0, ray_path[0].path['lat'].max(), len(ray_path[0].path['lat'])), ray_path[0].path['lat'])
|
534 |
+
# interp_longitude = interp1d(np.linspace(0, ray_path[0].path['lon'].max(), len(ray_path[0].path['lon'])), ray_path[0].path['lon'])
|
535 |
+
# interp_depth = interp1d(np.linspace(0, ray_path[0].path['depth'].max(), len(ray_path[0].path['depth'])), ray_path[0].path['depth'])
|
536 |
+
|
537 |
+
# # Resample the ray path to N points
|
538 |
+
# lat_values_interp = interp_latitude(np.linspace(0, ray_path[0].path['lat'].max(), num_points))
|
539 |
+
# lon_values_interp = interp_longitude(np.linspace(0, ray_path[0].path['lon'].max(), num_points))
|
540 |
+
# depth_values_interp = interp_depth(np.linspace(0, ray_path[0].path['depth'].max(), num_points))
|
541 |
+
|
542 |
+
# # Loop through the interpolated coordinates and update the grid cells with the average P-wave velocity
|
543 |
+
# for lat, lon, depth in zip(lat_values_interp, lon_values_interp, depth_values_interp):
|
544 |
+
# lat_index = find_closest_index(lat_values, lat)
|
545 |
+
# lon_index = find_closest_index(lon_values, lon)
|
546 |
+
# depth_index = find_closest_index(depth_values, depth)
|
547 |
|
548 |
+
# if velocity_model[lat_index, lon_index, depth_index] == initial_velocity:
|
549 |
+
# velocity_model[lat_index, lon_index, depth_index] = df['velocity_p, km/s'].iloc[i]
|
550 |
+
# else:
|
551 |
+
# velocity_model[lat_index, lon_index, depth_index] = (velocity_model[lat_index, lon_index, depth_index] +
|
552 |
+
# df['velocity_p, km/s'].iloc[i]) / 2
|
553 |
+
|
554 |
+
# # Create the figure and axis
|
555 |
+
# fig = plt.figure(figsize=(8, 8))
|
556 |
+
# ax = fig.add_subplot(111, projection='3d')
|
557 |
+
|
558 |
+
# # Set the plot limits
|
559 |
+
# ax.set_xlim3d(lat_range[0], lat_range[1])
|
560 |
+
# ax.set_ylim3d(lon_range[0], lon_range[1])
|
561 |
+
# ax.set_zlim3d(depth_range[1], depth_range[0])
|
562 |
+
|
563 |
+
# ax.set_xlabel('Latitude')
|
564 |
+
# ax.set_ylabel('Longitude')
|
565 |
+
# ax.set_zlabel('Depth (km)')
|
566 |
+
# ax.set_title('Velocity Model')
|
567 |
|
568 |
+
# # Create the meshgrid
|
569 |
+
# x, y, z = np.meshgrid(
|
570 |
+
# np.linspace(lat_range[0], lat_range[1], velocity_model.shape[0]+1),
|
571 |
+
# np.linspace(lon_range[0], lon_range[1], velocity_model.shape[1]+1),
|
572 |
+
# np.linspace(depth_range[0], depth_range[1], velocity_model.shape[2]+1),
|
573 |
+
# indexing='ij'
|
574 |
+
# )
|
575 |
+
|
576 |
+
# # Create the color array
|
577 |
+
# norm = plt.Normalize(vmin=2, vmax=8)
|
578 |
+
# colors_vel = plt.cm.plasma(norm(velocity_model))
|
579 |
|
580 |
+
# # Plot the voxels
|
581 |
+
# if interpolate:
|
582 |
+
# interpolated_velocity_model = interpolate_vel_model(velocity_model, initial_velocity, lat_values, lon_values, depth_values, n_lat, n_lon, n_depth)
|
583 |
+
# colors_interp = plt.cm.plasma(norm(interpolated_velocity_model))
|
584 |
+
# ax.voxels(x, y, z, interpolated_velocity_model > 0, facecolors=colors_interp, alpha=0.5, edgecolor='k')
|
585 |
|
586 |
+
# ax.voxels(x, y, z, velocity_model > 0, facecolors=colors_vel, alpha=1, edgecolor='black')
|
587 |
|
588 |
+
# # Set the view angle
|
589 |
+
# ax.view_init(elev=elevation, azim=azimuth)
|
590 |
|
591 |
+
# m = cm.ScalarMappable(cmap=plt.cm.plasma, norm=norm)
|
592 |
+
# m.set_array([])
|
593 |
+
# plt.colorbar(m)
|
594 |
|
595 |
+
# # Show the plot
|
596 |
+
# fig.canvas.draw();
|
597 |
+
# image = np.array(fig.canvas.renderer.buffer_rgba())
|
598 |
+
# plt.close(fig)
|
599 |
|
600 |
+
# return image
|
601 |
|
602 |
# model = torch.jit.load("model.pt")
|
603 |
model = torch.jit.load("model.pt")
|
|
|
604 |
model.eval()
|
605 |
|
606 |
with gr.Blocks() as demo:
|
|
|
627 |
-webkit-text-fill-color: transparent;
|
628 |
background-clip: text;">uncertainty</span></p>
|
629 |
<ul style="font-size: 16px; margin-bottom: 40px;">
|
630 |
+
<li>Tab 1: Detect seismic phases by selecting a sample waveform or uploading your own waveform in <code>.npy</code> format.</li>
|
631 |
+
<li>Tab 2: Select an earthquake from the global earthquake catalogue and PhaseHunter will analyze seismic stations in the given radius.</li>
|
632 |
<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>
|
633 |
</ul>
|
634 |
<p style="font-size: 16px; margin-bottom: 20px;">Please contact me at anovosel@stanford.edu with questions and feedback</p>
|
|
|
778 |
button_phases = gr.Button("Predict phases")
|
779 |
output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)
|
780 |
|
781 |
+
# with gr.Row():
|
782 |
+
# with gr.Column(scale=2):
|
783 |
+
# azimuth_input = gr.Slider(minimum=-180, maximum=180, value=0, step=5, label="Azimuth", interactive=True)
|
784 |
+
# elevation_input = gr.Slider(minimum=-90, maximum=90, value=30, step=5, label="Elevation", interactive=True)
|
785 |
+
|
786 |
+
# with gr.Row():
|
787 |
+
# interpolate_input = gr.Checkbox(label="Interpolate", info="Interpolate velocity model")
|
788 |
+
# n_lat_input = gr.Slider(minimum=5, maximum=100, value=50, step=5, label="N lat", info='Number of Lat grid points', interactive=True)
|
789 |
+
# n_lon_input = gr.Slider(minimum=5, maximum=100, value=50, step=5, label="N lon", info='Number of Lon grid points', interactive=True)
|
790 |
+
# n_depth_input = gr.Slider(minimum=5, maximum=100, value=50, step=5, label="N depth", info='Number of Depth grid points', interactive=True)
|
791 |
|
792 |
+
# button = gr.Button("Look at 3D Velocities")
|
793 |
+
# outputs_vel_model = gr.Image(label="3D Velocity Model")
|
794 |
+
|
795 |
+
# button.click(compute_velocity_model,
|
796 |
+
# inputs=[azimuth_input, elevation_input,
|
797 |
+
# interpolate_input, n_lat_input,
|
798 |
+
# n_lon_input, n_depth_input],
|
799 |
+
# outputs=[outputs_vel_model])
|
800 |
|
801 |
with gr.Row():
|
802 |
output_picks = gr.Dataframe(label='Pick data',
|
data/velocity/35.766_-117.605_10.0_2019-07-04T17:33:49-00_15.csv
CHANGED
@@ -1,16 +1,16 @@
|
|
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 |
-
|
3 |
-
|
4 |
-
CI.
|
5 |
-
NN.
|
6 |
-
|
7 |
-
CI.
|
8 |
-
|
9 |
-
CI.
|
10 |
-
CI.
|
11 |
-
CI.
|
12 |
-
|
13 |
-
CI.
|
14 |
-
CI.
|
15 |
-
CI.
|
16 |
-
CI.
|
|
|
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 |
+
NN.GWY,36.186001,-116.6698,2019-07-04T17:33:48.493781Z,15.700143814086914,0.032990213949233294,27.400177001953125,0.021678594639524817,6.130438626794903,3.5127060703751187
|
3 |
+
NN.QSM,35.965,-116.869102,2019-07-04T17:33:45.081547Z,10.825798034667969,0.03368678851984441,19.0788516998291,0.019648977904580534,6.4577673283107595,3.664292062807735
|
4 |
+
CI.SHO,35.899529,-116.275299,2019-07-04T17:33:51.673022Z,19.146766662597656,0.035460374783724546,33.84723663330078,0.04468856379389763,6.30872871300763,3.568733185348003
|
5 |
+
NN.STHB,36.645401,-116.338799,2019-07-04T17:33:55.443778Z,23.533306121826172,0.30755365267395973,44.214805603027344,0.1947527378797531,6.369670568636879,3.390253679565082
|
6 |
+
CI.ADO,34.550461,-117.433907,2019-07-04T17:33:53.650962Z,21.59795379638672,0.06652493728324771,39.832244873046875,0.07596344919875264,6.299665909869628,3.4158228763577374
|
7 |
+
CI.CWC,36.439049,-118.080498,2019-07-04T17:33:47.189005Z,16.31502342224121,0.03174463869072497,28.542631149291992,0.03808272653259337,5.282087714150544,3.0192516003149317
|
8 |
+
CI.EDW2,34.8811,-117.993881,2019-07-04T17:33:49.567241Z,17.189565658569336,0.027216661255806684,31.171907424926758,0.13113449793308973,6.081292405081156,3.3534930558182605
|
9 |
+
CI.OSI,34.6145,-118.7235,2019-07-04T17:33:57.203547Z,27.027793884277344,0.2828584983944893,49.76795196533203,0.1476773852482438,6.048733936517377,3.284923884569468
|
10 |
+
CI.HEC,34.8294,-116.335,2019-07-04T17:33:56.148977Z,23.56346893310547,0.12240480165928602,41.065738677978516,0.039880009135231376,6.5925417090174125,3.782792097538392
|
11 |
+
CI.ISA,35.66278,-118.47403,2019-07-04T17:33:46.297658Z,14.406868934631348,0.03547209897078574,26.673168182373047,0.04885842092335224,5.5041294893778305,2.972922886794878
|
12 |
+
LB.DAC,36.277,-117.593697,2019-07-04T17:33:43.387184Z,34.548667907714844,0.15354723203927279,41.79047393798828,1.0928620398044586,,
|
13 |
+
CI.JRC2,35.98249,-117.80885,2019-07-04T17:33:39.947494Z,7.319685935974121,0.013258439430501312,13.406767845153809,0.024791041505523026,4.136901812685252,2.2586220904663317
|
14 |
+
CI.RRX,34.875332,-116.996841,2019-07-04T17:33:50.712219Z,17.288339614868164,0.037936256267130375,30.341846466064453,0.12148946989327669,6.557900828103267,3.7365958200229463
|
15 |
+
CI.WMF,36.11758,-117.85486,2019-07-04T17:33:41.867962Z,9.49942398071289,0.009130067483056337,17.041561126708984,0.028638315852731466,4.748203277468246,2.646776063760303
|
16 |
+
CI.SRT,35.69235,-117.75051,2019-07-04T17:33:38.029990Z,4.530585289001465,0.018513815011829138,9.206761360168457,0.01343689626082778,3.4166289646533787,1.6813001140882917
|
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.
|
3 |
-
CI.
|
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
|
|
|
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.SRT,35.69235,-117.75051,2019-07-04T17:33:38.029990Z,4.52931022644043,0.014338254695758224,9.210612297058105,0.013868825335521251,3.417590792273917,1.6805971661817796
|
3 |
+
CI.WMF,36.11758,-117.85486,2019-07-04T17:33:41.867962Z,9.509395599365234,0.017237813444808125,17.024826049804688,0.043195366160944104,4.743224278343435,2.6493777937777434
|
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
|
requirements.txt
CHANGED
@@ -15,4 +15,5 @@ obspy
|
|
15 |
pandas
|
16 |
bmi_topography
|
17 |
earthpy
|
|
|
18 |
git+http://github.com/nikitadurasov/masksembles
|
|
|
15 |
pandas
|
16 |
bmi_topography
|
17 |
earthpy
|
18 |
+
geographiclib
|
19 |
git+http://github.com/nikitadurasov/masksembles
|