from pylab import *
from CieXYZ import CIEXYZ
cie=CIEXYZ("ciexyz31.txt")
clf()
xlabel('lambda (nm)')
plot(cie.Lambda,cie.xc,c='r',label='xc')
plot(cie.Lambda,cie.yc,c='g',label='yc') 
plot(cie.Lambda,cie.zc,c='b',label='zc')
title(u'Fonctions colorim\xe9triques')
legend()
grid(True)

xy=cie.xyColor()
clf()
xlabel('x')
ylabel('y')
plot(xy[0],xy[1],c='k')
title(u"Diagramme de chromaticit\xe9")
grid(True)  
            
cie.readA("IlluminantA.txt")
cie.readD65("IlluminantD65.txt")
clf()
xlabel('lambda (nm)')
ylabel('S')
plot(cie.illumALambda,cie.illumASpectre,c='r',label='A')
plot(cie.illumD65Lambda,cie.illumD65Spectre,c='b',label='D65')
L=linspace(300,800,200)
corpsNoir6504=zeros(200)
for p in range(200):
    corpsNoir6504[p]=cie.corpsNoir(L[p],6504)
plot(L,corpsNoir6504,c='g',label='T=6504 K')
legend()
title('Illuminants')
grid(True)
                

cie.setIlluminant("CN",5000)
def Rf(L):
    return 1
XYZ=cie.spectralF2XYZ(Rf)
xy5000=cie.XYZ2xy(XYZ[0],XYZ[1],XYZ[2])
           

clf()
xlabel('x')
ylabel('y')
xy=cie.xyColor()
plot(xy[0],xy[1],c='k',label='Spectrum locus')
plot([xy5000[0]],[xy5000[1]],c='r',marker='o',label='T=5000 K')
cie.setIlluminant("D65",0)
XYZ=cie.spectralF2XYZ(Rf)
xyD65=cie.XYZ2xy(XYZ[0],XYZ[1],XYZ[2])
plot([xyD65[0]],[xyD65[1]],c='b',marker='o',label='D65')
cie.setIlluminant("A",0)
XYZ=cie.spectralF2XYZ(Rf)
xyA=cie.XYZ2xy(XYZ[0],XYZ[1],XYZ[2])
plot([xyA[0]],[xyA[1]],c='g',marker='o',label='A')
legend()
grid(True)
           
