Skip to content

irspec edit: peak add, remove, clear and auto - #2

Merged
aliperdehan merged 2 commits into
mainfrom
claude/edit-peaks
Oct 23, 2026
Merged

aliperdehan merged 2 commits into
mainfrom
claude/edit-peaks

Conversation

@aliperdehan

@aliperdehan aliperdehan commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Second slice of roadmap 1a: peak editing in irspec edit, on manifest.json only.

irspec edit DIR FILE peak add X [X ...]      # each X snapped to the nearest local band
irspec edit DIR FILE peak remove X [X ...]   # removes the stored peak nearest X within 15 cm-1
irspec edit DIR FILE peak clear
irspec edit DIR FILE peak auto               # re-pick with the entry's threshold/prominence/distance

How it works

  • The peaks are worked out by session's own code (ir_organize._finish / resolve_peaks, hence find_peaks_manual, find_peaks_auto, assign_label_y), so snapping, label heights and rounding are exactly what session produces. peak auto on a fresh session changes nothing, byte for byte.
  • add, remove and clear write an explicit peaks list, which session keeps. They start from what the figure shows now, so an entry with no peaks key starts from the automatic list.
  • The spectrum is read as session reads it: an own .SPA from the file (this is what makes auto match session; the plain CSV's 3-decimal x flips a tie, 1446.3 against 1446.4). If the .SPA is gone, the copies in plain/ or csv/ are used. A reference spectrum is read from plain/NAME.csv. If none exists, exit 2 on stderr.
  • Same conventions as set/unset: atomic write, entry and key order kept, idempotent, each change printed as old -> new, --json prints exactly one object. Exit 2 means the command cannot be carried out; exit 1 means the manifest is missing or broken.
  • remove finds nothing within the tolerance: no change, a note on stderr, exit 0.
  • peak auto says it replaces hand edits and lists what it dropped.

One change outside edit.py

ir_organize.resolve_peaks treated "peaks": [] like a missing key and picked again, so peak clear (or removing the last peak) would have been undone by the next irspec session. It now takes [] as "no peaks"; deleting the key still picks again. The README, CHANGELOG and roadmap say so. A legacy empty string for peaks now also means no peaks instead of picking.

Tests

tests/test_edit_peaks.py has 31 tests on the sample .SPA and the phenacetin_T.jdx fixture. One runs irspec session --build none after edits and checks that they survive and reach figures.json and the .md. Another does the same after clear. Each test was mutation-checked: 17 mutants of edit.py and ir_organize.py, all killed. One survived at first (adding a band that is already present), and a test was added for it.

Full suite on Python 3.13 in a venv: 120 tests, OK, 19 skipped. lualatex and R are not installed in this environment, so the TeX and R paths were not run. Please run the suite locally before merging.

Not touched: version, tags, session.py, irspec-ir.sty, rename/remove/move, per-figure limits, --no-build, preview. Not merged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GqBTMN8XHvB3aG8T6PmfYS

claude and others added 2 commits October 23, 2026 07:33
Second slice of roadmap 1a. `add` snaps each wavenumber to the nearest local band and
`auto` picks again, both through session's own peak code (ir_organize._finish), so the
label heights are session's and `peak auto` on a fresh session changes nothing. `remove`
takes out the stored peak nearest X within 15 cm-1, `clear` leaves none. Atomic, idempotent,
old -> new, --json, exit 2 (cannot be carried out, including no spectrum to read) and 1.

"peaks": [] now means no peaks in resolve_peaks (it was picked again), so clear survives a
session re-run. Tests in tests/test_edit_peaks.py, mutation-checked; README, CHANGELOG
(Unreleased) and roadmap updated. No version change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GqBTMN8XHvB3aG8T6PmfYS
… .md found

The session folder is copied from a template, so a stale ir_template.md sat beside the new ir_session.md and glob picked the stale one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@aliperdehan
aliperdehan merged commit 7c0fe1d into main Oct 23, 2026
4 checks passed
@aliperdehan
aliperdehan deleted the claude/edit-peaks branch October 23, 2026 07:44
aliperdehan added a commit that referenced this pull request Oct 23, 2026
… for the second), and that PR #2 needed a CI-found test fix. Documentation only: no version change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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