Ejemplo n.º 1
0
def main():

        lens = Eye()
        iris = getFloat("Iris",1.0)
        lens.setIris(iris)

        u = getUnit3d("Direction",0.0)

        vpencil = RayPencil().addBeam(lens,u,key="vl").addMonitor(RayPath())
        spencil = RayPencil().addBeam(lens,u,key="array")


        vpencil *= lens
        spencil *= lens
        plane = lens.getRetina()

        ps = Psf().setWithRays(spencil,plane)
        tprint("PSF is",repr(ps))

        plt.subplot(2,1,1)
        lens.draw()
        vpencil.draw()
        plt.axis("equal")

        plt.subplot(2,1,2)
        spot = SpotDiagram(spencil)
        spot.draw(plane,True)

        plt.show()
Ejemplo n.º 2
0
def main():

    grating = Grating(pitch=3.3, height=100, angle=math.radians(0))

    #print(repr(grating[0]))
    #print(repr(grating[1]))

    #disc = Disc(-50,10)
    #pencil = RayPencil().addBeam(disc,0.0).addMonitor(RayPath())
    ip = ImagePlane(50, xsize=30)
    orders = [0, 1, 2, 3]
    for order in orders:

        pencil = RayPencil().addRays(
            -60, math.radians(0), [0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7])
        pencil.addMonitor(RayPath())

        pencil *= grating

        for ray in pencil:
            yi = ray.director.y
            ym = yi + order * ray.wavelength / grating.pitch
            zm = math.sqrt(1.0 - ym * ym)
            ray.director = Unit3d(0.0, ym, zm)

        pencil *= ip

        pencil.draw()

    grating.draw()
    ip.draw()
    plt.axis("equal")
    plt.grid()
    plt.show()
Ejemplo n.º 3
0
def main():

    lens = ParaxialThickLens(30, 0.025, 1.61, 10.0, -0.035, 5.0)
    lens.setFocalLength(50)  # Scale to 50 mm focal length
    print(repr(lens))

    mag = -0.3
    obj, ima = lens.planePair(50, mag)  #  Make pair of planes
    print("Object Plane : " + str(repr(obj)))
    print("New Image Plane : " + str(repr(ima)))

    #        Make paraxial pencil from a point on object plane
    pencil = RayPencil().addSourceParaxialBeam(lens, -0.5 * obj.getHeight(),
                                               obj)
    pencil.addMonitor(RayPath())

    pencil *= lens
    pencil *= ima

    # Draw diagram
    lens.draw(True)
    obj.draw()
    ima.draw()
    pencil.draw()
    plt.axis("equal")
    plt.show()
Ejemplo n.º 4
0
    def animate(self, i):
        """
        The main animate function to draw / redra the diagram
        """

        #     make a pencil of the right wavelengh and propagate throgh lens to back focal plane
        pencil = RayPencil().addBeam(self.lens,self.angle,"vl",wavelength = self.wavelength)\
            .addMonitor(RayPath())
        pencil *= self.lens
        pencil *= self.op

        self.ax.figure.clear()  # Clear the current figure
        self.lens.draw()  # Draw new diagram
        self.op.draw()
        pencil.draw()
        self.ax.axis("equal")
        self.ax.figure.canvas.draw()  # Display new fugure

        #      Update the angle (reversing when it reached angle_range)
        if abs(self.angle) > self.anglerange:
            self.delta = -self.delta
        self.angle += self.delta

        #                       Return the plot
        return self.ln,
