Skip to content

Correctness fixes: no eval on file content, readrawfile rewrite, dead code - #2

Open
ehennestad wants to merge 2 commits into
fix-batch-a-algorithm-correctnessfrom
fix-batch-r1-correctness
Open

ehennestad wants to merge 2 commits into
fix-batch-a-algorithm-correctnessfrom
fix-batch-r1-correctness

Conversation

@ehennestad

Copy link
Copy Markdown
Contributor

Summary

Batch R1 from the module review: correctness fixes, stacked on #1. Two commits: the readrawfile rewrite with the INI reader, and the rest.

readrawfile rewritten from scratch

The old function built its arrays through eval, changed its loop index inside the loop, opened a file dialog when called without a path, and stopped at the end of the file by catching fread errors. The new one has an arguments block (Channel, SkipFrames, NumFrames), derives the frame count from the file size, reads with one fread per request (a block-skip for a single channel), raises typed errors for a missing .ini, an unsupported file.format, no recorded channels and an invalid channel, and warns when fewer frames are available than requested. Output layout is unchanged: x-by-y-by-frames(-by-channels) in the file's sample type. readinivar is now the single INI reader (the static method on SciScanRaw delegates to it): it matches whole variable names at line start, returns logicals for TRUE/FALSE and doubles for numbers, and evaluates nothing. SciScanRawFileTest covers both sample types, channel selection, skip and count, truncation, the error paths and the INI typing. The function has no callers in NANSEN or the module today; it is kept as a public utility.

Other fixes

  • eval on file content. getParameterValueFromString parses the literal subset ScanImage writes (numbers, strings, logicals, bracketed arrays, cell arrays, zeros(1,0)-style constructors) and returns anything else as text with a warning, so a TIFF tag can no longer execute code. ScanImageParameterParsingTest covers 25 literal forms and the fallbacks.
  • Mixin contract. TwoPhotonRecording documents that its host must be a VirtualArray and which members it uses. Declaring them abstract in the mixin is not possible: MATLAB rejects an abstract declaration of a property that another superclass defines with a type constraint.
  • Unreachable code. Removed the never-taken branches in MotionCorrection (statistics are always computed up front; updating the reference image after drift correction is not implemented, now stated in a comment), the abandoned frame-count algorithm behind a return in ScanImageTiff, the if 1 / else in both suite2p segmentation functions, and FluFinder's debug plotting blocks, the unused showDetectedEdges function and a try/catch that printed 'a'.
  • Unset outputs. improveRoiMasks drops its never-implemented second output. SciScanRaw loses an empty readFrameSet placeholder (readFrames is the base-class API).
  • Deleted, no callers. roi.stats.roiEdgyness was a template stub whose function was named computeRoi; roi.extractDff was error('Deprecated') over a commented-out body.

Not changed: the ScanImage getScanParameters warning-state item from the review was a false positive of my scan; that function restores the state. The cnmf and legacy extract/ImviewerPlugin sites flagged by the analyzer are dead code for the deletion batch.

🤖 Generated with Claude Code

ehennestad and others added 2 commits September 13, 2026 07:18
readrawfile is rewritten from scratch: an arguments block with Channel,
SkipFrames and NumFrames, the frame count derived from the file size
instead of a try/catch around every fread, one fread per request with a
block-skip for a single channel, typed errors for a missing .ini,
unsupported file.format, no recorded channels and an invalid channel,
and a warning when fewer frames are available than requested. The old
version built its arrays through eval, modified its loop index inside
the loop and opened a file dialog when called without a path.

readinivar is now the single INI reader (SciScanRaw's static method
delegates to it). It matches whole variable names at the start of a
line, returns TRUE/FALSE as logicals and numbers as doubles, and never
evaluates file text. SciScanRaw also loses an empty readFrameSet
placeholder; readFrames is the VirtualArray API.

Covered by SciScanRawFileTest on synthetic .raw/.ini recordings in both
sample types.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…move dead code

- getParameterValueFromString parses the literal subset ScanImage writes
  (numbers, strings, logicals, bracketed arrays, cell arrays, size
  constructors) and returns anything else as text with a warning, so a
  TIFF tag can no longer execute code. Covered by
  ScanImageParameterParsingTest.
- TwoPhotonRecording documents the members it needs from its host class
  (VirtualArray defines them with type validation, so they cannot be
  declared abstract in the mixin).
- Unreachable code removed: the never-taken branches in MotionCorrection
  (image statistics are always computed up front; reference update after
  drift is not implemented), the abandoned frame-count algorithm behind a
  return in ScanImageTiff, the if 1/else in the suite2p segmentation, and
  the debug plotting blocks, the unused showDetectedEdges function and a
  try/catch that printed 'a' in FluFinder's edge detection and shape
  detection.
- improveRoiMasks drops its never-implemented second output.
- roi.stats.roiEdgyness (a template stub whose function was named
  computeRoi) and roi.extractDff (error('Deprecated') with a
  commented-out body) are deleted; neither had callers.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

78 tests   77 ✅  5s ⏱️
 8 suites   1 💤
 1 files     0 ❌

Results for commit 6c5040b.

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.

1 participant