Apply suggestions from code review of branch dont-mutate-tuning-files
Co-authored-by: Joe Knapper <joe.knapper@glasgow.ac.uk>
This commit is contained in:
parent
e9c912d910
commit
7d583dcf94
2 changed files with 14 additions and 7 deletions
|
|
@ -17,11 +17,11 @@ def camera_test_client(
|
||||||
):
|
):
|
||||||
"""Yield a camera ThingClient on a camera server.
|
"""Yield a camera ThingClient on a camera server.
|
||||||
|
|
||||||
This is a context manager not a pytest fixture as it needs to be created
|
This is a context manager, not a pytest fixture, as it needs to be created
|
||||||
multiple times in some tests.
|
multiple times in some tests.
|
||||||
|
|
||||||
:param cam: The camera Thing to be used. If not supplied a new one will be created.
|
:param cam: The camera Thing to be used. If not supplied a new one will be created.
|
||||||
:param settings_folder: The settings folder for the camera, if none is supplies new
|
:param settings_folder: The settings folder for the camera, if none is supplied, new
|
||||||
temporary directory will be used as the settings folder.
|
temporary directory will be used as the settings folder.
|
||||||
"""
|
"""
|
||||||
if cam is None:
|
if cam is None:
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,22 @@ def find_tuning_algo(tuning: dict[str, dict], name: str) -> dict[str, Any]:
|
||||||
This is the same methodolgy used in the PiCamera2 library but is provided here so
|
This is the same methodolgy used in the PiCamera2 library but is provided here so
|
||||||
it can be tested independently of installing picamera2
|
it can be tested independently of installing picamera2
|
||||||
|
|
||||||
:param tuning: The camera tuningdictionary
|
:param tuning: The camera tuning dictionary
|
||||||
:param name: The name of the algorithm
|
:param name: The key for the algorithm in the tuning file
|
||||||
:return: The algorithm from the tuning dictionary. Editing this will edit the
|
:return: The algorithm from the tuning dictionary. Editing this will edit the
|
||||||
original dictionary.
|
original dictionary.
|
||||||
"""
|
"""
|
||||||
version = tuning.get("version", 1)
|
version = tuning.get("version", 1)
|
||||||
|
# Version 1 of the tuning files was simply a dictionary of algorithms. Later
|
||||||
|
# versions have an "algorithms" key, the value of which is a list of algorithms.
|
||||||
if version == 1:
|
if version == 1:
|
||||||
return tuning[name]
|
return tuning[name]
|
||||||
return next(algo for algo in tuning["algorithms"] if name in algo)[name]
|
# The tuning file "algorithms" is a list of dictionaries
|
||||||
|
algorithms = tuning["algorithms"]
|
||||||
|
# The list is a list of dictionaries that have 1 key: the algorithm name
|
||||||
|
algo_dict = next(algo for algo in algorithms if name in algo)
|
||||||
|
# We want the value for that key, which is a dictionary of algorithm parameters
|
||||||
|
return algo_dict[name]
|
||||||
|
|
||||||
|
|
||||||
def set_static_lst(
|
def set_static_lst(
|
||||||
|
|
@ -136,8 +143,8 @@ def set_ce_to_disabled(
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""Set ``ce_enable`` in ``rpi.contrast`` to zero to disable adaptive contrast enhancement.
|
"""Set ``ce_enable`` in ``rpi.contrast`` to zero to disable adaptive contrast enhancement.
|
||||||
|
|
||||||
:param tuning: The raspberry pi tuning file.
|
:param tuning: The raspberry pi camera tuning file.
|
||||||
:returns: A deepcopu of the input file set ce_enable to 0.
|
:returns: A deepcopy of the input file with ce_enable set to 0.
|
||||||
"""
|
"""
|
||||||
output_tuning = deepcopy(tuning)
|
output_tuning = deepcopy(tuning)
|
||||||
contrast = find_tuning_algo(output_tuning, "rpi.contrast")
|
contrast = find_tuning_algo(output_tuning, "rpi.contrast")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue