From 1a2f70a53a97094771a6b8def783254eb3e90e9e Mon Sep 17 00:00:00 2001 From: Christian Tabedzki <35670232+tabedzki@users.noreply.github.com> Date: Mon, 17 Aug 2026 13:17:49 -0400 Subject: [PATCH] revert: require fileSizeBytes in SpikeGLX meta validation Reverts the frame-alignment fallback added in #4. The root cause (SpikeGLX crashing before finishing its shutdown sequence, so fileSizeBytes/fileTimeSecs/fileSHA1 were never written) has been fixed upstream in SpikeGLX itself. These fields are relied on downstream for values we need, so validate_file should go back to treating their absence as an error rather than silently tolerating it. Previously-affected files will be corrected by a separate one-off script. This reverts commit 0f2e909. Assisted-by: ClaudeCode:claude-sonnet-5 --- element_array_ephys/readers/spikeglx.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/element_array_ephys/readers/spikeglx.py b/element_array_ephys/readers/spikeglx.py index 4dac6956..b8e6d2a0 100644 --- a/element_array_ephys/readers/spikeglx.py +++ b/element_array_ephys/readers/spikeglx.py @@ -174,31 +174,10 @@ def validate_file(self, file_type="ap"): else: raise KeyError(f"Unknown file_type {file_type} - must be 'ap' or 'lf'") - expected_file_size = meta.meta.get("fileSizeBytes") - if expected_file_size is not None: - if file_size != expected_file_size: - raise IOError( - f"File size error! {file_path} may be corrupted or in transfer?" - ) - return - - # "fileSizeBytes" is written by SpikeGLX only as one of the last - # steps of its shutdown sequence (after computing "fileSHA1"), so a - # recording whose acquisition finished normally can still be missing - # it if the app was closed/killed before that step completed. Fall - # back to a frame-alignment check: a genuinely truncated/corrupted - # file will not divide evenly into whole sample frames, whereas a - # fully-written recording that only failed to finalize its metadata - # will. - bytes_per_frame = meta.meta["nSavedChans"] * np.dtype("int16").itemsize - if file_size % bytes_per_frame: + if file_size != meta.meta["fileSizeBytes"]: raise IOError( f"File size error! {file_path} may be corrupted or in transfer?" ) - logger.warning( - f"{meta.fname} is missing 'fileSizeBytes' (recording may not have" - " shut down cleanly) - validated file size by frame alignment instead." - ) def compress(self): from mtscomp import compress as mts_compress