physical_apertures.polygon#
Polygon Aperture Module
This module contains the PolygonAperture class, which represents a polygonal aperture that clips rays based on a set of vertices. It also contains the FileAperture class, which reads an aperture definition from a file and creates a polygon-based aperture.
Kramer Harrison, 2025
Classes
|
Reads an aperture definition from a file and creates a polygon-based aperture. |
|
Represents a polygonal aperture that clips rays based on their position. |
- class FileAperture(filepath, delimiter=None, skip_header=0)[source]#
Reads an aperture definition from a file and creates a polygon-based aperture.
The file should contain two columns representing the x and y coordinates, respectively. It supports various file formats (e.g. CSV, TXT) by allowing you to specify a delimiter and the number of header lines to skip. Comments can be added to the file by starting a line with ‘//’.
- Parameters:
- Raises:
ValueError – If the file cannot be read or does not contain exactly two columns.
- contains(x, y)#
Checks if the given point is inside the aperture.
- Parameters:
x (be.ndarray) – The x-coordinate of the point.
y (be.ndarray) – The y-coordinate of the point.
- Returns:
- Boolean array indicating if the point is inside the
aperture
- Return type:
be.ndarray
- property extent#
Returns the extent of the aperture.
- Returns:
The extent of the aperture in the x and y directions.
- Return type:
- classmethod from_dict(data)[source]#
Create an aperture from a dictionary representation.
- Parameters:
data (dict) – The dictionary representation of the aperture.
- Returns:
The aperture object.
- Return type:
- scale(scale_factor)#
Scales the aperture by the given factor.
- Parameters:
scale_factor (float) – The factor by which to scale the aperture.
- to_dict()[source]#
Convert the aperture to a dictionary.
- Returns:
The dictionary representation of the aperture.
- Return type:
- class PolygonAperture(x, y)[source]#
Represents a polygonal aperture that clips rays based on their position.
- Variables:
Note
The implementation of the point-in-polygon algorithm used in this class has slightly different behavior for each backend. FOr the NumPy backend, points on the edge of the polygon are considered to be inside the polygon, while for the PyTorch backend, they are considered to be outside.
- contains(x, y)[source]#
Checks if the given point is inside the aperture.
- Parameters:
x (be.ndarray) – The x-coordinate of the point.
y (be.ndarray) – The y-coordinate of the point.
- Returns:
- Boolean array indicating if the point is inside the
aperture
- Return type:
be.ndarray
- property extent#
Returns the extent of the aperture.
- Returns:
The extent of the aperture in the x and y directions.
- Return type:
- classmethod from_dict(data)[source]#
Create an aperture from a dictionary representation.
- Parameters:
data (dict) – The dictionary representation of the aperture.
- Returns:
The aperture object.
- Return type:
- scale(scale_factor)[source]#
Scales the aperture by the given factor.
- Parameters:
scale_factor (float) – The factor by which to scale the aperture.
- to_dict()[source]#
Convert the aperture to a dictionary.
- Returns:
The dictionary representation of the aperture.
- Return type: