From 1bbdef350663fe38c8be0468e3239e1a61c8d7b4 Mon Sep 17 00:00:00 2001 From: Shahid Shamim Shah Date: Sun, 1 Nov 2026 01:45:19 +0530 Subject: [PATCH 1/2] fix: honor fast step three for individual color channels --- ledsa/core/parser_arguments_run.py | 2 +- .../UnitTests/test_parser_arguments_run.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ledsa/tests/UnitTests/test_parser_arguments_run.py diff --git a/ledsa/core/parser_arguments_run.py b/ledsa/core/parser_arguments_run.py index 8e5fa95..27bb1b6 100644 --- a/ledsa/core/parser_arguments_run.py +++ b/ledsa/core/parser_arguments_run.py @@ -57,7 +57,7 @@ def run_data_extraction_arguments(args: argparse.Namespace) -> None: if len(channels) == 0: channels.append(0) - if args.red or args.green or args.blue or args.rgb and not args.step_3_fast: + if (args.red or args.green or args.blue or args.rgb) and not args.step_3_fast: args.step_3 = True if args.step_1 or args.step_2: diff --git a/ledsa/tests/UnitTests/test_parser_arguments_run.py b/ledsa/tests/UnitTests/test_parser_arguments_run.py new file mode 100644 index 0000000..de0726a --- /dev/null +++ b/ledsa/tests/UnitTests/test_parser_arguments_run.py @@ -0,0 +1,34 @@ +"""Channel flags select the requested step 3 mode without a second analysis.""" +import argparse +from unittest.mock import Mock + +import pytest + +from ledsa.core.parser_arguments_declaration import add_parser_arguments_data_extraction +from ledsa.core import parser_arguments_run + + +@pytest.mark.parametrize('flags, channels', [ + (['-r'], [0]), + (['-g'], [1]), + (['-b'], [2]), + (['-rgb'], [0, 1, 2]), + (['-r', '-b'], [0, 2]), +]) +@pytest.mark.parametrize('fast', [False, True]) +def test_channel_flags_run_step_three_once(tmp_path, monkeypatch, flags, channels, fast): + monkeypatch.chdir(tmp_path) + (tmp_path / 'config.ini').touch() + extractor = Mock() + monkeypatch.setattr(parser_arguments_run, 'DataExtractor', extractor) + parser = add_parser_arguments_data_extraction(argparse.ArgumentParser()) + args = parser.parse_args(flags + (['-s3_fast'] if fast else [])) + + parser_arguments_run.run_data_extraction_arguments(args) + + kwargs = {'build_experiment_infos': True, 'channels': channels} + if fast: + kwargs['fit_leds'] = False + extractor.assert_called_once_with(**kwargs) + extractor.return_value.setup_step3.assert_called_once_with() + extractor.return_value.process_image_data.assert_called_once_with() From f2e3eadc33a1d523964a477795839edac977a443 Mon Sep 17 00:00:00 2001 From: Kristian Date: Mon, 9 Nov 2026 12:46:54 +0100 Subject: [PATCH 2/2] let a colour flag pick the channels of -re instead of running step 3 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 --- doc/cli_documentation.rst | 6 ++--- ledsa/core/parser_arguments_declaration.py | 3 ++- ledsa/core/parser_arguments_run.py | 3 ++- .../UnitTests/test_parser_arguments_run.py | 24 +++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/doc/cli_documentation.rst b/doc/cli_documentation.rst index 02d371c..d3dd1b7 100644 --- a/doc/cli_documentation.rst +++ b/doc/cli_documentation.rst @@ -32,13 +32,13 @@ Data Extraction - -- * - ``-s3``, ``--step_3`, ``--analyse_photo`` - Step 3: Analyse all images to extract pixel values inside the search areas and fit them to an LED model (SLOW!). - - ``--r`` (Use the red channel, default), ``--g`` (Use the green channel), ``--b`` (Use the blue channel), ``-rgb`` (Run for each channel) + - ``-r`` (Use the red channel, default), ``-g`` (Use the green channel), ``-b`` (Use the blue channel), ``-rgb`` (Run for each channel) * - ``-s3_fast``, ``--step_3_fast`, ``--analyse_photo_fast`` - Step 3: Analyse all images to extract pixel values and calculate the accumulated values inside the search areas (FAST!). Besides the plain sum, the background-corrected sums ``bgsub_sum_col_val``, ``bgsub2_sum_col_val`` and ``sidebg_sum_col_val`` are written (see ``reference_property`` in the analysis configuration). - - -- + - Channel flags as for ``-s3`` * - ``-re``, ``--restart`` - Restart step 3 if it was previously interrupted. Only the images that have not been analysed are taken into account. - - -- + - The channel flags of the interrupted run, as for ``-s3`` Analysis diff --git a/ledsa/core/parser_arguments_declaration.py b/ledsa/core/parser_arguments_declaration.py index 8143c75..6186f87 100644 --- a/ledsa/core/parser_arguments_declaration.py +++ b/ledsa/core/parser_arguments_declaration.py @@ -23,7 +23,8 @@ def add_parser_arguments_data_extraction(parser: argparse.ArgumentParser) -> arg help='creates the default configuration file. optional arguments are are: img_directory, ' 'reference_img, number_of_cores.') parser.add_argument('-re', '--restart', action='store_true', - help='Restarts step 3 of the analysis after the program was terminated before it finished.') + help='Restarts step 3 of the analysis after the program was terminated before it finished. ' + 'Give the channel flags of the interrupted run, e.g. -re -rgb.') parser.add_argument('-r', '--red', action='store_true', help='Use the red channel for step3. Default value.') parser.add_argument('-g', '--green', action='store_true', diff --git a/ledsa/core/parser_arguments_run.py b/ledsa/core/parser_arguments_run.py index 27bb1b6..8f26163 100644 --- a/ledsa/core/parser_arguments_run.py +++ b/ledsa/core/parser_arguments_run.py @@ -57,7 +57,8 @@ def run_data_extraction_arguments(args: argparse.Namespace) -> None: if len(channels) == 0: channels.append(0) - if (args.red or args.green or args.blue or args.rgb) and not args.step_3_fast: + # A colour flag on its own runs step 3. With -s3_fast or -re it only selects the channels of that run. + if (args.red or args.green or args.blue or args.rgb) and not (args.step_3_fast or args.restart): args.step_3 = True if args.step_1 or args.step_2: diff --git a/ledsa/tests/UnitTests/test_parser_arguments_run.py b/ledsa/tests/UnitTests/test_parser_arguments_run.py index de0726a..5fe7744 100644 --- a/ledsa/tests/UnitTests/test_parser_arguments_run.py +++ b/ledsa/tests/UnitTests/test_parser_arguments_run.py @@ -32,3 +32,27 @@ def test_channel_flags_run_step_three_once(tmp_path, monkeypatch, flags, channel extractor.assert_called_once_with(**kwargs) extractor.return_value.setup_step3.assert_called_once_with() extractor.return_value.process_image_data.assert_called_once_with() + + +@pytest.mark.parametrize('flags, channels', [ + ([], [0]), + (['-r'], [0]), + (['-g'], [1]), + (['-b'], [2]), + (['-rgb'], [0, 1, 2]), + (['-g', '-b'], [1, 2]), +]) +def test_restart_resumes_the_selected_channels_without_step_three(tmp_path, monkeypatch, flags, channels): + monkeypatch.chdir(tmp_path) + (tmp_path / 'config.ini').touch() + extractor = Mock() + monkeypatch.setattr(parser_arguments_run, 'DataExtractor', extractor) + parser = add_parser_arguments_data_extraction(argparse.ArgumentParser()) + args = parser.parse_args(['-re'] + flags) + + parser_arguments_run.run_data_extraction_arguments(args) + + extractor.assert_called_once_with(build_experiment_infos=False, channels=channels, fit_leds=False) + extractor.return_value.setup_restart.assert_called_once_with() + extractor.return_value.setup_step3.assert_not_called() + extractor.return_value.process_image_data.assert_called_once_with()