Geometry Module#
- class Geometry(x_bounds=DomainAlignment.CENTERING, y_bounds=DomainAlignment.CENTERING, resolution=100, index_scrambling=0.0, gaussian_filter=None, boundary_pad_factor=1.3, coordinate_system=None, mesh=None)[source]#
Bases:
objectRepresents 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.
coordinate_system (CoordinateSystem | None)
mesh (ndarray | None)
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)[source]#
Add a structure to the internal structure list.
- Parameters:
structure (object) – The structure to be added.
- Return type:
None
- classmethod validate_resolution(v)[source]#
Validate resolution is positive.
- Parameters:
v (int)
- Return type:
int
- classmethod validate_boundary_pad_factor(v)[source]#
Validate boundary pad factor is positive.
- Parameters:
v (float)
- Return type:
float
- classmethod validate_index_scrambling(v)[source]#
Validate index scrambling is non-negative.
- Parameters:
v (float)
- Return type:
float
- 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()[source]#
Generate the coordinate system for the mesh construction.
- Raises:
ValueError – If boundaries cannot be determined from the structures.
- Return type:
None
- classmethod validate_x_bounds(v)[source]#
Validate x_bounds parameter.
- Parameters:
v (DomainAlignment | Tuple[float, float])
- Return type:
DomainAlignment | Tuple[float, float]
- classmethod validate_y_bounds(v)[source]#
Validate y_bounds parameter.
- Parameters:
v (DomainAlignment | Tuple[float, float])
- Return type:
DomainAlignment | Tuple[float, float]
- get_boundaries()[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()[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)[source]#
Rotate all structures within the geometry by a given angle.
- Parameters:
angle (float) – Angle to rotate the geometry, in degrees.
- Return type:
None
- randomize_fiber_structures_index(random_factor)[source]#
Randomize the refractive index of fiber structures by a specified factor.
- Parameters:
random_factor (float) – Factor to randomize the refractive index.
- Return type:
None
- rasterize_polygons()[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()[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)[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.
axes (Axes)
- Return type:
None
- plot_raster(axes, gamma=5)[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.
axes (Axes)
- Return type:
None
- plot(axes, gamma=5)[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