Ejemplo n.º 5
0
def main():

    #
    #      Read lens in from database
    #
    lens = DataBaseLens()
    lens.setIris(0.7)  # Set iris to 0.7 of max
    #
    #       Make collimated pencil and add ray monitor to each ray
    u = getUnit3d("Direction", 0.0)
    pencil = RayPencil().addBeam(lens, u, "vl").addMonitor(RayPath())
    #
    tprint("Focal length is : ", lens.backFocalLength())
    tprint("Petzal sum is : ", lens.petzvalSum())
    #
    #        Set the output plane (being the back focal plane)
    op = lens.backFocalPlane()

    #         Propagate pencil through lens and one to back plane
    pencil *= lens  # Through lens
    pencil *= op  # To plane
    #
    #                    Draw the diagram

    plt.axis('equal')
    lens.draw(planes=True, legend=True)
    op.draw()
    pencil.draw()
    #                    Add decorations.
    plt.grid()
    plt.xlabel("Optical Axis")
    plt.ylabel("Height")
    plt.title("Diagram of lens " + lens.title)
    plt.show()
Ejemplo n.º 6
0
def main():

    #      Make a 40m high prism of F4 glass at the origin
    prism = Prism(0, height=40, index="F4")
    prism.setTilt(math.radians(5))
    #      Calcuate min deviation angle a
    minDev = prism.minDeviation(Green)
    print("Min deviation at Green: {0:6.4f}".format(math.degrees(minDev)))

    # Form a pencil and add in three beams of R,G,B along the optical axis
    # Start of beeams given by 10mm diameter disc at -50mm before prism
    disc = Disc(-50.0, 8.0)
    pencil = RayPencil()  # Make blank pencil
    pencil.addBeam(disc, 0.0,
                   wavelength=Green)  # Add the three coloured beams.
    pencil.addBeam(disc, 0.0,
                   wavelength=Blue)  # default of 21 rays in vertical line
    pencil.addBeam(disc, 0.0, wavelength=Red)
    angle = minDev / 2  # Angle of beam at half min deviation
    pencil.rotateAboutX(
        angle, prism.getInputPoint())  # retate beam about inpout point
    print("Numnber of rays : " + str(len(pencil)))
    pencil.addMonitor(RayPath())  # Add a monitor to allow plotting

    pencil *= prism  # propagate beam through prism
    pencil += 50.0

    #       Generate the diagram
    prism.draw()
    pencil.draw()
    plt.axis("equal")
    plt.grid()
    plt.xlabel("mm along optical axis")
    plt.show()
Ejemplo n.º 7
0
def main():

    lens = DataBaseMatrix("Tessar-100")  # get a lens from the database
    lens.setFocalLength(80.0)  # Set the focal length to 80mm
    lens.setInputPlane(120)

    #               Get system parameters
    mag = getFloat("Magnification", -2)
    ysize = getFloat("Height of Object plane", 20.0)

    #               Mage a pair of io / outplut place
    op, ip = lens.planePair(ysize, mag)
    tprint("Object plane at ; " + str(op.inputPlane()))
    tprint("Image plane at ; " + str(ip.inputPlane()))

    #               make a stsrem that conatins planes and lens in ordedr

    #                Maake a source bema from lower edge of object plane
    pencil = RayPencil().addSourceParaxialBeam(lens, -ysize,
                                               op).addMonitor(RayPath())
    #                Portagate throgh system
    pencil *= lens
    pencil *= ip

    #                Draw out the sytsem
    op.draw()
    lens.draw(True)  # Add a legend box
    ip.draw()
    pencil.draw()
    plt.axis("equal")
    plt.show()
Ejemplo n.º 8
0
def main():

    #        Form a disc and two apertures both 20mm with Iris closed to 0.5 ratio
    disc = Disc(20, 20)
    ca = CircularAperture(50, 20)
    iris = IrisAperture(80, 20, 0.5)
    #        Forma an angle for the pencil at 10deg up nore "10" specified in degrees.
    u = Unit3d().parseAngle("10")
    #        Form a pencil is the circular aperture as specified angle of 0.45 microns
    #        and add a RayPath to ech ray
    pencil = RayPencil().addBeam(disc, u,
                                 wavelength=0.59).addMonitor(RayPath())

    #        Propgate throgh the iris aperture and another 30 mm to make it visible
    pencil *= ca
    pencil *= iris
    pencil += 30

    #               Make a diagram
    disc.draw()
    ca.draw()
    iris.draw()
    pencil.draw()
    plt.axis("equal")
    plt.show()
