def mySimpleDumpRMSSpotSizeMeritFunction(s): """ This is a test Merit function for RMS spot size on axis with modifications implemented suggested by Mo :param s: OpticalSystem object :return merit: merit function value (float) """ nray = 1e3 # number of rays rasterType= raster.RectGrid pupilType= pupil.StopDiameter # EntrancePupilDiameter pupilSizeParameter = 3.0 # 5.5 wavelength = 0.55 stopPosition = 5 fieldType= field.ObjectHeight fieldpoints = [0., 0.1] aimy = aim.aimFiniteByMakingASurfaceTheStop(s, pupilType, pupilSizeParameter, fieldType, rasterType, nray, wavelength, stopPosition) # RMS at all field points merit_squared = 0 for y in fieldpoints: initialBundle = aimy.getInitialRayBundle(s, array([0.,y]), wavelength) raypath_on_axis = RayPath(initialBundle, s) merit_squared += ( raypath_on_axis.raybundles[-1].getRMSspotSizeCentroid() )**2 return merit_squared
def myPersonalMeritFunctionForTestingPurposes(s): """ This is a test Merit function for RMS of a finite corrected 20x microscope objective. The microscope sample is on the object side. Parfocal or tube length are not enforced. :param s: OpticalSystem object :return merit: merit function value (float) """ nray = 1E3 # number of rays rasterType = raster.RectGrid pupilType = pupil.ObjectSpaceNA pupilSizeParameter = 0.25 wavelengths = [0.48, 0.55, 0.65] stopPosition = 5 mag = 20 fieldType = field.ObjectHeight fieldpoints = 1. / mag * 0.5 * array([0., 17.5, 25.]) aimy = aim.aimFiniteByMakingASurfaceTheStop(s, pupilType, pupilSizeParameter, fieldType, rasterType, nray, wavelengths[1], stopPosition) # RMS at all field points merit_squared = 0 for wavelength in wavelengths: for y in fieldpoints: initialBundle = aimy.getInitialRayBundle(s, array([0., y]), wavelength) raypath_on_axis = RayPath(initialBundle, s) merit_squared += ( raypath_on_axis.raybundles[-1].getRMSspotSizeCentroid())**2 initialBundle = aimy.getInitialRayBundle(s, array([0., 0.]), wavelengths[1]) # magnification merit_squared += (s.getParaxialMagnification(initialBundle) - mag)**2 # positive thicknesses for i in arange(s.getNumberOfSurfaces()): merit_squared += (int(s.getThickness(i) < 0)) return merit_squared
def myPersonalMeritFunctionForTestingPurposes(s): """ This is a test Merit function for RMS of a finite corrected 20x microscope objective. The microscope sample is on the object side. Parfocal or tube length are not enforced. :param s: OpticalSystem object :return merit: merit function value (float) """ nray = 1E3 # number of rays rasterType= raster.RectGrid pupilType= pupil.ObjectSpaceNA pupilSizeParameter = 0.25 wavelengths = [0.48, 0.55, 0.65] stopPosition = 5 mag = 20 fieldType= field.ObjectHeight fieldpoints = 1./mag * 0.5*array([0., 17.5,25.]) aimy = aim.aimFiniteByMakingASurfaceTheStop(s, pupilType, pupilSizeParameter, fieldType, rasterType, nray, wavelengths[1], stopPosition) # RMS at all field points merit_squared = 0 for wavelength in wavelengths: for y in fieldpoints: initialBundle = aimy.getInitialRayBundle(s, array([0.,y]), wavelength) raypath_on_axis = RayPath(initialBundle, s) merit_squared += ( raypath_on_axis.raybundles[-1].getRMSspotSizeCentroid() )**2 initialBundle = aimy.getInitialRayBundle(s, array([0.,0.]), wavelengths[1]) # magnification merit_squared += ( s.getParaxialMagnification(initialBundle) - mag ) **2 # positive thicknesses for i in arange(s.getNumberOfSurfaces()): merit_squared += ( int(s.getThickness(i) < 0) ) return merit_squared
def mySimpleDumbRMSSpotSizeMeritFunction(s): """ This is a test Merit function for RMS spot size on axis with modifications implemented suggested by Mo :param s: OpticalSystem object :return merit: merit function value (float) """ nray = 1e3 # number of rays rasterType = raster.RectGrid pupilType = pupil.StopDiameter # EntrancePupilDiameter pupilSizeParameter = 3.0 # 5.5 wavelength = 0.55 stopPosition = 5 fieldType = field.ObjectHeight fieldpoints = [0., 0.1, -0.1] aimy = aim.aimFiniteByMakingASurfaceTheStop(s, pupilType, pupilSizeParameter, fieldType, rasterType, nray, wavelength, stopPosition) # RMS at all field points merit_squared = 0 for y in fieldpoints: initialBundle = aimy.getInitialRayBundle(s, array([0., y]), wavelength) raypath_on_axis = RayPath(initialBundle, s) merit_squared += ( raypath_on_axis.raybundles[-1].getRMSspotSizeCentroid())**2 return merit_squared
s.insertSurface(3, Surface(surfShape.Conic(curv=1/15.884, semidiam=1.3), thickness=3.0, material=material.ConstantIndexGlass(1.7), aperture=CircularAperture(1.3))) # 1.3 s.insertSurface(4, Surface(surfShape.Conic(curv=1/-12.756, semidiam=1.3), thickness=3.0, aperture=CircularAperture(1.3))) # 1.3 s.insertSurface(5, Surface(surfShape.Conic(semidiam=1.01), thickness=2.0, aperture=CircularAperture(1.01))) # semidiam=1.01 # STOP s.insertSurface(6, Surface(surfShape.Conic(curv=1/3.125, semidiam=1.0), thickness=3.0, material=material.ConstantIndexGlass(1.5), aperture=CircularAperture(1.0))) # semidiam=1.0 s.insertSurface(7, Surface(surfShape.Conic(curv=0.1*1/1.479, semidiam=1.0), thickness=19.0, aperture=CircularAperture(1.0))) # semidiam=1.0 # benchmark # definition of rays nray = 1E5 # number of rays aimy = aim.aimFiniteByMakingASurfaceTheStop(s, pupilType=pupil.ObjectSpaceNA, #.StopDiameter, pupilSizeParameter=0.2,#3.0, fieldType= field.ObjectHeight, rasterType= raster.RectGrid, nray=nray, wavelength=0.55, stopPosition=5) initialBundle = aimy.getInitialRayBundle(s, fieldXY=np.array([0, 0]), wavelength=.55) nray = len(initialBundle.o[0, :]) t0 = time.clock() r = RayPath(initialBundle, s) print "benchmark : ", time.clock() - t0, "s for tracing ", nray, " rays through ", len(s.surfaces) - 1, " surfaces." print " That is ", int(round(nray * (len(s.surfaces) - 1) / (time.clock() - t0))), "ray-surface-operations per second" # plot aimy.setPupilRaster(rasterType= raster.RectGrid, nray=20) initialBundle2 = aimy.getInitialRayBundle(s, fieldXY=np.array([0, 0]), wavelength=.55) r2 = RayPath(initialBundle2, s)