### Install RayOpt via Conda Source: https://github.com/quartiq/rayopt/blob/master/README.rst Installs the RayOpt package using the Conda package manager from the project's specific channel. ```bash conda install -c https://conda.anaconda.org/jordens/channel/ci rayopt ``` -------------------------------- ### Parse Zemax Lens Catalogs Source: https://github.com/quartiq/rayopt/blob/master/README.rst Uses the rayopt.library module to parse Zemax glass and stock catalogs. Requires paths to the local Zemax installation directories. ```bash python -m rayopt.library Users/$USER/My\ Documents/Zemax/Glasscat Users/$USER/My\ Documents/Zemax/Stockcat ``` -------------------------------- ### Parse OSLO Lens Catalogs Source: https://github.com/quartiq/rayopt/blob/master/README.rst Uses the rayopt.library module to parse OSLO binary and glass files. Requires paths to the OSLO installation directory. ```bash python -m rayopt.library Users/Public/Documents/OSLO66\ EDU/bin/lmo Users/Public/Documents/OSLO66\ EDU/bin/glc ``` -------------------------------- ### Search and Load Optical Materials and Lenses Source: https://context7.com/quartiq/rayopt/llms.txt Demonstrates how to query material catalogs for specific properties and load lens systems from a database. Requires an initialized library object. ```python for mat in lib.get_all("material", catalog="SCHOTT"): if mat.vd > 60: # Low dispersion glasses print(f"{mat.name}: nd={mat.nd:.4f}, vd={mat.vd:.1f}") try: lens_system = lib.get("lens", "DOUBLET-025-050") print(lens_system) except KeyError: print("Lens not found in database") ``` -------------------------------- ### Access Lens and Material Catalogs via Library Source: https://context7.com/quartiq/rayopt/llms.txt Illustrates how to use the `rayopt.Library` class to access a singleton instance for retrieving optical materials and lens designs. It shows how to fetch a material by its name and catalog, demonstrating access to both built-in and external catalog data. ```python import rayopt as ro from rayopt import Library # Get singleton library instance lib = Library.one() # Get a material by name bk7 = lib.get("material", "N-BK7", catalog="SCHOTT") print(f"Material: {bk7.name}, nd={bk7.nd:.5f}") ``` -------------------------------- ### Visualize Optical Systems Source: https://context7.com/quartiq/rayopt/llms.txt Uses matplotlib to render 2D layouts of optical systems, including ray paths, paraxial traces, and Gaussian beam profiles. ```python import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(14, 5)) s.plot(ax, axis=1, npoints=51, color='black') s.paraxial.plot(ax, color='blue', principals=True, pupils=True) g = ro.GeometricTrace(s) g.rays_clipping((0, 0.7)) g.plot(ax, axis=1, color='green') gauss = ro.GaussianTrace(s) gauss.plot(ax, axis=1, scale=3, color='red') plt.show() ``` -------------------------------- ### Manage Optical Materials and Dispersion Source: https://context7.com/quartiq/rayopt/llms.txt Demonstrates how to access and utilize optical materials from the rayopt library. It shows how to load materials by name, retrieve their properties like refractive index (nd) and Abbe number (vd), calculate refractive indices at specific wavelengths, and create approximate materials using Abbe numbers or tuples. It also highlights access to standard Fraunhofer lines and special materials like mirror, air, and vacuum. ```python import rayopt as ro from rayopt.material import ( Material, AbbeMaterial, CoefficientsMaterial, fraunhofer, lambda_d, lambda_F, lambda_C ) # Get materials from the library bk7 = Material.make("SCHOTT/N-BK7") sf11 = Material.make("SCHOTT/N-SF11") # Material properties print(f"N-BK7 nd: {bk7.nd:.5f}, Vd: {bk7.vd:.2f}") print(f"N-SF11 nd: {sf11.nd:.5f}, Vd: {sf11.vd:.2f}") # Refractive index at specific wavelengths wavelengths = [486.13e-9, 587.56e-9, 656.27e-9] # F, d, C lines for wl in wavelengths: n = bk7.refractive_index(wl) print(f"N-BK7 at {wl*1e9:.1f}nm: n={n:.6f}") # Dispersion (Abbe number) vd = bk7.dispersion(lambda_F, lambda_d, lambda_C) print(f"N-BK7 Abbe number: {vd:.2f}") # Create material from Abbe number (for initial design) glass_approx = AbbeMaterial(n=1.5168, v=64.17, name="BK7-approx") print(f"Approximate glass nd: {glass_approx.nd:.4f}") # Create from tuple (nd, vd) glass_tuple = Material.make((1.5168, 64.17)) # Create from string "nd/vd" glass_string = Material.make("1.6727/32.17") # Access Fraunhofer lines print(f"\nFraunhofer d-line: {fraunhofer['d']*1e9:.2f} nm") print(f"Fraunhofer F-line: {fraunhofer['F']*1e9:.2f} nm") print(f"Fraunhofer C-line: {fraunhofer['C']*1e9:.2f} nm") # Special materials mirror = Material.make("mirror") air = Material.make("air") vacuum = Material.make("vacuum") ``` -------------------------------- ### Optimize Optical System Design Source: https://context7.com/quartiq/rayopt/llms.txt Utilizes the optimization module to adjust lens parameters based on custom merit functions. It leverages scipy.optimize to minimize aberrations or spot sizes. ```python from rayopt.optimize import PathVariable, FuncOp, optimize variables = [ PathVariable(s, [1, "curvature"], bounds=(-0.1, 0.1), scale=0.01), PathVariable(s, [2, "curvature"], bounds=(-0.1, 0.1), scale=0.01), ] def spot_rms(system): system.update() g = ro.GeometricTrace(system) g.rays_point((0, 0), nrays=50, distribution="hexapolar") return g.rms() operands = [FuncOp(s, spot_rms, weight=1.0)] result = optimize(variables, operands, method="SLSQP", tol=1e-6) ``` -------------------------------- ### Perform Comprehensive Optical System Analysis Source: https://context7.com/quartiq/rayopt/llms.txt Loads an optical system from a YAML definition and performs a comprehensive analysis using the `rayopt.Analysis` class. This includes options for updating the system, refocusing, printing system and paraxial data, plotting various optical performance metrics like ray fans, spot diagrams, OPD maps, and longitudinal aberrations. The analysis results are printed, and generated figures are saved. ```python import rayopt as ro import matplotlib.pyplot as plt # Load system s = ro.system_from_yaml(""" description: 'Cooke Triplet 50mm f/4 20deg' wavelengths: [587.56e-9, 656.27e-9, 486.13e-9] object: {angle_deg: 20, pupil: {radius: 6.25, aim: True}} image: {type: finite, pupil: {radius: 0, update_radius: True}} elements: - {material: air} - {roc: 21.25, distance: 5.0, material: SCHOTT-SK|N-SK16, radius: 6.5} - {roc: -158.65, distance: 2.0, material: air, radius: 6.5} - {roc: -20.25, distance: 6.0, material: SCHOTT-F|N-F2, radius: 5.0} - {roc: 19.6, distance: 1.0, material: air, radius: 5.0} - {material: air, radius: 4.75} - {roc: 141.25, distance: 6.0, material: SCHOTT-SK|N-SK16, radius: 6.5} - {roc: -17.285, distance: 2.0, material: air, radius: 6.5} - {distance: 42.95, radius: 0.364} stop: 5 """) s.update() # Run full analysis with custom options analysis = ro.Analysis( s, update=True, # Update system before analysis resize_full=False, # Don't resize elements to ray bundle refocus_full=True, # Refocus to best geometric focus print_system=True, # Print system table print_paraxial=True, # Print paraxial data plot_transverse=True, # Plot ray fan diagrams plot_spots=True, # Plot spot diagrams plot_opds=True, # Plot OPD maps and PSF plot_longitudinal=True,# Plot longitudinal aberrations defocus=5, # Number of defocus positions for spots run=True, # Auto-run analysis print=False # Don't auto-print (we'll do it manually) ) # Access analysis results for text in analysis.text: print(text) # Save all figures for i, fig in enumerate(analysis.figures): fig.savefig(f'analysis_fig_{i}.png', dpi=150, bbox_inches='tight') plt.close('all') ``` -------------------------------- ### Create and Configure Optical Systems using System Class Source: https://context7.com/quartiq/rayopt/llms.txt The System class is the core container for optical elements in RayOpt. It manages wavelengths, field points, conjugates, aperture stops, and element pickups. Systems can be initialized programmatically or loaded from YAML/JSON configurations. The `update()` method calculates paraxial data and updates conjugates. ```python import rayopt as ro import numpy as np # Create a simple doublet lens system from YAML definition system_yaml = """ description: 'Simple Doublet 50mm f/4' wavelengths: [587.56e-9, 656.27e-9, 486.13e-9] object: {angle_deg: 10, pupil: {radius: 6.25, aim: True}} image: {type: finite, pupil: {radius: 0, update_radius: True}} elements: - {material: air} - {roc: 30.0, distance: 5.0, material: 1.5168/64.17, radius: 8.0} - {roc: -30.0, distance: 3.0, material: 1.6727/32.17, radius: 8.0} - {roc: -90.0, distance: 2.0, material: air, radius: 8.0} - {distance: 45.0, radius: 5.0} stop: 1 """ # Load and initialize the system s = ro.system_from_yaml(system_yaml) s.update() # Calculate paraxial data and update conjugates # Print system summary print(s) # Access system properties print(f"Wavelengths: {s.wavelengths}") print(f"Stop surface index: {s.stop}") print(f"Aperture radius: {s.aperture.radius}") # Export system to JSON json_str = ro.system_to_json(s) ``` -------------------------------- ### Import External Lens Files Source: https://context7.com/quartiq/rayopt/llms.txt Provides methods to parse industry-standard optical prescription files, specifically Zemax (.zmx) and OSLO (.len) formats, into RayOpt system objects. ```python from rayopt.zemax import zmx_to_system from rayopt.oslo import len_to_system zmx_data = """UNIT MM NAME Simple Doublet SURF 0 SURF 1 CURV 0.02 DISZ 5.0 GLAS N-BK7 DIAM 12.5 SURF 2 CURV -0.033 DISZ 3.0 GLAS N-SF2 DIAM 12.5 SURF 3 CURV -0.0125 DISZ 45.0 DIAM 12.5 SURF 4 DISZ 0 DIAM 5.0 WAVL 0.58756 STOP 1""" s = zmx_to_system(zmx_data) s.update() ``` -------------------------------- ### Calculate and Print Gaussian Beam Properties Source: https://context7.com/quartiq/rayopt/llms.txt Calculates and prints various properties of a Gaussian beam, including spot size at specific z-positions, waist position, Rayleigh range, curvature radius, stability parameter, and eigenmode q-parameters. It also generates a plot of the Gaussian beam propagation and saves it to a file. ```python import numpy as np import matplotlib.pyplot as plt # Assuming 's' and 'g' are pre-defined rayopt System and GaussianBeam objects # Example initialization (replace with actual object creation if needed): # s = ro.System() # g = ro.GaussianBeam(s) z_positions = np.linspace(0, s.path[-1], 100) spot_sizes = g.spot_radius_at(z_positions) print(f"\nSpot size at output: {spot_sizes[-1]} mm") print(f"\nWaist positions (from surfaces): {g.waist_position[-1]} mm") print(f"Rayleigh ranges: {g.rayleigh_range[-1]} mm") print(f"Curvature radii: {g.curvature_radius[-1]} mm") print(f"\nStability parameter m: {g.m}") print(f"System is stable: {g.stable}") eigenmodes = g.eigenmodes print(f"Eigenmode q parameters: {eigenmodes}") fig, ax = plt.subplots(figsize=(12, 4)) s.plot(ax) g.plot(ax, scale=5, waist=True) # Scale beam for visibility plt.savefig('gaussian_beam.png') ``` -------------------------------- ### Perform Ray Tracing using GeometricTrace Class Source: https://context7.com/quartiq/rayopt/llms.txt The GeometricTrace class performs real ray tracing through optical systems, tracking ray positions, directions, and optical path lengths. It supports various ray distribution patterns and is used to calculate spot diagrams and optical path difference (OPD) maps. This class requires an initialized RayOpt System object. ```python import rayopt as ro import numpy as np import matplotlib.pyplot as plt # Load a Cooke triplet system cooke = """ description: 'Cooke Triplet 50mm f/4' wavelengths: [587.56e-9, 656.27e-9, 486.13e-9] object: {angle_deg: 20, pupil: {radius: 6.25, aim: True}} image: {type: finite, pupil: {radius: 0, update_radius: True}} elements: - {material: air} - {roc: 21.25, distance: 5.0, material: SCHOTT-SK|N-SK16, radius: 6.5} - {roc: -158.65, distance: 2.0, material: air, radius: 6.5} - {roc: -20.25, distance: 6.0, material: SCHOTT-F|N-F2, radius: 5.0} - {roc: 19.6, distance: 1.0, material: air, radius: 5.0} - {material: air, radius: 4.75} - {roc: 141.25, distance: 6.0, material: SCHOTT-SK|N-SK16, radius: 6.5} - {roc: -17.285, distance: 2.0, material: air, radius: 6.5} - {distance: 42.95, radius: 0.364} stop: 5 """ s = ro.system_from_yaml(cooke) s.update() # Create geometric trace g = ro.GeometricTrace(s) ``` -------------------------------- ### Define Optical Surfaces using Spheroid Class Source: https://context7.com/quartiq/rayopt/llms.txt The Spheroid class represents spherical and aspherical optical surfaces. It handles curvature, conic constant, and aspheric polynomial terms, and calculates refraction, reflection, and ray intercepts. Surfaces can be created with specified distances, curvatures, radii, materials, and aspheric coefficients. ```python import rayopt as ro from rayopt.elements import Spheroid from rayopt.material import Material # Create a spherical surface with BK7 glass surface1 = Spheroid( distance=10.0, # Distance from previous surface (mm) curvature=0.02, # 1/radius of curvature (1/mm), roc=50mm radius=12.5, # Clear aperture radius (mm) material=Material.make("SCHOTT/N-BK7") ) # Create an aspheric surface with conic and polynomial terms aspheric_surface = Spheroid( distance=5.0, curvature=0.025, # roc=40mm conic=-0.5, # Conic constant (0=sphere, -1=parabola) aspherics=[1e-6, 2e-9, 0, 0], # A4, A6, A8, A10 coefficients radius=10.0, material=Material.make("air") ) # Create a mirror surface mirror = Spheroid( distance=20.0, curvature=-0.01, # Concave mirror (roc=-100mm) radius=15.0, material=Material.make("mirror") ) # Access surface properties print(f"Surface sag at edge: {surface1.edge_sag(axis=1):.4f} mm") print(f"Curvature: {surface1.curvature}") # Build a system with these elements s = ro.System( elements=[ Spheroid(material=Material.make("air")), # Object surface surface1, aspheric_surface, Spheroid(distance=45.0, radius=5.0) # Image surface ], wavelengths=[587.56e-9], stop=1 ) s.update() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.