Ejemplo n.º 9
0
def main():

    lens = DataBaseLens("Tessar-F4.5")  # Get lens from database
    lens.setFocalLength(50)             # Set focal length by scaling
    tprint(repr(lens))

    mag = -0.3                          # Set magnification
    obj,ima = lens.planePair(mag)        # Make pair of planes,
    tprint("Object Plane : " + str(repr(obj)))
    tprint("New Image Plane : " + str(repr(ima)))

    #     Make a ray pencil from point in object
    pencil = RayPencil().addBeam(lens,obj.getSourcePoint(0.0,10.0))
    pencil.addMonitor(RayPath())

    # Propgate pencil through lens to image plane
    pencil *= lens
    pencil *= ima


    #     Make plot
    lens.draw(True,True)    # With paraxial planes and legend
    obj.draw()
    ima.draw()
    pencil.draw()
    plt.title(lens.title)
    plt.axis("equal")
    plt.show()
Ejemplo n.º 10
0
def main():

    #      Make a 40m high prism of F4 glass at the origin
    prism = Prism(0,height = 40, index = "F4")
    #      Calcuate min deviation angle a
    minDev = prism.minDeviation(Green)
    print("Min deviation at Green: {0:6.4f}".format(math.degrees(minDev)))

    # Form a pencil and add in three beams of R,G,B along the optical axis
    # Start of beeams given by 10mm diameter disc at -50mm before prism
    disc = Disc(-50.0 ,10.0)
    pencil = RayPencil()               # Make blank pencil
    pencil.addBeam(disc,0.0,wavelength = Green)  # Add the three coloured beams.
    pencil.addBeam(disc,0.0,wavelength = Blue)   # default of 21 rays in vertical line
    pencil.addBeam(disc,0.0,wavelength = Red)
    angle = minDev/2                       # Angle of beam at half min deviation
    pencil.rotateAboutX(angle,prism.getInputPoint()) # retate beam about inpout point
    print("Numnber of rays : " + str(len(pencil)))
    pencil.addMonitor(RayPath())           # Add a monitor to allow plotting

    pencil *= prism                        # propagate beam through prism

    # Beam will be a dirction -angle with green rays centered at output point of prsim
    # so rotate beam so green pencil is parallel to optical axis
    pencil.rotateAboutX(angle,prism.getOutputPoint())

    #       Get a imagin lens, (a 140mm optimised doublet)
    lens = DataBaseLens("Linos140Doublet")
    lens.setPoint(50.0)        # Set it 50mm beyond the centre of the prism
    bf = lens.backFocalPlane(Green)  # Get back focal plane where rays wil be images

    #      propagate pencil theorugh lens to back focal plane
    pencil *=lens
    pencil *= bf

    #       Generate the diagram
    prism.draw()
    lens.draw(True,True)
    bf.draw()
    pencil.draw()
    plt.axis("equal")
    plt.grid()
    plt.xlabel("mm along optical axis")
    plt.show()
Ejemplo n.º 11
0
def main():

    #      Get lens from database
    lens = DataBaseLens()

    #           Get angle of beam and wavelnegth
    angle = getFloat("Angle in degrees", 0.0, 0.0, 15.0)
    u = Unit3d(Angle().setDegrees(angle))  # Angle as unit vectr
    w = getFloat("Wavelength", Default)

    #    Make two ray pencils, one for spot diagram and one for display (vertical only)
    pencil = RayPencil().addBeam(lens, u, "array", wavelength=w)
    vpencil = RayPencil().addBeam(lens, u, "vl",
                                  wavelength=w).addMonitor(RayPath())
    bf = lens.backFocalPlane()

    #            Propagate through lens to back focal plane
    pencil *= lens

    vpencil *= lens
    vpencil *= bf

    #            Get optimal area psf and create a SpotDiagram
    sd = SpotDiagram(pencil)

    #             Go round loop plotting the sopt diagram as various zplane positions

    while True:
        zp = getFloat("Zplane", bf.getPoint().z)
        plane = OpticalPlane(zp)
        plt.subplot(2, 1, 1)
        lens.draw()
        vpencil.draw()
        plt.axis("equal")
        plt.title("Lens " + lens.title)

        plt.subplot(2, 1, 2)
        sd.draw(plane, True)
        plt.title("Spot diagram")
        plt.show(block=True)
