Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Session 7, volcano track: Mount St Helens, 2004 to 2008

🌋 Wednesday 14 October 2026, self-guided. Each question has a self-check, and a worked solution to open after you try.

Updated 14 October, afternoon: more cells where you write the analysis yourself. If you already finished the earlier version, submit it as is.

Learning outcomes. After this session you can:

  • show that a seismogram or catalog you downloaded is the file the provider served;

  • say what a seismometer and a network catalog record, and what lies between the ground and each file;

  • tell a real extreme from an error, with a physical reason;

  • measure how instrument, telemetry, clock and catalog problems bias the regularity of repeating earthquakes;

  • turn a catalog into a learning problem without leaking test data;

  • write rules and instructions that let another person, or an AI tool, rerun your chain from the raw ComCat and HSR files to the drumbeat clock, and check whether it did.

Objectives for today. You will:

  • fetch the 2004 to 2008 catalog and six hours of station HSR, and check both;

  • screen the catalog and count drumbeats;

  • read a spectrogram;

  • hunt six problems in a synthetic HSR record and measure the drumbeat clock (drumbeat rate, median spacing, and the coefficient of variation of the spacing) before and after cleaning;

  • compute two correlations and name their traps;

  • write the chain from catalog to a labelled daily table;

  • start the two agent skill files you submit on Friday, and test an AI tool on your twin.

Start. In mlgeo-book (not MLGEO2026_UWNETID), pull and work only in a copy named with your NetID. Do not commit, push or stash.

cd mlgeo-book
git pull
cp book/Chapter2-DataManipulation/lab_s07_volcano.ipynb book/Chapter2-DataManipulation/lab_s07_volcano_UWNETID.ipynb
pixi run jupyter lab
PartWhat you doRough time (min)
0The system and the question3
1Pull the raw data and check it12
2A table: the catalog14
3A 1D array: one seismometer15
4A 2D array: the spectrogram (if you have time)10
5A synthetic twin with planted problems25
6Correlations15
7From data to a learning problem15
8Instructions for an AI tool (if you have time)7
Wrap-upThree answers and the summary3

The times are rough estimates of how long each part takes, not a schedule: about 100 min without Parts 4 and 8 and the steps marked if you have time, all of which are optional; skip them if you want more time for Part 5. Answers replace None or empty values; the check below each prints correct, a hint, or not answered yet.

Your turn cells ask you to write 2 to 5 lines of the analysis yourself, between # --- your code and # --- end. Each says what to compute and gives a one-line hint; the check below it prints correct or a hint. If you leave one as it is, the next cells continue with a reference result and say so. The worked solution sits right after; its results end in _sol, so opening it keeps yours. If a Your-turn cell still stops with an error, put its lines back to name = None before Restart and Run All: the summary prints only if every cell runs.

Submit to Canvas, “Session 7: explore your system’s data”, by Friday 16 October, 9:00: this notebook (.ipynb; HTML optional), the three files of Part 8, and a two- or three-sentence comment on your AI exchange. Completion only: the work does not count toward your grade, but a missing submission costs 10 points.

Not using git pull? Download this track as one zip, lab_s07_volcano.zip, unzip it and open the notebook from the unzipped folder; the start page explains how.

NetID: (empty: you get the class twin, the one the worked solutions use)
offline mode: True

Part 0. The system and the question (about 3 min)

Do: read, run the map, write one prediction.

On 23 September 2004, after almost 18 years of quiet, shallow earthquakes began under the crater of Mount St Helens. Small explosions followed; then lava pushed up through the 1980 crater floor as solid dacite spines until 2008 (Dzurisin and others, 2015). From 16 October the earthquakes came at such regular intervals that the Pacific Northwest Seismic Network (PNSN) and the USGS Cascades Volcano Observatory (CVO) “dubbed them ‘drumbeat’ earthquakes” (Moran and others, 2008, p. 37): “repetitive LF and hybrid earthquakes” (LF: low frequency) that “accompanied the regular rate of extrusion of several dacite spines”. They came “only ~20 s apart” until 12 November, then “event spacing increased to ~40 s, and visual inspections show that most events were detected” (p. 39); daily averages stayed “between 40 and 80 s” until April 2005 (p. 37). By 31 January 2008 “seismicity had declined to 1–2 earthquakes per day, a rate similar to pre-eruption levels” (Dzurisin and others).

The drumbeats were watched daily as the pulse of the eruption, yet “drumbeat size and spacing may be more a function of the mechanics of extrusion than of the extrusion rate” (p. 27). More than one million earthquakes were recorded by the end of 2005 and about 8,000 were located (p. 28); “the limited dynamic range of the short-period analog stations was frequently exceeded” (p. 50).

Labels (1.7): 📍 In-situ sensor · 🪨 Solid Earth · 🌋 Volcanology for the seismograms; 🗂️ Catalog & compiled product for the catalog.

Guiding question. How regular was the drumbeat clock under the growing lava dome, and how much of that clock do a single seismometer near the vent and the regional earthquake catalog each record?

Sources. Dzurisin and others (2015), Bulletin of Volcanology 77, 89, Dzurisin et al. (2015). Moran and others (2008), USGS Professional Paper 1750, chap. 2, p. 27-60, Morgan et al. (2008); page numbers refer to this chapter.

Station  Elevation                StartTime                  EndTime
    EDM     1611.0 1980-06-01T00:00:00.0000                      NaN
    HSR     1720.0 1985-08-12T00:00:00.0000                      NaN
    JUN     1049.0 1980-05-08T00:00:00.0000                      NaN
    SEP     2116.0 1997-09-01T00:00:00.0000 2004-10-06T00:00:00.0000
    SHW     1442.0 1972-10-01T00:00:00.0000                      NaN
    YEL     1750.0 1981-10-01T00:00:00.0000 2007-09-18T00:00:00.0000
<Figure size 990x468 with 3 Axes>

Grey triangles: stations whose metadata end. SEP, on the old dome and closest to the earthquakes: “The October 1 explosion destroyed seismic station SEP” (p. 35). YEL ends in September 2007.

Prediction. From the spacing quoted above, how many earthquakes per hour do you expect 2.5 km from the vent in late November 2004?

