Пример #1
0
    def pyoptools_repr(self, obj):
        matcat1 = obj.matcat1
        matref1 = obj.matref1
        if matcat1 == "Value":
            material1 = float(matref1.replace(",", "."))
        else:
            material1 = getattr(matlib.material, matcat1)[matref1]

        matcat2 = obj.matcat2
        matref2 = obj.matref2
        if matcat2 == "Value":
            material2 = float(matref2.replace(",", "."))
        else:
            material2 = getattr(matlib.material, matcat2)[matref2]

        if obj.ILD.Value == 0:
            radius = obj.D.Value / 2.0
            curv_s1 = obj.CS1_1
            curv_s2 = obj.CS2_1
            curv_s3 = obj.CS2_2
            th1 = obj.Thk_1.Value
            th2 = obj.Thk_2.Value
            db = comp_lib.Doublet(
                radius,
                curv_s1,
                curv_s2,
                curv_s3,
                th1,
                th2,
                material1,
                material2,
            )
        else:
            radius = obj.D.Value / 2.0
            curv_s1 = obj.CS1_1
            curv_s2 = obj.CS2_1
            curv_s3 = obj.CS1_2
            curv_s4 = obj.CS2_2

            th1 = obj.Thk_1.Value
            th2 = obj.Thk_2.Value

            ag = obj.ILD.Value
            db = comp_lib.AirSpacedDoublet(
                radius,
                curv_s1,
                curv_s2,
                curv_s3,
                curv_s4,
                th1,
                ag,
                th2,
                material1,
                material2,
            )

        return db
Пример #2
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