Ejemplo n.º 12
0
def main():

    #        Form two apertures both 20mm with Iris closed to 0.5 ratio
    ca = CircularAperture(50, 20)
    iris = IrisAperture(80, 20, 0.5)
    #        source for the rays at (0,10,-50) in global coordinates
    source = SourcePoint(Vector3d(0.0, 10, -50))
    #        Form a pencil is the circular aperture as specified angle of 0.45 microns
    #        and add a RayPath to ech ray
    pencil = RayPencil().addBeam(ca, source,
                                 wavelength=0.65).addMonitor(RayPath())

    #        Propgate throgh the the both aperture and another 30 mm to make it visible
    pencil *= ca
    pencil *= iris
    pencil += 30

    #               Make a diagram
    ca.draw()
    iris.draw()
    pencil.draw()
    plt.axis("equal")
    plt.show()
Ejemplo n.º 13
0
def main():

    eye = Eye(0.0)
    print("Original Focalength : " + str(eye.backFocalLength(wl.PhotopicPeak)))
    #eye.setIris(0.5)
    eye.moveRetina(1.0)

    #eye.setNearPoint(300)
    #print("Modified Focalength : " + str(eye.backFocalLength(wl.PhotopicPeak)))

    theta = 10
    u = Unit3d().parseAngle(math.radians(theta))
    pencil = RayPencil().addBeam(eye, u, "vl", 10, wl.Red)
    pencil.addBeam(eye, u, "vl", 10, wl.Green)
    pencil.addBeam(eye, u, "vl", 10, wl.Blue)
    pencil.addMonitor(RayPath())
    pencil *= eye

    eye.draw()
    pencil.draw()
    plt.axis("equal")
    plt.grid()
    plt.show()
Ejemplo n.º 14
0
def main():

    doublet = AchromaticDoublet(0.0, 120, 20.0, ct=10)  # 120mm, 20mm radius
    t.tprint("Focal length is :", doublet.backFocalLength())
    u = Unit3d().parseAngle("5")  # trace at 5 degrees

    #           Make ray pencil of three coloured rays
    pencil = RayPencil().addBeam(doublet, u, nrays=5, wavelength=Red)
    pencil.addBeam(doublet, u, nrays=5, wavelength=Green)
    pencil.addBeam(doublet, u, nrays=5, wavelength=Blue)
    pencil.addMonitor(RayPath())  # Add monitor to all rays to allow plotting

    ip = doublet.backFocalPlane()  # Back focal plane
    pencil *= doublet  # Propagte through lens to back focal plane
    pencil *= ip

    #      Draw the diagram
    doublet.draw(True, True)
    ip.draw()
    pencil.draw()
    plt.axis("equal")
    plt.grid()
    plt.title(repr(doublet))
    plt.show()
Ejemplo n.º 15
0
    def subPlot(self):
        """
        Method to do the actual plot, automatically called
        """
        panel = self.figure.add_subplot(111)
        panel.axis('equal')

        u = getCurrentAngle()
        pencil = RayPencil().addBeam(getCurrentLens(),u,"vl",\
                                               wavelength=getCurrentWavelength()).addMonitor(RayPath())

        #
        #        Set the output plane (being the back focal plane)
        op = getCurrentLens().backFocalPlane()

        #         Propagate pencil through lens and one to back plane
        pencil *= getCurrentLens()  # Through lens
        pencil *= op  # To plane

        # plot data
        getCurrentLens().draw(True, True)
        op.draw()
        pencil.draw()
        plt.grid()
        plt.xlabel("Optical Axis")
        plt.ylabel("Height")
        plt.title("Diagram of lens " + getCurrentLens().title)