Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/cli_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ledsa/core/parser_arguments_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion ledsa/core/parser_arguments_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
58 changes: 58 additions & 0 deletions ledsa/tests/UnitTests/test_parser_arguments_run.py
Original file line number Diff line number Diff line change
@@ -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()
Loading