Geometry Module#
- class Geometry(x_bounds: Tuple[float, float] | DomainAlignment = DomainAlignment.CENTERING, y_bounds: Tuple[float, float] | DomainAlignment = DomainAlignment.CENTERING, resolution: int = 100, index_scrambling: float = 0.0, gaussian_filter: int | None = None, boundary_pad_factor: float = 1.3, coordinate_system: CoordinateSystem | None = None, mesh: ndarray | None = None)[source]#
Bases:
object
Represents the refractive index (RI) geometric profile including background and fiber structures.
- Parameters:
x_bounds (Union[Tuple[float, float], DomainAlignment], optional) – X boundaries for rendering the structure. Can be a tuple of bounds or one of [‘auto’, ‘left’, ‘right’, ‘centering’]. Default is ‘centering’.
y_bounds (Union[Tuple[float, float], DomainAlignment], optional) – Y boundaries for rendering the structure. Can be a tuple of bounds or one of [‘auto’, ‘top’, ‘bottom’, ‘centering’]. Default is ‘centering’.
resolution (int, optional) – Number of points in x and y directions for evaluating the rendering. Default is 100.
index_scrambling (float, optional) – Index scrambling for degeneracy lifting. Default is 0.0.
gaussian_filter (Optional[int], optional) – Standard deviation of the Gaussian blurring for the mesh. Default is None.
boundary_pad_factor (float, optional) – Factor multiplying the boundary value to keep padding between mesh and boundary. Default is 1.3.
The Geometry class defines the geometric profiles, including background and fiber structures, used in the package. This class provides methods for configuring and visualizing these structures.
- x_bounds: Tuple[float, float] | DomainAlignment = 'centering'#
- y_bounds: Tuple[float, float] | DomainAlignment = 'centering'#
- resolution: int = 100#
- index_scrambling: float = 0.0#
- gaussian_filter: int | None = None#
- boundary_pad_factor: float = 1.3#
- coordinate_system: CoordinateSystem | None = None#
- mesh: ndarray | None = None#
- add_structure(*structure: object) None [source]#
Add a structure to the internal structure list.
- Parameters:
structure (object) – The structure to be added.
- classmethod validate_boundary_pad_factor(v: float) float [source]#
Validate boundary pad factor is positive.
- classmethod validate_index_scrambling(v: float) float [source]#
Validate index scrambling is non-negative.
- initialize()[source]#
Initialize the geometry by generating the coordinate system and mesh. This method calculates the boundaries based on the defined structures and sets up the coordinate system.
- update_coordinate_system() None [source]#
Generate the coordinate system for the mesh construction.
- Raises:
ValueError – If boundaries cannot be determined from the structures.
- classmethod validate_x_bounds(v: DomainAlignment | Tuple[float, float]) DomainAlignment | Tuple[float, float] [source]#
Validate x_bounds parameter.
- classmethod validate_y_bounds(v: DomainAlignment | Tuple[float, float]) DomainAlignment | Tuple[float, float] [source]#
Validate y_bounds parameter.
- get_boundaries() Tuple[float, float, float, float] [source]#
Calculate the boundaries from the collection of defined structures.
- Returns:
The boundaries as (x_min, y_min, x_max, y_max).
- Return type:
Tuple[float, float, float, float]
- property refractive_index_maximum: float#
Calculate the maximum refractive index across all structures.
- Returns:
Maximum refractive index.
- Return type:
float
- property refractive_index_minimum: float#
Calculate the minimum refractive index across all non-background structures.
- Returns:
Minimum refractive index.
- Return type:
float
- get_index_range() List[float] [source]#
Get a list of all refractive indices associated with the elements of the geometry.
- Returns:
List of refractive indices.
- Return type:
List[float]
- rotate(angle: float) None [source]#
Rotate all structures within the geometry by a given angle.
- Parameters:
angle (float) – Angle to rotate the geometry, in degrees.
- randomize_fiber_structures_index(random_factor: float) None [source]#
Randomize the refractive index of fiber structures by a specified factor.
- Parameters:
random_factor (float) – Factor to randomize the refractive index.
- rasterize_polygons() ndarray [source]#
Rasterize the polygons defined in the geometry onto a mesh.
- Parameters:
coordinates (numpy.ndarray) – The coordinates at which to evaluate the mesh.
- Returns:
The rasterized mesh.
- Return type:
numpy.ndarray
- generate_mesh() ndarray [source]#
Generate the full mesh for the geometry using the defined coordinate system.
- Returns:
The fully generated mesh.
- Return type:
numpy.ndarray
- Raises:
AttributeError – If the coordinate system has not been generated before calling this method.
- plot_patch(axes: Axes) None [source]#
Render the patch representation of the geometry onto a given matplotlib axis.
- Parameters:
ax (plt.Axes, optional) – The matplotlib axis on which the patch representation will be plotted. If not provided, a new axis is created.
show (bool, optional) – Whether to display the plot immediately. Default is True.
- Return type:
None
- plot_raster(axes: Axes, gamma: float = 5) None [source]#
Render the rasterized representation of the geometry onto a given matplotlib axis.
- Parameters:
ax (plt.Axes, optional) – The matplotlib axis on which the rasterized representation will be plotted. If not provided, a new axis is created.
show (bool, optional) – Whether to display the plot immediately. Default is True.
gamma (float, optional) – The gamma correction value for the color normalization. Default is 5.
- Return type:
None
- plot(axes, gamma: float = 5) Figure [source]#
Plot the different representations (patch and mesh) of the geometry.
- Parameters:
show (bool, optional) – Whether to immediately show the plot. Default is True.
gamma (float, optional) – The gamma correction value for the color normalization used in the mesh plot. Default is 5.
- Returns:
The matplotlib figure encompassing all the axes used in the plot.
- Return type:
plt.Figure