Skip to content

Fix low-risk QC/post-processing bugs (no catalog outputs change)#8

Open
mdenolle wants to merge 1 commit into
mainfrom
fix/qc-postprocessing-lowrisk
Open

Fix low-risk QC/post-processing bugs (no catalog outputs change)#8
mdenolle wants to merge 1 commit into
mainfrom
fix/qc-postprocessing-lowrisk

Conversation

@mdenolle

@mdenolle mdenolle commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes four low-risk bugs found in a QC / post-processing audit. None of these change any published catalog output — they fix a display bug, two crash bugs, and a divide-by-zero in an unused-by-the-filter metric.

The amplitude-plot fix resolves the undergrad reports about ARIDs 999395, 999382, 999384, 178428: the amplitude values were always correct, but the full-window QC plot misplaced the pick marker and amplitude window, so the true peak appeared to fall outside the purple band.

Changes

File Fix
4_relocation/quality_control/examine_..._w_amp.ipynb Both plot functions: replaced the fake np.linspace(-window_before, window_after, npts) time axis with tr.times(reftime=time_pick) (honors tr.stats.starttime); added sdata.merge(method=1) so gappy multi-segment channels are plotted/selected as one record instead of only tr_select[0]. Display-only.
4_relocation/event_waveform_processing.py Guard print(picks_df.loc[mask]) with if measurements:mask was undefined for the first event with no data → NameError.
3_post_processing/get_waveform_amplitude.py Same crash guard.
utils/qc_utils.py (calc_snr, 3 sites) Guard 20*log10(signal/noise) against zero amplitudes → NaN instead of inf/-inf. Not used by the QC pass/fail filter.

Why these are safe

  • Amplitude plot: cosmetic; the stored Amplitude values (from calculate_amplitudes.py) are unchanged and were verified correct.
  • The two batch scripts are superseded by calculate_amplitudes.py; the fix only prevents a crash.
  • calc_snr's SNR column is not consumed by the rms<2.5 & p_picks>4 & s_picks>4 filter.

Verification

  • All three .py files pass python -m py_compile.
  • Notebook re-parses; embedded outputs untouched (diff confined to the two function cells).

Deliberately NOT included (change outputs / need a decision)

  • QC pick-count threshold: qc_metrics_..._cc.ipynb uses p_picks > 4 & s_picks > 4 (≥5), but the output file is named ..._p_4_s_4_... (≥4). Reconcile intent before changing the catalog.
  • Morton nearest-neighbor match has no acceptance threshold; concat_anss does no dedup / magnitude-type reconciliation.
  • Aligning the qc_metrics pick-assignment inputs to the _cc catalog version.
  • Removing the 3_post_processing4_relocation duplicate files; rewriting hardcoded /wd1//home/hbito paths.

🤖 Generated with Claude Code

Amplitude QC plot (examine_..._w_amp.ipynb):
- Replace fake np.linspace(-window_before, window_after, npts) time axis with
  tr.times(reftime=time_pick) in both plot_waveforms_for_picks and
  plot_waveforms_for_picks_window. The linspace axis assumed the returned trace
  exactly fills the request; for gappy/partial OBS records this misplaced the
  pick marker and the amplitude window, making the true peak appear to fall
  outside the purple band (source of the ARID 999395/999382/999384/178428
  reports). Amplitude values were always correct; this is a display-only fix.
- sdata.merge(method=1) so gappy multi-segment channels are plotted/selected as
  one record instead of only tr_select[0].

event_waveform_processing.py / get_waveform_amplitude.py:
- Guard `print(picks_df.loc[mask])` with `if measurements:`; mask was undefined
  for the first event with no data -> NameError crash.

utils/qc_utils.py (calc_snr):
- Guard 20*log10(signal/noise) against zero amplitudes (returns NaN instead of
  inf/-inf) at all three SNR branches. calc_snr is not used by the QC pass/fail
  filter, so no catalog output changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 1, 2026 20:08
@mdenolle mdenolle requested a review from hbito26 July 1, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses several QC/post-processing robustness and display issues: it prevents two batch scripts from crashing when no measurements are produced, corrects QC notebook time-axis alignment for amplitude windows/pick markers, and avoids divide-by-zero/-inf SNR values by returning NaN.

Changes:

  • QC amplitude plotting: use true trace-relative sample times (tr.times(reftime=time_pick)) and merge gappy channels before selecting/plotting.
  • Crash guards: only print picks_df.loc[mask] when measurements exist (prevents NameError).
  • SNR computation: return NaN instead of inf/-inf when signal/noise amplitudes are zero.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
utils/qc_utils.py Guards SNR computation to avoid divide-by-zero and log-of-zero producing inf/-inf.
4_relocation/quality_control/examine_Cascadia_updated_catalog_picks_assignment_ver_3_w_amp.ipynb Fixes QC plot time axis to honor tr.stats.starttime, and merges gappy channels so selection/plotting uses the full record.
4_relocation/event_waveform_processing.py Prevents NameError by guarding debug printing on measurements.
3_post_processing/get_waveform_amplitude.py Same crash guard as relocation script.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

" sdata.detrend(type='demean')\n",
" sdata.taper(max_percentage=0.05)\n",
" sdata.filter(type='highpass', freq=freq_highpass)\n",
" sdata.merge(method=1) # merge gappy multi-segment channels so plotting/selection uses the full record\n",
" sdata.detrend(type='demean')\n",
" sdata.taper(max_percentage=0.05)\n",
" sdata.filter(type='highpass', freq=freq_highpass)\n",
" sdata.merge(method=1) # merge gappy multi-segment channels so plotting/selection uses the full record\n",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants