
from pylab import *
from Spectrometre import *
spectreIlluminant = Spectre("IlluminantTungstene.txt")
spectreRouge = Spectre("papierRougeIT.txt")
spectreFond = Spectre("bruitFond1500.txt")
clf()
xlabel('lambda (nm)')
ylabel('I')
plot(spectreIlluminant.Lambda,spectreIlluminant.I,c='k')
plot(spectreRouge.Lambda,spectreRouge.I,c='r')
plot(spectreFond.Lambda,spectreFond.I,c='y')
grid(True)
axis([400,700,0,20])
            

for k in range(2048):
    spectreRouge.I[k] = spectreRouge.I[k] - spectreFond.I[k]
            

def rapport(spectre1,spectre2): 
    L = spectre1.Lambda
    R = []
    for k in range(2048):
        if k < 1423: 
            R.append(spectre1.I[k]/spectre2.I[k])
        else:
            R.append(1)
    return [L,R]
[L,Rrouge] = rapport(spectreRouge,spectreIlluminant)
clf()
xlabel('lambda (nm)')
ylabel('R')
plot(L,Rrouge,c='r')
grid(True)
axis([400,700,0,1])
            

from CieXYZ import CIEXYZ
cie = CIEXYZ("../ciexyz/ciexyz31.txt") 
cie.readD65("../ciexyz/IlluminantD65.txt");
cie.setIlluminant("D65",0)
def Rf(l):
    k = spectreIlluminant.indiceLambda(l)  
    return Rrouge[k]
XYZ=cie.spectralF2XYZ(Rf) 
xyRouge=cie.XYZ2xy(XYZ[0],XYZ[1],XYZ[2])
                

spectreJaune = Spectre("papierJauneIT.txt")
for k in range(2048):
    spectreJaune.I[k] = spectreJaune.I[k] - spectreFond.I[k]
[L,Rjaune] = rapport(spectreJaune,spectreIlluminant)
clf()
xlabel('lambda (nm)')
ylabel('R')
plot(L,Rjaune,c='r')
axis([400,700,0,1])
grid(True)
                

def Rf(l):
    k = spectreIlluminant.indiceLambda(l)  
    return Rjaune[k]
XYZ=cie.spectralF2XYZ(Rf) 
xyJaune=cie.XYZ2xy(XYZ[0],XYZ[1],XYZ[2])
                
 
spectreBlanc = Spectre("papierBlancIT.txt")
for k in range(2048):
    spectreBlanc.I[k] = spectreBlanc.I[k] - spectreFond.I[k]
[L,Rblanc] = rapport(spectreBlanc,spectreIlluminant)
clf()
xlabel('lambda (nm)')
ylabel('R')
plot(L,Rblanc,c='r')
axis([400,700,0,1])
grid(True)
                

def Rf(l):
    k = spectreIlluminant.indiceLambda(l)  
    return Rblanc[k]
XYZ=cie.spectralF2XYZ(Rf) 
xyBlanc=cie.XYZ2xy(XYZ[0],XYZ[1],XYZ[2])
                

from DiaChrom import *
diagram=DiaChrom(cie)
diagram.plotSpectre()
sRGB = XYZ2RGB([0.64,0.33],[0.3,0.6],[0.15,0.06],[0.3127,0.329])
diagram.paintRGB(sRGB,"sRGB",0.002)
figure(1,figsize=(9,8))
xlabel('x')
ylabel('y')
plot([xyRouge[0]],[xyRouge[1]],color="r",marker="o",label="Rouge")
plot([xyJaune[0]],[xyJaune[1]],color="y",marker="o",label="Jaune")
plot([xyBlanc[0]],[xyBlanc[1]],color="w",marker="o",label="Blanc")
legend();
axis([0,1,0,1])
grid(True)
                
