mef3io 2.4.0¶
Released 2026-11-18
This release adds remove_annotations, the first way to take a stored
annotation back, and an optional Reader(open_files=) for viewers that page
through a recording on a slow or network drive. mef3io.time_range also reads
less. Nothing that worked in 2.3.0 changes unless you use the new calls, or a
session is in the middle of an annotation edit (see Upgrading).
Highlights¶
mef3io.remove_annotations: take a stored annotation back (Python and C++).write_annotationsis unchanged and still only appends; removal is a separate, explicitly named call. Name the records to remove by whatReader.records()returns (level, channel, segment, time, type and every body field) and, in the same call, optionallyadd=the corrected ones, so changing a note is one rewrite. See the Python guide.
notes = mef3io.Reader(path).records()
wrong = [n for n in notes if n["type"] == "Note" and n["text"] == "typo"]
mef3io.remove_annotations(path, remove=wrong,
add=[{"time": wrong[0]["time"], "text": "fixed"}])
- A removed annotation is gone for good. There is no undo and no history; the old files are kept only until the swap is complete. Read the records first and keep a copy if you may need them back.
- What is rewritten. Only the annotation files (
.rdat+.ridx) of the levels named. Signal files and metadata are never opened for writing. Kept records are carried over byte for byte (including their encryption level); the headers are made right and stamped with the new provenance operationrecords-edit(code 10). When the last record of a level goes, its two files go (the state of a level that never had annotations). - What it refuses, and then removes nothing. A selector that matches
nothing (
no-match), more records than it expects (ambiguous: identical duplicates needexpect=orall_copies=True), fewer (count-mismatch), leaves out a field the stored record has (selector-incomplete) or names a record twice; all levels of the call succeed or none does. Also refused: a.mefd.tararchive (tar-read-only), an annotation file that is torn or damaged (record-torn,record-damaged, ...: runrecover_sessionfirst, nothing is ever trimmed silently), wrong passwords, a session that is being written or is mid-operation, and annotations that changed while the call worked (records-changed). Refusals about the session or the selection carry a stable.code; a wrongly typed or malformed argument (a fractional or non-numeric selectortime, an unknownlevel,remove=given one dict) raisesValueError/TypeErroras usual, without a code. Note text that is not valid UTF-8 cannot be selected. - Crash safe. The new files are written beside the old ones, flushed and
read back, then swapped under the session's operation marker, which carries
the plan. After a crash or power cut at any step the session is either as
it was or carries the marker: opening it warns
(
SessionOperationWarning), writes are refused, the validator reports the new checkrecords.interrupted-edit, andrecover_session(path, apply=True)finishes the swap, or rolls it back when a new file is not intact (the report inRecoveryReport.record_editsthen says the removal was NOT done, andpython -m mef3io recoverexits with status 1). The nextremove_annotationssettles it first. Leftovers that cannot be placed are moved to<session>.edit-leftovers, never deleted; a marker whose plan cannot be read is settled from the files alone, or refused (edit-unsettled, exit status 2) with nothing touched. - What a reader sees during an edit. While the marker is present every
reader of annotations raises
WriteConflictErrorwith.code == "edit-interrupted"instead of returning a level that may be half swapped:Reader.records(),MultiReader.records(),MefReader.get_annotations(), the C API (so MATLAB'srecords) and C++Session::read_records. An edit that is still running looks the same, so the message says "in progress or was interrupted". Samples stay readable.inspectstill describes the session but reports each channel'srecordsasNone(nullin JSON) with the warningannotation-edit-interrupted. edit-in-progressand the override.recover_session(apply=True)andremove_annotationsrefuse with this code while the program that started the edit is still running on this machine (a zombie counts as dead), or while another thread of the same process is editing the session (runningis set in a dry run); a dead, remote or unknown owner is settled. The owner is read from its own checked line at the top of the marker, so even an unreadable plan does not hide a running edit. A marker written by a newer mef3io is always refused (edit-newer-format, no override): settle it with a mef3io at least as new as the one that wrote it. If you are sure no program is editing (a reused process id, a zombie in a container), passassume_owner_gone=True(recover_session,remove_annotations) or runpython -m mef3io recover --owner-gone <session>; it skips only the live-owner refusal and the report records it (owner_override). If a program is in fact still editing, its edit can fail part-way or report success for a removal that was then rolled back, and a level's annotations can read as empty until the leftover.oldfiles are put back by hand; nothing is deleted. The new validator warningrecords.edit-leftoversflags such.new/.oldfiles beside record files when no marker is present.- What the marker holds. While an edit is in progress or interrupted, the marker holds the process id and the machine name of the editing program (and its start time where the system gives it); it is removed when the edit is settled. A session that carries it must be recovered before it can be copied, anonymized, merged or archived: every copy refuses it, so those names never reach a copy.
- Password-protected sessions: pass both passwords as for
Writer; added records are level-2 encrypted. Cancel and progress work until the swap starts. - Limits.
- There is no cross-process lock. Stop other writers of the session
first.
write_annotationslooks for the marker at its start, right before its append and once after; an edit that started during the append makes it raise (WriteConflictError, "may have been lost"), and an append that is already running when the marker appears and lands after the edit's last check of that file is lost. - Another machine's edit on a shared drive is not seen: the owner check works on one machine only (two machines with the same name look alike, and a marker written in a container counts as another machine), so on a network drive make sure no other machine is editing before you recover.
- Where the system gives no process start time (macOS and Windows), a
process id reused by an unrelated program after a crash can make recovery
refuse falsely (
edit-in-progress) until the override is used. - If the marker's owner line itself is torn or missing (a damaged file), the owner is unknown and recovery settles from the files: the one case on this machine in which recovery cannot protect a running edit.
- Memory: the annotation files of the levels involved are held in memory roughly ten to twenty times over while the call works.
- On Windows a record file another program holds open stops the swap
(
edit-failed; the old files are put back). - No MATLAB call, and no C API function to remove (like the copies and
rename_session). MATLAB'srecoverSession(the C API's recovery summary) settles an interrupted edit and now says how it ended: finished, rolled back ("the removal was NOT done"), settled from the files or not settled; a refusal arrives as the error message. It has no override argument: the way out from C and MATLAB ispython -m mef3io recover --owner-gone <session>on the command line.
- There is no cross-process lock. Stop other writers of the session
first.
- Optional: a
Readercan keep data files open between calls (Reader(open_files=N), off by default: nothing changes unless you ask). Paging through a recording then no longer reopens the same.tdatfor every read: up toNread-only files are kept, least recently used first, and read with positional reads. Each read first asks the file system for the file's size and identity, so an appended file is read to its new end and a file that was replaced, or deleted and recreated, is never served from the old open file. The samples are identical at every setting. Measured (local disk, request counts, option on): the 20 reads after the first of a 16-channel viewer window went from 400 opens + 400 closes to 96 opens + 0 closes; the saving on a given network drive depends on the drive and is not measured here. New:Reader.open_files(settable),Reader.release_files(), the same onMultiReader(ONE budget for all its recordings), and in C++set_open_files/open_files/release_open_filesonSessionandReader. A tar archive is read through one kept file. The C API and MATLAB have no such option and keep nothing open. - When to use it: one or a few Readers rereading the same files on a slow or network drive (a viewer, an analysis paging through days). Not for many Readers alive at once, or a fast local disk.
- What it costs: descriptors held until
release_files()/close()(if the process runs out, the library tries to recover by letting go of the kept files and retrying once; best effort, so keep it well under a quarter of the descriptor limit); on Windows a folder cannot be renamed or removed, nor a file replaced by renaming over it, while files are held (callrelease_files()first); and a single call that touches more files thanopen_filesreopens them (raiseopen_files). What it cannot see: on Windows a replacement with the same creation time, last-write time and size, and on file systems with unstable inode numbers a reused number. See Paging through a recording on a network drive. - Not changed: the first read of a channel still reads the block index of every segment of that channel, because skipping a segment needs its index (a start or end time in the metadata can be stale).
- New validator checks
records.interrupted-edit(error, not repairable byrepair_session: a session left in the middle of an annotation edit) andrecords.edit-leftovers(warning: temporary.new/.oldfiles beside record files with no marker). See Validation.
Fixes¶
mef3io.time_rangeis faster. It looks only at the first and last complete segment of each channel (three existence checks, then two metadata reads) and no longer touches the other segments at all. Measured on 64 channels x 12 parts: 3272 -> 1352 system calls in total (-59%). The result is the same as before.- The copy checks,
merge_sessions,transform_sessionandReaderopen are unchanged: a cheaper way of asking which segment files exist (a folder listing) was tried and dropped because it made more system calls in total than asking for each file. - Regression tests for segment headers whose times are far from the data (the stale-header class fixed in 2.3.0).
Upgrading from 2.3.0¶
Python and C++ code need no change; nothing that worked is removed, and
write_annotations behaves as before except in the cases below.
Reader(open_files=)is off by default. AReaderholds no file open between calls, exactly as in 2.3.0, until you pass it or setReader.open_files.- During an interrupted or running annotation edit (only in a session that
carries the marker of
remove_annotations, which 2.3.0 never created): Reader.records(),MultiReader.records()andMefReader.get_annotations()raiseWriteConflictError(edit-interrupted).get_annotationsused to print a warning and returnNonewhen a read failed; this one error is raised instead, so it cannot be mistaken for "no annotations". Code that expectsNonethere should catch it.Writer.write_annotationsis refused while the marker is present, and can raiseWriteConflictErrorafter its append when an edit started during it (the records may have been lost; read them back and write them again).inspectreports a channel'srecordsasNone(soChannelSummary.recordsisint | None) and adds the warningannotation-edit-interrupted; the record tables are empty. Code that does arithmetic on the count should test forNone.recover_sessionexamines the annotation files only after settling the edit; it gains the keywordassume_owner_gone(default off) and the CLI--owner-gone;RecoveryReportgainsrecord_edits(withrunningandowner_override) andnothing_to_doaccounts for it.copy-type calls (anonymize_session,transform_session,merge_sessions,archive_session) refuse a session that carries the marker (source-mid-operation).python -m mef3io recoverexits with status 1 when a removal was rolled back. Opening such a session emits aSessionOperationWarningthat names the edit;available_checks()lists one more check.- Provenance. Record files rewritten by
remove_annotationscarry operationrecords-edit(code 10; see the format reference). - New names.
mef3io.remove_annotations,RemoveAnnotationsReport,RecordFileEditandInterruptedRecordEditare exported frommef3io. - MATLAB is unchanged apart from the
edit-interruptederror itsrecordsraises while an edit is interrupted, and arecoverSessionsummary that says how an interrupted annotation edit ended.