[0.guess] not answered yet

Part 1. Pull the raw data and check it (about 12 min)

Do: fetch (about 30 s), compare with the course copies, read what the instrument measured. Six questions, two Your-turn cells.

You fetch (1) every earthquake in a box around the volcano, 2004 to 2008, from the USGS Advanced National Seismic System (ANSS) Comprehensive Catalog (ComCat), through the service of the International Federation of Digital Seismograph Networks (FDSN), and (2) six hours of the vertical seismometer HSR, 2.5 km south of the 2004 vent, on 29 November 2004, from EarthScope. If a download fails, the cell uses the course copy in snapshots/.

offline mode: no download; the comparison uses the course copies only

Was the file modified or corrupted? Four checks, cheapest first: size, number of rows or samples, first and last records, and the fingerprint (SHA-256, Secure Hash Algorithm), a 64-character code computed from every byte: one changed byte changes it. The course copy’s is in snapshots/msh_2004-2008.provenance.json.

Loading...

A different fingerprint is not always corruption. ComCat is revised continuously (relocations, new magnitudes, deleted events); updated gives each row’s last revision, so look for rows updated after the course copy was retrieved. EarthScope can repackage old waveforms, so equal samples can sit in different bytes.

Your turn: count and date the catalog. Write q1_rows, the number of earthquakes (rows) in the course copy cat, and q1_updated, the latest year in which any row was revised (column updated): two integers. Then answer q1_same from the comparison table.

Hint: len(cat); cat["updated"].dt.year gives the year of each revision and .max() the latest.

course copy retrieved (UTC): 2026-10-14 06:39
[1.rows] not answered yet
[1.same] not answered yet
[1.updated] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
rows: 11305 ; latest revision year: 2025
rows by year of last revision: {2014: 9, 2016: 11290, 2022: 1, 2025: 5}

Native resolution

HSR is a Geotech S-13 short-period velocity seismometer. Its analog signal was digitized at the network’s recording center at “the 100-Hz sample rate used by the PNSN and CVO for all short-period stations” (p. 60). The StationXML lists every stage from ground to stored number: read the stages, the flat band and the gain history.

stage 1: PolesZerosResponseStage        gain        340.4  m/s -> V
stage 2: PolesZerosResponseStage        gain         1047  V -> V
stage 3: PolesZerosResponseStage        gain      0.02399  V -> V
stage 4: CoefficientsTypeResponseStage  gain         1622  V -> counts
sensor: S-13,Velocity Sensor,GEOTECH; sampling rate 100.0 Hz
overall sensitivity: 1.387e+07 counts per m/s at 1.0 Hz

Gain history of this channel (FDSN station text, column 'Scale' = counts per m/s):
      Scale  SampleRate                StartTime                  EndTime
 16924400.0       100.0 1985-08-12T00:00:00.0000 1988-07-21T23:59:59.0000
 33768700.0       100.0 1988-07-22T00:00:00.0000 1994-12-31T23:59:59.0000
535197000.0       100.0 1995-01-01T00:00:00.0000 1995-01-18T23:59:59.0000
134436000.0       100.0 1995-01-19T00:00:00.0000 1997-12-10T23:59:59.0000
134436000.0       100.0 1997-12-11T00:00:00.0000 2002-09-04T23:59:59.0000
138672000.0       100.0 2002-09-05T00:00:00.0000 2004-10-04T23:59:59.0000
 13867200.0       100.0 2004-10-05T00:00:00.0000 2007-07-10T00:00:00.0000
138672000.0       100.0 2007-07-10T00:00:00.0000 2008-04-01T00:00:00.0000
 70063200.0       100.0 2008-04-01T00:00:00.0000 2024-06-06T00:00:00.0000
<Figure size 630x270 with 1 Axes>

The scale drops tenfold on 5 October 2004 (UTC; “a gain reduction on October 4, 2004”, appendix 2): equal counts on 3 and 6 October mean ground motions ten times apart. This calibration change is recorded only in the metadata.

The seismogram is close to raw: counts every 0.01 s, without averaging, gap filling or instrument correction. After sensor, analog filters, telemetry and digitizer, it holds no frequency above half the sampling rate and no motion beyond the telemetry’s range.

The catalog is derived: arrivals picked on nst stations, a hypocenter fitted in a velocity model (rms, misfit in s), and a duration magnitude Md from how long the shaking lasted.

Your turn: where the HSR record stops. Write q1_nyquist, the highest frequency (Hz) the HSR record can represent, and q1_vclip, the ground velocity (m/s) at which HSR reaches its largest count: put every count of the record in one NumPy array d_hsr, subtract the record’s offset (its median count) from the largest count, and divide by the sensitivity resp.instrument_sensitivity.value (counts per m/s). Then answer q1_kind.

Hint: np.concatenate([tr.data for tr in read(str(course["waveform"]))]) joins the traces; the sampling rate is cha.sample_rate; np.median.

[1.nyquist] not answered yet
[1.vclip] not answered yet
[1.kind] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
Nyquist frequency: 50.0 Hz
(3582 - 162) counts / 1.387e+07 counts per m/s = 2.47e-04 m/s at 1 Hz
at 2.5 Hz the response is 2.1e+07 counts per m/s, so the record stops at 1.63e-04 m/s
at 9.1 Hz the response is 2.21e+07 counts per m/s, so the record stops at 1.55e-04 m/s
The sensitivity is quoted at 1 Hz, below the plateau, so at drumbeat frequencies the record stops at a smaller
velocity. Moran and others (p. 44) define their larger events by this limit: 'those post-October 2004 events with
amplitudes large enough to clip on station HSR'.
seismogram: raw (counts as digitized); catalog: derived (picks, a velocity model and a magnitude formula).

Part 2. A table: the earthquake catalog (about 14 min)

Do: write physical limits, then screen the table. Five questions, two Your-turn cells.

One row is one earthquake as the network located it: origin time (UTC), epicenter, depth, magnitude and its type, and the quality of the solution. The next cell prints the ComCat definitions.

