RayFile#
- class ansys.speos.core.input_files.ray_file.RayFile(rays=None, radiant_flux=1.0, luminous_flux=683.0)#
Bases:
ansys.speos.core.input_files._base.SpeosFileFormatSpeos ray file, holding the rays emitted by a measured or simulated source.
save()andload()handle the binary*.rayflavor, whileRayFile.save_text()andRayFile.load_text()handle the text flavor that the Speos ray file editors also accept.RayFile.save_sdf()andRayFile.load_sdf()handle Zemax spectral binary source files.- Parameters:
- Parameters:
Notes
The binary layout is 7 little-endian 32-bit floats, the total radiant flux followed by 5 format markers and the total luminous flux, then 8 floats per ray: the position, the direction cosines, the wavelength and the energy. The text flavor does not carry any flux, so
RayFile.load_text()leavesRayFile.radiant_fluxandRayFile.luminous_fluxat their default. TheRayFile.raysgetter copies the container but keeps ray objects shared. Assign an edited list back to replace rays. An empty list permits a draft but cannot be saved. Polarization consistency across rays is required byRayFile.save_text()only. Binarysave()rejects polarized rays; useRayFile.save_text()to retain polarization.Examples
>>> from ansys.speos.core.input_files.ray_file import Ray, RayFile >>> rays = [Ray(position=(0.0, 0.0, 0.0), direction=(0.0, 0.0, 1.0), wavelength=633.0)] >>> RayFile(rays=rays, radiant_flux=1.0, luminous_flux=112.0).save("laser.ray")
Overview#
Ray collection with a copied container and shared rays. |
|
Total radiant flux, in W. |
|
Total luminous flux, in lm. |
Usual file extension of the format. |
Import detail#
from ansys.speos.core.input_files.ray_file import RayFile
Property detail#
- property RayFile.rays: List[Ray]#
Ray collection with a copied container and shared rays.
- Parameters:
- values
List[Ray] New rays of the file.
- values
- Returns:
List[Ray]Editable validated ray objects.
Attribute detail#
- RayFile.EXTENSION = '.ray'#
Usual file extension of the format.
Method detail#
- RayFile.validate()#
Check the rays against the constraints of the ray file formats.
- Raises:
ValueErrorIf the file holds no ray, or if a ray direction is not a unit vector.
- RayFile.save_sdf(file_path)#
Write an unpolarized Zemax spectral binary source file.
- Parameters:
- file_path
Union[str,pathlib.Path] Path of the file to write. An existing file is overwritten after validation.
- file_path
- Returns:
pathlib.PathPath of the written file.
- Raises:
ValueErrorIf the rays are invalid or polarized, the radiant flux is negative, wavelengths are not positive, positive power has no nonzero weights, or data cannot be represented by the format’s 32-bit floats.
Notes
The 208-byte little-endian header identifies spectral records in watts with millimeter coordinates. Each 32-byte record holds
x y z l m n flux wavelength. Wavelengths are converted from nm to micrometers. Ray energies are relative weights: each output flux isradiant_flux * energy / sum(energies). Zero total power writes zero ray fluxes. Neither the model nor its energy weights are modified. Luminous flux and polarization are not stored; useRayFile.save_text()for polarization.References
- classmethod RayFile.load_sdf(file_path, *, luminous_flux=683.0)#
Read a Zemax spectral binary source file in millimeter coordinates.
- Parameters:
- file_path
Union[str,pathlib.Path] Path of the file to read.
- luminous_flux
float,optional Known photometric flux in lm. By default,
683.0, the model’s default, not a value inferred from the SDF spectrum.
- file_path
- Returns:
ansys.speos.core.input_files.ray_file.RayFileUnpolarized rays with wavelengths in nm, normalized relative energy weights, and radiant flux from the header’s
RaySetFlux.
- Raises:
FileNotFoundErrorIf
file_pathdoes not point to an existing file.ValueErrorIf the header, record count or ray data are invalid, coordinates are not in mm, the source has a nonneutral transform, or the file is not spectral radiometric SDF.
Notes
Identifiers
1010and8675309are accepted. Monochromatic DAT and photometric formats are not supported. Wavelengths in micrometers are converted to nm. Record fluxes are normalized to relative weights; their sum need not equalRaySetFlux. Positive ray-set power requires a positive sum of record fluxes. An all-zero set is represented by zero energies without dividing by zero. Original luminous flux, description, angular limits andSourceFluxmetadata are not reconstructed. Re-export preserves the ray-set power and distribution, not arbitrary original energy scaling or header-only metadata.References
- RayFile.save_text(file_path)#
Write the rays to a text ray file.
Each ray takes one line,
index x y z l m n wavelength energy, extended witho p q r swhen the rays are polarized. The line count opens the file.- Parameters:
- file_path
Union[str,pathlib.Path] Path of the file to write. An existing file is overwritten.
- file_path
- Returns:
pathlib.PathPath of the written file.
- Raises:
ValueErrorIf the rays are invalid, or if only some of them carry a polarization.
- classmethod RayFile.load_text(file_path)#
Read a text ray file.
- Parameters:
- file_path
Union[str,pathlib.Path] Path of the file to read.
- file_path
- Returns:
ansys.speos.core.input_files.ray_file.RayFileRay file model. The flux is not carried by the text flavor, so
RayFile.radiant_fluxandRayFile.luminous_fluxkeep their default value.
- Raises:
FileNotFoundErrorIf
file_pathdoes not point to an existing file.ValueErrorIf the count is not a positive integer, does not match the file content, or a ray line is invalid or does not hold 9 values, or 14 when polarized.