# For a family of filters: the best lattice (exhaustive over (A, B)/N), the three floors, and how close
# the best lattice comes to the floor no dither can beat. Prints a table (out/sweep.txt).
import numpy as np
import filters as F, lattice as L

NS = list(range(2, 65)) + [128, 256]   # every lattice with up to 64 levels, and 128 and 256

CASES = [('Starlock pass, full (radius 5)', F.kuwahara(5)), ('Starlock pass, lite (radius 2)', F.kuwahara(2))]
CASES += [(f'centre {c:.2f} + Gaussian sigma {s}', F.centre_plus_gaussian(c, s)) for s in (1.0, 2.0) for c in (0.0, 0.05, 0.1, 0.2, 0.4)]
CASES += [('box 2x2', F.box(2)), ('box 3x3', F.box(3)), ('box 4x4', F.box(4))]

if __name__ == '__main__':
    print(f'{"filter":34s} {"best lattice (A,B)/N":>20s} {"RMS":>7s} {"floor":>7s} {"ratio":>6s}   array bound  lattice bound')
    for name, t in CASES:
        r, a, b, N = L.best(t, NS)
        bd = L.bounds(t)
        ratio = r / bd['any'] if bd['any'] > 1e-9 else float('inf')
        print(f'{name:34s} {f"({a},{b})/{N}":>20s} {r:7.4f} {bd["any"]:7.4f} {ratio:6.2f}   {bd["array"]:.4f}       {bd["lattice"]:.4f}')