source: https://web.archive.org/web/2023id_/https://earthquake.usgs.gov/data/comcat/index.php
The live ComCat event-terms page (https://earthquake.usgs.gov/data/comcat/data-eventterms.php) now redirects; the definitions below are quoted from the Internet Archive copy of the ComCat documentation page.

time: time Data Type Long Integer Description Time when the event occurred. Times are reported in milliseconds since the epoch ( 1970-01-01T00:00:00.000Z ), and do not include leap seconds . In certain output formats, the date is formatted for readability. Additional Information We indicate the date and time when the earthquake initia...

depth: depth Data Type Decimal Typical Values [0, 1000] Description Depth of the event in kilometers. Additional Information The depth where the earthquake begins to rupture. This depth may be relative to the WGS84 geoid, mean sea-level, or the average elevation of the seismic stations which provided arrival-time data for the earthquak...

mag: mag Data Type Decimal Typical Values [-1.0, 10.0] Description The magnitude for the event. See also magType . Additional Information The magnitude reported is that which the U.S. Geological Survey considers official for this earthquake, and was the best available estimate of the earthquake’s size, at the time that this page was ...

magType: magType Data Type String Typical Values “Md”, “Ml”, “Ms”, “Mw”, “Me”, “Mi”, “Mb”, “MLg” Description The method or algorithm used to calculate the preferred magnitude for the event. Additional Information See Magnitude Types Table . mmi Data Type Decimal Typical Values [0.0, 10.0] Description The maximum estimated instrumental in...

nst: nst Data Type Integer Description The total number of seismic stations used to determine earthquake location. Additional Information Number of seismic stations which reported P- and S-arrival times for this earthquake. This number may be larger than the Number of Phases Used if arrival times are rejected because the distance to ...

rms: rms Data Type Decimal Typical Values [0.13,1.39] Description The root-mean-square (RMS) travel time residual, in sec, using all weights. This parameter provides a measure of the fit of the observed arrival times to the predicted arrival times for this location. Smaller numbers reflect a better fit of the data. The value is depen...

dmin: dmin Data Type Decimal Typical Values [0.4, 7.1] Description Horizontal distance from the epicenter to the nearest station (in degrees). 1 degree is approximately 111.2 kilometers. In general, the smaller this number, the more reliable is the calculated depth of the earthquake. felt Data Type Integer Typical Values [44, 843] Des...

Loading...

Limits first. Depth is in km, positive down, possibly from sea level. HSR sits at 1,720 m and SEP at 2,116 m. Which depths and magnitudes are possible for earthquakes under this volcano?

Your turn: the rows outside your limits. Fill LIMITS first. Then write out_d, the rows of cat whose depth is outside LIMITS["depth_km"], and out_m, the rows whose magnitude is outside LIMITS["mag"]: two pandas DataFrames.

Hint: cat["depth"].between(LIMITS["depth_km"][0], LIMITS["depth_km"][1]) is True inside the limits; ~ turns True into False; cat[...] keeps the rows where the condition is True.

[2.limits] not answered yet
[2.outside] not answered yet
[out_d, out_m] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
1 rows outside the depth limits, 1 outside the magnitude limits
1 rows outside the reference depth limits, 1 outside the reference magnitude limits
                            time  depth  depthError  mag  nst         id
2007-05-22 03:41:45.670000+00:00 42.319         1.0  0.9   13 uw10718303
                            time  mag magType  nst         id
2004-09-23 21:48:47.190000+00:00 -2.5      md    4 uw10627148

Your turn: screen the table. Write q2_missing, the name of the column with the most missing values (a string); q2_magtypes, how many distinct magnitude types the catalog uses (an integer); and q2_largest, the date (YYYY-MM-DD, a string) of the largest earthquake in the box.

Hint: cat.isna().sum() counts per column and .idxmax() names the largest; .nunique(); cat.sort_values("mag", ascending=False).iloc[0] is the row of the largest magnitude.

[2.missing] not answered yet
[2.magtypes] not answered yet
[2.largest] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
dmin 3 2004-10-01
event types: {'earthquake': 11304, 'explosion': 1}

rows that share an origin time with another row:
                            time  latitude   longitude  depth  mag  nst  rms         id
2004-10-04 14:30:03.270000+00:00 46.167667 -122.211833  0.390  1.4    7 0.30 uw10642533
2004-10-04 14:30:03.270000+00:00 46.196667 -122.190833 -0.428  0.3    7 0.03 uw10642498

depth distribution (km): {'count': 11305.0, 'mean': -1.08, 'std': 1.25, 'min': -2.01, '25%': -1.74, '50%': -1.35, '75%': -0.74, 'max': 42.32}
most common depth values (km): {-1.834: 198, -1.824: 171, -1.884: 146, -1.814: 143}

One real extreme, one error. A real extreme is a rare value the Earth produced: keep it. An error is a value the measuring or processing chain produced: flag it, with a reason. Pick one of each.

[2.error] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
magnitude types: 3 {'md': 11299, 'ml': 5, 'mh': 1}
most missing: dmin (dmin, the distance to the nearest station, is blank for most 2004-2008 rows)
Error: rows ['uw10642533', 'uw10642498'] share an origin time to the hundredth of a second, sit 3.6 km apart
with Md [1.4, 0.3] and nst [7, 7]. One earthquake entered twice with different picks is far
more likely than two starting in the same hundredth of a second: flag both, check the waveforms.
Real extreme: Md 3.9 on 2004-10-01 17:13 UTC, the day of the first explosion: keep it. Its magnitude
is uncertain: that week it became 'increasingly difficult to manually pick earthquakes and determine accurate coda
magnitudes' (Moran and others, p. 33).

Depth: the shallowest row is -2.01 km; 2 rows are at or above -2.00 km;
1804 rows lie between -1.9 and -1.8 km, 198 of them at exactly -1.834 km.
Median depthError there 0.10 km, elsewhere 0.26 km;
99th percentile of depth 2.78 km, 2 rows deeper than 20 km.
The pile-up is 1.8 to 1.9 km above sea level, about the elevation of the crater floor: the drumbeats were very shallow.
Identical depths to the metre in 198 separate earthquakes are set not by the ground but by the
location program. Their formal depthError is small, so a small formal error does not mean a correct depth.
The datum matters: Moran and others plot the same events relative to a datum 'roughly 1.1 km above sea level' (fig. 2).
The 42 km row (2007-05-22, uw10718303) is far deeper than 99% of the rows: keep it flagged for a
separate check (nst 13, gap 90°, depthError 1.0 km).
The Md -2.5 row (2004-09-23, uw10627148, nst 4) is the other defensible flag: the next lowest
magnitude is -1.6. Both are accepted by the self-check, with a reason.
Defensible limits: depth from about -2.5 km (stations sit 1.0 to 2.1 km above sea level)
to a few tens of km; magnitude from about -2 to 5.

Part 3. A 1D array: six hours of one seismometer (about 15 min)

Do: find the sampling interval and gap, count drumbeats and measure their spacing, and, if you have time, find a real sensor problem. Seven questions, two Your-turn cells.

Raw counts from UW.HSR..EHZ, 15:00 to 21:00 UTC on 29 November 2004. Two processes shape the record: drumbeats every few tens of seconds, and occasional larger earthquakes, a separate process (fig. 19 covers this day).

2 Trace(s) in Stream:
UW.HSR..EHZ | 2004-11-29T15:00:00.000900Z - 2004-11-29T20:19:01.860900Z | 100.0 Hz, 1914187 samples
UW.HSR..EHZ | 2004-11-29T20:39:18.869900Z - 2004-11-29T20:59:59.999900Z | 100.0 Hz, 124114 samples
<Figure size 990x540 with 2 Axes>

Your turn: the record and the catalog in the same six hours. Write q3_dt, the sampling interval (s); q3_gap_min, the length of the data gap (minutes); q3_n_extreme, the number of samples equal to the record’s largest or smallest value (d holds every count); and in_window, the rows of cat (a DataFrame) from 15:00 to 21:00 UTC on 29 November 2004.

Hint: st[0].stats.delta; st.get_gaps() gives one list per gap, whose item [6] is its length in s; (d == d.max()).sum() counts; put each time condition in its own parentheses, then join them: (cond1) & (cond2), as in (cat["time"] >= "2004-11-29 15:00").

[3.dt] not answered yet
[3.gap] not answered yet
[3.extreme] not answered yet
[3.window] not answered yet
[in_window] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
0.01 s; 20.28 min; 444 samples at the extremes; 10 ComCat rows
615 detections in 5.66 h of data
Loading...

Your turn: the drumbeat rate and spacing. Write rate, detections per hour of data (a float); intervals, the seconds between consecutive detections, without the one that spans the data gap (a pandas Series: keep values below 600 s); cv_real, the coefficient of variation of intervals, standard deviation over mean (a float); and per10, the number of detections in each 10-minute bin (a pandas Series).

Hint: det["time"].diff().dt.total_seconds() gives the spacing; .std(), .mean(); det.set_index("time").resample("10min").size() counts per bin.

[3.rate] not answered yet
[3.clock] not answered yet
[rate, intervals, cv_real, per10] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
108.6 per hour; median spacing 34.5 s; CV 0.37; 36 bins
108.6 detections per hour of data; your Part 0 guess: none per hour
median time between detections 34.5 s
coefficient of variation of the spacing (standard deviation / mean): 0.37, false triggers included
ComCat lists 10 earthquakes in the same six hours
<Figure size 990x225 with 1 Axes>

Compare the rate with your guess: the detector also counts bursts and large events, and the published spacing is a daily average. The 10-minute bins that fall in the data gap hold fewer detections or none: no data, not a quiet volcano.

If you have time: a real sensor problem. You counted the samples at the record’s extremes; now look at the earthquake at 15:14:55 and the burst at 20:00:32, at HSR and three other crater stations. The cell also lists every second whose energy above 15 Hz exceeds 20 times its median.

median of the record (the digitizer offset): 162 counts
distance from HSR (km): {'EDM': 3.4, 'JUN': 3.7, 'SHW': 4.7}
EDM: burst starts at 2004-11-29T20:00:32.090000Z
JUN: burst starts at 2004-11-29T20:00:32.080000Z
SHW: no burst between 20:00:30 and 20:00:40
HSR: burst starts at 2004-11-29T20:00:32.050900Z
8 bursts above 15 Hz: ['16:33:15', '16:58:09', '17:35:55', '17:59:59', '18:30:46', '19:04:43', '19:27:37', '20:00:32']
minutes between them: [25, 38, 24, 31, 34, 23, 33]
<Figure size 990x720 with 5 Axes>
[3.burst] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
sampling interval 0.01 s; gap 20.28 min (2004-11-29T20:19:01.860900Z to 2004-11-29T20:39:18.869900Z)
samples at the extremes: 444, from the clipped earthquake and from the bursts.
The large earthquake at 15:14:55 is cut flat at 3582 and -3584 counts: the record cannot hold more, so its peak
amplitude, and any magnitude from it, is a lower bound.
108.6 detections per hour of data (615 in 5.66 h), median spacing 34.5 s;
ComCat located 10 of them. After 12 November Moran and others report a spacing of about 40 s with most events detected.
The 20:00:32 burst starts within a few hundredths of a second at HSR, EDM and JUN (3 to 4 km apart), is absent at SHW,
and has no coda. A seismic wave would arrive later at the farther stations: it came through a shared part of the
telemetry, not through the ground.
The high-frequency search finds 8 such bursts between 16:33 and 20:00,
23 to 38 min apart; none is in ComCat. Moran and others list 'noise glitches (including telemetry
and/or Internet dropouts, radio interference, and calibration pulses)' as a reason their detector needed
station-specific filters (appendix 2, p. 60).

