"""joint_search.py で主ローブが一致しない点の内訳: どの部位で、窓の山と全域の最大の山がそれぞれ何nmか。"""
import itertools, collections, numpy as np
import table2_model as m
import joint_search as J
cnt = collections.Counter(); ex = {}
for sp in ('branickii', 'hybrid', 'gularis'):
    for dn, fa, cs, pt in itertools.product(J.DN, J.FA, J.CS, J.PT):
        m.n_mel = lambda l: J.n_orig(l) + dn
        for p in J.P:
            air, cor, ker, lay, mel, ptt = m.T2[(sp, p)]
            top = (2*mel + air) + pt*(ptt - (2*mel + air))
            R = m.refl(J.lams, m.stack(air, max(cs*cor, 0.001), ker, lay, mel, top, fa=fa, fa_top=fa))
            win = (J.lams >= 400) & (J.lams <= 800)
            iw = int(np.flatnonzero(win)[np.argmax(R[win])]); ig = int(np.argmax(R))
            if abs(iw - ig) > 3:
                cnt[(sp, p)] += 1
                ex.setdefault((sp, p), []).append((J.lams[iw], J.lams[ig], round(R[ig]/R[iw], 2)))
        m.n_mel = J.n_orig
for k, v in sorted(cnt.items()):
    e = ex[k]; print(k, v, '点  窓の山→全域の山 (nm, 高さの比) の例:', e[0], e[len(e)//2], e[-1],
                    ' 全域の山の範囲', min(x[1] for x in e), '〜', max(x[1] for x in e))
