Exemplo n.º 1
0
    def __init__(self, rootlc = None, matbackground = None, name = ""):
        # TODO: rename variable name to label
        """
        Creates an optical system object. Initially, it contains 2 plane surfaces (object and image).


        :param objectLC: local coordinate system of object (class LocalCoordinates).


        """
        if rootlc is None:        
            rootlc = LocalCoordinates(name="global")
        self.rootcoordinatesystem = rootlc

        super(OpticalSystem, self).__init__(self.rootcoordinatesystem, label = name)
        
        if matbackground is None:
            matbackground = ConstantIndexGlass(self.rootcoordinatesystem, 1.0)

        self.material_background = matbackground # Background material        
        self.elements = {}
Exemplo n.º 2
0
    def __init__(self, rootlc = None, matbackground = None, **kwargs):
        """
        Creates an optical system object. Initially, it contains 2 plane surfaces (object and image).


        :param rootlc: local coordinate system of object (class LocalCoordinates).
        :param matbackground: background material (class Material)
        :param name: name of system (string)

        """
        if rootlc is None:        
            rootlc = LocalCoordinates(name="global")
        self.rootcoordinatesystem = rootlc

        super(OpticalSystem, self).__init__(self.rootcoordinatesystem, **kwargs)
        
        if matbackground is None:
            matbackground = ConstantIndexGlass(self.rootcoordinatesystem, 1.0)

        self.material_background = matbackground # Background material        
        self.elements = {}
Exemplo n.º 3
0
    def createOpticalSystem(self, matdict = {}, elementname="zmxelem"):

        optical_system = OpticalSystem()

        # extract surface blockstrings
        surface_blockstrings = self.filterBlockStrings("SURF")

        # construct basis coordinate system
        lc0 = optical_system.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=optical_system.rootcoordinatesystem.name)
        elem = OpticalElement(lc0, label=elementname)
        
        # construct materials
        if matdict != {}:        
            for (key, mat) in matdict.iteritems():
                mat.lc = lc0 
                # different material coordinate systems are not supported
                elem.addMaterial(key, mat)
        else:
            print("need external material objects in dict with the following identifiers")
            for blk in surface_blockstrings:
                surfres = self.readSurfBlock(blk)
                material_name = surfres.get("GLAS", None)
                if material_name is not None and material_name != "MIRROR":
                    print(material_name)
            print("exiting")
            return (optical_system, [("zmxelem", [])])

        refname = lc0.name
        lastlc = lc0
        lastmat = None
        surflist_for_sequence = []
        lastthickness = 0
        thickness = 0

        for blk in surface_blockstrings:
            lastthickness = thickness
            print "----"
            surfres = self.readSurfBlock(blk)
            print(surfres)    

            surf_options_dict = {}
            
            comment = surfres.get("COMM", "")
            surfname = "surf" + str(surfres["SURF"])
            thickness = surfres["DISZ"]
            curv = surfres["CURV"]
            cc = surfres.get("CONI", 0.0)
            stop = surfres["STOP"]
            surftype = surfres["TYPE"]
            parms = surfres["PARM"]
            
            sqap = surfres.get("SQAP", None)
            clap = surfres.get("CLAP", None)
            
            if math.isinf(thickness):
                print("infinite object distance!")
                thickness = 0
            if stop:
                surf_options_dict["is_stop"] = True

            mat = surfres.get("GLAS", None)
            if mat == "MIRROR":
                mat = lastmat
                surf_options_dict["is_mirror"] = True

            lc = optical_system.addLocalCoordinateSystem(LocalCoordinates(name=surfname, decz=lastthickness), refname=refname)
            if sqap is None and clap is None:
                ap = None
            elif sqap is not None:
                ap = RectangularAperture(lc, w=sqap[0]*2, h=sqap[1]*2)
            elif clap is not None:
                ap = CircularAperture(lc, semidiameter=clap[1])

            if surftype == "STANDARD":
                print("Standard surface found")                
                actsurf = Surface(lc, shape=Conic(lc, curv=curv, cc=cc), apert=ap)
            elif surftype == "EVENASPH":
                # param(1) corresponds to A2*r**2 coefficient in asphere
                # this is not implemented, yet
                print("Polynomial asphere found")

                if abs(parms.get(1, 0.0)) > numerical_tolerance:
                    print("warning: A2 coefficient ignored by our asphere implementation")
                acoeffs = [parms.get(2+i, 0.0) for i in range(7)]
                print(acoeffs)
                actsurf = Surface(lc, shape=Asphere(lc, curv=curv, cc=cc, acoeffs=acoeffs), apert=ap)
            elif surftype == "COORDBRK":
                print("Coordinate break found")
                """
                COORDBRK
                parm1: decx
                parm2: decy
                parm3: rx
                parm4: ry
                parm5: rz
                parm6: order 0: means 1. decx, 2. decy, 3. rx, 4. ry, 5. rz
                        order 1: means 1. rz 2. ry 3. rz, 4. decy, 5. decx
                disz: thickness (where does this appear in the transform? step 6)
                all in all: 1st step: transform coordinate system by former disz, dec, tilt (or tilt, dec)
                2nd step: update vertex
                """
                lc.decx.setvalue(parms.get(1, 0.0))
                lc.decy.setvalue(parms.get(2, 0.0))
                lc.tiltx.setvalue(parms.get(3, 0.0)*math.pi/180.0)
                lc.tilty.setvalue(parms.get(4, 0.0)*math.pi/180.0)
                lc.tiltz.setvalue(parms.get(5, 0.0)*math.pi/180.0)
                lc.tiltThenDecenter = bool(parms.get(6, 0))
                lc.update()
                actsurf = Surface(lc)
                
            elem.addSurface(surfname, actsurf, (lastmat, mat))
            print("addsurf: %s at material boundary %s" % (surfname, (lastmat, mat)))        
            
            lastmat = mat
            refname = lc.name
            surflist_for_sequence.append((surfname, surf_options_dict))
            
            lastlc = lc            
            
        optical_system.addElement(elementname, elem)
        seq = [(elementname, surflist_for_sequence)]    

        return (optical_system, seq)
