Skip to content

Resume -re in the fit mode and in all channels of the interrupted run - #183

Merged
kriboe90 merged 4 commits into
masterfrom
claude/restart-fit-mode
Nov 9, 2026
Merged

kriboe90 merged 4 commits into
masterfrom
claude/restart-fit-mode

Conversation

@kriboe90

@kriboe90 kriboe90 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What changed

-re now resumes in the mode of the interrupted run: with the LED fits after -s3, without them after -s3_fast. #182 named this as a limitation it left unchanged. Until now the restart always analysed without fits.

  • ledsa/data_extraction/step_3_functions.py: find_fit_leds_for_restart(channels) reads the header of every result file of the selected channels. Only a file written with fits names the fit columns in its column header. fit_success is one of them in every version of the header since 2020, including the shorter one of the v0.13.0 cleanup. The mode is read from the names, never from the number of columns.

    • No result file in any of the channels: no fits, as before.
    • Files of one channel, or of different channels, written in both modes: the restart stops with a ValueError that says how to go on. One restart writes all of its channels in one mode, so it cannot guess.
    • Empty result files, which an interruption can leave, are ignored.

    _find_result_files lists the files for this and for _find_analysed_img_ids. It returns nothing for a channel without a directory, because the mode is read before the DataExtractor creates the directories.

  • ledsa/core/parser_arguments_run.py: the restart passes that mode to the DataExtractor as fit_leds, the same way -s3 and -s3_fast choose theirs.

  • Images of a multi-channel restart (second commit): setup_restart took the images still to do from self.channels[0] alone. Now an image is analysed again, in all channels of the restart, unless every one of them has its result file. The commented-out exit for multi-channel restarts is gone. The remaining images now come straight from image_infos_analysis.csv, in its order. Before, the name of every analysed image was looked up in that file, which read it once per image and wrote the list in set order.

  • doc/cli_documentation.rst and the help of -re describe both.

Why

After an interrupted -s3 run, the resumed images got the -s3_fast columns, and the analysis then refused the channel:

analysis/channel0/3_led_positions.csv has 10 columns, while analysis/channel0/1_led_positions.csv has 24 columns. The result files of channel 0 were written with different column layouts …

-s3 is the slow run, so it is the one most likely to be interrupted. On the 100-LED test images it takes about 9 s per image, against about 8 ms for -s3_fast.

The task offered the multi-channel image selection as optional. I made the change because each image is analysed one channel after the other. An interrupted -rgb run therefore almost always stops between the channels of an image, and with several cores this happens for up to one image per worker. With the first channel deciding, the restart skipped those images for the remaining channels, and the analysis left them out there ("No analysis results for the image IDs …"). Since #182 makes -re -rgb reachable, this hit nearly every interrupted RGB run.

For the reviewer

  • This branch contains the commits of fix: honor fast step three for individual color channels #180 and Let a colour flag pick the channels of -re instead of running step 3 #182. All three change the same lines of run_data_extraction_arguments and the same test file. Merge fix: honor fast step three for individual color channels #180 and Let a colour flag pick the channels of -re instead of running step 3 #182 first, and the diff here shows only this change.
  • The mode is chosen in run_data_extraction_arguments and passed to the constructor, rather than set inside setup_restart. That is where -s3 and -s3_fast choose theirs. It also means disagreeing files stop the run before the DataExtractor asks for missing config values.
  • A channel with files of both modes now stops the restart. Two ways to get one: a channel that the old -re resumed after an interrupted -s3 run, or an interrupted rerun of step 3 in the other mode over complete results. In the second case every image already has a file, so the restart could not see which images are left anyway. Real output, on the channel the old restart produced in the end-to-end check below:

    The result files of channel 0 were written both with the LED fits (-s3, 2 files, e.g. analysis/channel0/1_led_positions.csv) and without them (-s3_fast, 2 files, e.g. analysis/channel0/3_led_positions.csv), so the restart cannot tell in which mode to resume. Delete the files of the mode you do not want and run -re again, or run -s3 or -s3_fast for the channel again.

  • Cost of the multi-channel image selection: an image written for some of the channels is analysed again for those too. A restart whose channels come from different runs analyses, in all of its channels, every image that one of them lacks. For example, -re -rgb after a red-only run redoes red as well.
  • v0.13.0 cleanup: the detection depends only on fit_success, which _create_header keeps on that branch. The tests take their headers from _create_header or write one with the base columns only, so they use none of the columns the cleanup removes.
  • Unchanged: a result file that an interruption cut short still counts as analysed, and the restart does not redo it.
  • Found while testing, not fixed here: loading a channel without led_search_areas_with_coordinates.csv (no -coord) fails on NumPy 2, because _append_nans_to_params in file_handling.py uses np.NaN. pyproject.toml pins numpy ~= 1.26.4, so supported installs are not affected until that pin is lifted. It is the same on master and on the cleanup branch.

