broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            m[a], m[b] = m.get(b), m.get(a)
    if 'Orientation' in m:
        m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = '1'
    m.pop('ThumbOrientation', None)
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]], [{'Orientation': 8, 'PixelXDimension': 3494, 'PixelYDimension': 3689, 'ImageLength': 3230, 'XResolution': 115, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageWidth', 3230], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3689], ['PixelYDimension', 3494], ['XMP:Orientation', '1'], ['YResolution', 115]]], [{'Orientation': 6, 'PixelYDimension': 2215, 'ImageWidth': 3631, 'YResolution': 135, 'XMP:Orientation': '6'}, [['ImageLength', 3631], ['Orientation', 1], ['PixelXDimension', 2215], ['XMP:Orientation', '1'], ['XResolution', 135]]], [{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 7, 'PixelXDimension': 2873, 'PixelYDimension': 1191, 'ImageWidth': 2585, 'ImageLength': 4554}, [['ImageLength', 2585], ['ImageWidth', 4554], ['Orientation', 1], ['PixelXDimension', 1191], ['PixelYDimension', 2873]]]], [[{'Orientation': 6, 'ImageWidth': 3998, 'XResolution': 106, 'YResolution': 377, 'ThumbOrientation': 1}, [['ImageLength', 3998], ['Orientation', 1], ['XResolution', 377], ['YResolution', 106]]], [{'Orientation': 6, 'PixelYDimension': 359, 'ImageWidth': 4056, 'ImageLength': 4624, 'XResolution': 104, 'YResolution': 235, 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 4056], ['ImageWidth', 4624], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 359], ['XResolution', 235], ['YResolution', 104]]], [{'PixelXDimension': 611, 'PixelYDimension': 1679, 'ImageWidth': 4933, 'ImageLength': 565, 'XMP:Orientation': '1', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 565], ['ImageWidth', 4933], ['Make', 'Acme'], ['PixelXDimension', 611], ['PixelYDimension', 1679], ['XMP:Orientation', '1']]], [{'Orientation': 0, 'PixelYDimension': 4669, 'ImageWidth': 1458, 'ImageLength': 3813, 'XResolution': 143, 'YResolution': 303}, [['ImageLength', 3813], ['ImageWidth', 1458], ['Orientation', 1], ['PixelYDimension', 4669], ['XResolution', 143], ['YResolution', 303]]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]], [{'Orientation': 1, 'PixelXDimension': 2816, 'PixelYDimension': 2864, 'ImageWidth': 461, 'ImageLength': 2237, 'XResolution': 277, 'YResolution': 373, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 2237], ['ImageWidth', 461], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2816], ['PixelYDimension', 2864], ['XResolution', 277], ['YResolution', 373]]], [{'Orientation': 8, 'PixelXDimension': 2357, 'ImageWidth': 4348, 'ImageLength': 2027, 'XResolution': 114, 'XMP:Orientation': '3', 'Make': 'Acme'}, [['ImageLength', 4348], ['ImageWidth', 2027], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 2357], ['XMP:Orientation', '1'], ['YResolution', 114]]]], [[{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]], [{'Orientation': 6, 'PixelXDimension': 1678, 'PixelYDimension': 2248, 'ImageWidth': 1422, 'ImageLength': 2871, 'YResolution': 243, 'XMP:Orientation': '1'}, [['ImageLength', 1422], ['ImageWidth', 2871], ['Orientation', 1], ['PixelXDimension', 2248], ['PixelYDimension', 1678], ['XMP:Orientation', '1'], ['XResolution', 243]]], [{'Orientation': 6, 'PixelXDimension': 1839, 'ImageWidth': 3327, 'ImageLength': 2385, 'YResolution': 260, 'ThumbOrientation': 8}, [['ImageLength', 3327], ['ImageWidth', 2385], ['Orientation', 1], ['PixelYDimension', 1839], ['XResolution', 260]]], [{'Orientation': 1, 'PixelYDimension': 4637, 'ImageWidth': 844, 'ImageLength': 4281, 'XResolution': 123, 'XMP:Orientation': '1'}, [['ImageLength', 4281], ['ImageWidth', 844], ['Orientation', 1], ['PixelYDimension', 4637], ['XMP:Orientation', '1'], ['XResolution', 123]]], [{'Orientation': 9, 'PixelXDimension': 2099, 'PixelYDimension': 2710, 'XResolution': 330, 'YResolution': 270, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2099], ['PixelYDimension', 2710], ['XResolution', 330], ['YResolution', 270]]], [{'Orientation': 4, 'PixelYDimension': 2321, 'ImageWidth': 1769, 'XResolution': 96, 'YResolution': 275, 'XMP:Orientation': '3'}, [['ImageWidth', 1769], ['Orientation', 1], ['PixelYDimension', 2321], ['XMP:Orientation', '1'], ['XResolution', 96], ['YResolution', 275]]], [{'Orientation': 0, 'PixelXDimension': 3801, 'PixelYDimension': 833, 'ImageWidth': 655, 'ImageLength': 2578, 'XResolution': 340}, [['ImageLength', 2578], ['ImageWidth', 655], ['Orientation', 1], ['PixelXDimension', 3801], ['PixelYDimension', 833], ['XResolution', 340]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]]], [[{'Orientation': 5, 'ImageWidth': 4453, 'ImageLength': 2889, 'XResolution': 346, 'YResolution': 99, 'Make': 'Acme'}, [['ImageLength', 4453], ['ImageWidth', 2889], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 99], ['YResolution', 346]]], [{'Orientation': 6, 'PixelXDimension': 3185, 'ImageWidth': 1218, 'XResolution': 140, 'YResolution': 141, 'Make': 'Acme'}, [['ImageLength', 1218], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 3185], ['XResolution', 141], ['YResolution', 140]]], [{'Orientation': 5, 'PixelXDimension': 4666, 'ImageLength': 4021, 'XResolution': 343, 'YResolution': 153, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['ImageWidth', 4021], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 4666], ['XMP:Orientation', '1'], ['XResolution', 153], ['YResolution', 343]]], [{'Orientation': 2, 'PixelXDimension': 4921, 'PixelYDimension': 3995, 'ImageWidth': 1616, 'XResolution': 341, 'XMP:Orientation': '6'}, [['ImageWidth', 1616], ['Orientation', 1], ['PixelXDimension', 4921], ['PixelYDimension', 3995], ['XMP:Orientation', '1'], ['XResolution', 341]]], [{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'Orientation': 8, 'ImageWidth': 4397, 'ImageLength': 4112, 'XResolution': 282, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4397], ['ImageWidth', 4112], ['Make', 'Acme'], ['Orientation', 1], ['YResolution', 282]]]], [[{'Orientation': 8, 'PixelXDimension': 522, 'XResolution': 367, 'XMP:Orientation': '3'}, [['Orientation', 1], ['PixelYDimension', 522], ['XMP:Orientation', '1'], ['YResolution', 367]]], [{'Orientation': 8, 'PixelXDimension': 4024, 'PixelYDimension': 3617, 'ImageLength': 2606, 'XResolution': 247, 'XMP:Orientation': '8', 'ThumbOrientation': 1}, [['ImageWidth', 2606], ['Orientation', 1], ['PixelXDimension', 3617], ['PixelYDimension', 4024], ['XMP:Orientation', '1'], ['YResolution', 247]]], [{'Orientation': 1, 'XResolution': 149, 'YResolution': 285, 'XMP:Orientation': '3', 'ThumbOrientation': 1}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 149], ['YResolution', 285]]], [{'PixelXDimension': 385, 'ImageWidth': 1099, 'ImageLength': 3036, 'XMP:Orientation': '8', 'ThumbOrientation': 8}, [['ImageLength', 3036], ['ImageWidth', 1099], ['PixelXDimension', 385], ['XMP:Orientation', '1']]], [{'Orientation': 9, 'PixelXDimension': 4218, 'PixelYDimension': 1148, 'ImageWidth': 1525, 'XResolution': 171, 'YResolution': 311, 'XMP:Orientation': '6', 'Make': 'Acme'}, [['ImageWidth', 1525], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4218], ['PixelYDimension', 1148], ['XMP:Orientation', '1'], ['XResolution', 171], ['YResolution', 311]]], [{'Orientation': 0, 'PixelXDimension': 1579, 'PixelYDimension': 2508, 'ImageWidth': 104, 'ImageLength': 3875, 'XResolution': 311, 'YResolution': 283, 'ThumbOrientation': 8}, [['ImageLength', 3875], ['ImageWidth', 104], ['Orientation', 1], ['PixelXDimension', 1579], ['PixelYDimension', 2508], ['XResolution', 311], ['YResolution', 283]]], [{'Orientation': 9, 'ImageWidth': 4790, 'ImageLength': 4004, 'XResolution': 219, 'YResolution': 340, 'Make': 'Acme'}, [['ImageLength', 4004], ['ImageWidth', 4790], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 219], ['YResolution', 340]]], [{'Orientation': 5, 'PixelXDimension': 2301, 'PixelYDimension': 1707, 'ImageWidth': 1166, 'ImageLength': 3560, 'XResolution': 383, 'ThumbOrientation': 8}, [['ImageLength', 1166], ['ImageWidth', 3560], ['Orientation', 1], ['PixelXDimension', 1707], ['PixelYDimension', 2301], ['YResolution', 383]]]]]
labels = ["regression: pair with a single member", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            va, vb = m.pop(a, None), m.pop(b, None)
            if va is not None and vb is not None:
                m[a], m[b] = vb, va
    if 'Orientation' in m:
        m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = '1'
    m.pop('ThumbOrientation', None)
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]], [{'Orientation': 8, 'PixelXDimension': 3494, 'PixelYDimension': 3689, 'ImageLength': 3230, 'XResolution': 115, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageWidth', 3230], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3689], ['PixelYDimension', 3494], ['XMP:Orientation', '1'], ['YResolution', 115]]], [{'Orientation': 6, 'PixelYDimension': 2215, 'ImageWidth': 3631, 'YResolution': 135, 'XMP:Orientation': '6'}, [['ImageLength', 3631], ['Orientation', 1], ['PixelXDimension', 2215], ['XMP:Orientation', '1'], ['XResolution', 135]]], [{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 7, 'PixelXDimension': 2873, 'PixelYDimension': 1191, 'ImageWidth': 2585, 'ImageLength': 4554}, [['ImageLength', 2585], ['ImageWidth', 4554], ['Orientation', 1], ['PixelXDimension', 1191], ['PixelYDimension', 2873]]]], [[{'Orientation': 6, 'ImageWidth': 3998, 'XResolution': 106, 'YResolution': 377, 'ThumbOrientation': 1}, [['ImageLength', 3998], ['Orientation', 1], ['XResolution', 377], ['YResolution', 106]]], [{'Orientation': 6, 'PixelYDimension': 359, 'ImageWidth': 4056, 'ImageLength': 4624, 'XResolution': 104, 'YResolution': 235, 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 4056], ['ImageWidth', 4624], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 359], ['XResolution', 235], ['YResolution', 104]]], [{'PixelXDimension': 611, 'PixelYDimension': 1679, 'ImageWidth': 4933, 'ImageLength': 565, 'XMP:Orientation': '1', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 565], ['ImageWidth', 4933], ['Make', 'Acme'], ['PixelXDimension', 611], ['PixelYDimension', 1679], ['XMP:Orientation', '1']]], [{'Orientation': 0, 'PixelYDimension': 4669, 'ImageWidth': 1458, 'ImageLength': 3813, 'XResolution': 143, 'YResolution': 303}, [['ImageLength', 3813], ['ImageWidth', 1458], ['Orientation', 1], ['PixelYDimension', 4669], ['XResolution', 143], ['YResolution', 303]]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]], [{'Orientation': 1, 'PixelXDimension': 2816, 'PixelYDimension': 2864, 'ImageWidth': 461, 'ImageLength': 2237, 'XResolution': 277, 'YResolution': 373, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 2237], ['ImageWidth', 461], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2816], ['PixelYDimension', 2864], ['XResolution', 277], ['YResolution', 373]]], [{'Orientation': 8, 'PixelXDimension': 2357, 'ImageWidth': 4348, 'ImageLength': 2027, 'XResolution': 114, 'XMP:Orientation': '3', 'Make': 'Acme'}, [['ImageLength', 4348], ['ImageWidth', 2027], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 2357], ['XMP:Orientation', '1'], ['YResolution', 114]]]], [[{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]], [{'Orientation': 6, 'PixelXDimension': 1678, 'PixelYDimension': 2248, 'ImageWidth': 1422, 'ImageLength': 2871, 'YResolution': 243, 'XMP:Orientation': '1'}, [['ImageLength', 1422], ['ImageWidth', 2871], ['Orientation', 1], ['PixelXDimension', 2248], ['PixelYDimension', 1678], ['XMP:Orientation', '1'], ['XResolution', 243]]], [{'Orientation': 6, 'PixelXDimension': 1839, 'ImageWidth': 3327, 'ImageLength': 2385, 'YResolution': 260, 'ThumbOrientation': 8}, [['ImageLength', 3327], ['ImageWidth', 2385], ['Orientation', 1], ['PixelYDimension', 1839], ['XResolution', 260]]], [{'Orientation': 1, 'PixelYDimension': 4637, 'ImageWidth': 844, 'ImageLength': 4281, 'XResolution': 123, 'XMP:Orientation': '1'}, [['ImageLength', 4281], ['ImageWidth', 844], ['Orientation', 1], ['PixelYDimension', 4637], ['XMP:Orientation', '1'], ['XResolution', 123]]], [{'Orientation': 9, 'PixelXDimension': 2099, 'PixelYDimension': 2710, 'XResolution': 330, 'YResolution': 270, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2099], ['PixelYDimension', 2710], ['XResolution', 330], ['YResolution', 270]]], [{'Orientation': 4, 'PixelYDimension': 2321, 'ImageWidth': 1769, 'XResolution': 96, 'YResolution': 275, 'XMP:Orientation': '3'}, [['ImageWidth', 1769], ['Orientation', 1], ['PixelYDimension', 2321], ['XMP:Orientation', '1'], ['XResolution', 96], ['YResolution', 275]]], [{'Orientation': 0, 'PixelXDimension': 3801, 'PixelYDimension': 833, 'ImageWidth': 655, 'ImageLength': 2578, 'XResolution': 340}, [['ImageLength', 2578], ['ImageWidth', 655], ['Orientation', 1], ['PixelXDimension', 3801], ['PixelYDimension', 833], ['XResolution', 340]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]]], [[{'Orientation': 5, 'ImageWidth': 4453, 'ImageLength': 2889, 'XResolution': 346, 'YResolution': 99, 'Make': 'Acme'}, [['ImageLength', 4453], ['ImageWidth', 2889], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 99], ['YResolution', 346]]], [{'Orientation': 6, 'PixelXDimension': 3185, 'ImageWidth': 1218, 'XResolution': 140, 'YResolution': 141, 'Make': 'Acme'}, [['ImageLength', 1218], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 3185], ['XResolution', 141], ['YResolution', 140]]], [{'Orientation': 5, 'PixelXDimension': 4666, 'ImageLength': 4021, 'XResolution': 343, 'YResolution': 153, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['ImageWidth', 4021], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 4666], ['XMP:Orientation', '1'], ['XResolution', 153], ['YResolution', 343]]], [{'Orientation': 2, 'PixelXDimension': 4921, 'PixelYDimension': 3995, 'ImageWidth': 1616, 'XResolution': 341, 'XMP:Orientation': '6'}, [['ImageWidth', 1616], ['Orientation', 1], ['PixelXDimension', 4921], ['PixelYDimension', 3995], ['XMP:Orientation', '1'], ['XResolution', 341]]], [{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'Orientation': 8, 'ImageWidth': 4397, 'ImageLength': 4112, 'XResolution': 282, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4397], ['ImageWidth', 4112], ['Make', 'Acme'], ['Orientation', 1], ['YResolution', 282]]]], [[{'Orientation': 8, 'PixelXDimension': 522, 'XResolution': 367, 'XMP:Orientation': '3'}, [['Orientation', 1], ['PixelYDimension', 522], ['XMP:Orientation', '1'], ['YResolution', 367]]], [{'Orientation': 8, 'PixelXDimension': 4024, 'PixelYDimension': 3617, 'ImageLength': 2606, 'XResolution': 247, 'XMP:Orientation': '8', 'ThumbOrientation': 1}, [['ImageWidth', 2606], ['Orientation', 1], ['PixelXDimension', 3617], ['PixelYDimension', 4024], ['XMP:Orientation', '1'], ['YResolution', 247]]], [{'Orientation': 1, 'XResolution': 149, 'YResolution': 285, 'XMP:Orientation': '3', 'ThumbOrientation': 1}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 149], ['YResolution', 285]]], [{'PixelXDimension': 385, 'ImageWidth': 1099, 'ImageLength': 3036, 'XMP:Orientation': '8', 'ThumbOrientation': 8}, [['ImageLength', 3036], ['ImageWidth', 1099], ['PixelXDimension', 385], ['XMP:Orientation', '1']]], [{'Orientation': 9, 'PixelXDimension': 4218, 'PixelYDimension': 1148, 'ImageWidth': 1525, 'XResolution': 171, 'YResolution': 311, 'XMP:Orientation': '6', 'Make': 'Acme'}, [['ImageWidth', 1525], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4218], ['PixelYDimension', 1148], ['XMP:Orientation', '1'], ['XResolution', 171], ['YResolution', 311]]], [{'Orientation': 0, 'PixelXDimension': 1579, 'PixelYDimension': 2508, 'ImageWidth': 104, 'ImageLength': 3875, 'XResolution': 311, 'YResolution': 283, 'ThumbOrientation': 8}, [['ImageLength', 3875], ['ImageWidth', 104], ['Orientation', 1], ['PixelXDimension', 1579], ['PixelYDimension', 2508], ['XResolution', 311], ['YResolution', 283]]], [{'Orientation': 9, 'ImageWidth': 4790, 'ImageLength': 4004, 'XResolution': 219, 'YResolution': 340, 'Make': 'Acme'}, [['ImageLength', 4004], ['ImageWidth', 4790], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 219], ['YResolution', 340]]], [{'Orientation': 5, 'PixelXDimension': 2301, 'PixelYDimension': 1707, 'ImageWidth': 1166, 'ImageLength': 3560, 'XResolution': 383, 'ThumbOrientation': 8}, [['ImageLength', 1166], ['ImageWidth', 3560], ['Orientation', 1], ['PixelXDimension', 1707], ['PixelYDimension', 2301], ['YResolution', 383]]]]]
labels = ["regression: pair with a single member", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Files that recorded only PixelXDimension gain a null PixelXDimension and a moved width.

After pixels have been baked upright, rewrite the metadata dictionary. When the (valid) Orientation is 5..8, exchange PixelXDimension/PixelYDimension, ImageWidth/ImageLength and XResolution/YResolution, moving a lone member of a pair to its partner key. Invalid or missing Orientation values mean no swap. Orientation is set to 1 only if the key exists; XMP:Orientation, if present, becomes the string "1"; ThumbOrientation is removed because the thumbnail is regenerated. Return sorted [key, value] pairs.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            va, vb = m.pop(a, None), m.pop(b, None)
            if vb is not None:
                m[a] = vb
            if va is not None:
                m[b] = va
    m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = '1'
    m.pop('ThumbOrientation', None)
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]], [{'Orientation': 8, 'PixelXDimension': 3494, 'PixelYDimension': 3689, 'ImageLength': 3230, 'XResolution': 115, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageWidth', 3230], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3689], ['PixelYDimension', 3494], ['XMP:Orientation', '1'], ['YResolution', 115]]], [{'Orientation': 4, 'ImageWidth': 2819, 'ImageLength': 178, 'XResolution': 230, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['ImageLength', 178], ['ImageWidth', 2819], ['Make', 'Acme'], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 230]]], [{'Orientation': 7, 'PixelXDimension': 2873, 'PixelYDimension': 1191, 'ImageWidth': 2585, 'ImageLength': 4554}, [['ImageLength', 2585], ['ImageWidth', 4554], ['Orientation', 1], ['PixelXDimension', 1191], ['PixelYDimension', 2873]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]]], [[{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]], [{'Orientation': 0, 'PixelXDimension': 2319, 'PixelYDimension': 3774, 'ImageWidth': 317, 'ImageLength': 1288, 'XResolution': 400, 'YResolution': 335, 'ThumbOrientation': 1}, [['ImageLength', 1288], ['ImageWidth', 317], ['Orientation', 1], ['PixelXDimension', 2319], ['PixelYDimension', 3774], ['XResolution', 400], ['YResolution', 335]]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'Orientation': 1, 'PixelXDimension': 2816, 'PixelYDimension': 2864, 'ImageWidth': 461, 'ImageLength': 2237, 'XResolution': 277, 'YResolution': 373, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 2237], ['ImageWidth', 461], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2816], ['PixelYDimension', 2864], ['XResolution', 277], ['YResolution', 373]]], [{'Orientation': 2, 'PixelXDimension': 3185, 'PixelYDimension': 993, 'ImageWidth': 1724, 'ImageLength': 1648, 'XResolution': 309, 'YResolution': 91, 'ThumbOrientation': 1}, [['ImageLength', 1648], ['ImageWidth', 1724], ['Orientation', 1], ['PixelXDimension', 3185], ['PixelYDimension', 993], ['XResolution', 309], ['YResolution', 91]]], [{'Orientation': 5, 'PixelXDimension': 2022, 'XResolution': 123, 'YResolution': 222, 'ThumbOrientation': 8}, [['Orientation', 1], ['PixelYDimension', 2022], ['XResolution', 222], ['YResolution', 123]]], [{'Orientation': 6, 'ImageWidth': 3998, 'XResolution': 106, 'YResolution': 377, 'ThumbOrientation': 1}, [['ImageLength', 3998], ['Orientation', 1], ['XResolution', 377], ['YResolution', 106]]], [{'ImageWidth': 3876, 'ImageLength': 923, 'XResolution': 383, 'YResolution': 223}, [['ImageLength', 923], ['ImageWidth', 3876], ['XResolution', 383], ['YResolution', 223]]]], [[{'PixelXDimension': 611, 'PixelYDimension': 2096, 'ImageWidth': 3720, 'ImageLength': 4669, 'XResolution': 104, 'XMP:Orientation': '6', 'Make': 'Acme'}, [['ImageLength', 4669], ['ImageWidth', 3720], ['Make', 'Acme'], ['PixelXDimension', 611], ['PixelYDimension', 2096], ['XMP:Orientation', '1'], ['XResolution', 104]]], [{'Orientation': 0, 'XResolution': 393, 'YResolution': 135, 'XMP:Orientation': '8'}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 393], ['YResolution', 135]]], [{'Orientation': 9, 'PixelXDimension': 2099, 'PixelYDimension': 2710, 'XResolution': 330, 'YResolution': 270, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2099], ['PixelYDimension', 2710], ['XResolution', 330], ['YResolution', 270]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]], [{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]], [{'Orientation': 6, 'PixelXDimension': 1678, 'PixelYDimension': 2248, 'ImageWidth': 1422, 'ImageLength': 2871, 'YResolution': 243, 'XMP:Orientation': '1'}, [['ImageLength', 1422], ['ImageWidth', 2871], ['Orientation', 1], ['PixelXDimension', 2248], ['PixelYDimension', 1678], ['XMP:Orientation', '1'], ['XResolution', 243]]], [{'Orientation': 5, 'PixelXDimension': 3958, 'PixelYDimension': 4449, 'ImageLength': 2850, 'XResolution': 243, 'YResolution': 171, 'XMP:Orientation': '8'}, [['ImageWidth', 2850], ['Orientation', 1], ['PixelXDimension', 4449], ['PixelYDimension', 3958], ['XMP:Orientation', '1'], ['XResolution', 171], ['YResolution', 243]]], [{'PixelXDimension': 2001, 'ImageWidth': 642, 'YResolution': 161, 'ThumbOrientation': 8}, [['ImageWidth', 642], ['PixelXDimension', 2001], ['YResolution', 161]]]], [[{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]], [{'Orientation': 0, 'PixelXDimension': 4484, 'PixelYDimension': 2133, 'XResolution': 320, 'YResolution': 385, 'XMP:Orientation': '3', 'ThumbOrientation': 8, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4484], ['PixelYDimension', 2133], ['XMP:Orientation', '1'], ['XResolution', 320], ['YResolution', 385]]], [{'Orientation': 6, 'PixelXDimension': 2290, 'ImageWidth': 1257, 'ImageLength': 2949, 'XResolution': 142, 'YResolution': 251, 'XMP:Orientation': '8'}, [['ImageLength', 1257], ['ImageWidth', 2949], ['Orientation', 1], ['PixelYDimension', 2290], ['XMP:Orientation', '1'], ['XResolution', 251], ['YResolution', 142]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'Orientation': 3, 'PixelXDimension': 1081, 'PixelYDimension': 160, 'ImageWidth': 4451, 'ImageLength': 4974, 'XResolution': 180, 'YResolution': 379, 'XMP:Orientation': '8', 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4974], ['ImageWidth', 4451], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1081], ['PixelYDimension', 160], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 379]]], [{'Orientation': 5, 'ImageWidth': 4453, 'ImageLength': 2889, 'XResolution': 346, 'YResolution': 99, 'Make': 'Acme'}, [['ImageLength', 4453], ['ImageWidth', 2889], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 99], ['YResolution', 346]]], [{'PixelXDimension': 2406, 'PixelYDimension': 3046, 'ImageLength': 2138, 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 2138], ['Make', 'Acme'], ['PixelXDimension', 2406], ['PixelYDimension', 3046]]]], [[{'PixelXDimension': 2095, 'PixelYDimension': 4143, 'ImageWidth': 3622, 'ImageLength': 1172, 'XResolution': 182, 'ThumbOrientation': 6}, [['ImageLength', 1172], ['ImageWidth', 3622], ['PixelXDimension', 2095], ['PixelYDimension', 4143], ['XResolution', 182]]], [{'Orientation': 0, 'ImageWidth': 1668, 'ImageLength': 1751, 'XResolution': 393, 'YResolution': 309}, [['ImageLength', 1751], ['ImageWidth', 1668], ['Orientation', 1], ['XResolution', 393], ['YResolution', 309]]], [{'Orientation': 2, 'PixelXDimension': 2531, 'PixelYDimension': 3008, 'ImageWidth': 4056, 'YResolution': 253}, [['ImageWidth', 4056], ['Orientation', 1], ['PixelXDimension', 2531], ['PixelYDimension', 3008], ['YResolution', 253]]], [{'Orientation': 4, 'PixelYDimension': 1209, 'ImageWidth': 3039, 'ImageLength': 4709, 'XResolution': 133, 'YResolution': 298, 'XMP:Orientation': '3', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 4709], ['ImageWidth', 3039], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 1209], ['XMP:Orientation', '1'], ['XResolution', 133], ['YResolution', 298]]], [{'Orientation': 1, 'XResolution': 149, 'YResolution': 285, 'XMP:Orientation': '3', 'ThumbOrientation': 1}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 149], ['YResolution', 285]]], [{'Orientation': 9, 'PixelXDimension': 4218, 'PixelYDimension': 1148, 'ImageWidth': 1525, 'XResolution': 171, 'YResolution': 311, 'XMP:Orientation': '6', 'Make': 'Acme'}, [['ImageWidth', 1525], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4218], ['PixelYDimension', 1148], ['XMP:Orientation', '1'], ['XResolution', 171], ['YResolution', 311]]], [{'Orientation': 8, 'PixelXDimension': 522, 'XResolution': 367, 'XMP:Orientation': '3'}, [['Orientation', 1], ['PixelYDimension', 522], ['XMP:Orientation', '1'], ['YResolution', 367]]], [{'PixelXDimension': 385, 'ImageWidth': 1099, 'ImageLength': 3036, 'XMP:Orientation': '8', 'ThumbOrientation': 8}, [['ImageLength', 3036], ['ImageWidth', 1099], ['PixelXDimension', 385], ['XMP:Orientation', '1']]]]]
labels = ["regression: orientation key normalisation", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            va, vb = m.pop(a, None), m.pop(b, None)
            if vb is not None:
                m[a] = vb
            if va is not None:
                m[b] = va
    if m.get('Orientation'):
        m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = '1'
    m.pop('ThumbOrientation', None)
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]], [{'Orientation': 8, 'PixelXDimension': 3494, 'PixelYDimension': 3689, 'ImageLength': 3230, 'XResolution': 115, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageWidth', 3230], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 3689], ['PixelYDimension', 3494], ['XMP:Orientation', '1'], ['YResolution', 115]]], [{'Orientation': 4, 'ImageWidth': 2819, 'ImageLength': 178, 'XResolution': 230, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['ImageLength', 178], ['ImageWidth', 2819], ['Make', 'Acme'], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 230]]], [{'Orientation': 7, 'PixelXDimension': 2873, 'PixelYDimension': 1191, 'ImageWidth': 2585, 'ImageLength': 4554}, [['ImageLength', 2585], ['ImageWidth', 4554], ['Orientation', 1], ['PixelXDimension', 1191], ['PixelYDimension', 2873]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]]], [[{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]], [{'Orientation': 0, 'PixelXDimension': 2319, 'PixelYDimension': 3774, 'ImageWidth': 317, 'ImageLength': 1288, 'XResolution': 400, 'YResolution': 335, 'ThumbOrientation': 1}, [['ImageLength', 1288], ['ImageWidth', 317], ['Orientation', 1], ['PixelXDimension', 2319], ['PixelYDimension', 3774], ['XResolution', 400], ['YResolution', 335]]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'Orientation': 1, 'PixelXDimension': 2816, 'PixelYDimension': 2864, 'ImageWidth': 461, 'ImageLength': 2237, 'XResolution': 277, 'YResolution': 373, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 2237], ['ImageWidth', 461], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2816], ['PixelYDimension', 2864], ['XResolution', 277], ['YResolution', 373]]], [{'Orientation': 2, 'PixelXDimension': 3185, 'PixelYDimension': 993, 'ImageWidth': 1724, 'ImageLength': 1648, 'XResolution': 309, 'YResolution': 91, 'ThumbOrientation': 1}, [['ImageLength', 1648], ['ImageWidth', 1724], ['Orientation', 1], ['PixelXDimension', 3185], ['PixelYDimension', 993], ['XResolution', 309], ['YResolution', 91]]], [{'Orientation': 5, 'PixelXDimension': 2022, 'XResolution': 123, 'YResolution': 222, 'ThumbOrientation': 8}, [['Orientation', 1], ['PixelYDimension', 2022], ['XResolution', 222], ['YResolution', 123]]], [{'Orientation': 6, 'ImageWidth': 3998, 'XResolution': 106, 'YResolution': 377, 'ThumbOrientation': 1}, [['ImageLength', 3998], ['Orientation', 1], ['XResolution', 377], ['YResolution', 106]]], [{'ImageWidth': 3876, 'ImageLength': 923, 'XResolution': 383, 'YResolution': 223}, [['ImageLength', 923], ['ImageWidth', 3876], ['XResolution', 383], ['YResolution', 223]]]], [[{'PixelXDimension': 611, 'PixelYDimension': 2096, 'ImageWidth': 3720, 'ImageLength': 4669, 'XResolution': 104, 'XMP:Orientation': '6', 'Make': 'Acme'}, [['ImageLength', 4669], ['ImageWidth', 3720], ['Make', 'Acme'], ['PixelXDimension', 611], ['PixelYDimension', 2096], ['XMP:Orientation', '1'], ['XResolution', 104]]], [{'Orientation': 0, 'XResolution': 393, 'YResolution': 135, 'XMP:Orientation': '8'}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 393], ['YResolution', 135]]], [{'Orientation': 9, 'PixelXDimension': 2099, 'PixelYDimension': 2710, 'XResolution': 330, 'YResolution': 270, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2099], ['PixelYDimension', 2710], ['XResolution', 330], ['YResolution', 270]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]], [{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]], [{'Orientation': 6, 'PixelXDimension': 1678, 'PixelYDimension': 2248, 'ImageWidth': 1422, 'ImageLength': 2871, 'YResolution': 243, 'XMP:Orientation': '1'}, [['ImageLength', 1422], ['ImageWidth', 2871], ['Orientation', 1], ['PixelXDimension', 2248], ['PixelYDimension', 1678], ['XMP:Orientation', '1'], ['XResolution', 243]]], [{'Orientation': 5, 'PixelXDimension': 3958, 'PixelYDimension': 4449, 'ImageLength': 2850, 'XResolution': 243, 'YResolution': 171, 'XMP:Orientation': '8'}, [['ImageWidth', 2850], ['Orientation', 1], ['PixelXDimension', 4449], ['PixelYDimension', 3958], ['XMP:Orientation', '1'], ['XResolution', 171], ['YResolution', 243]]], [{'PixelXDimension': 2001, 'ImageWidth': 642, 'YResolution': 161, 'ThumbOrientation': 8}, [['ImageWidth', 642], ['PixelXDimension', 2001], ['YResolution', 161]]]], [[{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]], [{'Orientation': 0, 'PixelXDimension': 4484, 'PixelYDimension': 2133, 'XResolution': 320, 'YResolution': 385, 'XMP:Orientation': '3', 'ThumbOrientation': 8, 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4484], ['PixelYDimension', 2133], ['XMP:Orientation', '1'], ['XResolution', 320], ['YResolution', 385]]], [{'Orientation': 6, 'PixelXDimension': 2290, 'ImageWidth': 1257, 'ImageLength': 2949, 'XResolution': 142, 'YResolution': 251, 'XMP:Orientation': '8'}, [['ImageLength', 1257], ['ImageWidth', 2949], ['Orientation', 1], ['PixelYDimension', 2290], ['XMP:Orientation', '1'], ['XResolution', 251], ['YResolution', 142]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'Orientation': 3, 'PixelXDimension': 1081, 'PixelYDimension': 160, 'ImageWidth': 4451, 'ImageLength': 4974, 'XResolution': 180, 'YResolution': 379, 'XMP:Orientation': '8', 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4974], ['ImageWidth', 4451], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1081], ['PixelYDimension', 160], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 379]]], [{'Orientation': 5, 'ImageWidth': 4453, 'ImageLength': 2889, 'XResolution': 346, 'YResolution': 99, 'Make': 'Acme'}, [['ImageLength', 4453], ['ImageWidth', 2889], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 99], ['YResolution', 346]]], [{'PixelXDimension': 2406, 'PixelYDimension': 3046, 'ImageLength': 2138, 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 2138], ['Make', 'Acme'], ['PixelXDimension', 2406], ['PixelYDimension', 3046]]]], [[{'PixelXDimension': 2095, 'PixelYDimension': 4143, 'ImageWidth': 3622, 'ImageLength': 1172, 'XResolution': 182, 'ThumbOrientation': 6}, [['ImageLength', 1172], ['ImageWidth', 3622], ['PixelXDimension', 2095], ['PixelYDimension', 4143], ['XResolution', 182]]], [{'Orientation': 0, 'ImageWidth': 1668, 'ImageLength': 1751, 'XResolution': 393, 'YResolution': 309}, [['ImageLength', 1751], ['ImageWidth', 1668], ['Orientation', 1], ['XResolution', 393], ['YResolution', 309]]], [{'Orientation': 2, 'PixelXDimension': 2531, 'PixelYDimension': 3008, 'ImageWidth': 4056, 'YResolution': 253}, [['ImageWidth', 4056], ['Orientation', 1], ['PixelXDimension', 2531], ['PixelYDimension', 3008], ['YResolution', 253]]], [{'Orientation': 4, 'PixelYDimension': 1209, 'ImageWidth': 3039, 'ImageLength': 4709, 'XResolution': 133, 'YResolution': 298, 'XMP:Orientation': '3', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 4709], ['ImageWidth', 3039], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 1209], ['XMP:Orientation', '1'], ['XResolution', 133], ['YResolution', 298]]], [{'Orientation': 1, 'XResolution': 149, 'YResolution': 285, 'XMP:Orientation': '3', 'ThumbOrientation': 1}, [['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 149], ['YResolution', 285]]], [{'Orientation': 9, 'PixelXDimension': 4218, 'PixelYDimension': 1148, 'ImageWidth': 1525, 'XResolution': 171, 'YResolution': 311, 'XMP:Orientation': '6', 'Make': 'Acme'}, [['ImageWidth', 1525], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 4218], ['PixelYDimension', 1148], ['XMP:Orientation', '1'], ['XResolution', 171], ['YResolution', 311]]], [{'Orientation': 8, 'PixelXDimension': 522, 'XResolution': 367, 'XMP:Orientation': '3'}, [['Orientation', 1], ['PixelYDimension', 522], ['XMP:Orientation', '1'], ['YResolution', 367]]], [{'PixelXDimension': 385, 'ImageWidth': 1099, 'ImageLength': 3036, 'XMP:Orientation': '8', 'ThumbOrientation': 8}, [['ImageLength', 3036], ['ImageWidth', 1099], ['PixelXDimension', 385], ['XMP:Orientation', '1']]]]]
labels = ["regression: orientation key normalisation", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Metadata diffs show a new Orientation key on images that were stored without it.

After pixels have been baked upright, rewrite the metadata dictionary. When the (valid) Orientation is 5..8, exchange PixelXDimension/PixelYDimension, ImageWidth/ImageLength and XResolution/YResolution, moving a lone member of a pair to its partner key. Invalid or missing Orientation values mean no swap. Orientation is set to 1 only if the key exists; XMP:Orientation, if present, becomes the string "1"; ThumbOrientation is removed because the thumbnail is regenerated. Return sorted [key, value] pairs.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            va, vb = m.pop(a, None), m.pop(b, None)
            if vb is not None:
                m[a] = vb
            if va is not None:
                m[b] = va
    if 'Orientation' in m:
        m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = 1
    m.pop('ThumbOrientation', None)
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'Orientation': 4, 'ImageWidth': 2819, 'ImageLength': 178, 'XResolution': 230, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['ImageLength', 178], ['ImageWidth', 2819], ['Make', 'Acme'], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 230]]], [{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 7, 'PixelXDimension': 2873, 'PixelYDimension': 1191, 'ImageWidth': 2585, 'ImageLength': 4554}, [['ImageLength', 2585], ['ImageWidth', 4554], ['Orientation', 1], ['PixelXDimension', 1191], ['PixelYDimension', 2873]]], [{'Orientation': 0, 'PixelXDimension': 426, 'PixelYDimension': 2753, 'ImageLength': 1686, 'XResolution': 268, 'YResolution': 397, 'ThumbOrientation': 1}, [['ImageLength', 1686], ['Orientation', 1], ['PixelXDimension', 426], ['PixelYDimension', 2753], ['XResolution', 268], ['YResolution', 397]]], [{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]]], [[{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]], [{'Orientation': 8, 'PixelXDimension': 2357, 'ImageWidth': 4348, 'ImageLength': 2027, 'XResolution': 114, 'XMP:Orientation': '3', 'Make': 'Acme'}, [['ImageLength', 4348], ['ImageWidth', 2027], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 2357], ['XMP:Orientation', '1'], ['YResolution', 114]]], [{'Orientation': 8, 'PixelXDimension': 4972, 'ImageWidth': 1028, 'ImageLength': 1331, 'XResolution': 377, 'YResolution': 144, 'XMP:Orientation': '6', 'ThumbOrientation': 8}, [['ImageLength', 1028], ['ImageWidth', 1331], ['Orientation', 1], ['PixelYDimension', 4972], ['XMP:Orientation', '1'], ['XResolution', 144], ['YResolution', 377]]], [{'Orientation': 0, 'PixelYDimension': 4669, 'ImageWidth': 1458, 'ImageLength': 3813, 'XResolution': 143, 'YResolution': 303}, [['ImageLength', 3813], ['ImageWidth', 1458], ['Orientation', 1], ['PixelYDimension', 4669], ['XResolution', 143], ['YResolution', 303]]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'Orientation': 1, 'PixelXDimension': 2816, 'PixelYDimension': 2864, 'ImageWidth': 461, 'ImageLength': 2237, 'XResolution': 277, 'YResolution': 373, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 2237], ['ImageWidth', 461], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2816], ['PixelYDimension', 2864], ['XResolution', 277], ['YResolution', 373]]], [{'Orientation': 2, 'PixelXDimension': 3185, 'PixelYDimension': 993, 'ImageWidth': 1724, 'ImageLength': 1648, 'XResolution': 309, 'YResolution': 91, 'ThumbOrientation': 1}, [['ImageLength', 1648], ['ImageWidth', 1724], ['Orientation', 1], ['PixelXDimension', 3185], ['PixelYDimension', 993], ['XResolution', 309], ['YResolution', 91]]], [{'Orientation': 4, 'PixelXDimension': 3641, 'PixelYDimension': 200, 'ImageWidth': 281, 'ImageLength': 2394, 'XResolution': 180, 'YResolution': 93, 'XMP:Orientation': '3'}, [['ImageLength', 2394], ['ImageWidth', 281], ['Orientation', 1], ['PixelXDimension', 3641], ['PixelYDimension', 200], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 93]]]], [[{'Orientation': 1, 'PixelYDimension': 4637, 'ImageWidth': 844, 'ImageLength': 4281, 'XResolution': 123, 'XMP:Orientation': '1'}, [['ImageLength', 4281], ['ImageWidth', 844], ['Orientation', 1], ['PixelYDimension', 4637], ['XMP:Orientation', '1'], ['XResolution', 123]]], [{'Orientation': 8, 'PixelXDimension': 3881, 'PixelYDimension': 1916, 'ImageWidth': 365, 'ImageLength': 1485, 'XResolution': 239, 'XMP:Orientation': '3'}, [['ImageLength', 365], ['ImageWidth', 1485], ['Orientation', 1], ['PixelXDimension', 1916], ['PixelYDimension', 3881], ['XMP:Orientation', '1'], ['YResolution', 239]]], [{'Orientation': 2, 'ImageWidth': 3444, 'XResolution': 148, 'YResolution': 258, 'XMP:Orientation': '8'}, [['ImageWidth', 3444], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 148], ['YResolution', 258]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]], [{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]], [{'Orientation': 0, 'PixelXDimension': 3801, 'PixelYDimension': 833, 'ImageWidth': 655, 'ImageLength': 2578, 'XResolution': 340}, [['ImageLength', 2578], ['ImageWidth', 655], ['Orientation', 1], ['PixelXDimension', 3801], ['PixelYDimension', 833], ['XResolution', 340]]], [{'PixelXDimension': 2001, 'ImageWidth': 642, 'YResolution': 161, 'ThumbOrientation': 8}, [['ImageWidth', 642], ['PixelXDimension', 2001], ['YResolution', 161]]], [{'Orientation': 0, 'ImageLength': 2958, 'XResolution': 117, 'YResolution': 164, 'XMP:Orientation': '1', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 2958], ['Make', 'Acme'], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 117], ['YResolution', 164]]]], [[{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'Orientation': 5, 'PixelXDimension': 2116, 'PixelYDimension': 1027, 'XResolution': 398, 'YResolution': 346, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1027], ['PixelYDimension', 2116], ['XMP:Orientation', '1'], ['XResolution', 346], ['YResolution', 398]]], [{'Orientation': 3, 'PixelXDimension': 2569, 'PixelYDimension': 4610, 'ImageWidth': 2772, 'ImageLength': 696, 'XMP:Orientation': '1'}, [['ImageLength', 696], ['ImageWidth', 2772], ['Orientation', 1], ['PixelXDimension', 2569], ['PixelYDimension', 4610], ['XMP:Orientation', '1']]], [{'PixelXDimension': 491, 'PixelYDimension': 1510, 'ImageWidth': 3083, 'ImageLength': 4807, 'XResolution': 307, 'YResolution': 118, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4807], ['ImageWidth', 3083], ['Make', 'Acme'], ['PixelXDimension', 491], ['PixelYDimension', 1510], ['XResolution', 307], ['YResolution', 118]]], [{'Orientation': 8, 'ImageWidth': 4397, 'ImageLength': 4112, 'XResolution': 282, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4397], ['ImageWidth', 4112], ['Make', 'Acme'], ['Orientation', 1], ['YResolution', 282]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 5, 'ImageWidth': 4453, 'ImageLength': 2889, 'XResolution': 346, 'YResolution': 99, 'Make': 'Acme'}, [['ImageLength', 4453], ['ImageWidth', 2889], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 99], ['YResolution', 346]]], [{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]]], [[{'PixelXDimension': 385, 'ImageWidth': 1099, 'ImageLength': 3036, 'XMP:Orientation': '8', 'ThumbOrientation': 8}, [['ImageLength', 3036], ['ImageWidth', 1099], ['PixelXDimension', 385], ['XMP:Orientation', '1']]], [{'Orientation': 7, 'PixelXDimension': 3494, 'PixelYDimension': 1145, 'XMP:Orientation': '6'}, [['Orientation', 1], ['PixelXDimension', 1145], ['PixelYDimension', 3494], ['XMP:Orientation', '1']]], [{'Orientation': 3, 'PixelXDimension': 2182, 'PixelYDimension': 1138, 'ImageWidth': 2425, 'ImageLength': 2209, 'XResolution': 105, 'YResolution': 375, 'XMP:Orientation': '3', 'ThumbOrientation': 8}, [['ImageLength', 2209], ['ImageWidth', 2425], ['Orientation', 1], ['PixelXDimension', 2182], ['PixelYDimension', 1138], ['XMP:Orientation', '1'], ['XResolution', 105], ['YResolution', 375]]], [{'Orientation': 2, 'PixelXDimension': 2531, 'PixelYDimension': 3008, 'ImageWidth': 4056, 'YResolution': 253}, [['ImageWidth', 4056], ['Orientation', 1], ['PixelXDimension', 2531], ['PixelYDimension', 3008], ['YResolution', 253]]], [{'Orientation': 0, 'PixelXDimension': 1579, 'PixelYDimension': 2508, 'ImageWidth': 104, 'ImageLength': 3875, 'XResolution': 311, 'YResolution': 283, 'ThumbOrientation': 8}, [['ImageLength', 3875], ['ImageWidth', 104], ['Orientation', 1], ['PixelXDimension', 1579], ['PixelYDimension', 2508], ['XResolution', 311], ['YResolution', 283]]], [{'Orientation': 5, 'ImageWidth': 837, 'ImageLength': 4624, 'XResolution': 268, 'YResolution': 385}, [['ImageLength', 837], ['ImageWidth', 4624], ['Orientation', 1], ['XResolution', 385], ['YResolution', 268]]], [{'Orientation': 9, 'ImageWidth': 4790, 'ImageLength': 4004, 'XResolution': 219, 'YResolution': 340, 'Make': 'Acme'}, [['ImageLength', 4004], ['ImageWidth', 4790], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 219], ['YResolution', 340]]], [{'Orientation': 0, 'PixelXDimension': 1747, 'PixelYDimension': 1995, 'ImageWidth': 3753, 'ImageLength': 2338, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 2338], ['ImageWidth', 3753], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1747], ['PixelYDimension', 1995], ['XMP:Orientation', '1']]]]]
labels = ["regression: XMP orientation value type", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(meta):
    m = dict(meta)
    t = m.get('Orientation', 1)
    if t not in (1, 2, 3, 4, 5, 6, 7, 8):
        t = 1
    if t >= 5:
        for a, b in (('PixelXDimension', 'PixelYDimension'), ('ImageWidth', 'ImageLength'), ('XResolution', 'YResolution')):
            va, vb = m.pop(a, None), m.pop(b, None)
            if vb is not None:
                m[a] = vb
            if va is not None:
                m[b] = va
    if 'Orientation' in m:
        m['Orientation'] = 1
    if 'XMP:Orientation' in m:
        m['XMP:Orientation'] = str(t)
    m.pop('ThumbOrientation', None)
    return [[k, m[k]] for k in sorted(m)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'Orientation': 2, 'PixelXDimension': 3483, 'PixelYDimension': 682, 'ImageWidth': 1196, 'ImageLength': 620, 'XMP:Orientation': '6', 'ThumbOrientation': 6}, [['ImageLength', 620], ['ImageWidth', 1196], ['Orientation', 1], ['PixelXDimension', 3483], ['PixelYDimension', 682], ['XMP:Orientation', '1']]], [{'Orientation': 4, 'ImageWidth': 2819, 'ImageLength': 178, 'XResolution': 230, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['ImageLength', 178], ['ImageWidth', 2819], ['Make', 'Acme'], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 230]]], [{'PixelXDimension': 3713, 'PixelYDimension': 3107, 'ImageWidth': 3378, 'ImageLength': 411, 'YResolution': 121}, [['ImageLength', 411], ['ImageWidth', 3378], ['PixelXDimension', 3713], ['PixelYDimension', 3107], ['YResolution', 121]]], [{'PixelXDimension': 3102, 'PixelYDimension': 263, 'ImageWidth': 1654, 'ImageLength': 2684}, [['ImageLength', 2684], ['ImageWidth', 1654], ['PixelXDimension', 3102], ['PixelYDimension', 263]]], [{'Orientation': 0, 'ImageWidth': 4760, 'ImageLength': 4173, 'XResolution': 182, 'Make': 'Acme'}, [['ImageLength', 4173], ['ImageWidth', 4760], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 182]]], [{'Orientation': 7, 'PixelXDimension': 2873, 'PixelYDimension': 1191, 'ImageWidth': 2585, 'ImageLength': 4554}, [['ImageLength', 2585], ['ImageWidth', 4554], ['Orientation', 1], ['PixelXDimension', 1191], ['PixelYDimension', 2873]]], [{'Orientation': 0, 'PixelXDimension': 426, 'PixelYDimension': 2753, 'ImageLength': 1686, 'XResolution': 268, 'YResolution': 397, 'ThumbOrientation': 1}, [['ImageLength', 1686], ['Orientation', 1], ['PixelXDimension', 426], ['PixelYDimension', 2753], ['XResolution', 268], ['YResolution', 397]]], [{'Orientation': 5, 'PixelXDimension': 3085, 'PixelYDimension': 271, 'XResolution': 264, 'YResolution': 241, 'XMP:Orientation': '1', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 271], ['PixelYDimension', 3085], ['XMP:Orientation', '1'], ['XResolution', 241], ['YResolution', 264]]]], [[{'PixelXDimension': 2501, 'ImageWidth': 4285, 'ImageLength': 4215, 'XResolution': 212, 'YResolution': 316, 'XMP:Orientation': '1', 'ThumbOrientation': 8}, [['ImageLength', 4215], ['ImageWidth', 4285], ['PixelXDimension', 2501], ['XMP:Orientation', '1'], ['XResolution', 212], ['YResolution', 316]]], [{'Orientation': 8, 'PixelXDimension': 2357, 'ImageWidth': 4348, 'ImageLength': 2027, 'XResolution': 114, 'XMP:Orientation': '3', 'Make': 'Acme'}, [['ImageLength', 4348], ['ImageWidth', 2027], ['Make', 'Acme'], ['Orientation', 1], ['PixelYDimension', 2357], ['XMP:Orientation', '1'], ['YResolution', 114]]], [{'Orientation': 8, 'PixelXDimension': 4972, 'ImageWidth': 1028, 'ImageLength': 1331, 'XResolution': 377, 'YResolution': 144, 'XMP:Orientation': '6', 'ThumbOrientation': 8}, [['ImageLength', 1028], ['ImageWidth', 1331], ['Orientation', 1], ['PixelYDimension', 4972], ['XMP:Orientation', '1'], ['XResolution', 144], ['YResolution', 377]]], [{'Orientation': 0, 'PixelYDimension': 4669, 'ImageWidth': 1458, 'ImageLength': 3813, 'XResolution': 143, 'YResolution': 303}, [['ImageLength', 3813], ['ImageWidth', 1458], ['Orientation', 1], ['PixelYDimension', 4669], ['XResolution', 143], ['YResolution', 303]]], [{'Orientation': 9, 'PixelXDimension': 1450, 'PixelYDimension': 714, 'ImageWidth': 3388, 'ImageLength': 3368, 'YResolution': 224, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 3368], ['ImageWidth', 3388], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1450], ['PixelYDimension', 714], ['YResolution', 224]]], [{'Orientation': 1, 'PixelXDimension': 2816, 'PixelYDimension': 2864, 'ImageWidth': 461, 'ImageLength': 2237, 'XResolution': 277, 'YResolution': 373, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 2237], ['ImageWidth', 461], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 2816], ['PixelYDimension', 2864], ['XResolution', 277], ['YResolution', 373]]], [{'Orientation': 2, 'PixelXDimension': 3185, 'PixelYDimension': 993, 'ImageWidth': 1724, 'ImageLength': 1648, 'XResolution': 309, 'YResolution': 91, 'ThumbOrientation': 1}, [['ImageLength', 1648], ['ImageWidth', 1724], ['Orientation', 1], ['PixelXDimension', 3185], ['PixelYDimension', 993], ['XResolution', 309], ['YResolution', 91]]], [{'Orientation': 4, 'PixelXDimension': 3641, 'PixelYDimension': 200, 'ImageWidth': 281, 'ImageLength': 2394, 'XResolution': 180, 'YResolution': 93, 'XMP:Orientation': '3'}, [['ImageLength', 2394], ['ImageWidth', 281], ['Orientation', 1], ['PixelXDimension', 3641], ['PixelYDimension', 200], ['XMP:Orientation', '1'], ['XResolution', 180], ['YResolution', 93]]]], [[{'Orientation': 1, 'PixelYDimension': 4637, 'ImageWidth': 844, 'ImageLength': 4281, 'XResolution': 123, 'XMP:Orientation': '1'}, [['ImageLength', 4281], ['ImageWidth', 844], ['Orientation', 1], ['PixelYDimension', 4637], ['XMP:Orientation', '1'], ['XResolution', 123]]], [{'Orientation': 8, 'PixelXDimension': 3881, 'PixelYDimension': 1916, 'ImageWidth': 365, 'ImageLength': 1485, 'XResolution': 239, 'XMP:Orientation': '3'}, [['ImageLength', 365], ['ImageWidth', 1485], ['Orientation', 1], ['PixelXDimension', 1916], ['PixelYDimension', 3881], ['XMP:Orientation', '1'], ['YResolution', 239]]], [{'Orientation': 2, 'ImageWidth': 3444, 'XResolution': 148, 'YResolution': 258, 'XMP:Orientation': '8'}, [['ImageWidth', 3444], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 148], ['YResolution', 258]]], [{'Orientation': 8, 'PixelXDimension': 4471, 'PixelYDimension': 854, 'ImageWidth': 4083, 'ImageLength': 2109}, [['ImageLength', 4083], ['ImageWidth', 2109], ['Orientation', 1], ['PixelXDimension', 854], ['PixelYDimension', 4471]]], [{'Orientation': 6, 'PixelYDimension': 2320, 'ImageWidth': 4268, 'ImageLength': 4198, 'XResolution': 376, 'YResolution': 302, 'ThumbOrientation': 1}, [['ImageLength', 4268], ['ImageWidth', 4198], ['Orientation', 1], ['PixelXDimension', 2320], ['XResolution', 302], ['YResolution', 376]]], [{'Orientation': 0, 'PixelXDimension': 3801, 'PixelYDimension': 833, 'ImageWidth': 655, 'ImageLength': 2578, 'XResolution': 340}, [['ImageLength', 2578], ['ImageWidth', 655], ['Orientation', 1], ['PixelXDimension', 3801], ['PixelYDimension', 833], ['XResolution', 340]]], [{'PixelXDimension': 2001, 'ImageWidth': 642, 'YResolution': 161, 'ThumbOrientation': 8}, [['ImageWidth', 642], ['PixelXDimension', 2001], ['YResolution', 161]]], [{'Orientation': 0, 'ImageLength': 2958, 'XResolution': 117, 'YResolution': 164, 'XMP:Orientation': '1', 'ThumbOrientation': 6, 'Make': 'Acme'}, [['ImageLength', 2958], ['Make', 'Acme'], ['Orientation', 1], ['XMP:Orientation', '1'], ['XResolution', 117], ['YResolution', 164]]]], [[{'Orientation': 1, 'PixelXDimension': 717, 'ImageWidth': 4963, 'ImageLength': 644, 'XResolution': 201, 'YResolution': 305, 'XMP:Orientation': '1'}, [['ImageLength', 644], ['ImageWidth', 4963], ['Orientation', 1], ['PixelXDimension', 717], ['XMP:Orientation', '1'], ['XResolution', 201], ['YResolution', 305]]], [{'Orientation': 5, 'PixelXDimension': 2116, 'PixelYDimension': 1027, 'XResolution': 398, 'YResolution': 346, 'XMP:Orientation': '8', 'Make': 'Acme'}, [['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1027], ['PixelYDimension', 2116], ['XMP:Orientation', '1'], ['XResolution', 346], ['YResolution', 398]]], [{'Orientation': 3, 'PixelXDimension': 2569, 'PixelYDimension': 4610, 'ImageWidth': 2772, 'ImageLength': 696, 'XMP:Orientation': '1'}, [['ImageLength', 696], ['ImageWidth', 2772], ['Orientation', 1], ['PixelXDimension', 2569], ['PixelYDimension', 4610], ['XMP:Orientation', '1']]], [{'PixelXDimension': 491, 'PixelYDimension': 1510, 'ImageWidth': 3083, 'ImageLength': 4807, 'XResolution': 307, 'YResolution': 118, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4807], ['ImageWidth', 3083], ['Make', 'Acme'], ['PixelXDimension', 491], ['PixelYDimension', 1510], ['XResolution', 307], ['YResolution', 118]]], [{'Orientation': 8, 'ImageWidth': 4397, 'ImageLength': 4112, 'XResolution': 282, 'ThumbOrientation': 8, 'Make': 'Acme'}, [['ImageLength', 4397], ['ImageWidth', 4112], ['Make', 'Acme'], ['Orientation', 1], ['YResolution', 282]]], [{'Orientation': 3, 'PixelXDimension': 317, 'PixelYDimension': 1770, 'ImageWidth': 3506, 'XResolution': 328, 'YResolution': 264}, [['ImageWidth', 3506], ['Orientation', 1], ['PixelXDimension', 317], ['PixelYDimension', 1770], ['XResolution', 328], ['YResolution', 264]]], [{'Orientation': 5, 'ImageWidth': 4453, 'ImageLength': 2889, 'XResolution': 346, 'YResolution': 99, 'Make': 'Acme'}, [['ImageLength', 4453], ['ImageWidth', 2889], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 99], ['YResolution', 346]]], [{'PixelXDimension': 1405, 'PixelYDimension': 3697, 'ImageWidth': 3644, 'ImageLength': 3874, 'YResolution': 207, 'XMP:Orientation': '1'}, [['ImageLength', 3874], ['ImageWidth', 3644], ['PixelXDimension', 1405], ['PixelYDimension', 3697], ['XMP:Orientation', '1'], ['YResolution', 207]]]], [[{'PixelXDimension': 385, 'ImageWidth': 1099, 'ImageLength': 3036, 'XMP:Orientation': '8', 'ThumbOrientation': 8}, [['ImageLength', 3036], ['ImageWidth', 1099], ['PixelXDimension', 385], ['XMP:Orientation', '1']]], [{'Orientation': 7, 'PixelXDimension': 3494, 'PixelYDimension': 1145, 'XMP:Orientation': '6'}, [['Orientation', 1], ['PixelXDimension', 1145], ['PixelYDimension', 3494], ['XMP:Orientation', '1']]], [{'Orientation': 3, 'PixelXDimension': 2182, 'PixelYDimension': 1138, 'ImageWidth': 2425, 'ImageLength': 2209, 'XResolution': 105, 'YResolution': 375, 'XMP:Orientation': '3', 'ThumbOrientation': 8}, [['ImageLength', 2209], ['ImageWidth', 2425], ['Orientation', 1], ['PixelXDimension', 2182], ['PixelYDimension', 1138], ['XMP:Orientation', '1'], ['XResolution', 105], ['YResolution', 375]]], [{'Orientation': 2, 'PixelXDimension': 2531, 'PixelYDimension': 3008, 'ImageWidth': 4056, 'YResolution': 253}, [['ImageWidth', 4056], ['Orientation', 1], ['PixelXDimension', 2531], ['PixelYDimension', 3008], ['YResolution', 253]]], [{'Orientation': 0, 'PixelXDimension': 1579, 'PixelYDimension': 2508, 'ImageWidth': 104, 'ImageLength': 3875, 'XResolution': 311, 'YResolution': 283, 'ThumbOrientation': 8}, [['ImageLength', 3875], ['ImageWidth', 104], ['Orientation', 1], ['PixelXDimension', 1579], ['PixelYDimension', 2508], ['XResolution', 311], ['YResolution', 283]]], [{'Orientation': 5, 'ImageWidth': 837, 'ImageLength': 4624, 'XResolution': 268, 'YResolution': 385}, [['ImageLength', 837], ['ImageWidth', 4624], ['Orientation', 1], ['XResolution', 385], ['YResolution', 268]]], [{'Orientation': 9, 'ImageWidth': 4790, 'ImageLength': 4004, 'XResolution': 219, 'YResolution': 340, 'Make': 'Acme'}, [['ImageLength', 4004], ['ImageWidth', 4790], ['Make', 'Acme'], ['Orientation', 1], ['XResolution', 219], ['YResolution', 340]]], [{'Orientation': 0, 'PixelXDimension': 1747, 'PixelYDimension': 1995, 'ImageWidth': 3753, 'ImageLength': 2338, 'XMP:Orientation': '6', 'ThumbOrientation': 1, 'Make': 'Acme'}, [['ImageLength', 2338], ['ImageWidth', 3753], ['Make', 'Acme'], ['Orientation', 1], ['PixelXDimension', 1747], ['PixelYDimension', 1995], ['XMP:Orientation', '1']]]]]
labels = ["regression: XMP orientation value type", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The XMP serializer emits a typed value that differs from the text property it replaces.

After pixels have been baked upright, rewrite the metadata dictionary. When the (valid) Orientation is 5..8, exchange PixelXDimension/PixelYDimension, ImageWidth/ImageLength and XResolution/YResolution, moving a lone member of a pair to its partner key. Invalid or missing Orientation values mean no swap. Orientation is set to 1 only if the key exists; XMP:Orientation, if present, becomes the string "1"; ThumbOrientation is removed because the thumbnail is regenerated. Return sorted [key, value] pairs.

split: open-access