Exemplo n.º 4
0
        for (ind, (xp, yp)) in enumerate(zip(x.tolist(), y.tolist())):        
            u.x = xp
            u.y = yp
            retval = self.us_surf(ctypes.byref(u), ctypes.byref(f))
            z[ind] = u.sag1 if retval == 0 else u.sag2
            
        return z
            
if __name__=="__main__":
    
    from localcoordinates import LocalCoordinates
    import matplotlib.pyplot as plt    
    
    
    lc = LocalCoordinates()
    
    s = ZMXDLLShape(lc, 
                    "../us_stand_gcc.so", 
                    xdata_dict={"xd1":(1, 0.1), "xd2":(2, 0.2)}, 
                    param_dict={"p1":(1, 0.3), "p2":(2, 0.4)}, curv=0.01, cc=0)

    x = np.random.random(100)
    y = np.random.random(100)
    
    z = s.getSag(x, y)

    print(z)    
    
    sz = ZernikeFringe(lc)
Exemplo n.º 5
0
        :return pmag: real space paraxial magnification (float)
        """
        abcd = self.getABCDMatrix(ray)
        print abcd
        return abcd[0, 0] - abcd[0, 1] * abcd[1, 0] / abcd[1, 1]


    def draw2d(self, ax, vertices=50, color="grey", inyzplane=True, **kwargs):
        for e in self.elements.itervalues():
            e.draw2d(ax, vertices=vertices, color=color, inyzplane=inyzplane, **kwargs)
            


if __name__ == "__main__":

   
    os = OpticalSystem()
    
    lc1 = os.addLocalCoordinateSystem(LocalCoordinates(decz=10.0), refname=os.rootcoordinatesystem.name)
    lc2 = os.addLocalCoordinateSystem(LocalCoordinates(decz=20.0), refname=lc1.name)
    lc3 = os.addLocalCoordinateSystem(LocalCoordinates(decz=30.0), refname=lc2.name)
    lc4 = os.addLocalCoordinateSystem(LocalCoordinates(decz=40.0), refname=lc3.name)
    
    lc5 = os.addLocalCoordinateSystem(LocalCoordinates(name="COM", decx=10.0, decy=5.0, decz=10.), refname=lc1.name)
    
    print(os.rootcoordinatesystem.pprint())



       
Exemplo n.º 6
0
        return abcd[0, 0] - abcd[0, 1] * abcd[1, 0] / abcd[1, 1]

    def draw2d(self, ax, vertices=50, color="grey", inyzplane=True, **kwargs):
        for e in self.elements.itervalues():
            e.draw2d(ax,
                     vertices=vertices,
                     color=color,
                     inyzplane=inyzplane,
                     **kwargs)


if __name__ == "__main__":

    os = OpticalSystem()

    lc1 = os.addLocalCoordinateSystem(LocalCoordinates(decz=10.0),
                                      refname=os.rootcoordinatesystem.name)
    lc2 = os.addLocalCoordinateSystem(LocalCoordinates(decz=20.0),
                                      refname=lc1.name)
    lc3 = os.addLocalCoordinateSystem(LocalCoordinates(decz=30.0),
                                      refname=lc2.name)
    lc4 = os.addLocalCoordinateSystem(LocalCoordinates(decz=40.0),
                                      refname=lc3.name)

    lc5 = os.addLocalCoordinateSystem(LocalCoordinates(name="COM",
                                                       decx=10.0,
                                                       decy=5.0,
                                                       decz=10.),
                                      refname=lc1.name)

    print(os.rootcoordinatesystem.pprint())
Exemplo n.º 7
0
    def testf2hess(x, y, z):
        result = np.zeros((6, len(x)))

        result[0] = -2. * np.ones_like(x)
        result[1] = -2. * np.ones_like(x)
        result[2] = np.zeros_like(x)
        result[3] = np.zeros_like(x)
        result[4] = np.zeros_like(x)
        result[5] = np.zeros_like(x)
        return result

    # it makes sense that external functions cannot access some internal
    # optimizable parameters. if you need access to optimizable parameters
    # derive a class from the appropriate shape classes

    lcroot = LocalCoordinates("root")

    imsh = ImplicitShape(lcroot,
                         testf,
                         testfgrad,
                         testfhess,
                         paramlist=[],
                         eps=1e-6,
                         iterations=10)
    exsh = ExplicitShape(lcroot,
                         testf2,
                         testf2grad,
                         testf2hess,
                         paramlist=[],
                         eps=1e-6,
                         iterations=10)