CoolFace
Apppublic

Mizzou-Student-Research-Team/Alt-v2-Seismometer-Network-Builder

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
App README

(Alternative Version 1) Seismometer Network Builder

A Streamlit Web Tool for Computational Nodal Seismometer Deployment

Team: Natalie Lloyd, Vickie Moore, Prisha Puri, Louis Youmans Partners: U.S. Geological Survey (USGS), MU Institute for Data Science & Informatics, BrightData License: MIT


About This Repository

Feel free to join this repo as a member by using the request button: https://huggingface.co/Mizzou-Student-Research-Team

This project includes three versions of the Seismometer Network Builder. Below are the three available versions of the Seismometer Network Builder, each designed for different performance, dependency, and customization needs.

πŸ”Ή Main Version (default)

Full‑featured implementation with the complete Site Suitability Analysis (SSA) workflow and the full BigQuery β†’ Power Automate β†’ ArcGIS dashboard pipeline.

  • β€”Link: https://huggingface.co/spaces/Mizzou-Student-Research-Team/Seismometer-Network-Builder
  • β€”Disclaimer: ArcGIS access has been discontinued for this project. Pages that rely on ArcGIS services, specifically Page 3, will no longer function as originally designed. All other pages remain fully operational. To continue working without interruption, please use the alternative versions provided in the README.

πŸ”Ή Alternative Version 1 β€” Reduced Computational Time (same logic, less data, fewer dependencies)

Same modeling logic as the main version, but optimized for speed:

  • β€”Building data replaced with an empty placeholder dataset (any building‑related score shown in the UI should be ignored)
  • β€”ArcGIS dashboard and its entire backend workflow removed
  • β€”Link: https://huggingface.co/spaces/Mizzou-Student-Research-Team/Alt-v1-Seismometer-Network-Builder

πŸ”Ή Alternative Version 2 β€” Lightweight & Customizable (different logic, less data, fewer dependencies)

A simplified version with:

  • β€”Modified logic for faster computation and better results
  • β€”Replaced the Site Suitability Analysis (SSA) by allowing user to depict unsuitable areas by drawing on the map
  • β€”More user‑controlled customization
  • β€”Reduced datasets
  • β€”ArcGIS dashboard and its entire backend workflow removed
  • β€”Link: https://huggingface.co/spaces/Mizzou-Student-Research-Team/Alt-v2-Seismometer-Network-Builder

πŸ”Ή Alternative Version 3 β€” Reduced Computational Time (same logic, less data (but more than Alt Version 1), fewer dependencies)

Same modeling logic as the main version, but optimized for speed:

  • β€”Building data replaced with an empty placeholder dataset (any building‑related score shown in the UI should be ignored)
  • β€”ArcGIS dashboard and its entire backend workflow removed
  • β€”Integrated oceans data in the Site Suitability Analysis to prevent deployment out in the ocean
  • β€”Added three additional layers and another basemap to the map on Page 3 along with a legend for better data analysis
  • β€”Link: https://huggingface.co/spaces/Mizzou-Student-Research-Team/Alt-v3-Seismometer-Network-Builder

Table of Contents

  1. 1.Overview
  2. 2.Features
  3. 3.System Architecture
  4. 4.Repository Structure
  5. 5.Technical Workflow
  6. 6.Step 1 β€” Earthquake Selection
  7. 7.Step 2 β€” Nodal Network Generation
  8. 8.Step 3 β€” Results
  9. 9.AI Assistant
  10. 10.Downloads & Resources
  11. 11.Running the Tool Locally
  12. 12.Reusing This Codebase
  13. 13.Contributing
  14. 14.Limitations of Our Web Tool
  15. 15.Acknowledgements
  16. 16.Glossary

Overview

The Seismometer Network Builder is an open‑source, multipage Streamlit application designed to help USGS researchers and other individuals rapidly generate nodal seismometer deployment plans following an earthquake.