Part 4. A 2D array: the spectrogram (about 10 min, if you have time)

Do: compute a one-hour spectrogram, name its axes and resolution, compare it with published spectra. Four questions, one Your-turn cell.

A spectrogram holds the power (counts² per Hz, plotted in dB) at each frequency (rows) in short windows (columns): here 512 samples, overlapping by half.

array shape (frequencies, times): (257, 1405) ; rows: freqs (Hz), columns: times (s)
time step 2.56 s
212 of 1405 windows (columns) hold a detection onset

Your turn: median spectra. Write q4_df, the frequency step of the spectrogram (Hz, a float), and three NumPy arrays with one value per frequency: med_all, the median of S over all windows (columns); med_with, over the windows where has is True; med_without, over the others.

Hint: np.median(S, axis=1) takes the median along the time axis; S[:, has] keeps the columns where has is True and S[:, ~has] the others.

[4.df] not answered yet
[4.spectra] not answered yet
[med_all, med_with, med_without] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
0.1953 Hz; arrays of shape (257,)
median spectrum of all windows: highest above 0.5 Hz at 1.37 Hz
median spectrum of 212 windows with a detection: highest above 0.5 Hz at 1.37 Hz
median spectrum of 1193 windows without: highest above 0.5 Hz at 1.76 Hz
windows with a detection exceed windows without by the largest factor (47) at 5.08 Hz
median spectrum of the first 2.56 s after 106 triggers: highest at 2.34 Hz
<Figure size 1080x360 with 2 Axes>

