Skip to content

Commit d69fcb1

Browse files
committed
Prepare ground for *AMF* updates.
Signed-off-by: Thomas Mansencal <[email protected]>
1 parent 2758949 commit d69fcb1

File tree

3 files changed

+60
-104
lines changed

3 files changed

+60
-104
lines changed
Submodule aces updated from 35e1e6a to 101f126

opencolorio_config_aces/config/reference/discover/classify.py

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,12 @@ def _exclusion_filterer_ARRIIDT(ctl_transform: CTLTransform) -> bool:
195195
PATTERNS_DESCRIPTION_CTL : dict
196196
"""
197197

198-
PATH_AMF_COMPONENTS_FILE: Path = (
199-
Path(__file__).parents[0] / "resources" / "ACES_AMF_Components.json"
200-
)
198+
PATH_TRANSFORMS_FILE: Path = Path(__file__).parents[1] / "aces" / "transforms.json"
201199

202200
"""
203-
Path to the *ACES* *AMF* components file.
201+
Path to the *ACES* transforms file containing comprehensive metadata.
204202
205-
PATH_AMF_COMPONENTS_FILE : unicode
203+
PATH_TRANSFORMS_FILE : unicode
206204
"""
207205

208206

@@ -1461,10 +1459,10 @@ def print_aces_taxonomy() -> None:
14611459
def generate_amf_components(
14621460
ctl_transforms: dict[str, dict[str, dict[str, CTLTransform | CTLTransformPair]]]
14631461
| list[CTLTransform],
1464-
raise_exception: bool = False,
1462+
include_previous_transform_ids: bool = False,
14651463
) -> dict[str, list[str]]:
14661464
"""
1467-
Generate the *ACES* *AMF* components from given *ACES* *CTL* transforms.
1465+
Generate the *ACES* *AMF* components from the `transforms.json` file.
14681466
14691467
Parameters
14701468
----------
@@ -1473,9 +1471,9 @@ def generate_amf_components(
14731471
:func:`opencolorio_config_aces.classify_aces_ctl_transforms` or
14741472
:func:`opencolorio_config_aces.unclassify_aces_ctl_transforms`
14751473
definitions.
1476-
raise_exception : bool, optional
1477-
Whether to raise an exception if an *ACES* *ACEStransformID* is
1478-
missing.
1474+
include_previous_transform_ids : bool
1475+
Whether to include the previous *ACEStransformID* in the *ACES* *AMF*
1476+
components.
14791477
14801478
Returns
14811479
-------
@@ -1485,47 +1483,49 @@ def generate_amf_components(
14851483

14861484
amf_components = defaultdict(list)
14871485

1488-
with open(PATH_AMF_COMPONENTS_FILE) as json_file:
1489-
content = json_file.readlines()
1490-
content = json.loads(
1491-
"\n".join([line for line in content if not line.strip().startswith("//")])
1492-
)
1493-
1494-
attest(content["header"]["schema_version"].split(".")[0] == "1")
1495-
1496-
amf_components_implicit = content["amf_components"]
1486+
with open(PATH_TRANSFORMS_FILE) as json_file:
1487+
json_data = json.load(json_file)
1488+
1489+
all_transforms = [
1490+
transform
1491+
for version_data in json_data["transformsData"].values()
1492+
for transform in version_data["transforms"]
1493+
]
1494+
1495+
for transform in all_transforms:
1496+
transform_id = transform["transformId"]
1497+
1498+
if (
1499+
include_previous_transform_ids
1500+
and "previousEquivalentTransformIds" in transform
1501+
):
1502+
for previous_transform_id in transform["previousEquivalentTransformIds"]:
1503+
if (
1504+
previous_transform_id
1505+
and transform_id
1506+
and transform_id not in amf_components[previous_transform_id]
1507+
):
1508+
amf_components[previous_transform_id].append(transform_id)
1509+
1510+
inverse_transform_id = transform.get("inverseTransformId", "")
1511+
1512+
if (
1513+
inverse_transform_id
1514+
and transform_id
1515+
and inverse_transform_id not in amf_components[transform_id]
1516+
):
1517+
amf_components[transform_id].append(inverse_transform_id)
1518+
1519+
if (
1520+
inverse_transform_id
1521+
and transform_id
1522+
and transform_id not in amf_components[inverse_transform_id]
1523+
):
1524+
amf_components[inverse_transform_id].append(transform_id)
14971525

14981526
if isinstance(ctl_transforms, Mapping):
14991527
ctl_transforms = unclassify_ctl_transforms(ctl_transforms)
15001528

1501-
# Checking that the explicit "ACEStransformID" do exist.
1502-
for aces_transform_id, relations in amf_components_implicit.items():
1503-
explicit_aces_transform_ids = [aces_transform_id]
1504-
explicit_aces_transform_ids.extend(relations)
1505-
1506-
for explicit_aces_transform_id in explicit_aces_transform_ids:
1507-
filtered_ctl_transforms = filter_ctl_transforms(
1508-
ctl_transforms,
1509-
[
1510-
lambda x, y=explicit_aces_transform_id: (
1511-
x.aces_transform_id.aces_transform_id == y
1512-
)
1513-
],
1514-
)
1515-
1516-
ctl_transform = next(iter(filtered_ctl_transforms), None)
1517-
1518-
if ctl_transform is None:
1519-
exception_message = (
1520-
f'"aces-dev" has no transform with '
1521-
f'"{explicit_aces_transform_id}" "ACEStransformID!'
1522-
)
1523-
1524-
if raise_exception:
1525-
attest(False, exception_message)
1526-
else:
1527-
LOGGER.critical(exception_message)
1528-
15291529
for ctl_transform in ctl_transforms:
15301530
aces_transform_id = ctl_transform.aces_transform_id.aces_transform_id
15311531

@@ -1541,22 +1541,21 @@ def generate_amf_components(
15411541
)
15421542
]:
15431543
for sibling in siblings:
1544-
amf_components[aces_transform_id].append(
1545-
sibling.aces_transform_id.aces_transform_id
1546-
)
1547-
1548-
# Extending with explicit relations.
1549-
for aces_transform_id, relations in amf_components_implicit.items():
1550-
amf_components[aces_transform_id].extend(relations)
1544+
sibling_id = sibling.aces_transform_id.aces_transform_id
1545+
if sibling_id not in amf_components[aces_transform_id]:
1546+
amf_components[aces_transform_id].append(sibling_id)
15511547

1552-
# Generating the permutations.
1553-
for aces_transform_id, relations in amf_components.copy().items():
1548+
for aces_transform_id, relations in list(amf_components.items()):
15541549
for relation in relations:
1555-
amf_components[relation] = sorted(
1556-
{*relations, *amf_components[relation], aces_transform_id} - {relation}
1557-
)
1550+
if relation in amf_components:
1551+
amf_components[relation] = sorted(
1552+
set(amf_components[relation] + relations + [aces_transform_id])
1553+
- {relation}
1554+
)
1555+
1556+
result = {key: sorted(set(value)) for key, value in amf_components.items() if value}
15581557

1559-
return dict(amf_components)
1558+
return result
15601559

15611560

15621561
if __name__ == "__main__":

opencolorio_config_aces/config/reference/discover/resources/ACES_AMF_Components.json

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)