Skip to content

Commit 4408349

Browse files
authored
Merge pull request #117 from ampas/feature/add_validation_to_key_settings
Feature/add validation to key settings
2 parents 04cbf24 + a6b6204 commit 4408349

File tree

11 files changed

+118
-16
lines changed

11 files changed

+118
-16
lines changed

aces/idt/application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def validate_project_settings(self) -> None:
406406
If any of the validations fail
407407
"""
408408

409-
# Check the aces_transform_id is a valid idt_urn
409+
# Check the aces_transform_id is a valid idt_urn and try and auto populate it
410410
if not is_valid_csc_urn(self.project_settings.aces_transform_id):
411411
# If the aces_transform_id is not valid, generate a new one
412412
new_name = generate_idt_urn(
@@ -418,3 +418,8 @@ def validate_project_settings(self) -> None:
418418
# Update the project settings with the new name, if this is still invalid
419419
# it will raise an error from the setter
420420
self.project_settings.aces_transform_id = new_name
421+
422+
valid, errors = self.project_settings.validate()
423+
if not valid:
424+
msg = f"Invalid project settings\n: {'\n'.join(errors)}"
425+
raise ValueError(msg)

aces/idt/framework/project_settings.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,3 +778,86 @@ def __str__(self) -> str:
778778
attributes.append({"line_break": True})
779779

780780
return multiline_str(self, attributes)
781+
782+
def validate(self) -> tuple[bool, list[str]]:
783+
"""Validate the project settings to ensure that all the minimally required
784+
inputs are set
785+
786+
Returns
787+
-------
788+
:class:`tuple`
789+
Whether the minimum required settings are valid or not from the ui and what
790+
the errors are
791+
792+
"""
793+
valid, errors = self.validate_core_requirements(
794+
self.aces_user_name,
795+
self.encoding_colourspace,
796+
self.encoding_transfer_function,
797+
self.camera_make,
798+
self.camera_model,
799+
self.aces_transform_id,
800+
)
801+
return valid, errors
802+
803+
@staticmethod
804+
def validate_core_requirements(
805+
aces_user_name: str,
806+
encoding_colourspace: str,
807+
encoding_transfer_function: str,
808+
camera_make: str,
809+
camera_model: str,
810+
aces_transform_id: str,
811+
) -> tuple[bool, list[str]]:
812+
"""
813+
Validate the key values needed to have a valid project
814+
815+
Parameters
816+
----------
817+
aces_user_name: str
818+
the ACES username
819+
encoding_colourspace: str
820+
the encoding colourspace
821+
encoding_transfer_function: str
822+
the encoding transfer function
823+
camera_make: str
824+
the camera make
825+
camera_model : str
826+
the camera model
827+
aces_transform_id: str
828+
the ACES transform id
829+
830+
Returns
831+
-------
832+
:class:`tuple`
833+
Whether the minimum required settings are valid or not from the ui and
834+
what the errors are
835+
836+
"""
837+
valid = True
838+
errors = []
839+
if not camera_make:
840+
valid = False
841+
errors.append("No Camera Make Specified")
842+
843+
if not camera_model:
844+
valid = False
845+
errors.append("No Camera Model Specified")
846+
847+
if not aces_user_name:
848+
valid = False
849+
errors.append("No ACES User Name Specified")
850+
851+
if not encoding_colourspace:
852+
valid = False
853+
errors.append("No Encoding Colourspace Specified")
854+
855+
if not encoding_transfer_function:
856+
valid = False
857+
errors.append("No Encoding Transfer Function Specified")
858+
859+
if not is_valid_csc_urn(aces_transform_id):
860+
valid = False
861+
errors.append("Invalid ACES Transform ID")
862+
863+
return valid, errors

aces/idt/generators/base_generator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ def to_clf(self, output_directory: Path | str) -> Path:
720720
aces_user_name = project_settings.aces_user_name
721721
camera_make = project_settings.camera_make
722722
camera_model = project_settings.camera_model
723+
encoding_colourspace = project_settings.encoding_colourspace
724+
encoding_transfer_function = project_settings.encoding_transfer_function
723725

724726
root = ET.Element(
725727
"ProcessList",
@@ -788,10 +790,11 @@ def format_array(a: NDArray) -> str:
788790
self.project_settings.include_exposure_factor_in_clf,
789791
)
790792

791-
clf_path = (
792-
Path(output_directory)
793-
/ f"{camera_make}.Input.{camera_model}_to_ACES2065-1.clf"
793+
file_name = (
794+
f"idt.{aces_user_name}.{camera_model}.{encoding_colourspace}_"
795+
f"{encoding_transfer_function}_to_ACES2065-1.clf"
794796
)
797+
clf_path = Path(output_directory) / file_name
795798

796799
ET.indent(root)
797800

apps/idt_calculator_camera.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
hash_file,
7979
png_compare_colour_checkers,
8080
)
81-
from aces.idt.core.transform_id import generate_idt_urn, is_valid_csc_urn
81+
from aces.idt.core.transform_id import generate_idt_urn
8282
from app import APP, SERVER_URL, __version__
8383
from apps.common import (
8484
COLOUR_ENVIRONMENT,
@@ -1274,8 +1274,8 @@ def compute_idt_camera(
12741274

12751275
aces_transform_id = str(aces_transform_id)
12761276
aces_user_name = str(aces_user_name or "")
1277-
camera_make = str(camera_make)
1278-
camera_model = str(camera_model)
1277+
camera_make = str(camera_make or "")
1278+
camera_model = str(camera_model or "")
12791279
iso = float(iso)
12801280
temperature = float(temperature)
12811281
additional_camera_settings = str(additional_camera_settings)
@@ -1285,9 +1285,17 @@ def compute_idt_camera(
12851285
encoding_colourspace = str(encoding_colourspace or "")
12861286
encoding_transfer_function = str(encoding_transfer_function or "")
12871287

1288-
# Validation: Check if the ACES transform ID is valid
1289-
if not is_valid_csc_urn(aces_transform_id):
1290-
error_message = "Invalid ACES Transform ID!"
1288+
# Validation: Check if the inputs are valid
1289+
is_valid, errors = IDTProjectSettings.validate_core_requirements(
1290+
aces_user_name,
1291+
encoding_colourspace,
1292+
encoding_transfer_function,
1293+
camera_make,
1294+
camera_model,
1295+
aces_transform_id,
1296+
)
1297+
if not is_valid:
1298+
error_components = [P(e) for e in errors]
12911299
return (
12921300
"", # loading-div children
12931301
[], # output-data-div children
@@ -1304,7 +1312,7 @@ def compute_idt_camera(
13041312
debayering_settings, # debayering-settings-field value
13051313
encoding_colourspace, # encoding-colourspace-field value
13061314
encoding_transfer_function, # encoding-transfer-function-field value
1307-
error_message, # Modal body content (error message)
1315+
error_components, # Modal body content (error message)
13081316
True, # Show the modal
13091317
)
13101318

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"FULL_STOPS_EXR.zip": {
33
"URL": "https://www.dropbox.com/scl/fi/srna8mw98wxn47np0adoj/FULL_STOPS_EXR.zip?rlkey=e2n0t59g0olu40gxk31mm01sh&dl=0",
4-
"SHA256": "90b9d9a83ccfa5550513ec94e5a82758c078be9404551a747b6aac460e6cb38a"
4+
"SHA256": "7f4bb72394e502815e85ef4a45c4a1c027d111e6a54b058b9d4d75e5b76e1127"
55
},
66
"PTZ_160.zip": {
77
"URL": "https://www.dropbox.com/scl/fi/9ni9vcpwahrx8s3l1zqkf/PTZ_160.zip?rlkey=m3ddjysrhmkbfxx7ktgpmgfft&dl=0",
8-
"SHA256": "1be3d45442df67e62445b2792e1d73afdea3869b7f0326bdc579cd338fb143b6"
8+
"SHA256": "4c3c85a293166ef4896713fc99f28870b90821c1f1d0118c6ceae3b40520d4c2"
99
}
1010
}

tests/resources/synthetic_001.zip

-609 Bytes
Binary file not shown.

tests/resources/synthetic_001/synthetic_001.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lighting_setup_description": "D65",
1212
"debayering_platform": "",
1313
"debayering_settings": "",
14-
"encoding_colourspace": "",
14+
"encoding_colourspace": "synthetic_colourspace",
15+
"encoding_transfer_function": "synthetic_tf",
1516
"rgb_display_colourspace": "sRGB",
1617
"cat": "CAT02",
1718
"optimisation_space": "CIE Lab",

tests/resources/synthetic_002.zip

-609 Bytes
Binary file not shown.

tests/resources/synthetic_002/synthetic_002.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lighting_setup_description": "D65",
1212
"debayering_platform": "",
1313
"debayering_settings": "",
14-
"encoding_colourspace": "",
14+
"encoding_colourspace": "synthetic_colourspace",
15+
"encoding_transfer_function": "synthetic_tf",
1516
"rgb_display_colourspace": "sRGB",
1617
"cat": "CAT02",
1718
"optimisation_space": "CIE Lab",

tests/resources/synthetic_003.zip

-610 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)