{ "cells": [ { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7923\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "This app allows one to detect P and S seismic phases along with \n", " uncertainty\n", " of the detection.
\n", "Please upload your waveform in .npy
(numpy) format.
Your waveform should be sampled at 100 samples per second and have 3 (Z, N, E) or 1 (Z) channels. If your file is longer than 60 seconds, the app will only use the first 60 seconds of the waveform.
\n", " \"\"\")\n", " with gr.Tab(\"Try on a single station\"):\n", " with gr.Row(): \n", " # Define the input and output types for Gradio\n", " inputs = gr.Dropdown(\n", " [\"data/sample/sample_0.npy\", \n", " \"data/sample/sample_1.npy\", \n", " \"data/sample/sample_2.npy\"], \n", " label=\"Sample waveform\", \n", " info=\"Select one of the samples\",\n", " value = \"data/sample/sample_0.npy\"\n", " )\n", "\n", " upload = gr.File(label=\"Or upload your own waveform\")\n", "\n", " button = gr.Button(\"Predict phases\")\n", " outputs = gr.Image(label='Waveform with Phases Marked', type='numpy', interactive=False)\n", " \n", " button.click(mark_phases, inputs=[inputs, upload], outputs=outputs)\n", " \n", " with gr.Tab(\"Select earthquake from catalogue\"):\n", " gr.Markdown(\"\"\"Select an earthquake from the global earthquake catalogue and the app will download the waveform from the FDSN client of your choice.\n", " \"\"\")\n", " with gr.Row(): \n", " client_inputs = gr.Dropdown(\n", " choices = list(URL_MAPPINGS.keys()), \n", " label=\"FDSN Client\", \n", " info=\"Select one of the available FDSN clients\",\n", " value = \"IRIS\",\n", " interactive=True\n", " )\n", "\n", " velocity_inputs = gr.Dropdown(\n", " choices = ['1066a', '1066b', 'ak135', \n", " 'ak135f', 'herrin', 'iasp91', \n", " 'jb', 'prem', 'pwdk'], \n", " label=\"1D velocity model\", \n", " info=\"Velocity model for station selection\",\n", " value = \"1066a\",\n", " interactive=True\n", " )\n", "\n", " with gr.Column(scale=4):\n", " with gr.Row(): \n", " timestamp_inputs = gr.Textbox(value='2019-07-04 17:33:49',\n", " placeholder='YYYY-MM-DD HH:MM:SS',\n", " label=\"Timestamp\",\n", " info=\"Timestamp of the earthquake\",\n", " max_lines=1,\n", " interactive=True)\n", " \n", " eq_lat_inputs = gr.Number(value=35.766, \n", " label=\"Latitude\", \n", " info=\"Latitude of the earthquake\",\n", " interactive=True)\n", " \n", " eq_lon_inputs = gr.Number(value=-117.605,\n", " label=\"Longitude\",\n", " info=\"Longitude of the earthquake\",\n", " interactive=True)\n", " \n", " source_depth_inputs = gr.Number(value=10,\n", " label=\"Source depth (km)\",\n", " info=\"Depth of the earthquake\",\n", " interactive=True)\n", " \n", "\n", " \n", " with gr.Column(scale=2):\n", " with gr.Row(): \n", " radius_inputs = gr.Slider(minimum=1, \n", " maximum=150, \n", " value=50, label=\"Radius (km)\", \n", " step=10,\n", " info=\"\"\"Select the radius around the earthquake to download data from.\\n \n", " Note that the larger the radius, the longer the app will take to run.\"\"\",\n", " interactive=True)\n", " \n", " max_waveforms_inputs = gr.Slider(minimum=1,\n", " maximum=100,\n", " value=10,\n", " label=\"Max waveforms per section\",\n", " step=1,\n", " info=\"Maximum number of waveforms to show per section\\n (to avoid long prediction times)\",\n", " interactive=True,\n", " )\n", " \n", " button = gr.Button(\"Predict phases\")\n", " output_image = gr.Image(label='Waveforms with Phases Marked', type='numpy', interactive=False)\n", " output_picks = gr.Dataframe(label='# Pick data', type='pandas', interactive=False)\n", "\n", " button.click(predict_on_section, \n", " inputs=[client_inputs, timestamp_inputs, \n", " eq_lat_inputs, eq_lon_inputs, \n", " radius_inputs, source_depth_inputs, \n", " velocity_inputs, max_waveforms_inputs],\n", " outputs=[output_image, output_picks])\n", "\n", "demo.launch()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "phasehunter", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.2" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "6bf57068982d7b420bddaaf1d0614a7795947176033057024cf47d8ca2c1c4cd" } } }, "nbformat": 4, "nbformat_minor": 2 }