Obspy
by SteadfastAsArt
|
Skill Details
Repository Files
6 files in this skill directory
name: obspy description: | Seismology data processing with ObsPy. Helps with reading seismic waveforms, filtering/processing time series, fetching data from FDSN services, and earthquake analysis. Use when Claude needs to: (1) Read seismic data formats (MiniSEED, SAC, GSE2, SEGY), (2) Filter or process waveforms, (3) Fetch data from IRIS/USGS/FDSN services, (4) Search for earthquakes by magnitude/location, (5) Plot seismograms or spectrograms, (6) Remove instrument response, (7) Analyze station metadata.
ObsPy - Seismology Data Processing
Quick Reference
from obspy import read, UTCDateTime
from obspy.clients.fdsn import Client
# Read local file (MiniSEED, SAC, etc.)
st = read("data.mseed")
tr = st[0] # First trace
print(tr.stats) # Metadata
# Fetch from FDSN
client = Client("IRIS")
t = UTCDateTime("2023-02-06T01:17:00")
st = client.get_waveforms("IU", "ANMO", "00", "LHZ", t, t + 3600)
st.plot()
Key Classes
| Class | Purpose |
|---|---|
Stream |
Container for multiple Trace objects |
Trace |
Single waveform with data + metadata |
UTCDateTime |
Precise time handling |
Inventory |
Station/channel metadata |
Catalog |
Earthquake event information |
Essential Operations
Read and Inspect
st = read("data.mseed") # Auto-detect format
tr = st[0]
print(tr.stats.station, tr.stats.channel, tr.stats.sampling_rate)
Filter and Process
st.detrend("demean") # Remove mean
st.detrend("linear") # Remove trend
st.taper(max_percentage=0.05) # Taper edges
st.filter("bandpass", freqmin=0.1, freqmax=10.0)
Fetch Waveforms from FDSN
client = Client("IRIS")
t1 = UTCDateTime("2023-02-06T01:17:00")
st = client.get_waveforms("IU", "ANMO", "00", "LHZ", t1, t1 + 3600)
st.write("output.mseed", format="MSEED")
Search Earthquakes
client = Client("USGS")
cat = client.get_events(
starttime=UTCDateTime("2023-01-01"),
endtime=UTCDateTime("2023-12-31"),
minmagnitude=7.0
)
event = cat[0]
print(f"M{event.magnitudes[0].mag} at {event.origins[0].latitude}")
Get Station Metadata
inv = client.get_stations(
network="IU", station="ANMO",
level="response" # Required for response removal
)
Remove Instrument Response
st = client.get_waveforms("IU", "ANMO", "00", "LHZ", t, t + 3600)
inv = client.get_stations(network="IU", station="ANMO", level="response")
st.remove_response(inventory=inv, output="VEL") # VEL, DISP, or ACC
Trim and Select
st.trim(UTCDateTime("2023-01-01"), UTCDateTime("2023-01-01T01:00:00"))
st_z = st.select(channel="*Z") # Vertical only
st_bh = st.select(channel="BH*") # BH channels
Merge and Handle Gaps
st.print_gaps() # Check for gaps
st.merge(method=1, fill_value="interpolate")
Writing Data
st.write("output.mseed", format="MSEED")
st.write("output.sac", format="SAC")
Error Handling
from obspy.clients.fdsn.header import FDSNNoDataException
try:
st = client.get_waveforms("IU", "ANMO", "00", "LHZ", t1, t2)
except FDSNNoDataException:
print("No data available")
Common Tips
- Always detrend and taper before filtering to avoid artifacts
- Use
level="response"when fetching stations for instrument correction - Check for gaps before processing with
st.print_gaps() - Wildcards work in queries:
station="A*",channel="BH?" - UTCDateTime accepts ISO strings, timestamps, datetime objects
References
- FDSN Data Centers - Available data centers and capabilities
- Channel Codes - Channel naming convention details
- Troubleshooting - Common issues and solutions
Scripts
- scripts/fetch_earthquake.py - Fetch waveforms for an earthquake
- scripts/batch_process.py - Batch process seismic files
Related Skills
Attack Tree Construction
Build comprehensive attack trees to visualize threat paths. Use when mapping attack scenarios, identifying defense gaps, or communicating security risks to stakeholders.
Grafana Dashboards
Create and manage production Grafana dashboards for real-time visualization of system and application metrics. Use when building monitoring dashboards, visualizing metrics, or creating operational observability interfaces.
Matplotlib
Foundational plotting library. Create line plots, scatter, bar, histograms, heatmaps, 3D, subplots, export PNG/PDF/SVG, for scientific visualization and publication figures.
Scientific Visualization
Create publication figures with matplotlib/seaborn/plotly. Multi-panel layouts, error bars, significance markers, colorblind-safe, export PDF/EPS/TIFF, for journal-ready scientific plots.
Seaborn
Statistical visualization. Scatter, box, violin, heatmaps, pair plots, regression, correlation matrices, KDE, faceted plots, for exploratory analysis and publication figures.
Shap
Model interpretability and explainability using SHAP (SHapley Additive exPlanations). Use this skill when explaining machine learning model predictions, computing feature importance, generating SHAP plots (waterfall, beeswarm, bar, scatter, force, heatmap), debugging models, analyzing model bias or fairness, comparing models, or implementing explainable AI. Works with tree-based models (XGBoost, LightGBM, Random Forest), deep learning (TensorFlow, PyTorch), linear models, and any black-box model
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Query Writing
For writing and executing SQL queries - from simple single-table queries to complex multi-table JOINs and aggregations
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Scientific Visualization
Meta-skill for publication-ready figures. Use when creating journal submission figures requiring multi-panel layouts, significance annotations, error bars, colorblind-safe palettes, and specific journal formatting (Nature, Science, Cell). Orchestrates matplotlib/seaborn/plotly with publication styles. For quick exploration use seaborn or plotly directly.
