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 8e5fa95..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 new file mode 100644 index 0000000..5fe7744 --- /dev/null +++ b/ledsa/tests/UnitTests/test_parser_arguments_run.py @@ -0,0 +1,58 @@ +"""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() + + +@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()