{ "cells": [ { "cell_type": "markdown", "id": "67a5d713", "metadata": {}, "source": [ "# Step 7: Prepare and Launch Dashboards\n" ] }, { "cell_type": "markdown", "id": "981fe94b", "metadata": {}, "source": [ "This notebook prepares the files used by the interactive Spatial-VTK dashboards. You will export dashboard-ready Parquet data, create summary tables, and build portable commands for the metrics and QC dashboards.\n" ] }, { "cell_type": "markdown", "id": "be25de52", "metadata": {}, "source": [ "## Imports\n", "\n", "These helpers write dashboard datasets and make readable dashboard table previews.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "34183421", "metadata": { "execution": { "iopub.execute_input": "2026-06-07T01:51:21.882825Z", "iopub.status.busy": "2026-06-07T01:51:21.882461Z", "iopub.status.idle": "2026-06-07T01:51:44.591560Z", "shell.execute_reply": "2026-06-07T01:51:44.590526Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Run time: 1.16 s\n" ] } ], "source": [ "from spatial_vtk.config.notebook import notebook_timer, register_svtk_cell_timer\n", "\n", "with notebook_timer():\n", " import pandas as pd\n", "\n", " from spatial_vtk.config import SpatialVTKConfig\n", " from spatial_vtk.io import load_output_table, write_output_table\n", " from spatial_vtk.visualize.dashboard import (\n", " display_table,\n", " write_dashboard_metric_dataset,\n", " write_dashboard_summary_dataset,\n", " )\n", " register_svtk_cell_timer()" ] }, { "cell_type": "markdown", "id": "cf4a1981", "metadata": {}, "source": [ "## Configuration\n", "\n", "Load the config and choose dashboard output folders and ports.\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "955b197f", "metadata": { "execution": { "iopub.execute_input": "2026-06-07T01:51:44.595060Z", "iopub.status.busy": "2026-06-07T01:51:44.594725Z", "iopub.status.idle": "2026-06-07T01:51:44.619585Z", "shell.execute_reply": "2026-06-07T01:51:44.618683Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Run time: 20.9 ms\n" ] } ], "source": [ "from pathlib import Path\n", "\n", "# Use the repository root so paths match the public source checkout.\n", "repo_root = Path.cwd()\n", "config_path = repo_root / \"data/examples/configuration/example_spatial_vtk_config.yaml\"\n", "\n", "# Load the tutorial run scenario and make it the active config for later package calls.\n", "cfg = SpatialVTKConfig.from_file(config_path, run_scenario=\"tutorial\").activate()\n", "\n", "notebook_overrides = {\"metrics_port\": 8501, \"qc_port\": 8502}" ] }, { "cell_type": "markdown", "id": "0e7d1c85", "metadata": {}, "source": [ "## Write Dashboard Datasets\n", "\n", "The metrics dashboard reads Parquet files. Summary tables keep common filters and views fast.\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "546fb2f3", "metadata": { "execution": { "iopub.execute_input": "2026-06-07T01:51:44.622802Z", "iopub.status.busy": "2026-06-07T01:51:44.622341Z", "iopub.status.idle": "2026-06-07T01:52:26.026376Z", "shell.execute_reply": "2026-06-07T01:52:26.025622Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
event_idstationnetworkcomponentmodelbandmetricmetric_groupperiod_svalue_obs...strikediprakeusgs_urlobserved_pickleevent_jsonsynthetic_mseedselected_station_countoverlapping_broadband_station_countevent_count
0ci38038071BFSCIZcvmsi1-2 secPGAamplitudeNaN0.118...312.079.0178.0https://earthquake.usgs.gov/earthquakes/eventp...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/synth...30524.0
1ci38038071BHPCIZcvmsi1-2 secPGVamplitudeNaN5.410...312.079.0178.0https://earthquake.usgs.gov/earthquakes/eventp...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/synth...30525.0
2ci38695658BLCCIRcvmsi2-3 secPSAspectral2.00.284...96.048.0108.0https://earthquake.usgs.gov/earthquakes/eventp...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/synth...30754.0
3ci39812319BRECITcvmsi3-5 secFASspectral3.00.037...122.085.0179.0https://earthquake.usgs.gov/earthquakes/eventp...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/synth...30775.0
4ci38695658CACCIZcvmsi1-2 secPGAamplitudeNaN0.096...96.048.0108.0https://earthquake.usgs.gov/earthquakes/eventp...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/obser...data/examples/example_five_event_subset/synth...3075NaN
\n", "

5 rows × 47 columns

\n", "
" ], "text/plain": [ " event_id station network component model band metric metric_group \\\n", "0 ci38038071 BFS CI Z cvmsi 1-2 sec PGA amplitude \n", "1 ci38038071 BHP CI Z cvmsi 1-2 sec PGV amplitude \n", "2 ci38695658 BLC CI R cvmsi 2-3 sec PSA spectral \n", "3 ci39812319 BRE CI T cvmsi 3-5 sec FAS spectral \n", "4 ci38695658 CAC CI Z cvmsi 1-2 sec PGA amplitude \n", "\n", " period_s value_obs ... strike dip rake \\\n", "0 NaN 0.118 ... 312.0 79.0 178.0 \n", "1 NaN 5.410 ... 312.0 79.0 178.0 \n", "2 2.0 0.284 ... 96.0 48.0 108.0 \n", "3 3.0 0.037 ... 122.0 85.0 179.0 \n", "4 NaN 0.096 ... 96.0 48.0 108.0 \n", "\n", " usgs_url \\\n", "0 https://earthquake.usgs.gov/earthquakes/eventp... \n", "1 https://earthquake.usgs.gov/earthquakes/eventp... \n", "2 https://earthquake.usgs.gov/earthquakes/eventp... \n", "3 https://earthquake.usgs.gov/earthquakes/eventp... \n", "4 https://earthquake.usgs.gov/earthquakes/eventp... \n", "\n", " observed_pickle \\\n", "0 data/examples/example_five_event_subset/obser... \n", "1 data/examples/example_five_event_subset/obser... \n", "2 data/examples/example_five_event_subset/obser... \n", "3 data/examples/example_five_event_subset/obser... \n", "4 data/examples/example_five_event_subset/obser... \n", "\n", " event_json \\\n", "0 data/examples/example_five_event_subset/obser... \n", "1 data/examples/example_five_event_subset/obser... \n", "2 data/examples/example_five_event_subset/obser... \n", "3 data/examples/example_five_event_subset/obser... \n", "4 data/examples/example_five_event_subset/obser... \n", "\n", " synthetic_mseed selected_station_count \\\n", "0 data/examples/example_five_event_subset/synth... 30 \n", "1 data/examples/example_five_event_subset/synth... 30 \n", "2 data/examples/example_five_event_subset/synth... 30 \n", "3 data/examples/example_five_event_subset/synth... 30 \n", "4 data/examples/example_five_event_subset/synth... 30 \n", "\n", " overlapping_broadband_station_count event_count \n", "0 52 4.0 \n", "1 52 5.0 \n", "2 75 4.0 \n", "3 77 5.0 \n", "4 75 NaN \n", "\n", "[5 rows x 47 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "Run time: 41.40 s\n" ] } ], "source": [ "# Read the enriched metrics table for the metrics dashboard.\n", "metrics = load_output_table(\"metrics_enriched\")\n", "\n", "# Read the QC inventory for the QC dashboard.\n", "qc_summary = load_output_table(\"qc_inventory\")\n", "\n", "# Write the dashboard-ready metrics dataset.\n", "write_dashboard_metric_dataset(metrics, partitioned=False)\n", "\n", "# Write dashboard summary tables used by the Streamlit app.\n", "write_dashboard_summary_dataset(format=\"parquet\")\n", "\n", "# Save the QC trace summary for the QC dashboard.\n", "write_output_table(\"qc_trace_summary\", qc_summary)\n", "\n", "metrics.head()" ] }, { "cell_type": "markdown", "id": "e5afc3d2", "metadata": {}, "source": [ "## Preview the Metrics Table\n", "\n", "The same label lookup used by the dashboards can also make notebook previews easier to read.\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "cde9758e", "metadata": { "execution": { "iopub.execute_input": "2026-06-07T01:52:26.030873Z", "iopub.status.busy": "2026-06-07T01:52:26.030614Z", "iopub.status.idle": "2026-06-07T01:52:26.044339Z", "shell.execute_reply": "2026-06-07T01:52:26.043489Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Event IDStationComponentPeriod BandMetricObserved ValueSynthetic ValueLog2 ResidualAnderson 2004 GOF
0ci38038071BFSZ1-2 secPeak acceleration (PGA)0.1180.1040.1848.7
1ci38038071BHPZ1-2 secPeak velocity (PGV)5.4106.220-0.2017.9
2ci38695658BLCR2-3 secPseudo-spectral acceleration (PSA)0.2840.2110.4298.2
3ci39812319BRET3-5 secFourier amplitude spectrum (FAS)0.0370.052-0.4917.4
4ci38695658CACZ1-2 secPeak acceleration (PGA)0.0960.0890.1098.9
\n", "
" ], "text/plain": [ " Event ID Station Component Period Band \\\n", "0 ci38038071 BFS Z 1-2 sec \n", "1 ci38038071 BHP Z 1-2 sec \n", "2 ci38695658 BLC R 2-3 sec \n", "3 ci39812319 BRE T 3-5 sec \n", "4 ci38695658 CAC Z 1-2 sec \n", "\n", " Metric Observed Value Synthetic Value \\\n", "0 Peak acceleration (PGA) 0.118 0.104 \n", "1 Peak velocity (PGV) 5.410 6.220 \n", "2 Pseudo-spectral acceleration (PSA) 0.284 0.211 \n", "3 Fourier amplitude spectrum (FAS) 0.037 0.052 \n", "4 Peak acceleration (PGA) 0.096 0.089 \n", "\n", " Log2 Residual Anderson 2004 GOF \n", "0 0.184 8.7 \n", "1 -0.201 7.9 \n", "2 0.429 8.2 \n", "3 -0.491 7.4 \n", "4 0.109 8.9 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "Run time: 10.5 ms\n" ] } ], "source": [ "# Show a dashboard-style preview with readable metric names, period bands, and column headers.\n", "display_table(\n", " metrics,\n", " columns=[\n", " \"event_id\",\n", " \"station\",\n", " \"component\",\n", " \"band\",\n", " \"metric\",\n", " \"value_obs\",\n", " \"value_syn\",\n", " \"log2_residual\",\n", " \"anderson_2004_gof\",\n", " ],\n", " max_rows=5,\n", ")" ] }, { "cell_type": "markdown", "id": "77a6902b", "metadata": {}, "source": [ "## Build Launch Commands\n", "\n", "Run these commands in a terminal when you want to open the interactive dashboards.\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "8acd6898", "metadata": { "execution": { "iopub.execute_input": "2026-06-07T01:52:26.047226Z", "iopub.status.busy": "2026-06-07T01:52:26.046964Z", "iopub.status.idle": "2026-06-07T01:52:26.051819Z", "shell.execute_reply": "2026-06-07T01:52:26.051222Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Metrics dashboard:\n", "svtk dashboard metrics --port 8501\n", "\n", "QC dashboard:\n", "svtk dashboard qc --port 8502\n", "Run time: 1.0 ms\n" ] } ], "source": [ "# Build portable CLI commands for launching the local Streamlit dashboards.\n", "metrics_command = f\"svtk dashboard metrics --port {notebook_overrides['metrics_port']}\"\n", "qc_command = f\"svtk dashboard qc --port {notebook_overrides['qc_port']}\"\n", "\n", "print(\"Metrics dashboard:\")\n", "print(metrics_command)\n", "print(\"\\nQC dashboard:\")\n", "print(qc_command)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.10.15" }, "nbsphinx": { "execute": "never" } }, "nbformat": 4, "nbformat_minor": 5 }