Tests

  • Unit tests: 434 passed (Python 3.12.2, NumPy 2.2.6, macOS; CI runs the declared NumPy 1.26).
    • In test_parser_arguments_run.py, the restart gets the fit_leds of the result files for -re, -re -g and -re -rgb, in both modes. The test files carry headers from _create_header and from LEDSA before the background-corrected sums, which had fewer columns. Further tests cover taking the mode from the channels that have files, ignoring an empty file, and stopping when the files disagree within a channel or between channels. Against the dispatcher of Let a colour flag pick the channels of -re instead of running step 3 #182, the 8 cases that expect fits or a stop fail.
    • The new test_restart.py checks that setup_restart picks every image that misses a channel, for an interruption inside an image and for images finished out of order by several cores. With the first-channel rule, 2 of its 3 tests fail.
  • End to end, on the synthetic images of the acceptance tests:
    • Run -s1 -s2 -coord -s3, delete the result files of images 3 and 4, then run -re and load channel 0 with create_binary_data. With Let a colour flag pick the channels of -re instead of running step 3 #182, images 3 and 4 are written without fits and loading fails with the error above. With this branch they are written with fits and 4 of 4 load.
    • With -s3_fast instead, the resumed images are written without fits and 4 of 4 load.
    • After -s3_fast -rgb, delete the green and blue files of image 3 and all files of image 4. -re -rgb then analyses images 3 and 4 in all channels, and each channel loads 4 of 4.
  • Robot Framework acceptance tests: 32 passed, run locally against this branch. 03_test_s3.robot runs plain -re on an emptied channel0, which takes the path without result files.

🤖 Generated with Claude Code

imshah-id and others added 4 commits November 1, 2026 01:45
A colour flag without a step runs step 3 with the LED fits. The guard
against that checked -s3_fast only, so -re -r, -re -g and -re -rgb
first ran the full step 3 on every image, which overwrote the partial
results, and the restart then found nothing left to analyse. Plain -re
resumes the red channel only, so an interrupted green, blue or RGB run
could not be resumed at all.

The guard now also leaves out -re, and the colour flags only select the
channels of the restart. -re alone, an explicit -s3 next to -re and a
colour flag next to -s1, -s2 or -coord behave as before.

The CLI documentation listed --r, which argparse rejects as ambiguous,
and no channel flags for -s3_fast and -re. The help of -re now says to
give the channel flags of the interrupted run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The restart always analysed without the LED fits. After an interrupted
-s3 run, the resumed images therefore got the -s3_fast columns, and
the analysis refused the channel because its result files were
written with different column layouts. -s3 is the slow run, so it is
the one most likely to be interrupted.

The restart now reads the mode from the headers of the result files of
its channels: only a file written with fits names the fit columns,
fit_success among them, in every version of the header. The number of
columns is not used, because it changes between LEDSA versions. If no
channel has a result file yet, the restart runs without fits as
before. If the files of a channel, or those of different channels,
were written in both modes, it stops and says how to go on instead of
guessing, because one restart writes all its channels in one mode.
Empty files, which an interruption can leave, are ignored.

The help of -re and the CLI documentation describe the mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The restart took the images still to analyse from the first of its
channels only. An image is analysed for one channel after the other,
so an interrupted multi-channel run usually stops after an image was
written for some channels but not for the others, and with several
cores this happens for several images. The restart skipped them, and
the analysis then left them out of the other channels.

An image is now analysed again, for all channels of the restart,
unless every one of them has its result file. The commented-out exit
for restarts of several channels is removed.

The images still to analyse are taken from image_infos_analysis.csv in
its order, instead of looking up the name of every analysed image in
that file, which read it once per image and wrote them in set order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kriboe90
kriboe90 merged commit c21f4f3 into master Nov 9, 2026
5 checks passed
kriboe90 added a commit that referenced this pull request Nov 9, 2026
Brings the fixes of the step 3 flags and the restart into develop:
#180 (-s3_fast with -r, -g or -b no longer
also runs the full step 3), #182 (a colour flag picks the channels of
-re instead of running step 3) and #183 (-re resumes in the fit mode
and in all channels of the interrupted run). They are merged before the
v0.13.0 cleanup (#181) lands on master, so that develop takes the fixes
without the removals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kriboe90 added a commit that referenced this pull request Nov 9, 2026
…-0-cleanup-cea6d8

Brings the fixes of the step 3 flags and the restart (#180, #182, #183)
into the cleanup. Two conflicts, both from changes on adjacent lines:

- doc/cli_documentation.rst: the -s3_fast row keeps the description
  without the background-corrected sums and takes the channel flags.
- ledsa/data_extraction/step_3_functions.py: find_fit_leds_for_restart
  goes before _generate_led_analysis_data, which keeps the signature
  without the noise, side band and background floor parameters.

The restart reads the fit mode from the header line of the column
names, which still starts with id and lists fit_success only with the
fits, so it works with the shorter header of the cleanup.

Co-Authored-By: Claude Opus 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