Fix rec index in plot_mag and plot_zed #847
Conversation
The quality flag in the datablock is at index 5, not 4 — index 4 is the type/blank column. Every datablock constructor in the codebase (ipmag.zeq, ipmag.zeq_magic, ipmag.plot_dmag, programs/zeq.py, programs/demag_gui.py, pmag.find_dmag_rec, etc.) places quality at index 5, and pmag.domean also reads it from index 5. With rec[4], plot_mag silently excluded every point from the main demag curve, and plot_zed's good/bad classification fell through to the else branch for all records. Also fix plot_zij axis scaling so amin is extended to include Y (the previous line was a duplicate no-op of the X/Z-only amin), remove leftover #DEBUG tags, and update the plot_zed docstring to reflect the 6-column datablock format.
|
Can you have a look at this @apivarunas? I want to merge in this pull request before the next pip release as I think it fixes a bug that needs to be addressed. It would be good to do the next pip release soon due to the igrf issue you identified in #850 that could be fixed by #851 I think it should be good to go, but it would benefit from a review from you. |
There was a problem hiding this comment.
Pull request overview
This PR corrects demagnetization plotting behavior in pmagpy/pmagplotlib.py by restoring the expected datablock quality-flag index and fixing Zijderveld axis-range calculation/documentation to match the rest of the codebase.
Changes:
- Restores
plot_magandplot_zedto read quality flags from column 5, matching how demag datablocks are built acrossipmagandprograms/zeq.py. - Fixes
plot_zijso the minimum axis extent considers Y as well as X/Z, keeping the scaling logic symmetric with the max calculation. - Updates the
plot_zeddocstring to document the actual 6-column datablock format and removes leftover debug comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| datablock : nested list of [step, dec, inc, M (Am2), type, quality] | ||
| step : units assumed in SI | ||
| M : units assumed Am2 | ||
| quality : [g,b], good or bad measurement; if bad will be marked as such |
There was a problem hiding this comment.
Should this docstring indicate what the "type" entry in the datablock is?
There was a problem hiding this comment.
Good call. I will add that. Something like:
datablock : nested list of [step, dec, inc, M (Am2), type, quality]
(type indicates the IZZI step for paleointensity experiments —
'ZI'/'IZ' or 1/0; empty string for pure demagnetization data)
|
@ltauxe It does look like a bug crept in with your commit 81a4339 that I tried to address here. There are some continued patches that need to be made moving forward related to the newest Pandas version. If you could test the issue you were having now that this PR has been merged that would be great. |
Summary
Commit 81a4339 (2026-04-16) included a useful
plot_zijpandas/matplotlib compatibility fix. However it seems like it also included changes that are problematic forplot_magandplot_zed.plot_magandplot_zed, revertrec[4]back torec[5]for the quality-flag check. Every datablock built in the codebase puts the quality flag at index 5 (index 4 is thetype/blankcolumn), so withrec[4]the check was never true —plot_magwas dropping every point from the demag curve andplot_zedwas classifying every record as "good" by accident.plot_zij, extendaminto includegXYZ.Y.min(). Theamaxline was correctly updated to include Y, but the parallelaminline in the commit ended up as a duplicate of the X/Z-onlyaminabove it, so I think extending it to Y as well matches the intent. Also stripped a couple of#DEBUGcomments left over from that session.plot_zeddocstring from the old 5-column signature to the actual 6-column form[step, dec, inc, M, type, quality]. The stale docstring may have been what prompted the index shift in the first place, so worth fixing at the same time.Context
Every place in the codebase that builds a datablock and hands it to one of these functions puts the quality flag at index 5:
programs/zeq.py[step, dec, inc, int, '', 'g']ipmag.zeq[treatment, declination, inclination, intensity, type, quality]ipmag.zeq_magic[treat, dec, inc, moment, blank, quality]ipmag.plot_dmag/dmag_magic[dmag, 0, 0, int, 1, quality]pmag.find_dmag_rec(7-col)[tr, dec, inc, int, ZI, flag, inst]programs/demag_gui.py,programs/thellier_gui.py[tr, dec, inc, int, ZI, flag, inst]pmag.domeanalso reads the quality flag from index 5, so keeping the plotting functions consistent with index 5 avoids it drifting out of step with the rest of the pipeline.