Example #1
0
    def get(self, cmp):
        global _av_comp
        assert self.parser.has_section(
            cmp), "Library error in component %s, type not defined" % (cmp, )
        type = self.parser.get(cmp, "type")

        # Check that the class name is defined in the comp_lib module
        if not type in _av_comp:
            raise TypeError("Component type " + type +
                            " not defined in comp_lib")
        options = self.parser.options(cmp)

        #Create the constructor string
        strobj = "CL." + type + "("
        for opt in options:
            #Remove options not needed for the class constructors
            if opt == "type":
                pass
            elif opt == "description":
                pass
            #Check if the material exists in the material library and
            elif opt[0:3] == "mat":
                mat = self.parser.get(cmp, opt).upper()
                m = get_material(mat)
                if m == None:
                    raise TypeError("material " + mat +
                                    " not defined in mat_lib")
                strobj = strobj + opt + "=get_material(\"" + mat + "\") ,"
            else:
                strobj = strobj + opt + "=" + self.parser.get(cmp, opt) + " ,"
        strobj = strobj[:-1] + ")"
        # strobj
        return eval(strobj)
Example #2
0
 def get(self, cmp):
     global _av_comp
     assert self.parser.has_section(cmp), "Library error in component %s, type not defined"%(cmp,)
     type=self.parser.get(cmp,"type")
     
     # Check that the class name is defined in the comp_lib module
     if not type in _av_comp:
         raise TypeError("Component type "+type+" not defined in comp_lib")
     options=self.parser.options(cmp)
     
     #Create the constructor string
     strobj="CL."+type+"("
     for opt in options:
         #Remove options not needed for the class constructors
         if opt=="type":
             pass
         elif opt=="description":
             pass
         #Check if the material exists in the material library and 
         elif opt[0:3]=="mat":
             mat=self.parser.get(cmp,opt).upper()
             m=get_material(mat)
             if m==None:
                 raise TypeError("material "+mat+" not defined in mat_lib")
             strobj=strobj+opt+"=get_material(\""+mat+"\") ,"
         else:
             strobj=strobj+opt+"="+self.parser.get(cmp,opt)+" ,"
     strobj=strobj[:-1]+")"
     # strobj
     return eval(strobj)
Example #3
0
def zmx_parse(data):
    """Función que lee e interpreta un archivo zmx de zemax.

    - Solo funciona para lentes esfericas y dobletes.
    - No tiene ne cuenta recubrimientos antireflectivos
    - Asume que las medidas están en milimetros. Hay que arreglar esto
    """

    lines = data.splitlines()

    # Interpretar el encabezado
    while True:
        line = lines.pop(0)

        if lines[0].startswith("SURF"):
            break

    # Separar las superficies en una lista de diccionarios
    surflist = []
    for line in lines:
        if line.startswith("SURF"):
            surflist.append(dict())
            continue
        line = line.lstrip()
        code = line[:4]
        data = line[5:].split()
        data = [convert(d) for d in data]
        surflist[-1][code] = data

    #Eliminar el plano objeto y el plano imagen

    surflist.pop(0)
    surflist.pop()

    # Identificar el tipo de lentes a partir de el numero de superficies
    # validas

    ns = len(surflist)

    if ns == 2:  #Lentes normales
        c0 = surflist[0]["CURV"][0]
        c1 = surflist[1]["CURV"][0]
        d0 = surflist[0]["DISZ"][0]
        r0 = surflist[0]["DIAM"][0]
        r1 = surflist[1]["DIAM"][0]
        g0 = surflist[0]["GLAS"][0]
        m0 = get_material(g0)

        ##c|Verificar que las superficies son iguales, si no emitir un error
        assert r0 == r1

        return CL.SphericalLens(r0, d0, c0, c1, material=m0)

    if ns == 3:  #Dobletes
        c0 = surflist[0]["CURV"][0]
        c1 = surflist[1]["CURV"][0]
        c2 = surflist[2]["CURV"][0]
        d0 = surflist[0]["DISZ"][0]
        d1 = surflist[1]["DISZ"][0]
        r0 = surflist[0]["DIAM"][0]
        r1 = surflist[1]["DIAM"][0]
        r2 = surflist[2]["DIAM"][0]
        g0 = surflist[0]["GLAS"][0]
        g1 = surflist[1]["GLAS"][0]
        m0 = get_material(g0)
        m1 = get_material(g1)

        #Verificar que las superficies son iguales, si no emitir un error
        assert r0 == r1 and r1 == r2

        return CL.Doublet(r0, c0, c1, c2, d0, d1, m0, m1)

    elif ns == 4 and "GLAS" not in surflist[1]:  #Dobletes con espaciado en Aire
        c0 = surflist[0]["CURV"][0]
        c1 = surflist[1]["CURV"][0]
        c2 = surflist[2]["CURV"][0]
        c3 = surflist[3]["CURV"][0]

        d0 = surflist[0]["DISZ"][0]
        d1 = surflist[1]["DISZ"][0]
        d2 = surflist[2]["DISZ"][0]

        r0 = surflist[0]["DIAM"][0]
        r1 = surflist[1]["DIAM"][0]
        r2 = surflist[2]["DIAM"][0]
        r3 = surflist[3]["DIAM"][0]

        g0 = surflist[0]["GLAS"][0]
        # g1=surflist[1]["GLAS"][0] Este parametro no existe. Es aire
        g2 = surflist[2]["GLAS"][0]

        m0 = get_material(g0)
        #m1=get_material(g1)
        m1 = get_material(g2)

        #Verificar que las superficies son iguales, si no emitir un error

        #assert r0==r1 and r1== r2 and r2 ==r3 Esto no siempre se cumple

        return CL.AirSpacedDoublet(r0, c0, c1, c2, c3, d0, d1, d2, m0, m1)

    else:
        for i in surflist:
            print("*", i)
        raise ValueError  # Esto toca arreglarlo y generar un error que realmente indique que está pasando