This web tool helps you explore where nodal seismometers could be placed in a specific region by guiding you through a simple, three‑step process. You choose the earthquake scenario, and the tool generates a recommended network of nodal sites for you to review! It saves time, reduces fieldwork, and makes it easier to place sensors fast when aftershocks are happening. Try it out!


Features

Three‑Step Workflow

  1. 1.Select an Earthquake Scenario Pulls real events from the USGS ComCat API and defines the study area.
  1. 1.Generate Nodal Network Generates nodal network after allowing the user to make any changes.
  1. 1.Explore Results Visualizes the data in a map and histogram.

Additional Features

  • β€”Built‑in AI assistant powered by Groq Llama‑3.1
  • β€”Exportable GeoJSON outputs
  • β€”Transparent and extensible codebase

System Architecture

text
User (Browser)
β”‚
└── Streamlit Frontend (Hugging Face Space)
    β”‚
    β”œβ”€β”€ Home.py
    β”‚   └── Overview, instructions, troubleshooting
    β”‚
    β”œβ”€β”€ 1_1️⃣_Step_1.py  (Earthquake Selection)
    β”‚   β”œβ”€β”€ Queries USGS ComCat via libcomcat
    β”‚   β”œβ”€β”€ Filters events by magnitude, date, and West Coast bounds
    β”‚   └── Stores selected_eq in st.session_state
    β”‚
    β”œβ”€β”€ 2_2️⃣_Step_2.py  (Nodal Network Generation)
    β”‚   β”œβ”€β”€ Nodal Site Generation
    β”‚   β”‚     β€’ Provide option to user to make any changes
    β”‚   β”‚     β€’ Generate nodal network based on magnitude of the earthquake
    β”‚
    β”œβ”€β”€ 3_3️⃣_Step_3.py  (Explore Results)
    β”‚   β”œβ”€β”€ Depicts map with the results
    β”‚   β”œβ”€β”€ Incorporates a data visualization
    β”‚
    β”œβ”€β”€ 4_πŸ€–_AI_Assistant.py
    β”‚   β”œβ”€β”€ Uses RAG (Retrieval-Augmented Generation) model
    β”‚   β”œβ”€β”€ Loads local knowledge/*.txt files 
    β”‚   β”œβ”€β”€ Maintains conversation history in st.session_state
    β”‚   └── Calls Groq LLM (OpenAI-compatible API)
    β”‚
    β”œβ”€β”€ 5_πŸ”_Further_Analysis_and_Resources.py
    β”‚   └── Provides GeoJSON downloads for nodal network and all cells
    β”‚
    └── 6_πŸ“ƒ_Credits_and_Policies.py
        └── Shows credits, terms, license, and citations


──────────────────────────────────────────────────────────────
Backend Components
──────────────────────────────────────────────────────────────
The backend of the Seismometer Network Builder is a coordinated set of
external data services and cloud storage that
support the Streamlit frontend. Each component is triggered in sequence
as the user progresses through the tool.

β€’ Hugging Face Dataset Repository  
    Stores all technical, contextual, and social datasets used in Steps 2–3.

β€’ USGS ComCat API  
    Triggered in Step 1 when the user searches for earthquakes.

---

## Repository Structure

.gitattributes .gitignore LICENSE README.md packages.txt requirements.txt

Home.py pages/ 0πŸ“šBackgroundInformation.py 11️⃣Step1.py 22️⃣Step2.py 33️⃣Step3.py 4πŸ€–AIAssistant.py 5πŸ”FurtherAnalysisandResources.py 6πŸ“ƒCreditsandPolicies.py

assets/ ProjectSlides.pdf NodalNetworksAIAnimation.mp4

knowledge/ overview.txt backgroundinfo.txt purposeandusers.txt howto_use.txt


---

# Technical Workflow

## Step 1 β€” Earthquake Selection (USGS ComCat)

**File:** `1_1️⃣_Step_1.py`

The tool queries the USGS ComCat API using `libcomcat.search` with filters for:

- Date range  
- Magnitude range (5.0–8.0)  
- West Coast bounding box  

Each event includes magnitude, depth, time, place, USGS URL, and epicenter geometry. The selected event is stored in:

st.sessionstate["selectedeq"]


This defines the epicenter, magnitude, and initial ROI.

---

## Step 2 β€” Nodal Network Generation

**File:** `2_2️⃣_Step_2.py`

This is the computational core of the tool.

### 2.1 ROI Definition (MMI Attenuation Model)

The tool uses the Atkinson, Worden & Wald (2014) Western North America MMI model to compute the radius where MMI = 5.0. The ROI is a square bounding box around the epicenter.

### 2.2 Allow user to make any changes
Users can make changes by adjusting the parameters or by drawing new shapes directly on the interactive map to define the unsuitable areas.

### 2.3 Greedy Spacing Algorithm

Magnitude‑based defaults:

| Magnitude | Target Nodes | Spacing |
|-----------|--------------|---------|
| 5.0–5.9 | 30 | 5 km |
| 6.0–6.9 | 70 | 7.5 km |
| 7.0–7.9 | 100 | 40 km |
| 8.0 | 150 | 40 km |

Users may override these values.

After this, the nodal network sites are stored in a geodataframe for analysis in the next step.

---

## Step 3 β€” Results

**File:** `3_3️⃣_Step_3.py`

### Map and Data Visualization Depicted
- Map shows the chosen nodal sites
- Data visualization is about the epicenter to seismometer site distances

---

## AI Assistant

**File:** `4_πŸ€–_AI_Assistant.py`

- Uses Groq Llama‑3.1 via OpenAI‑compatible API  
- Loads local knowledge files  
- Maintains conversation history  
- Helps users understand the workflow and provides background information

---

## Downloads & Resources

**File:** `5_πŸ”_Further_Analysis_and_Resources.py`

Users can download:

- Nodal Network Sites (GeoJSON)  
- All Candidate Sites (GeoJSON)  

Also links to:

- Dataset repository  
- Project slides  

---

# Running the Tool Locally

### 1. Clone the repository

git clone https://huggingface.co/spaces/Mizzou-Student-Research-Team/Seismometer-Network-Builder cd Seismometer-Network-Builder


### 2. Install dependencies

pip install -r requirements.txt


### 3. Add secrets

Create `.streamlit/secrets.toml`:

groq_key = "..."

- **groq_key** β€” Log into your Groq account β†’ go to API Keys β†’ create a new key β†’ paste it here.

### 4. Run Streamlit

streamlit run Home.py


---

# Reusing This Codebase

This project was intentionally designed so that users can reuse the
components independently. You do not need to deploy the full Streamlit
app to benefit from the underlying logic.

Below are three recommended reuse pathways.


## 1. Reusing the Core Step 2 Workflow

The entire nodal network generation workflow lives in `2_2️⃣_Step_2.py` and can
be extracted into a standalone Python module.

You can reuse:

- the ROI computation using the MMI attenuation model
- the uniform grid generator (create_grid) that builds fixed‑size cells across the ROI
- the drawing‑tool exclusion logic, which merges user‑drawn polygons and marks intersecting cells as unsuitable
- the suitability filter that removes excluded cells
- the centroid extraction that produces a clean GeoDataFrame of candidate seismometer locations

### How to use it independently
1. Copy the relevant functions from this file into a standalone module (e.g., suitability_workflow.py).
2. Replace Streamlit inputs with function arguments (e.g., ROI bounds, cell size, drawn shapes).
3. Call the workflow from any environment, such as:
   - a Jupyter notebook
   - a batch processing script
   - an automated backend service
   - a geospatial analysis pipeline

This allows users to run the model **without** Streamlit, BigQuery, or ArcGIS.

## 2. Reusing Only the Data Results Workflow

If you would like to depict data insights but not in the Streamlit UI:

You can reuse:

- The interactive map created with `leafmap` and `folium`
- The histogram-based spatial distribution analysis visualization

### How to use it independently
1. Generate your own GeoDataFrames (from Python, R, ArcGIS Pro, etc.).
2. Compute distances between geospatial features using GeoPandas.
3. Generate interactive maps with `leafmap` and `folium`.
4. Create statistical visualizations and distance histograms using Plotly.
5. Export the outputs into notebooks, dashboards, standalone web apps, or GIS platforms.


## 3. Reusing the AI Assistant

The AI assistant is fully modular and lives in `4_πŸ€–_AI_Assistant.py`.

You can reuse:

- The Groq API call wrapper
- The knowledge‑file retrieval system
- The conversation memory logic

### How to use it independently
1. Move the AI assistant code into a separate module (e.g., `assistant.py`).
2. Replace Streamlit chat UI with a tool of your choice such as:
   - a CLI interface  
   - a Slack bot  
   - a Teams bot  
   - an internal web app  

### Should you separate it into a Hugging Face model?
If you want the assistant to be reusable across multiple tools, yes β€”  
you can package the assistant logic in different ways such as:

- a **Hugging Face Model (API endpoint can be enabled)**  
- a **Python package**

This is optional but recommended if you want a unified assistant across projects.


## 4. Reusing the Remaining Code

The rest of the codebase is primarily:

- UI text  
- Page layout  
- Download buttons  
- Video embedding  
- Credits and policies  

These components are optional and can be removed or replaced without
affecting the core functionality.

---

# Contributing

We welcome contributions from users who want to improve the Seismometer Network Builder or adapt it for new use cases.

## How to Contribute
1. **Duplicate the repository**  
   Create your own copy of the project to work on.

2. **Create a feature branch** 
   `git checkout -b feature/my-improvement`

3. **Make your changes**  
- Add new features  
- Improve documentation  
- Fix bugs  
- Enhance performance  
- Add new datasets or workflows  

4. **Submit a pull request**  
Include a clear description of what you changed and why.

## Contribution Guidelines
- Keep code modular and consistent with existing structure.  
- Document new functions or workflows clearly.  
- Do NOT commit secrets or credentials. This poses a security risk. 
- If adding new datasets, include metadata and source information.  

We appreciate all contributions β€” whether small fixes or major enhancements!

--- 

# Limitations of Our Web Tool

While the tool is fully functional, here are some limitations to be aware of:

## 1. ROI Simplification
The Region of Interest is defined as a square bounding box based on MMI attenuation.  
This is intentionally simple but may not capture important details.

## 2. Raster Resolution
The workflow uses a 5.5 km grid to balance performance and spatial accuracy.  
Higher‑resolution grids are supported, but they may substantially increase processing time and memory usage.

## 3. AI Assistant Scope
The AI assistant uses local knowledge files and does not have access to the full codebase.  
It is designed for guidance, not for executing or modifying workflows.

## 4. Internet Connectivity
Several components require external APIs:
- USGS ComCat  
- IRIS FDSN  
- Overpass API  
- Hugging Face Datasets  

Offline use is limited unless datasets are cached locally.

--- 

# Acknowledgements

This project was developed in partnership with:

- USGS Research Geophysicists  
- MU Institute for Data Science & Informatics  
- BrightData  

And built upon:

- Streamlit multipage template by Dr. Qiusheng Wu  
- Open datasets from USGS, IRIS, FEMA, Esri, OSM, and others

---

# Glossary

- **HF:** Hugging Face
- **ROI:** Region of Interest
- **EDA:** Exploratory Data Analysis
- **OSM:** OpenStreetMap (a volunteer-run organization)
- **CLI:** Command Line Interface

--- 

**Note: This README documentation was created by Microsoft Copilot and edited by the team.**