Seismicity “was dominated by LF events (peak frequencies in the 2–3-Hz range)” (p. 42), measured on the first 2.56 s after each trigger (appendix 2). Expect a stripe every 30 to 40 s. The earthquake at minute 15 is brighter and broader; its clipped tops add high-frequency power the ground did not produce. Below some frequency the sensor’s response falls (Part 1), so the 0.2 Hz ocean microseism is weak here.

Three “peak frequencies” come from one array: the median of all windows (drumbeats, codas and background mixed), the ratio of windows with and without a detection (largest where the background is weakest), and the first 2.56 s after each trigger. Which answers “at what frequency do the drumbeats radiate”?

a narrow line in the one-hour spectrum at 19.98 Hz, 3.3 dB above the median of 18 to 22 Hz;
the response there is 3.1 dB below its maximum
[4.fpeak] not answered yet
[4.low] not answered yet
[4.line] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
frequency resolution = 100 Hz / 512 samples = 0.1953 Hz; time step 2.56 s
first 2.56 s after each trigger: peak at 2.34 Hz, inside the 2-3 Hz Moran and others report for LF drumbeats.
The median of all windows peaks at 1.37 Hz: background and codas set it, not the drumbeat onsets.
The with/without ratio peaks at 5.08 Hz because the background without detections is strongest
near 1.76 Hz, which shrinks the ratio there. A ratio measures contrast, not where energy is radiated.
the response is within 3 dB of its maximum from 1.16 Hz to about 20 Hz (StationXML)
The 19.98 Hz line: no source we have explains it, so treat it as an open question. Tests: is it present in every hour
and in the gap-free minutes without drumbeats; is it at the same frequency on EDM, JUN and SHW (two-minute file);
does its amplitude follow the ground motion? A line that stays at one frequency whatever the ground does is more likely
made by the recording chain than by the volcano, but only those tests can say.

Part 5. A synthetic twin with planted problems (about 25 min)

Do: (a) list what can go wrong, (b) hunt and measure the clock shift, (c) write the cleaning and measure the drumbeat clock, (d) reflect. Two Your-turn cells.

The twin imitates three hours of HSR with a known truth: counts at 100 samples per second, noise, drumbeats, three larger earthquakes, and the event list (time, peak amplitude within 6 s, magnitude, magnitude type, id). Like the real record it clips the large earthquakes; that is the instrument, not a planted problem. Your NetID chooses which six problems of real volcano records are planted, and where (empty: the class twin of the worked solution).

The drumbeat clock is the rate of drumbeats (magnitude below 2.0) per hour of data, their median spacing, and the coefficient of variation (CV) of the spacing, standard deviation over mean: near 0 for a clock, near 1 for a random (Poisson) process. The twin’s spacing (32 to 45 s) and CV (0.15 to 0.28) are chosen, not measured.

(a) Before you look, list the problems a seismometer on a volcano, its telemetry, its recording computer, and the people and programs that build an event list could introduce.

[5a] not answered yet
twin 'class': start 2005-01-01 00:00:00+00:00, 1080000 samples at 100 per second, 257 listed events
Loading...

(b) Hunt. Read each panel against what the ground and instrument can do; zoom(minute) shows the raw twin.

  1. Min and max in 10 s windows.

  2. Noise: median distance from the median count, per minute.

  3. Magnitude minus the amplitude magnitude 1 + log10(peak / 300): 300 counts is about Md 1.0 at HSR (appendix 2); one unit per factor of 10 is our assumption. Clipped events sit high, and for real drumbeats “long codas ... yield overly large Md values relative to magnitudes determined using amplitudes” (p. 44).

  4. Listed time minus the detected onset (s): about −0.3 s when they agree, because the detector triggers during each event’s 0.4 s rise. On real events under 300 counts “our algorithm commonly triggered on the S-wave” (p. 60).

  5. Time since the previous listed event (s).

A drumbeat just before a larger earthquake takes that earthquake’s amplitude into its 6 s window: a real overlap, keep it.

<Figure size 990x990 with 5 Axes>
largest count 3582 appears 215 times; smallest -3584 appears 194 times
runs of exact zeros longer than 1 s (minutes): [(115.57, 120.79)]
runs with no samples (NaN) (minutes): [(146.87, 163.65)]
minutes where the noise level jumps by more than a factor 1.5: {27: 1.7, 28: 0.56, 87: 1.62, 88: 0.59, 115: 3.61, 116: 0.0, 121: inf, 128: 1.61, 129: 0.59}
events whose magnitude is more than 1 unit below what their amplitude predicts:
                        time      minute  peak_counts  mag        id
14   2005-01-01T00:09:04.68Z    9.078000         3728  0.2  sy100118
62   2005-01-01T00:38:04.40Z   38.073333         2919  0.3  sy100454
99   2005-01-01T00:59:22.04Z   59.367333         3622  0.3  sy100705
134  2005-01-01T01:19:51.77Z   79.862833         3597  0.4  sy100956
218  2005-01-01T02:18:13.06Z  138.217667         3728  0.3  sy101546

Your turn: the clock shift. Panel 4 (listed time minus detected onset) steps at one minute if the clock of the event list jumped. Set JUMP_MINUTE to the minute where it steps; if it has no step, use 90, the middle of the twin, to confirm there is none. Then write late, True for the rows of ev at or after JUMP_MINUTE (a True/False Series), and SHIFT_S, the median of ev["lag_s"] on those rows minus the median on the others, in seconds (a float).