Example #4
0
def zmx_parse(data):
    """Función que lee e interpreta un archivo zmx de zemax.

    - Solo funciona para lentes esfericas y dobletes.
    - No tiene ne cuenta recubrimientos antireflectivos
    - Asume que las medidas están en milimetros. Hay que arreglar esto
    """

    lines=data.splitlines()

    # Interpretar el encabezado
    while True:
        line=lines.pop(0)

        if lines[0].startswith("SURF"):
            break

    # Separar las superficies en una lista de diccionarios
    surflist=[]
    for line in lines:
        if line.startswith("SURF"):
            surflist.append(dict())
            continue
        line=line.lstrip()
        code=line[:4]
        data=line[5:].split()
        data=[convert(d) for d in data]
        surflist[-1][code]=data


    #Eliminar el plano objeto y el plano imagen

    surflist.pop(0)
    surflist.pop()


    # Identificar el tipo de lentes a partir de el numero de superficies
    # validas

    ns=len(surflist)

    if ns==2: #Lentes normales
        c0=surflist[0]["CURV"][0]
        c1=surflist[1]["CURV"][0]
        d0=surflist[0]["DISZ"][0]
        r0=surflist[0]["DIAM"][0]
        r1=surflist[1]["DIAM"][0]
        g0=surflist[0]["GLAS"][0]
        m0=get_material(g0)


        ##c|Verificar que las superficies son iguales, si no emitir un error
        assert r0==r1

        return CL.SphericalLens(r0,d0,c0,c1,material=m0)

    if ns==3: #Dobletes
        c0=surflist[0]["CURV"][0]
        c1=surflist[1]["CURV"][0]
        c2=surflist[2]["CURV"][0]
        d0=surflist[0]["DISZ"][0]
        d1=surflist[1]["DISZ"][0]
        r0=surflist[0]["DIAM"][0]
        r1=surflist[1]["DIAM"][0]
        r2=surflist[2]["DIAM"][0]
        g0=surflist[0]["GLAS"][0]
        g1=surflist[1]["GLAS"][0]
        m0=get_material(g0)
        m1=get_material(g1)

        #Verificar que las superficies son iguales, si no emitir un error
        assert r0==r1 and r1== r2

        return CL.Doublet(r0,c0,c1,c2, d0,d1,m0,m1)

    elif ns==4 and not surflist[1].has_key("GLAS"): #Dobletes con espaciado en Aire
        c0=surflist[0]["CURV"][0]
        c1=surflist[1]["CURV"][0]
        c2=surflist[2]["CURV"][0]
        c3=surflist[3]["CURV"][0]

        d0=surflist[0]["DISZ"][0]
        d1=surflist[1]["DISZ"][0]
        d2=surflist[2]["DISZ"][0]



        r0=surflist[0]["DIAM"][0]
        r1=surflist[1]["DIAM"][0]
        r2=surflist[2]["DIAM"][0]
        r3=surflist[3]["DIAM"][0]

        g0=surflist[0]["GLAS"][0]
        # g1=surflist[1]["GLAS"][0] Este parametro no existe. Es aire
        g2=surflist[2]["GLAS"][0]

        m0=get_material(g0)
        #m1=get_material(g1)
        m1=get_material(g2)

        #Verificar que las superficies son iguales, si no emitir un error

        #assert r0==r1 and r1== r2 and r2 ==r3 Esto no siempre se cumple


        return CL.AirSpacedDoublet(r0,c0,c1,c2,c3, d0,d1,d2,m0,m1)

    else:
        for i in surflist:
            print("*", i)
        raise ValueError # Esto toca arreglarlo y generar un error que realmente indique que está pasando