def main(): "Main code for demo purposes" logging.basicConfig(level=logging.DEBUG) mysys = OpticalSystem(name="s") mysys.lst = [] mysys.lst.append({}) mysys.lst.append({}) mysys.lst[0]["a"] = FloatOptimizableVariable(FixedState(3.0), name="v1") mysys.lst[1]["b"] = FloatOptimizableVariable(VariableState(7.0), name="v2") mysys.rootcoordinatesystem.decz = FloatOptimizableVariable( FixedState(-99.0), name="decz") listOptimizableVariables(mysys) confmanager = ConfigManager(mysys, name="mc") [mysys2, mysys3] = confmanager.set_optimizable_variables( ("s2", "s3"), { "s.global.decz": (("pickup", lambda x: x + 2.0), ("pickup", lambda x: x + 3.0)), "s.global.decy": (("fixed", -2.), ("fixed", -3.)) }) mysys.rootcoordinatesystem.decx.setvalue(-98.0) for syscopy in (mysys2, mysys3): mydict = listOptimizableVariables(syscopy) print(mydict)
def initDemoSystem(self): s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=2.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=3.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf3", decz=5.0, tiltx=0.0*math.pi/180.0), refname=lc2.name) lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf4", decz=3.0), refname=lc3.name) lc5 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf5", decz=3.0), refname=lc4.name) lc6 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf6", decz=2.0), refname=lc5.name) lc7 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf7", decz=3.0), refname=lc6.name) lc8 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=19.0), refname=lc7.name) objectsurf = Surface(lc0) surf1 = Surface(lc1, shape=Conic(lc1, curv=1/-5.922)) surf2 = Surface(lc2, shape=Conic(lc2, curv=1/-3.160)) surf3 = Surface(lc3, shape=Conic(lc3, curv=1/15.884)) surf4 = Surface(lc4, shape=Conic(lc4, curv=1/-12.756)) stopsurf = Surface(lc5) surf6 = Surface(lc6, shape=Conic(lc6, curv=1/3.125)) surf7 = Surface(lc7, shape=Conic(lc7, curv=1/1.479)) image = Surface(lc8) elem = OpticalElement(lc0, label="lenssystem") glass = material_isotropic.ConstantIndexGlass(lc0, n=1.7) glass2 = material_isotropic.ConstantIndexGlass(lc0, n=1.5) elem.addMaterial("glass", glass) elem.addMaterial("glass2", glass2) elem.addSurface("object", objectsurf, (None, None)) elem.addSurface("surf1", surf1, (None, "glass")) elem.addSurface("surf2", surf2, ("glass", None)) elem.addSurface("surf3", surf3, (None, "glass")) elem.addSurface("surf4", surf4, ("glass", None)) elem.addSurface("stop", stopsurf, (None, None)) elem.addSurface("surf6", surf6, (None, "glass2")) elem.addSurface("surf7", surf7, ("glass2", None)) elem.addSurface("image", image, (None, None)) s.addElement("lenssys", elem) return s
from pyrateoptics.analysis.optical_system_analysis import OpticalSystemAnalysis logging.basicConfig(level=logging.DEBUG) wavelength = 0.5876e-3 rnd_data1 = np.random.random((3, 3)) # np.eye(3) rnd_data2 = np.random.random((3, 3)) # np.zeros((3, 3))# lc = LocalCoordinates("1") myeps = np.eye(3) + 0.1 * rnd_data1 + 0.01 * complex(0, 1) * rnd_data2 # aggressive complex choice of myeps # myeps = np.eye(3) + 0.01*np.random.random((3, 3)) crystal = AnisotropicMaterial(lc, myeps) # definition of optical system s = OpticalSystem(matbackground=crystal) lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="m1", decz=50.0, tiltx=-math.pi / 8), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="m2_stop", decz=-50.0, decy=-20, tiltx=math.pi / 16), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="m3", decz=50.0, decy=-30,
from pyrateoptics.raytracer.aperture import CircularAperture from pyrateoptics.raytracer.localcoordinates import LocalCoordinates from pyrateoptics.raytracer.globalconstants import degree from pyrateoptics import raytrace, draw logging.basicConfig(level=logging.DEBUG) wavelength = 0.5876e-3 wave_red = 0.700e-3 wave_blue = 0.470e-3 # definition of optical system s = OpticalSystem() dropletradius = 0.1 lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=0.0), refname=s.rootcoordinatesystem.name) lccomprism = s.addLocalCoordinateSystem(LocalCoordinates(name="dropletcenter", decz=2. * dropletradius), refname=lc0.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=-dropletradius), refname=lccomprism.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=dropletradius),
from pyrateoptics.raytracer.optical_system import OpticalSystem from pyrateoptics.raytracer.aperture import CircularAperture from pyrateoptics.raytracer.localcoordinates import LocalCoordinates from pyrateoptics.raytracer.analysis.optical_system_analysis import\ OpticalSystemAnalysis from pyrateoptics import draw logging.basicConfig(level=logging.DEBUG) wavelength = 0.5876e-3 # definition of optical system s = OpticalSystem(name='os') lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=-1.048), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=4.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf3", decz=2.5), refname=lc2.name) lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=97.2), refname=lc3.name) stopsurf = Surface(lc0, name="stopsurf") frontsurf = Surface(lc1, name="frontsurf",
def __init__(self, doc, name): self.__doc = doc obj = doc.addObject("App::FeaturePython", name) self.__obj = obj obj.Proxy = self self.__NameOSGroup = Group_OS_Label + "_" + uuidToName(uuid.uuid4()) self.__NameSurfaceGroup = Group_Surface_Label + "_" + uuidToName(uuid.uuid4()) self.__NameFunctionsGroup = Group_Functions_Label + "_" + uuidToName(uuid.uuid4()) self.__NameCoordinatesGroup = Group_Coordinates_Label + "_" + uuidToName(uuid.uuid4()) self.__group = doc.addObject("App::DocumentObjectGroup", self.__NameOSGroup) self.__group.addObject(obj) self.__surfacegroup = doc.addObject("App::DocumentObjectGroup", self.__NameSurfaceGroup) self.__functionsgroup = doc.addObject("App::DocumentObjectGroup", self.__NameFunctionsGroup) self.__coordinatesgroup = doc.addObject("App::DocumentObjectGroup", self.__NameCoordinatesGroup) self.__group.addObject(self.__surfacegroup) self.__group.addObject(self.__functionsgroup) self.__group.addObject(self.__coordinatesgroup) self.__functionsgroup.Label = Group_Functions_Label + "_" + name self.__surfacegroup.Label = Group_Surface_Label + "_" + name self.__coordinatesgroup.Label = Group_Coordinates_Label + "_" + name self.__group.Label = Group_OS_Label + "_" + name # TODO: all properties are not really operational # group links obj.addProperty("App::PropertyString", "NameOSGroup", "Groups", "Name of OS Group").NameOSGroup = self.__NameOSGroup obj.addProperty("App::PropertyString", "NameFunctionsGroup", "Groups", "Name of Functions Group").NameFunctionsGroup = self.__NameFunctionsGroup obj.addProperty("App::PropertyString", "NameSurfaceGroup", "Groups", "Name of Surface Group").NameSurfaceGroup = self.__NameSurfaceGroup obj.addProperty("App::PropertyString", "NameCoordinatesGroup", "Groups", "Name of Coordinates Group").NameCoordinatesGroup = self.__NameCoordinatesGroup obj.setEditorMode("NameOSGroup", 1) # readonly obj.setEditorMode("NameFunctionsGroup", 1) # readonly obj.setEditorMode("NameSurfaceGroup", 1) # readonly obj.setEditorMode("NameCoordinatesGroup", 1) # readonly # OS Properties obj.addProperty("App::PropertyPythonObject", "osclass", "OS", "os class interface").osclass = OpticalSystem() obj.addProperty("App::PropertyPythonObject", "coords", "OS", "os coords interface").coords = LC(None, obj.osclass.rootcoordinatesystem, doc, self.__coordinatesgroup) obj.addProperty("App::PropertyFloatList", "wavelengths", "OS", "wavelengths list").wavelengths = [550.0e-6] obj.addProperty("App::PropertyLinkList", "surfaces", "OS", "surface list").surfaces = [] # Field properties obj.addProperty("App::PropertyPythonObject", "fieldpoints", "Field", "Field points").fieldpoints = np.array([[0, 0]]) obj.addProperty("App::PropertyPythonObject", "fieldpointsbool", "Field", "Field points used?").fieldpointsbool = np.array([True], dtype=bool) obj.addProperty("App::PropertyEnumeration", "fieldtype", "Field", "Type of field?").fieldtype = \ ["ObjectHeight", "ObjectChiefAngle", "ParaxialImageHeight"] # Aiming properties obj.addProperty("App::PropertyInteger", "stopposition", "Aiming", "Which surface is stop?").stopposition = 0 obj.addProperty("App::PropertyEnumeration", "pupiltype", "Aiming", "Type of pupil?").pupiltype = \ ["EntrancePupilDiameter", "EntrancePupilRadius", "StopDiameter", "StopRadius", "ExitPupilDiameter", "ExitPupilRadius", "InfiniteConjugateImageSpaceFNumber", "InfiniteConjugateObjectSpaceFNumber", "WorkingImageSpaceFNumber", "WorkingObjectSpaceFNumber", "ObjectSpaceNA", "ImageSpaceNA"] obj.addProperty("App::PropertyDistance", "pupilsize", "Aiming", "Pupil size?").pupilsize = 1.0 obj.addProperty("App::PropertyEnumeration", "rastertype", "Aiming", "Type of pupil rasterization?").rastertype = \ ["RectGrid", "HexGrid", "RandomGrid", "PoissonDiskSampling", "MeridionalFan", "SagitalFan", "ChiefAndComa", "Single"] # TODO: -> text file obj.addProperty("App::PropertyInteger", "numrays", "Aiming", "How many rays to be drawn?").numrays = 10
exec(compile("self" + deref + " = var", "<string>", "exec")) def getVariable(self, key): """ Gets variable from short key. """ dict_of_vars = self.getAllVariables() variable = dict_of_vars["vars"][key] return variable ''' if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) s = OpticalSystem(name="s") s.lst = [] s.lst.append({}) s.lst.append({}) s.lst[0]["a"] = FloatOptimizableVariable(FixedState(3.0), name="v1") s.lst[1]["b"] = FloatOptimizableVariable(VariableState(7.0), name="v2") s.rootcoordinatesystem.decz = FloatOptimizableVariable(FixedState(-99.0), name="decz") listOptimizableVariables(s) m = ConfigManager(s, name="mc") [s2, s3] = m.setOptimizableVariables( ("s2", "s3"), {
from pyrateoptics.raytracer.surface import Surface from pyrateoptics.raytracer.globalconstants import canonical_ey, degree from pyrateoptics.analysis.optical_system_analysis import OpticalSystemAnalysis from pyrateoptics.analysis.surfShape_analysis import ShapeAnalysis from pyrateoptics.sampling2d.raster import RandomGrid from pyrateoptics.analysis.optical_system_analysis import OpticalSystemAnalysis wavelength = standard_wavelength logging.basicConfig(level=logging.DEBUG) # definition of optical system s = OpticalSystem() # objectDistance = 2.0 lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="object", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=2.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=3.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf3", decz=5.0, tiltx=2.5 * degree), refname=lc2.name) lc4 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf4", decz=3.0), refname=lc3.name) lc5 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf5", decz=3.0), refname=lc4.name)