Hint: ev["minute"] >= JUMP_MINUTE; ev.loc[late, "lag_s"].median(), and ~late selects the other rows.

[5.shift] not answered yet
[SHIFT_S] set JUMP_MINUTE first; continuing with no shift

Worked solution below (click ⋯ to open).

Notebook Cell
listed times from minute 33.3 on are shifted by -5.76 s

Record each problem: kind, one of calibration pulse, zeros, dropout, gain change, telemetry burst, clock jump, duplicate, magnitude method change, clipping, spike, unit change, drift; minute (start of a stretch); why it is physically implausible. Not every kind is planted; clipping never is. The three larger earthquakes are real.

not answered yet

(c) The drumbeat clock three ways: truth, as given, and after your cleaning.

Your turn: the cleaning. Inside clean, write one line per decision: (1) remove the duplicates, rows less than 2 s after the previous one (dt_s) with the same magnitude; (2) remove the listed glitches, rows whose magnitude is more than 1 unit below what their amplitude predicts (resid below -1) and whose magnitude is below 0.6 (run zoom(minute) on each first: a drumbeat just before a larger earthquake also has a low resid); (3) if panel 4 steps, move the rows from JUMP_MINUTE on by SHIFT_S (minute is in minutes). Fill EXCLUDE with the no-data stretches (start, end minute) so that intervals across them are not counted. Leave out a step your twin does not need. Defining clean prints nothing: run the cell after the worked solution to measure your cleaning; an error in clean shows up there.

Hint: e[~mask] keeps the rows where mask is False; e["mag"].shift(1) is the previous row’s magnitude; e.loc[mask, "minute"] -= SHIFT_S / 60 changes only the rows in mask; put each condition in parentheses before joining with &.

Worked solution below (click ⋯ to open).

Notebook Cell
clean_sol removes 9 rows of your twin's list; the full worked solution is after (d)
                     n_drumbeats  rate_per_hour  median_interval_s     cv
label                                                                    
truth                        280           93.3               38.6  0.152
contaminated                 254           84.7               38.3  1.601
after your cleaning          254           84.7               38.3  1.601
[5.clean] not answered yet

(d) Reflect. For each problem: did it bias the clock (rate, spacing, CV) or something else, such as a magnitude or an amplitude? Which could cleaning not undo, and what would recover them?

[5d] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
planted in the class twin: ['zeros', 'dropout', 'telemetry burst', 'clock jump', 'duplicate', 'magnitude method change']
exact zeros (minutes): [(115.57, 120.79)]   no samples: [(146.87, 163.65)]
clock: listed - onset is -0.33 s before minute 33.3 and -6.10 s after:
from there the listed times run 5.8 s early: subtract the shift (-5.77 s),
which moves them 5.8 s later
duplicates: 4 at minutes [45.2, 54.2, 65.9, 71.6]
listed glitches (amplitude far above the magnitude): [9.1, 38.1, 59.4, 79.9, 138.2]
drumbeats listed within seconds before a large earthquake:
     minute  peak_counts  mag  resid
146   87.27         3728  1.2  -0.89
  their 6 s amplitude window holds the earthquake, so their amplitude is too large for their magnitude:
  a real overlap, neither a duplicate nor a glitch. Keep them.
magnitudes 0.36 low from minute 94 to 108, while the noise level there is 22 counts against 23 overall: amplitudes unchanged.
after the correction, listed - onset after minute 33: -0.33 s
              n_drumbeats  rate_per_hour  median_interval_s     cv
label                                                             
truth                 280           93.3               38.6  0.152
contaminated          254           84.7               38.3  1.601
cleaned               245           93.5               38.6  0.156
worked solution: 6 of 6 planted problems found.
  kinds you missed: none
Not undone by cleaning: the drumbeats inside the zeros and the dropout are lost (the rate is right only per hour
of data); clipped peaks stay lower bounds; a magnitude block computed with another method needs that method's
conversion, which the list does not give. The duplicates, glitches and clock jump can be undone because the
seismogram is an independent witness for every row.

Part 6. Correlations on the real data (about 15 min)

Do: state the expected sign, compute Pearson and Spearman, name the trap. Six questions, two Your-turn cells (B if you have time).

A. Counts against shaking. Detections against mean absolute amplitude in 5-minute bins at HSR (the idea behind the real-time seismic amplitude measurement, RSAM, that CVO watched).

B. Magnitude against waiting time. From 16 October 2004 to the end of 2005, when “seismicity was dominated by these drumbeats” (p. 27), each located earthquake’s magnitude against the time since the previous one. If each drumbeat released strain stored since the last, larger ones would follow longer waits.

[6.sign] not answered yet
A: 67 complete 5-minute bins
Loading...

Your turn: counts against shaking (A). Write rA and sA, the Pearson and Spearman correlations between A["detections"] and A["mean_abs_counts"] (two floats), and disp, the variance over the mean of A["detections"] (a float; a random Poisson count gives 1).

Hint: stats.pearsonr(x, y)[0] and stats.spearmanr(x, y)[0]; .var() and .mean().

[6.pearsonA] not answered yet
[6.disp] not answered yet
[rA, sA, disp] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
Pearson -0.061, Spearman 0.015, variance / mean 0.21

Your turn: magnitude against waiting time (B), if you have time. Write B, the rows of cat from 16 October 2004 to the end of 2005 whose type is “earthquake”, with a new column wait_h, the hours since the previous row, and without the first row, which has no previous one (a DataFrame). Then rB and sB, the Pearson and Spearman correlations between B["mag"] and B["wait_h"].

Hint: Join three conditions with & and end the selection with .copy(); B["time"].diff().dt.total_seconds() / 3600; B.dropna(subset=["wait_h"]).

[6.spearmanB] not answered yet
[B, rB, sB] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
6669 earthquakes, Pearson -0.014, Spearman -0.009
A: 67 complete bins, Pearson -0.061, Spearman 0.015; lag-1 autocorrelation of amplitude 0.19,
   effective number of independent bins about 46
   detections per bin: 6 to 12, mean 9.0, variance / mean 0.21 (a random Poisson count gives 1)
   without the 11 bins holding samples beyond ±3000 counts: Pearson -0.074, Spearman -0.022
