summaryrefslogtreecommitdiff
path: root/src/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests.py')
-rw-r--r--src/tests.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/tests.py b/src/tests.py
new file mode 100644
index 0000000..9f20b3b
--- /dev/null
+++ b/src/tests.py
@@ -0,0 +1,91 @@
+from crl import *
+import random
+
+def pg(name):
+ pt()
+ print("\t%s" % name.upper())
+first = True
+def pt(name=None):
+ global first
+ if first:
+ first = False
+ else:
+ print("OK")
+
+ if name:
+ print("%s%s" % (name, "." * (40 - len(name))), end="")
+ else:
+ first = True
+def fail():
+ print("FAILED")
+
+def relerr(x, y):
+ return np.abs(x - y) / y
+
+
+pg("D series (SPD synthesis)")
+
+
+for T, ref in [[5000, Illuminants.D50],
+ [5500, Illuminants.D55],
+ [6500, Illuminants.D65]]:
+ pt(f"D{T//100}")
+ spec = CIEDaylightSpectrum(T)
+
+ wvl = np.linspace(380, 780, 1000)
+ Yspec = spec.Yi(wvl)
+ Yref = ref.Yi(wvl)
+ error = np.abs(Yspec - Yref) / Yref
+ if np.max(error) > 0.01:
+ fail()
+ exit(1)
+
+pg("Color space inversion tests")
+
+spaces = [sRGB, xyY, UVW, uvY, UVWstarD65, UVstarNormedD65, uvY76, LabstarD65, LuvstarD65]
+
+for CS in spaces:
+ pt(CS.full_name)
+
+ for i in range(150):
+ X0 = XYZ(random.random(), random.random(), random.random())
+ X = list(CS.from_XYZ(X0).to_XYZ())
+
+ for i in range(3):
+ if abs(X[i] - X0[i]) > 1e-9:
+ fail()
+ print(f" Input: {[*X0]}")
+ print(f"Output: {[*X]}")
+ exit(1)
+
+pg("F series (CCT, CRI Ra)")
+
+F_xs = [0.3131, 0.3721, 0.4091, 0.4402, 0.3138, 0.3779, 0.3129, 0.3458, 0.3741, 0.3458, 0.3805, 0.437]
+F_ys = [0.3371, 0.3751, 0.3941, 0.4031, 0.3452, 0.3882, 0.3292, 0.3586, 0.3727, 0.3588, 0.3769, 0.4042]
+F_CCTs = [6430, 4230, 3450, 2940, 6350, 4150, 6500, 5000, 4150, 5000, 4000, 3000]
+F_Ras = [76, 64, 57, 51, 72, 59, 90, 95, 90, 81, 83, 83]
+
+for i in range(12):
+ pt(f"F{i + 1}")
+
+ spec = Spectrum(tables.illuminants_F[:, 0], tables.illuminants_F[:, 1 + i])
+
+ x, y, _ = xyY(spec)
+ if relerr(x, F_xs[i]) > 0.01 or relerr(y, F_ys[i]) > 0.01:
+ fail()
+ print(f"Wrong chromaticity: {x}, {y} != {F_xs[i]}, {F_ys[i]}")
+ #exit(1)
+
+ CCT, _ = cct(spec)
+ if relerr(CCT, F_CCTs[i]) > 0.01:
+ fail()
+ print(f"Wrong CCT: {CCT} != {F_CCTs[i]}")
+ #exit(1)
+
+ res = cri_Ra(spec)
+ if round(res.CRI) != F_Ras[i]:
+ fail()
+ print(f"Wrong CRI Ra: {res.CRI} != {F_Ras[i]}")
+ #exit(1)
+
+pt()