Audit E: preprocessing policies (microscope, motion, gain, phase shift, segdiampick)¶
Audited 2026-10-21 against the working tree at fd5b5bc8e (+ the two dirty cartft files, not relevant). Read-only. Documents under /Users/elmlundho/src/SIMPLE/doc/policies/. Severity H/M/L, categories as in the brief.
0. Project I/O in the preprocessing strategies (extra focus 1)¶
0.1 Does any policy say who owns the project file?¶
- None of the five assigned documents does.
motion_correction_policy.mdL34 only says that "execution strategies ... merge project records". layering_and_project_ownership_policy.mdsection 5 (draft dated today) states the rule: one owner per file, "workers read the file and write part files; a worker does not write the project (proposed)", "read that segment, not the project (proposed)", "one write of a segment per iteration (ruled)". It is(ruled)only for refine3D/refine2D. Its section 8 ledger of known deviations names the preprocessing strategies only as importers of commanders, not for any of the I/O below.3D/refine3D_policy.mdsection 4 and2D/solve2D_policy.mdcover only refine3D/refine2D.- Net: for motion_correct, ctf_estimate, pick, gen_pspecs_and_thumbs, preprocess, extract, reextract, refine_motion_model no document states the project contract.
0.2 Counts per strategy (src/main/strategies/parallelization/, line numbers of the call)¶
ptr2oritype and merge_* are not called by any of these files directly (only inside merge_algndocs). "full read/write" = whole sp_project.
| Strategy | Worker reads | Worker writes | Master reads | Master writes |
|---|---|---|---|---|
| motion_correct | full read L176 | part document of its mic rows, binwrite_oritab(outfile,..,MIC_SEG,fromto) L234 |
read_segment(oritype) then kill L281/L289; full read L320 |
merge_algndocs L321 (writes the mic segment inside the project file) |
| ctf_estimate | full read L164 | binwrite_oritab L221 |
L263/L268; L295 | merge_algndocs L296 |
| pick | full read L436 | binwrite_oritab L457 |
L500/L503; L545 | merge_algndocs L546 |
| gen_pspecs_and_thumbs | full read L156 | binwrite_oritab L190 |
L230/L244; L259 | merge_algndocs L260 |
| preprocess | full read L207 | stream=yes: write_segment_inside(oritype) into the job project L337; else binwrite_oritab L339 |
L394/L401; L425 | merge_algndocs L426 |
| extract | stream: full read L216; else read_segment(oritype) L226 + read_non_data_segments L229 |
stream: full write L458 into the job project; else params%projfile=params%outfile L232 then full write L458 (a part PROJECT) |
full read L554; then 3 read_segment (mic L648, stk L666, ptcl2D L679) per part |
full write L588 BEFORE the workers (wipe of stk/ptcl/cls/out); full write L719 after |
| reextract | read_segment mic L192, stk L195, ptcl2D L249, ptcl3D L250 + read_non_data_segments L410 |
full write of a part project L436 | full read L518; 4 read_segment (mic L588, stk L602, ptcl2D+ptcl3D L624-625) per part |
full write L642 once (wipe is in memory only, L549-552) |
| refine_motion_model (not in the brief list, same family) | read_segment ptcl2D/3D L238-239, stk L364, mic/stk L394/L398 + read_non_data_segments L359 |
part project write(outfile) L385 and fraction projects write L348 |
full read L482; read_segment mic L569, stk L587, ptcl2D/3D L610-611 per part |
write(frame_project) L634 per frame range |
Around the strategies:
- segdiam_bin_picker%pick (a domain object in src/main/pick, called by the stream stage on the stage's own project) does write_segment_inside('mic') L322 and then a full write() L323; the early-return path also writes (L225); it deletes micrograph rows.
- The commanders exec_preprocess, exec_motion_correct, exec_ctf_estimate, exec_pick, exec_extract call gui_comm%add_metadata(params%projfile, ...) after the strategy (simple_commanders_preprocess.f90 L52/L78/L126, simple_commanders_pick.f90 L60/L85); with the GUI active that is up to 3 more read_segment calls (simple_gui_communicator.f90 L168-181).
- Stream stages hold their own project and use several more patterns: the preprocess stage creates one job-set project per job (sets%write_set, simple_stream_job_sets.f90 L105), the preprocess worker updates that file with write_segment_inside, and the stage reads the mic segment back with append_mics_from_projects (simple_mic_import.f90 L40). Rough counts by regex (reads/writes of a project or segment): initial_analysis 11/8, solve3D 9/9, pool2D module 4/10, pool2D stage 10/1, refpick 7/6, preprocess 2/4, optics 1/3. The stream audit owns these; the point here is that no shared helper exists.
0.3 One pattern or several? Several (four), with inconsistencies¶
Patterns: (A) mic-segment part documents merged by merge_algndocs (motion_correct, ctf_estimate, pick, gen_pspecs, preprocess); (B) full part projects assembled by hand by the master (extract, reextract, refine_motion_model); (C) job project written in place by the worker (stream=yes preprocess L337, extract L458); (D) stage-owned global project (stream). Inconsistencies:
- [M] Two worker output formats for the same job. A is range-checked by
merge_algndocs(coverage and overlap errors, simple_sp_project_core.f90 L586/L608/L636/L638). B has only count checks (extract L659cnt /= nmics_tot, reextract L605nstks /= nmics) and no coverage check of the ranges. - [M] Three copies of the "assemble mic/stk/ptcl2D/ptcl3D from part projects" code: extract L643-717, reextract L585-640, refine_motion_model L565-625; and three copies of the worker boilerplate "read non-data segments, set projname/projfile, new segments, transfer_ori, write" (extract L226-241, reextract L410-436, refine_motion_model L359-385).
- [M] extract copies particle fields one by one (boxcoords, dfx, dfy, angast, phshift, ogid, gid; L682-711, four near-identical
isthere/setblocks each for ptcl2D and ptcl3D) while reextract and refine_motion_model usetransfer_oriof the whole row (reextract L634-635). A new particle field set by the extract worker is dropped silently by the master. - [M] extract's master writes the full project before the workers (L588, only to wipe stk/ptcl/cls/out on disk) and again after (L719); reextract wipes in memory and writes once.
layering_and_project_ownership_policy.md5.4 ("one write per iteration") is not met by extract; undocumented why the wipe must reach the disk before the workers run (they read only mic/non-data segments). - [M] In A the master reads the project twice (a
read_segmentto count, kill, then a fullreadjust to givemerge_algndocsthe project name and a segment buffer): motion L281+L320, ctf L263+L295, pick L500+L545, gen_pspecs L230+L259, preprocess L394+L425. Layering 5.5 asks for "that segment, not the project". - [M] Workers in A read the whole project (
spproj%read, incl. stk/ptcl segments of a post-extraction project) to update a few mic rows (motion L176, ctf L164, pick L436, gen_pspecs L156, preprocess L207); extract and reextract read segments selectively. - [M]
npartslarger than the number of items: motion_correct L286-288 and preprocess L400 stop with an error; ctf_estimate L273-276, gen_pspecs L236-241, pick L508, extract L558, reextract L523 clamp. - [M] The same 5-line gain block (
flip_gain, thenparams%flipgain='no'andcline flipgain='no') is copied in motion_correct_strategy L157-161 and L291-295 and preprocess_strategy L164-168 and L406-410; the stream stage does the equivalent differently (simple_stream_stage_preprocess.f90 L456-487, L634). - [M] There is no shared-memory path.
npartsis a required UI key of these programs (simple_ui_params_common.f90 L489-491,.true.= required; added as UI_COMP in simple_ui_preproc.f90 L120/L160/L237/L310/L432/L524/L567), and the "inmem" strategies refuse to run withoutfromp/top(motion L206-210, ctf L174-178, pick L429-433, preprocess L243-248), sonparts=1is a master with one worker. The factory messages and file headers still say "SHARED-MEMORY / WORKER".gen_pspecs_and_thumbskeeps a non-worker branch (fromto=[1,nintgs], L172) that writesoutfile.simple, which nothing merges (L190): unreachable and wrong if reached. Thestreambranches in ctf_estimate (L170-173) and pick (L426-428) have no caller I could find (onlypreprocessandextractare launched with stream=yes). - [M] pick's master runs
make_pickrefs_implin its own process (L536), which callsparams%newa second time (L213) and runs a whole commander (commander_cluster_cavgs, L228-236), handing over by file (cluster_cavgs_from_stack.simple, L236-237). Layering 4 allows commander-calls-commander only for controllers and demandsmkdir=noand thread restoration;params%newreseeds the generator and resets threads in the master. - [L]
exec_pick_extract(simple_commanders_pick.f90 L111-238, a commander) repeats the pick strategy's per-mic loop and then runscommander_extractwith stream=yes; it writes the job project withwrite_segment_inside(L211/L231). A second copy of the pick loop (pick inmem L441-456). - [L]
ori%get_ctfvarsis used for the fit (ctf_estimate L208), extraction (extract L351, reextract L257) andget_micparams(motion L221, preprocess L271/L286);sp_project%get_ctfparamsis used for particles. See microscope policy finding 5.
Proposal (where the rule belongs): add a section "Preprocessing steps" to layering_and_project_ownership_policy.md (or a new preprocessing_policy.md): (i) nparts is required, the master is the only process that writes the project, a worker writes one part file; (ii) part files are mic-segment documents merged with merge_algndocs for steps that only change mic rows, and ONE shared "assemble part projects" routine for steps that create stacks and particles (extract, reextract, refine_motion_model); (iii) the master reads projinfo plus the segments it needs; (iv) the stream job project is the one documented exception where a worker updates its own job file; (v) a domain object (segdiam_bin_picker) does not write the caller's project. Add the deviations above to section 8 of that policy.
1. doc/policies/microscope_parameters_policy.md (196 lines; last commit 2026-07-20; verdict: minor drift)¶
- [M][STALE] L138-142: "The optics row inherits CTF-model values from a representative image in the group". True for the batch program (starproject%assign_optics, simple_starproject.f90 L1266-1280, first image of the group). The stream's routine of the same name
assign_optics_groups(src/main/stream/shared/simple_optics_groups.f90 L116-132) builds one template from the first accepted micrograph of the whole project and copies smpd/cs/kv/fraca onto every group row. Fix: "Batch: from the first image of the group. Stream: from the project's first accepted micrograph." - [M][GAP] L131-136: the section describes only the batch program. A second algorithm serves the stream (p02): single-linkage over
shiftx/shiftyinside tilt groups, grid-accelerated, nomaxpop,optics_offsetor XML, ids kept stable across passes bykept_ids(simple_optics_groups.f90 L309-379); its header says it could replace the batch clustering. Proposal: add a subsection "Two assignment paths" with the rule that neither splits by kv/cs/fraca/smpd and that stream ids are never reused or renumbered. - [M][GAP] L54-67, L97-107: the meaning of
os_mic%smpdchanges during processing.motion_correctoverwrites the mic row'ssmpdwith the output micrograph sampling (simple_motion_correct_iter.f90 L180;ctfvars%smpd=smpd_scaled, simple_motion_correct.f90 L307). A laterimport_moviesof movies at the original sampling is then rejected byadd_movies(simple_sp_project_mic.f90 L86) andexec_import_movies(simple_commanders_project_mov.f90 L86). Add: "mic smpd is the movie's before motion correction and the micrograph's after". - [M][GAP] L109-129: "ogid is metadata for these paths" omits a consumer. The solve3D frozen-project manifest digests smpd, kv, cs, fraca, dfx, dfy, angast, phshift and
ogidof every ptcl3D row and refuses a frozen input whose digest differs (src/main/solve/simple_solve3D_manifest.f90 L1005-1020, check L768). Editing a CTF-model value or re-runningassign_optics_groupson a project that has a manifest invalidates it. Add to "Consequences". - [M][GAP] L189-190 "no single resolver": two accessors with different failure behaviour.
ori%get_ctfvars(simple_ori.f90 L1279-1304) reads absent keys as 0 (hashgetreturns 0.0, src/utils/structs/simple_hash.f90 L304-313), so a mic row without kv/cs/fraca silently gives a zero CTF model to the fit (ctf_estimate_strategy L208), extraction (extract L351, reextract L257) andget_micparams;sp_project%get_ctfparams(simple_sp_project_core.f90 L938-954) throws. State both in "Current Gaps". - [L][DRIFT] L99-107: the worker uses
add_stk(extract L383) but the master builds the stack rows withadd_stktab(extract L675, reextract L618);ogidgoes to particles only (extract L415-418, L702-706), never to the stack rows. Fix: "add_stk (worker) and add_stktab (master)". - [L][DRIFT] L62-64: with
deftab,add_intgsalso takesphshiftper micrograph from the table (simple_sp_project_mic.f90 L241); only smpd/kv/cs/fraca are scalar. - [L][STRUCTURE] L187-196 "Current Gaps" is a work list that
refactoring_notes/planned/need2basis/multi_microscope_parameters.md("Remaining Work") also holds; L147 "The refactored merge_projects" is history wording. Keep the state as rules, move the list to the note. - [L][STRUCTURE] L145-163 "Project Merging" duplicates
project_stack_indexing_policy.mdL111-141 (ogid remap, class/out dropped) and omits that cls2D/cls3D/out are not carried, thatphshiftis required on os_mic/os_stk rows (simple_projfile_utils.f90 L884/L905), and that committed canonical sigma2 states are concatenated (L756-795). One owner for the merge contract. - Verified current: ctfparams location (simple_type_defs.f90 L59),
add_moviesconsistency check, STAR import ignores cmdline CTF values,get_ctfparamsreads os_stk,get_smpdfirst stack else first mic, optics not split by CTF model.
2. doc/policies/motion_correction_policy.md (408 lines; last commit 2026-10-13; verdict: minor drift)¶
- [L][STRUCTURE] L3-4: dated status line "Status - 2026-10-09: updated. This is a working policy ...". Replace by an undated scope note (or delete; README only asks for a note when a draft or open validation exists).
- [M][GAP] L29-49 (Ownership and execution): no execution and project contract. In code the three-step pattern is: master (
npartsrequired, see 0.3 item 9) -> worker updates its [fromp,top] mic rows and writes a part document (motion_correct_strategy L206-234) -> mastermerge_algndocsinto the mic segment (L320-322). Add a subsection "Execution and project contract" and cite layering policy section 5. - [M][GAP] L271, L294-299:
forctfis listed as a published product with no lifecycle. It is transient:ctf_estimateandpreprocessdelete the file and theforctfentry after the fit (ctf_estimate_strategy L211-214, preprocess_strategy L297-300). A consumer that expects it after CTF estimation fails. Add one sentence. - [M][GAP] L125-143, L339-352: detector-defect curation exists twice with different semantics.
cure_outliersin simple_motion_correct.f90 L569-685 (the policy's limitation: EER gain-only defects are uncured when there is no statistical outlier, L585/L598/L614) andcure_movie_outliers/cure_outliers/add_eer_gain_defectsin src/main/preprocess/simple_particle_extractor.f90 L647-745, which always recovers EER gain defects. The integrated micrograph and the particles extracted from movies are therefore cured differently for the same movie. State which is the contract, or unify. - [L][GAP] L279-283:
apply_dose_weighingalso rescales the per-frame dose by 1/0.8 at 200 kV and 1/0.64 at 100 kV (simple_image_ops.f90 L706-710). Not in the policy; the dose-weighting contract is incomplete without it. - [L][DRIFT] L161, L184-188:
mcconventionaccepts simple, unblur, motioncorr, relion, first, central, cryosparc, cs (simple_parameters_phases.f90 L1162-1165); code branches only onfirst/relion(motion_correct.f90 L291, patched L177, iter L111), everything else uses the central reference. The policy names three values. List them. - [L][DRIFT] L397-408 (Implementation references): missing
src/main/preprocess/simple_particle_extractor.f90(the consumer the policy names at L246-251 and L333-337, tested by theparticle extractorsub-suite),simple_refine_motion_model_strategy.f90, and the stream stage that resolves the gain (resolve_gain, simple_stream_stage_preprocess.f90 L456). - [L][GAP] L354-395: the list of contracts "changes must cover" is long; only gain, motion-model and extractor suites exist (
unit_motion;corrs2weightsin unit_numerics). Nothing in a tester callscalc_eer_fraction,apply_dose_weighing,motion_correct_iso/patchedor the retry logic (rg over tester). Mark which list items have a test and which are open. - Verified current (spot checks, all matched): module names and files, fewer than 2 frames error before and after max_dose (motion_correct.f90 L123/L139), central reference nint(0.5*nframes) L154, 6-sigma and 11x11 curation, 200 A / 200 px patch constants (simple_defs.f90 L112/L143), 4 / 5 pixel RMSD thresholds and one-retry halving (iter L15/L115/L133-138), 18-term basis and
pix2polycoords(utils L36-59), STAR conversion and-9999marker (motion_model.f90 L398/L436-447), FILE_VERSION=1/MODEL_VERSION=0 (L14-15),smpd_physicalhandling in the extractor, flip/reset lifecycle, stream sets worker flipgain to no (stage L634), test sub-suite names.
3. doc/policies/motion_gain_analysis_policy.md (152 lines; last commit 2026-10-13; verdict: stale in scope and helper contract)¶
- [M][STALE] L5-6 (and L12-15): "used by test-time gain-flip evaluation". The analyzer and helpers run in production: the stream preprocess stage resolves
flipgain=flip_autowithgain_flip_analyzer(simple_stream_stage_preprocess.f90 L456-463,detect_gain_flipL493-536) andflipgain=generatewith the helper module (L464-473,generate_gain_from_movies).policies/README.mdrepeats "and the gain-flip tests". Fix: "gain-orientation analysis and gain generation used by the stream's preprocessing stage". - [M][STALE] L50: "EER (fname2format == 'K') is rejected in this path".
read_movies_and_sum_framesaccepts EER: it decodes at upsampling 1 and adds one summed image per movie, counting one frame per movie (simple_motion_gain_helpers.f90 L45-50, L71-76). The stage filters EER out before batching (stage L592 "non-EER movies"). Fix: state that the helper sums EER movies as one decoded frame each and that callers decide whether to submit EER. - [M][GAP] L28-31 (ownership) and L35-52: the helper module also owns gain generation (
add_movies_to_gain_sum,normalized_inverse_average_intensity,write_gain_from_sum) and the gain preview JPEG used by every motion strategy (gainref_to_jpg); the analyzer's public result for callers isget_flip_mode()('x','y','xy','no', simple_motion_gain_analysis.f90 L243-256); after convergence further calls return immediately without accumulating (L114). The stage's own limits (at most 8 batches, 180 waits, default 'no' without gain reference or with too few movies; stage L497-536; generation target 1000 movies) are part of the contract. All are tested (test_write_gain_from_sum,test_gain_flip_mode_mapping, ...) but not stated. - [L][STRUCTURE] L13-15, L118-119: history ("retired on 2026-09-23", "formerly also the standalone ..."). Delete.
- [L][GAP] no pointer to
motion_correction_policy.mdL121-123 (auto must be resolved before workers) or todoc/algorithms/automatic_gain_flip.md. - Verified current: constants (GAIN_FIRST_ANALYSIS_AT 10, STEP 5, LP 200 A, conv constants), four candidates and "most negative" selection (L159-172), artifact names (L142/L184-194), batch size 10 (stage L101), batch-local counts, test module name.
4. doc/policies/phase_shift_ctf_policy.md (625 lines; last commit 2026-10-03; verdict: core current, structure rewrite)¶
- [M][CONTRADICTS] L84-89, L97-102 vs code: the policy says a window of 180 degrees "or more" is branch-ambiguous and that validation warns, and that the default 0-180 window (exactly 180) is "unique for any true phase" and retained. The code warns when
phshift_max - phshift_min >= 180(simple_parameters_phases.f90 L761-765), so everyfit_phshift=yesrun with the default window warns; the table recommends the default for Volta and laser-near-90. The warning's own example ("120 to 179" for a phase near 180) contradicts the table row "165-195 -> 120-240". Fix: say that the default always warns and why it is kept, or change the threshold to> 180; align the warning example. - [M][STALE] L207-220, L310, L620: "five fitting surfaces". The stream
masterprogram also declaresfit_phshift,phshift_min/max/step(simple_ui_stream.f90 L293-300, typed inline, not the sharedui_params) and copies its command line into the preprocessing stage (simple_commanders_stream_p00_master.f90 L459clines(STAGE_PREPROCESS) = cline).test_phshift_contractchecks five programs (simple_ui_visibility_tester.f90 L264-266). Fix: six,masteras pass-through; add it to the test. - [M][STRUCTURE] L3-12 dated status/revision log; L225-277 (7.1, a proposal for a future estimator); L295-326 (9, the 2026-07-20 test log naming retired executables and "12/12"); L327-566 (10, a 240-line validation protocol with EMPIAR accession tables and sign-off list); L567-583 (11, external basis). About 330 of 625 lines are history, plan or protocol. Keep 1-6, 8, 12, 13 (about 250 lines); move 10 and 7.1 to
doc/implementation_notes/planned/, drop 9, keep 11 as a short reference. - [L][DRIFT] L350-354:
build/production/simple_test_exec->build/bin/simple_test_exec(CLAUDE.md); theunit_projectline for the project-records sub-suite also lackssuite=project_records. - [L][DRIFT] L177 (5, "project field -> ctfparams ... for mic"):
get_ctfparamshas no mic branch (simple_sp_project_core.f90 L882-906); a mic query isget_micparams->ori%get_ctfvars, which canonicalizes (simple_ori.f90 L1302). Fix the row. - [L][DRIFT] L129-135 "preserves such values on import and export": storage is modulo 2*pi (setter simple_ori.f90 L462/L482), so a RELION value outside [0,360) is preserved only modulo 360.
- [L][GAP]
extractandreextractvalidatectfin {flip,no} (extract_strategy L138-142, reextract L123-127) but nothing flips and the stack keeps the mic row'sctf(extract L351/L383);ctfis not a UI key of either program. Vestigial; it blurs the "raw vs phase-flipped" contract of section 6. Delete or document. - Verified current: canonicalization modulo 2*pi (simple_type_defs.f90 L162-170),
orisetters, ctfparams/ctfvars fields and required phase argument (simple_ctf.f90 L78, L98-118), nophaseplateflag in src,fit_phshift/phshift_*parameters and validation ranges (phases.f90 L753-760), shared iterator owns the fit flag and the edge warning (simple_ctf_estimate_iter.f90 L60-92), patch fit holds phase and angle fixed (simple_ctf_estimate_fit.f90 L433), phase persisted on all four segments, zero materialized (simple_sp_project_io.f90 L1146-1149), merge requiresphshift(simple_projfile_utils.f90 L884/L905), RELION degree conversion (simple_starproject.f90 L91/L119/L142, starfile/relion/stream exporters), five-program UI test and the named sub-suites (star_project,ui_visibility,project_mergeresolve withsuite_id).
5. doc/policies/segdiampick_mics_policy.md (198 lines; last commit 2026-05-19; verdict: rewrite)¶
The document describes a version of segdiampick_mics (HAC backend, population z-score, 1.5 x max box, 1.2 x max mask) committed 2026-05-19 (14f07d941) and reverted the next day (a91048e76 "Reverted ministream to previous behaviour"). The current code in src/main/stream/simple_mini_stream_utils.f90 differs on every algorithmic claim. The stream no longer uses it.
- [H][STALE] L5-12, L168-172: "the diameter-estimation entry point for the mini-batch stream pipeline". The only caller is the validation program
mini_stream(simple_commanders_validate.f90 L96, "this is the actual test"). The stream picks withsegdiam_bin_picker(src/main/pick/simple_segdiam_bin_picker.f90; simple_stream_stage_initial_analysis.f90 L609, L765)..github/skills/simple-main-pick/SKILL.mdL12 sends developers to this policy and L21 sayssegdiampick_micsestimates the diameter in the stream (CONTRADICTS the code andstream/reference_generation_policy.mdL35). - [H][STALE] L19-21, L57-71, L175-178, L193-199: HAC backend and the optional
l_hacargument. The signature (L77) has nol_hac;hac_1d_fast(simple_math.f90 L539) has no caller anywhere (dead code).median_nocopy(L184) is not used. - [H][STALE] L72-100: two z-score criteria. Code applies only the absolute z-score of the cluster mean on clusters 2..9 of a 10-class
sortmeans(L179-200); no population z-score. - [H][STALE] L106-117: box = find_magic_box(nint(1.5*max/smpd)). Code:
find_magic_box(BOXFAC*nint(med/smpd)), BOXFAC = 3, median of the selected set (L211). - [H][STALE] L119-128: mask diameter min((box-COSMSKHALFWIDTH)smpd, 1.2max). Code: min((box-COSMSKHALFWIDTH)smpd, max), then min(avg + SIGMA_CRIT_MSKsdev, .) with SIGMA_CRIT_MSK = 2.5 (L214-215). The parameter table L145-151 marks SIGMA_CRIT_MSK and BOXFAC "inactive"; both are active.
- [M][VIOLATED] L29-36: "import diameters from the mic_diam file". The code reads only the first line of the file (5 values: x, y, box, box, diameter; L125-131) and appends all five as diameters. The file is written one box per line with the diameter in column 5 (simple_picksegdiam.f90 L334-377);
segdiam_bin_pickerreads all lines, column 5 (L118-132). Defect: corrupts the statistics whenever the preprocessing pre-picked (ninipick > 0). - [M][VIOLATED] L153-156 "diams_arr must be non-empty; no guard": still unguarded (L166 on an unallocated array when nothing is picked);
segdiam_bin_pickerguards it (L174). - [M][GAP] the module the stream uses has no policy. Rules to write: the first batch decides the accepted diameter bins (MOLDIAMS_PICK edges 20/100/200/300/400/500 A, SIGMA_CRIT 3.0 on the bin-mean robust z-score) and the box (factor 1.5 falling to 1.0 at 400 px, per bin max diameter), later batches reuse both; transient keys
mic_den/mic_topo/mic_bin/mic_diamwritten bysegdiampick_preprocess(preprocess_strategy L334) are consumed and deleted; micrographs without particles, state 0, or box file are deleted from the project, which is written (L297-323). Partly covered bystream/reference_generation_policy.mdsections 3 and 3.1. Proposal: rewrite this document assegdiam_bin_picker_policy.md, link it from the reference-generation policy and the pick skill, and state thatsegdiampick_micsis validation-only or retire it. - [M][VIOLATED] (cross-ref layering 5.4)
segdiam_bin_picker%pickwrites the caller's project twice in one call (L322 segment, L323 full) and also on the empty-bins path (L225); a domain object writing the stage's project.
Cross-cutting gaps in this cluster¶
- No policy for the preprocessing steps as a family (motion_correct, ctf_estimate, pick, extract, reextract, refine_motion_model): execution (nparts required, master plus workers), project contract (section 0), keys each step writes on the mic row, and failure rules. Proposal: one
preprocessing_policy.md(or a "Preprocessing steps" section in the layering policy) that the five assigned documents link to. - No CTF-estimation policy (only
doc/algorithms/ctf_estimation.md): mic-row keys written byctf_estimate_iter(dfx, dfy, df, angast, phshift, ctf_estimatecc, ctfres, icefrac, astig, ctfjpg, ctfdoc; L106-117), the patch documentctfdoc(writtenwrite_doc, read by extractread_doc, with the coordinate conversion+1+box/2at extract L407),forctfdeletion, and the thresholds the stream applies to ctfres/astig/icefrac. A change to the ctfdoc format or the pixel-origin convention breaks extraction silently. - No picking/extraction/re-extraction contract: box file format (x y w h [diam], lower-left corner, square windows,
box_inside,outside=nodrops edge particles), consistent box across micrographs unlessboxis given (extract L329-333),nptclson mic rows andstate=0for empty micrographs (extract L306-307), stacks named per micrograph,indstk/pind, and in reextract the shift convention (integer part of the 2D shift moves into the box position, residual stays as the particle shift; reextract L308-321),osmpdrescaling (sets stacksmpd, L385), removal of rows of empty micrographs from the project (L414-434),extractfrommovfallback (the motion policy covers only the model side). - No policy for optics-group assignment as one contract across the batch program and the stream stage (microscope finding 2).
refine_motion_modelhas no policy (the motion policy only calls it "separate", L19-22) although it is the third copy of the part-project assembly.- Layering policy section 8 ledger omits the deviations of section 0.3 (workers writing full part projects, double write in extract, master full reads,
params%newinmake_pickrefs_impl, domain object writing the project). Section 6 says the commander callsparams%new; in the preprocessing family the strategies'initializedoes (commanders only create the strategy). Clarify. policies/README.mdends by pointing todoc/refactoring_notes/planned/policy_set_audit_2026-10-21.md, which does not exist yet (broken link). It also listssegdiampick_mics_policy.mdandmotion_gain_analysis_policy.mdwith scopes that are now wrong.refactoring_notes/planned/need2basis/multi_microscope_parameters.md(not audited) listsphaseplateamong preserved fields and saysget_ctfparamsreadsphaseplate(L88-93, L140-142).phase_shift_ctf_policy.mdsection 2 rule 5 and the code have no such field; the merge validator requiresphshiftinstead (simple_projfile_utils.f90 L884/L905). Fix the note before it is promoted to policy.- Skill vs policy:
simple-main-pickpoints to a stale policy and misattributes the stream's diameter estimation (finding in section 5).simple-main-motion,simple-main-ctf,simple-main-project,simple-main-stardo not contradict the audited documents. - Dead or vestigial code found while auditing (for the release 4 cleanup inventory):
hac_1d_fast(no caller), the gen_pspecs non-worker branch, the ctf_estimate/pickstreambranches,ctf=flip|novalidation in extract/reextract,set_shmem_flagin simple_exec_helpers.f90 L268 (public, no caller).
Unverified¶
- External behaviour of RELION and cisTEM (phase policy 3.2, 11, commit hashes) and the cited paper and EMPIAR numbers (10.3, 10.8): not in the repository.
- The "12/12" check count and the pass results of 2026-07-20 (phase policy 9); the "about 5 percent" performance criterion (10.9). Not reproducible from the tree.
- The closed-form
intg/forctfcontrol (motion policy L286-292) was derived by reading the code (scalar weight 1/nframes inforctf, dose weights 1/sqrt(nframes) at zero frequency), not run. - Whether
npartsis enforced as required at command-line parse time: the UI flag and the strategies'fromp/topcheck were read; the cmdline checker was not. - Stream stage behaviour beyond the preprocess stage and the initial-analysis picker call (p03 to p07), including their project I/O counts (regex estimates only); the stream audit owns them.
- That nothing outside the repository (scripts, NICE) launches ctf_estimate or pick with
stream=yes. - Claims in
doc/algorithms/*.mdthat the policies cite (motion_correction, ctf_estimation, particle_picking, automatic_gain_flip) were not compared with code. - No claim in the brief appeared wrong. One wording note: "commanders build params" holds for the other families; the preprocessing commanders only create the strategy and the strategies build
params.