def main(): lens = SimpleSinglet(200, 80, 10) obj, im = lens.planePair(-0.2, 200.0) tprint("Object plane : " + repr(obj)) tprint("Image plane : " + repr(im)) objectTarget = TargetPlane(obj, wavelength=0.6) imageTarget = TargetPlane(im) objectTarget.addGrid(5, 5) fig = plt.figure() panel = fig.add_subplot(1, 1, 1) panel.axis('equal') imageTarget.draw() targetPencil = objectTarget.getPencils(lens, wavelength=0.45) for pencil in targetPencil: pencil *= lens pencil *= imageTarget psf = Psf().setWithRays(pencil, imageTarget) psf.draw(colour=WavelengthColour(0.45)) plt.show()
def main(): md = MaterialData() # get the database (this will load the default) while True: mat = md.getMaterial() # Null call to get for interacibe mode tprint(repr(mat)) # trpe %exit to exit loop
def main(): wl = tio.getFloat("Long Cut off",0.4) ws = tio.getFloat("Short Cut off",0.5) dw = tio.getFloat("dw",0.01) short = wave.ShortPassFilter(ws,dw) long = wave.LongPassFilter(wl,dw) stack = wave.FilterStack(short,long) tio.tprint(long.getValue(wl + dw/2)," ", long.getValue(wl - dw/2)) tio.tprint(short.getValue(ws + dw/2)," ", short.getValue(ws - dw/2)) notch = wave.NotchFilter(0.5) spectrum = wave.Spectrum() spectrum.addFilter(notch) spectrum.draw() plt.show()
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 main(): """ # Get a float with default and range checking f = getFloat("Give a float",3.0,0.0,5.0) tprint("Float is : ", f) # Get a logical within a if statemnet if getBool("Logical",True): tprint("True") else: tprint("False") # Get an integer with no default but range ckecking i = getInt("Integer Value", min = 5,max = 10) tprint("Integer Value is : ", i) # Get a complex with default and range check of maximum absolute value c = getComplex("Complex Number",3+4j, maxabs = 100.0) tprint("Complex is : ", c) v = getVector3d("Vector",maxabs = 100) tprint(repr(v)) """ u = getUnit3d("Direction","10") tprint(repr(u))
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(): #w = getFloat("Beam Waist",100) g = GaussianBeam(0.0, 0.23, wavelength=0.633) lens = ParaxialThinLens(750, 50) #tprint("Beam ",repr(g)) r = g.getRadius() #tprint("Radius is : ",r) print("Initial conditions") w = g.getWaist() tprint("Waist : ", w) z = g.getWaistLocation() tprint("Waist location is : ", z) g *= lens r = g.getRadius() print("Beam is : " + str(g.beam)) print("New Location of beam is : " + str(g.z)) tprint("New Radius is : ", r) tprint("New Waist : ", g.getWaist()) z = g.getWaistLocation() tprint("Waist location is : ", z)
def main(): while True: opts = "exit","quit","continue","restart","reset" opt,name = t.getOption("Option",opts) t.tprint("Option Number ",opt," Option name ", name) if opt == 0 or opt == 1: break
def main(): # Get name of index and make a default sprectometer with 60 degreee prism glassname = getString("Glass type",default = "BK7") prism = PrismSpectrometer(index = glassname) tprint(repr(prism)) # Show details of spectrometer # Get a wavelngth, calculate min deviation and display it while True: wavelength = getFloat("Wavelength in um",min = 0.35,max = 1.0) mindeviation = math.degrees(prism.minDeviation(wavelength)) tprint("Minimum deviation for {0:5.3f} um is : {1:7.4f} degrees".format(wavelength,mindeviation))
def main(): l0 = getFloat("Lambda_0", 0.08) beta = getFloat("Beta", 1.25) index = w.Sellmeier(beta, l0) nd = index.getNd() vd = index.getVd() tprint("Nd index : ", nd, " Abbe No: ", vd) index.draw() plt.show()
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(): # Read the wavefront in from a .wf file and display it contents wave = WaveFront().fromFile() #wave.setMask(AnnularMask(wave.radius,0.7)) # Uncomment for annual mask tprint(repr(wave)) # Get the tilts xt = getFloat("Xtilt", 0.0) yt = getFloat("Ytilt", 0.0) # Make the interferometed inter = Interferometer(wave) inter.setTilt(xt, yt) # Set the tilts inter.draw() # Display plt.show()
def main(): angle = Angle().setDegrees(30, 80) # Angle with theta = 30 , psi = 80 degrees tprint("Angle is : ", angle) # print, note tprint() automaticall take str() u = Unit3d(angle) # Convert to Unit3d tprint(repr(u)) # print using repr() angle = u.getAngle() # get angle from Unit3d theta, psi = angle.getDegrees() # get the angle as a list in degrees tprint("Theta is : ", theta, " and psi is : ", psi) # print it angle = getAngleDegrees("Get angle in degtrees") tprint(repr(angle)) u = Unit3d(angle) # Convert to Unit3d tprint(repr(u)) # print using repr()
def main(): # Read in a wavefront wf = WaveFront().fromFile() tprint(repr(wf)) wf.plot() # Make vertical + horizontal plot radius = wf.getRadius() yscan = np.linspace(-radius,radius,11) # x/y positions of points xscan = np.linspace(-radius,radius,11) ws = WavePointSet(radius) # Start with blanks set of points # Make grid of points for y in yscan: for x in xscan: if x*x + y*y <= radius*radius: # Inside circle pt = Vector2d(x,y) wp = WavePoint(wavelength = 0.65).setWithWaveFront(wf,pt) ws.add(wp) # Add to wavepoint set # Fit zernike to 4th orders zw = ws.fitZernike(4) tprint(repr(zw)) tprint("Error is : ",str(ws.zerr)) # Show the fitting error for each component zw.plot() # Plot to same graph #ws.plot() plt.show() # Show the final plot
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(): # Make a test image of 100 x 100 pixels and size 300 x 300 mm #a4 -400 mm oi = OpticalImage(-400, 100, 100, 300, 300) oi.addTestGrid(8, 8) # Add a 8 x 8 test grid #plt.subplot(1,2,1) #oi.draw() eye = Eye(pixels=100) #eye.setNearPoint(400) tprint(repr(eye)) #tprint("Focal length " + str(eye.backFocalLength())) ip = eye.getRetina() tprint(repr(ip)) #ip.getImage(eye,oi) # Make plot area and plot target on the left #plt.subplot(1,2,2) ip.draw() 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(): # Default spectrometer prism = PrismSpectrometer() prism.setUpWavelength(Helium_d) tprint(repr(prism)) # Get min deviation at current wavelength minDev = prism.minDeviation() midAngle = minDev / 2 tprint("Min deviations : ", minDev, " Beam angle : ", midAngle) dtilt = math.radians(10) tiltData = np.linspace(-dtilt, dtilt, 50) angleData = np.zeros(tiltData.size) for i, tilt in enumerate(tiltData): prism.setTilt(tilt) angleData[i] = prism.getOutputAngle(midAngle, Helium_d) plt.plot(np.degrees(tiltData), np.degrees(angleData)) plt.show()
def main(): # Make a test image of 100 x 100 pixels and size 300 x 300 mm oi = OpticalImage(0, 100, 100, 300, 300) oi.addTestGrid(8, 8) # Add a 8 x 8 test grid # Make plot area and plot target on the left plt.subplot(1, 2, 1) oi.draw() # Simple singlet of focal length 80mm, radius 10 mm at location 200mm lens = SimpleSinglet(200, 80, 10) # Get a system image with a -0.2 magnification im = oi.getSystemImage(lens, -0.2) tprint(repr(oi)) tprint(repr(im)) # Plot output image on right. plt.subplot(1, 2, 2) im.draw() plt.show()
def main(): # First set up prism n = MaterialIndex() # get materail, angle and height prismAngle = getFloat("Prism angle in degrees",60.0) prismHeight =getFloat("Height of prism in mm",100.0) beam =getFloat("Beam Radius in mm",10.0) # Set up spectrometer prism = PrismSpectrometer(0.0,prismAngle,prismHeight,n,beam) tprint(repr(prism)) # Get the setup wavelength (set prsm at min deviation) setupWavelength = getFloat("Set up wavelength",Mercury_e) prism.setUpWavelength(setupWavelength) # Print out details deviation = prism.minDeviation() tprint("Min deviation : {0:6.4f} at : {1:6.4f}".format(math.degrees(deviation),setupWavelength)) tprint("Max resolutions is : {0:7.3f}".format(prism.maxResolution(setupWavelength))) tprint("Resolution with specified beam : {0:7.3f}".format(prism.resolution())) # Get the wavelengths and intensities of the spcetrum fileName = getFilename("Wavelength file","csv") wavelengths,intensities = readCSV(fileName) # Give option for matplotplot or save to CSV if getBool("Display Graph",True): prism.plotSpectrum(wavelengths, intensities) plt.show() else: fieldAngle,spectrum = prism.getIntensitySpectum(wavelengths,intensities) fileName = getFilename("Output file","csv") n = writeCSV(fileName,[fieldAngle,spectrum]) tprint("No of lines written: ",n)
def main(): # Get the materail type and make a prism of default angle, size and location n = MaterialIndex() prism = Prism(index=n) tprint(repr(prism)) # Get input point on prism and min deviation at Mercury_i line pt = prism.getInputPoint() dev = prism.minDeviation(Mercury_e) tprint("Min deviation : ", math.degrees(dev), " at : ", Mercury_e) tprint("Max resolutions is ", prism.maxResolution(Mercury_e)) tprint("Resolution with 20 mm diameter beam : ", prism.resolution(10, Mercury_e)) u = Unit3d().parseAngle(dev / 2) # Set ray input angle at half min deviation # Form np array of wavelength and angle wavelengths = np.linspace(Mercury_i, Helium_r, 50) angle = np.zeros(wavelengths.size) # Go through each wavelength, make a ray and trace it for i, wave in enumerate(wavelengths): ray = r.IntensityRay(pt, u, wave) ray *= prism # Extract angle of ray in degrees angle[i] = math.degrees(Angle(ray.director).theta) # Do the plotting plt.plot(wavelengths, angle) plt.title("Spectrometer Output angle") plt.xlabel("Wavelength in microns") plt.ylabel("Output angle in degrees") plt.grid() plt.show()
def main(): # Get sprectometer from definition file spectrometer = PrismSpectrometer().fromFile("bk7") tprint(repr(spectrometer)) # Get wavelength from csv file (only first col) wavein = getFilename("File of wavelength", "csv") wave, = csv.readCSV(wavein, [True, False]) tprint(str(wave)) # Make array to hold angles angle = np.empty(wave.size) # Make the angle array in degrees for i, w in enumerate(wave): angle[i] = np.degrees(spectrometer.minDeviation(w)) tprint(str(angle)) # Output to csv file with wave , angle waveout = getFilename("Output file", "csv") n = csv.writeCSV(waveout, [wave, angle]) tprint("No of lines writen : ", n)
def main(): # Read in csv filename file = getFilename("File", "csv") # Open File wave, ref = readCSV(file) # Read to two np arrays # Create a Sellmier index and it it to the read in np arrays index = Sellmeier().fitIndex(wave, ref) # Print out results and Nd / Vd values tprint("Index : ", repr(index)) tprint("Nd : ", index.getNd(), " Vd : ", index.getVd()) # Get the digital rerivative at the Sodium Doublet dn = index.getDerivative(Sodium_D) tprint("Derivative is : ", dn) # Plot out the data valuse a s x plt.plot(wave, ref, "x") index.draw() # Defaul draw of the index from 0.35 -> 0.7 plt.title("Plot of Sellmeier index") plt.ylabel("Index") plt.show()
def main(): res = w.Sodium_D / (w.Sodium_D2 - w.Sodium_D1) tio.tprint("Resolution target for Na Doublet is : ", res) index = w.MaterialIndex() tio.tprint(repr(index)) tio.tprint("Nd index : ", index.getNd(), " Abbe No: ", index.getVd()) dn = index.getDerivative(w.Sodium_D) tio.tprint("dn / d :", dn) d = tio.getFloat("d in mm") d *= 1000 pr = d * dn tio.tprint("Prism resolution : ", pr) if abs(pr) > abs(res): tio.tprint("Doublet resolved") else: tio.tprint("Doublet not resolved")
def main(): n = t.getFilename("File Name", "csv", "$HOME/mydata") t.tprint("Name is : ", n) file = t.openFile("File", "r", "jpg", "$HOME/Desktop/wjh")