Fix low-risk QC/post-processing bugs (no catalog outputs change)#8
Open
mdenolle wants to merge 1 commit into
Open
Fix low-risk QC/post-processing bugs (no catalog outputs change)#8mdenolle wants to merge 1 commit into
mdenolle wants to merge 1 commit into
Conversation
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>
There was a problem hiding this comment.
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]whenmeasurementsexist (preventsNameError). - SNR computation: return
NaNinstead ofinf/-infwhen 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", |
This was referenced Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
4_relocation/quality_control/examine_..._w_amp.ipynbnp.linspace(-window_before, window_after, npts)time axis withtr.times(reftime=time_pick)(honorstr.stats.starttime); addedsdata.merge(method=1)so gappy multi-segment channels are plotted/selected as one record instead of onlytr_select[0]. Display-only.4_relocation/event_waveform_processing.pyprint(picks_df.loc[mask])withif measurements:—maskwas undefined for the first event with no data →NameError.3_post_processing/get_waveform_amplitude.pyutils/qc_utils.py(calc_snr, 3 sites)20*log10(signal/noise)against zero amplitudes →NaNinstead ofinf/-inf. Not used by the QC pass/fail filter.Why these are safe
Amplitudevalues (fromcalculate_amplitudes.py) are unchanged and were verified correct.calculate_amplitudes.py; the fix only prevents a crash.calc_snr's SNR column is not consumed by therms<2.5 & p_picks>4 & s_picks>4filter.Verification
.pyfiles passpython -m py_compile.Deliberately NOT included (change outputs / need a decision)
qc_metrics_..._cc.ipynbusesp_picks > 4 & s_picks > 4(≥5), but the output file is named..._p_4_s_4_...(≥4). Reconcile intent before changing the catalog.concat_anssdoes no dedup / magnitude-type reconciliation._cccatalog version.3_post_processing↔4_relocationduplicate files; rewriting hardcoded/wd1//home/hbitopaths.🤖 Generated with Claude Code