B: 6669 located earthquakes, Pearson -0.014, Spearman -0.009
   located per day: 15.1; the detector at HSR counts about 2607 per day
<Figure size 990x360 with 2 Axes>

Traps: (a) a shared seasonal cycle; (b) catalog completeness: only part of the earthquakes are listed; (c) overlapping events: a large earthquake’s coda covers nearby drumbeats; (d) a unit change; (e) the count barely varies between bins (a clock), leaving little variance to correlate.

[6.trapA] not answered yet
[6.trapB] not answered yet
[6.says] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
A: Pearson -0.06, Spearman 0.02. Expected positive (more earthquakes, more shaking), observed near zero.
The count per 5 minutes runs only from 6 to 12 (variance / mean 0.21, far below a
random count's 1): a clock leaves almost no variance to correlate (e). The loud bins are set by a few large
earthquakes and telemetry bursts, but removing them leaves the correlation near zero, so overlapping events (c)
are a smaller effect. Accept (c) or (e); (e) drives the number. Only about 46 bins are independent.

B: expected sign '+'. Moran and others (p. 40): 'In general, increases in event spacing corresponded to increases in
event size and vice versa (fig. 15)'. They saw it in daily averages of 'Roughly 370,000 events' detected at HSR
(fig. 13 caption, p. 39). Here: Spearman -0.009, near zero, from 6669 located events.
ComCat located about 15 per day out of about 2607 detected at HSR: 'time since the
previous located event' is not the time since the previous earthquake. Completeness (b), plus the averaging scale:
Moran's relation is between daily averages, not between single events.
Neither result says the drumbeats have no memory: the catalog cannot test it, a full detection list could.

Part 7. From data to a learning problem (about 15 min)

Do: write the chain from raw file to a learnable table, choose the task, look at the target, split and balance. Eight questions, two Your-turn cells (the second if you have time).

Could a day of catalog data tell whether the volcano is erupting, or predict an earthquake’s magnitude? Write your chain as ordered (step, reason) pairs: what you select, remove, flag, keep as a real extreme, how you aggregate, which anomalies you compute, and how you split so nothing leaks from test to training.

[7.steps] not answered yet
[7.task] not answered yet

Classification: a rare class. The Puget Sound copy of ComCat (2000 to 2025, notebook 2.7) covers the same box. Count earthquakes per day; label days from 16 October 2004 to 31 January 2008 “dome-building eruption” (Dzurisin and others describe “repetitive ‘drumbeat’ earthquakes that characterized much of the eruption”). The drumbeats were not uniform: they “became irregular” on 20 July 2005, and by October 2005 Moran and others questioned “whether the seismic events we were seeing were earthquakes” (p. 39). The swarm and explosions of 23 September to 15 October 2004 are neither background nor dome building: dropped.

The Puget copy holds earthquakes of magnitude 0 or more, and “By September 24, earthquakes had become so numerous that the PNSN began locating only a subset of them” (p. 30): located earthquakes per day also measure analyst capacity and station coverage, which changed with the label.

Puget copy query: {'eventtype': 'earthquake', 'minmagnitude': 0}
rows in the box for 2004-2008: 10645 in the Puget copy, 11305 in the Mount St Helens copy
  2000-01-01 to 2004-09-23:  1727 days,   0.34 located per day, 0.25 of days with one or more
  2004-09-23 to 2004-10-16:    23 days,  87.39 located per day, 1.00 of days with one or more
  2004-10-16 to 2006-01-01:   442 days,  14.98 located per day, 0.98 of days with one or more
  2006-01-01 to 2008-02-01:   761 days,   2.40 located per day, 0.81 of days with one or more
  2008-02-01 to 2016-01-01:  2891 days,   0.64 located per day, 0.38 of days with one or more
  2016-01-01 to 2026-01-01:  3653 days,   0.97 located per day, 0.47 of days with one or more
9474 days kept, 1203 in the dome-building eruption
Loading...

Your turn: the target and a time split. Write frac_pos, the fraction of the kept days labelled eruption (a float between 0 and 1); train and test, the rows of daily before split and from split on (two DataFrames); and w_pos, the class weight for eruption days computed on train only: the number of non-eruption days over the number of eruption days.

Hint: The mean of a True/False column is the fraction of True; daily[daily.index < split]; (~train["erupting"]).sum() counts the False.

[7.frac] not answered yet
[7.split] not answered yet
[frac_pos, train, test, w_pos] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
0.1270; 5821 training and 3653 test days; weight 3.8
12.70% of the kept days are eruption days
time split, train 2000-2015 / test 2016-2025: 5821 / 3653 days
class weight for eruption days, computed on the training set only: 3.8

Regression: a skewed target. Large earthquakes are rare. A model trained with equal weights learns the common sizes and can be poor where it matters.

Your turn: the magnitude distribution, if you have time. Write counts, the number of earthquakes in each magnitude bin of bins (a NumPy array); frac_big, the share of earthquakes with Md 2.5 or more (a float); and tr_m, the magnitudes of the rows before 1 July 2005, the training rows of a time split (a pandas Series).

Hint: np.histogram(values, bins=bins) returns the counts and the bin edges; the mean of a True/False Series is a fraction; cat.loc[condition, "mag"].

[7.hist] not answered yet
[7.big] not answered yet
[counts, frac_big, tr_m] Using the reference result so you can continue; compare with yours.

Worked solution below (click ⋯ to open).

Notebook Cell
[   1    9   40  197  412  464  770 1618 2946 3456  996  377   19] 0.123 7934
-2.5 to -2.0       1
-2.0 to -1.5       9
-1.5 to -1.0      40
-1.0 to -0.5     197
-0.5 to 0.0      412
0.0 to 0.5       464
0.5 to 1.0       770
1.0 to 1.5      1618
1.5 to 2.0      2946
2.0 to 2.5      3456
2.5 to 3.0       996
3.0 to 3.5       377
3.5 to 4.0        19
share of earthquakes with Md 2.5 or more: 0.123
weight per magnitude bin, computed on the training rows only: {-2.5: 610.31, -2.0: 67.81, -1.5: 16.95, -1.0: 3.74, -0.5: 2.41, 0.0: 2.01, 0.5: 1.3, 1.0: 0.62, 1.5: 0.31, 2.0: 0.22, 2.5: 0.96, 3.0: 2.22, 3.5: 40.69}
[7.acc] not answered yet
[7.test] not answered yet
[7.balance] not answered yet

Worked solution below (click ⋯ to open).

Notebook Cell
eruption days 0.1270; always-'not erupting' accuracy 0.8730: accuracy says little here.
A time split at 2016 leaves 0 eruption days to test on: one eruption cannot be split
in time and still be tested. Options: split within 2004-2008 by blocks of weeks with a buffer between them
(the days are autocorrelated), or test on another eruption or volcano.
The feature is not stationary: located events per day were higher after 2016 than before September 2004 (table above),
while the volcano was quiet in both periods. A model can learn the network's history as well as the volcano's.
Balancing comes after the split and only on the training data: class weights (here about 4),
or resampling the training days. Report recall and the precision-recall curve on the untouched test set.
Weighting changes the base rate the model learns, so its probabilities must be recalibrated before use.
Regression: 12.3% of magnitudes are 2.5 or more. Weight by magnitude bin (computed on training rows),
stratify validation folds by magnitude quantile, and report the error per quantile, not one overall RMSE.
Bins holding one or a few events get weights of tens to hundreds: merge sparse bins or cap the weights.
Clipping at HSR and the coda bias of Md for drumbeats mean the largest targets are themselves uncertain.
[7.steps] covers the topics

Part 8. Instructions for an AI tool (about 7 min, if you have time)

Do: start the agent skill files you submit, try them on an AI tool, compare its findings on your twin with yours. Two questions.

Templates with volcano hints are in lab_s07_templates/:

  • reproducibility_rules.md: rules, each checkable yes or no, that an AI tool must follow on your project data, built on the six AGENTS.md headings of HW1 (1.9, Step 7) and the class rubric.

  • pipeline_instructions.md: from raw ComCat and HSR files to the drumbeat clock: get the files from the providers, confirm they were not modified or corrupted, clean with a reason per step (flag, remove, or keep a real extreme), compute the clock, report what the tool could not do.

  • ai_conversation.md (the transcript may be a PDF beside it): the record of your conversation, and what you checked and corrected.

UW Purple cannot run code or read MiniSEED: upload your two agent skill files and the CSV files written below. Claude or GitHub Copilot in VS Code open files directly. In class, give the tool the twin files and the instructions below; enter its findings in the same format as yours. The twin test stays in this notebook (tool_findings, q8); item (d) is a separate conversation on the real data with your two files. The last cell of this part prints the real-data values to compare the tool’s numbers with.

files for the AI tool: {'mseed': 's07_my_files/s07_volcano_HSR_class_seismogram.mseed', 'csv1s': 's07_my_files/s07_volcano_HSR_class_seismogram_1s.csv', 'events': 's07_my_files/s07_volcano_HSR_class_events.csv'}
real data as CSV: s07_my_files/s07_volcano_HSR_2004-11-29_1s.csv and snapshots/comcat_msh_2004-2008.csv

I attach two files from a short-period vertical seismometer 2.5 km from an erupting lava dome:
(1) s07_volcano_HSR_class_seismogram.mseed (MiniSEED, 100 samples per second, raw counts; if you cannot read MiniSEED use s07_volcano_HSR_class_seismogram_1s.csv, which
gives for each second the minimum, maximum and mean count and the number of samples), and
(2) s07_volcano_HSR_class_events.csv (the list of events built from this record: time in UTC, peak amplitude in counts within 6 s
of the onset, duration magnitude, magnitude type, id).
The files contain problems introduced by the instrument, the telemetry, the clock, or the people and programs
that built the event list. List every problem you find, each with its kind, the time in minutes after the
start of the record, and the evidence. Then compute the coefficient of variation (standard deviation divided
by mean) of the time between consecutive events with magnitude below 2.0, before and after your cleaning.
Use only these files. Say which problems you could not undo, and say so if you could not run code or open a file.
not answered yet
[8] not answered yet
real data, every detection, as read: CV of the spacing 0.371, median spacing 34.5 s, 613 intervals
real data, detections at telemetry bursts removed: CV of the spacing 0.374, median spacing 34.7 s, 606 intervals

Wrap-up (about 3 min)

Three answers, two to four sentences each, each with one number or date from today’s work. Then Kernel, Restart Kernel and Run All Cells; read the summary at the end, save, and submit. If a Your-turn cell still stops with an error, put its lines back to name = None before Restart and Run All: the summary prints only if every cell runs.

[w1] not answered yet
[w2] not answered yet
[w3] not answered yet
==== SESSION 7 SUMMARY ====
track: volcano
netid: not answered
parts answered: P0 0/1 | P1 0/6 | P2 0/6 | P3 0/7 | P4 0/5 | P5 0/5 | P6 0/7 | P7 0/10 | P8 0/2
self-checks passed: 0 of 45
planted problems found: 0 of 6 (seed 4286574832)
derived quantity (truth / as given / after cleaning): 0.152 / 1.601 / not answered (CV of the drumbeat spacing, no unit)
reflection 1: not answered
reflection 2: not answered
reflection 3: not answered
==== END SUMMARY ====
References
  1. Dzurisin, D., Moran, S. C., Lisowski, M., Schilling, S. P., Anderson, K. R., & Werner, C. (2015). The 2004–2008 dome-building eruption at Mount St. Helens, Washington: epilogue. Bulletin of Volcanology, 77(10). 10.1007/s00445-015-0973-4
  2. Morgan, S. C., Malone, S. D., Qamar, A. I., Thelen, W. A., Wright, A. K., & Caplan-Auerbach, J. (2008). Seismicity associated with renewed dome building at Mount St. Helens, 2004-2005. In D. R. Sherrod, W. E. Scott, & P. H. Stauffer (Eds.), Professional Paper (pp. 27–60). US Geological Survey. 10.3133/pp17502