"""主なローブの重心（最大の点の両側で半分の高さまで）で山の位置を測り、表面の層の扱いでどれだけ動くかを、最大の点と比べる。"""
import numpy as np, table2_model as m
lams = np.arange(400, 1001, 2.0)
def both(L):
    R = m.refl(lams, L); i = int(np.argmax(R)); h = R[i]/2
    a = i
    while a > 0 and R[a-1] > h: a -= 1
    b = i
    while b < len(R)-1 and R[b+1] > h: b += 1
    w = R[a:b+1]
    return lams[i], float((lams[a:b+1]*w).sum()/w.sum())
for patch in ('gorget', 'crown'):
    for sp in ('branickii', 'hybrid', 'gularis'):
        air, cor, ker, lay, mel, ptt = m.T2[(sp, patch)]
        r = [both(m.stack(air, c, ker, lay, mel, p)) for c, p in ((cor, ptt), (0.001, ptt), (cor, 2*mel+air), (0.001, 2*mel+air))]
        print(f'{sp:9s} {patch:6s} 最大 ' + '/'.join(f'{x[0]:.0f}' for x in r) + '   重心 ' + '/'.join(f'{x[1]:.0f}' for x in r))
