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()
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()
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,
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()
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()
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)
def main(): lens = DataBaseLens("Tessar-F6.3") lens.setIris(0.7) u = Unit3d().parseAngle("5") pencil = RayPencil().addBeam(lens, u, "array", path=True) pencil *= lens ep = lens.exitPupil() t.tprint(repr(ep)) rpt = lens.imagePoint(u) rpt += Vector3d(0, 0, 0.2) t.tprint("Image point is ", repr(rpt)) ws = WavePointSet(ep.getRadius()).setWithRays(pencil, ep, refpt=rpt) zw = ws.fitZernike(4) t.tprint(repr(zw)) t.tprint("Error is : ", str(ws.zerr)) # Show the fitting error for each component zw.plot() ws.plot() inter = Interferometer(zw) inter.draw(0.0, 0.0) plt.show()
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()
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()
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()
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)
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()
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()
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()
def main(): # Get lens from database lens = DataBaseLens() # Get angle of beam and wavelnegth u = getUnit3d("Direction", 0.0) w = getFloat("Wavelength", Default) # Make a ray through lens pencil = RayPencil().addBeam(lens, u, "array", wavelength=w) pencil *= lens # Propagate through lens sd = SpotAnimation(pencil) # Go round loop plotting the sopt diagram as various zplane positions bf = lens.backFocalPlane() # Back focal plane sd.run(bf) #1.0,0.1,400)
def getWavePointSet(self,source,wave = None,nrays = 10,refopt = 1): """ Get the WavePointSet for collimated beam in the exitpupil of the lens :param source: source of input beeam, either SourcePoint, Unit3d or angle. :type source: SourcePoint, Unit3d, Angle or float :param wave: analysis wavelength :type wave: float :param nrays: number of raays across input aperture, (Default = 10) :type nrays: int :param refopt: reference point option, 0 = paraxial, 1 = centre of PSF in image plane, 2 = optimal area PSF :type refopt: int """ # Sort out angle if isinstance(source,SourcePoint): u = Vector3d(source) elif isinstance(source,float) or isinstance(source,int): u = Unit3d(Angle(source)) else: u = Unit3d(source) # Make pencil with array and record path, and propagate through lens pencil = RayPencil().addBeam(self.lens,u,"array",nrays=nrays,wavelength=wave,path=True) pencil *= self.lens # Get image point of object self.refpt = self.lens.imagePoint(u,self.design) # Paraxial point location pt = self.lens.getPoint() self.ip = OpticalPlane(Vector3d(pt.x,pt.y,self.refpt.z)) if refopt == 0: # got what we need aready None elif refopt == 1: self.refpt = Psf().setWithRays(pencil,self.ip) # Centre of PSF in image plane elif refopt == 2: self.refpt = Psf().optimalArea(pencil,self.ip) # Optimal area PSF, not in image plane else: print("Illegal ref type") ep = self.lens.exitPupil(self.design) # Exit pupil of lens # Form the wavefront wf = WavePointSet(ep.getRadius()).setWithRays(pencil,ep,self.refpt) return wf
def main(): singlet = SimpleSinglet() u = getUnit3d("Direction", 0.0) ip = singlet.backFocalPlane() bdata = np.linspace(-1.0, 1.0) adata = np.zeros(bdata.size) for i, bend in enumerate(bdata): singlet.setBend(bend, True) pencil = RayPencil().addBeam(singlet, u, "array") pencil *= singlet pencil *= ip psf = Psf().optimalArea(pencil, ip) adata[i] = psf.area() plt.plot(bdata, adata) plt.show()
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()
def drawAberrationPlot(self,angle,wavelength = None ,colour=["r","g","b"],legend = "lower left"): """ Form and draw the plots at specified angle :param angle: the ray angle :type angle: float or Angle or Unit3d :param colour: line colours is three elemnts list, Default = ["r","g","b"]) :param legend: location of ledgend, (Default = "lower left") :type legend: str """ if isinstance(angle,float): u = Unit3d(Angle(angle)) # direction of beam else: u = Unit3d(angle) angle = Angle(u).theta wavelength = getDefaultWavelength(wavelength) ref = self.lens.imagePoint(u,self.design) # Get image point at design wavelength ip = OpticalPlane(ref) # Image plane nrays = 50 ca = self.lens.entranceAperture() # Make list for plots mvals = [] # Meridional svalsx = [] # Sagittal x svalsy = [] # Sagittal y # Start of loop to make rays rscan = np.linspace(-ca.maxRadius,ca.maxRadius,nrays + 1) for r in rscan: # Make two rays mray = IntensityRay(ca.point + Vector3d(0.0, r, 0.0), u, wavelength) sray = IntensityRay(ca.point + Vector3d(r, 0.0, 0.0), u, wavelength) # Add to pencil and propagate both back to clear lens pencil = RayPencil(mray,sray).propagate(-ca.maxRadius) # propagate through lens to image surafce pencil *= self.lens pencil *= ip # If rays valid (so not blocked), abberations to list if mray: mpos = mray.position - ref mvals.append(mpos.y) else: mvals.append(float("nan")) if sray: spos = sray.position - ref svalsx.append(spos.x) svalsy.append(spos.y) else: svalsx.append(float("nan")) svalsy.append(float("nan")) # plots with suitable labels to the current axis. plt.plot(rscan,mvals, color = colour[0], label="Meridional") plt.plot(rscan,svalsx,color = colour[1], label="Sagittal x") plt.plot(rscan,svalsy,color = colour[2], label="Sagittal y") plt.title("{0:s}: a: {1:4.2f} w: {2:4.2f} d: {3:4.2f}".\ format(self.lens.title,math.degrees(angle),wavelength,\ self.design)) plt.legend(loc=legend,fontsize="small") plt.grid()
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()