lsurf.sources.RaySource

class lsurf.sources.RaySource(num_rays, wavelength, power=1.0)[source]

Abstract base class for ray sources.

A ray source defines initial conditions for a ray batch, including spatial distribution, angular distribution, wavelength spectrum, and intensity distribution.

Parameters:
  • num_rays (int) – Number of rays to generate. Must be positive.

  • wavelength (float or tuple of float) – Single wavelength in meters for monochromatic source, or (min, max) tuple for polychromatic source.

  • power (float, optional) – Total source power in watts. Default is 1.0.

num_rays

Number of rays generated by this source.

Type:

int

wavelength

Wavelength specification.

Type:

float or tuple

power

Total source power.

Type:

float

Notes

Derived classes must implement the generate() method which returns a fully initialized RayBatch.

The ray intensities should sum to the total power (conservation of energy). When generating rays, use _allocate_rays() to create the batch with proper initialization and _assign_wavelengths() to set wavelengths.

Examples

Creating a custom source:

>>> class MySource(RaySource):
...     def __init__(self, position, num_rays, wavelength, power=1.0):
...         super().__init__(num_rays, wavelength, power)
...         self.position = np.array(position)
...
...     def generate(self):
...         rays = self._allocate_rays()
...         rays.positions[:] = self.position
...         # Set directions...
...         self._assign_wavelengths(rays)
...         return rays
__init__(num_rays, wavelength, power=1.0)[source]

Initialize ray source.

Parameters:
  • num_rays (int) – Number of rays to generate. Must be positive.

  • wavelength (float or tuple of float) – Single wavelength (m) or (min, max) range.

  • power (float, optional) – Total source power in watts. Default is 1.0.

Raises:

ValueError – If num_rays <= 0, power <= 0, wavelength <= 0, or wavelength range is invalid.

Methods

__init__(num_rays, wavelength[, power])

Initialize ray source.

generate()

Generate ray batch with initial conditions.

__init__(num_rays, wavelength, power=1.0)[source]

Initialize ray source.

Parameters:
  • num_rays (int) – Number of rays to generate. Must be positive.

  • wavelength (float or tuple of float) – Single wavelength (m) or (min, max) range.

  • power (float, optional) – Total source power in watts. Default is 1.0.

Raises:

ValueError – If num_rays <= 0, power <= 0, wavelength <= 0, or wavelength range is invalid.

abstractmethod generate()[source]

Generate ray batch with initial conditions.

Creates and initializes a RayBatch with positions, directions, wavelengths, and intensities according to the source configuration.

Returns:

Initialized rays ready for propagation.

Return type:

RayBatch

Notes

Implementations should ensure: - All rays are marked as active - Directions are normalized - Intensities sum to total power - Wavelengths are set appropriately

__repr__()[source]

Return string representation.