File Conversion¶
fdtdx.core.conversion.load_stl.load_stl(stl, permittivity, target_shape, voxel_size, ambient_permittivity=1.0)
¶
Loads an STL file and converts it to a voxelized permittivity array.
This function takes either an STL file path or a trimesh.Trimesh object, voxelizes it at the specified resolution, and converts it to a permittivity array where voxels inside the mesh have the specified permittivity value and voxels outside have the ambient permittivity value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stl
|
str | Trimesh
|
Path to an STL file or a trimesh.Trimesh object containing the mesh |
required |
permittivity
|
float
|
Relative permittivity value for the object |
required |
target_shape
|
tuple[int, int, int]
|
Desired output shape as (nx, ny, nz) |
required |
voxel_size
|
float
|
Size of each voxel in the initial voxelization |
required |
ambient_permittivity
|
float
|
Relative permittivity value for the surrounding medium (default: 1.0) |
1.0
|
Returns:
Type | Description |
---|---|
Array
|
jax.Array: 4D array of shape (nx, ny, nz, 3) containing the permittivity values, where the last dimension represents the permittivity for each spatial direction |
Source code in src/fdtdx/core/conversion/load_stl.py
fdtdx.core.conversion.export.export_stl(matrix, stl_filename, voxel_grid_size=(1, 1, 1))
¶
Export a 3D boolean matrix to an STL file.
Converts a 3D boolean matrix into a mesh representation and saves it as an STL file. True values in the matrix are converted to solid voxels in the output mesh.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
ndarray
|
3D boolean numpy array representing the voxel grid. |
required |
stl_filename
|
Path | str
|
Output STL file path. |
required |
voxel_grid_size
|
tuple[int, int, int]
|
Physical size of each voxel as (x, y, z) integers. Defaults to (1, 1, 1). |
(1, 1, 1)
|
Raises:
Type | Description |
---|---|
Exception
|
If input matrix is not 3-dimensional. |
Source code in src/fdtdx/core/conversion/export.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
fdtdx.core.conversion.export.idx_to_xyz(idx, shape)
¶
Convert flattened array indices to 3D coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx
|
ndarray
|
Array of flattened indices. |
required |
shape
|
tuple[int, int, int]
|
3D shape tuple (d0, d1, d2) of the original array. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[ndarray, ndarray, ndarray]
|
(x, y, z) coordinate arrays corresponding to the input indices. |
Source code in src/fdtdx/core/conversion/export.py
fdtdx.core.conversion.export.xyz_to_idx(x, y, z, shape)
¶
Convert 3D coordinates to flattened array indices.
This is the inverse operation of idx_to_xyz(). Used for converting physical coordinates back to array indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
Array of x coordinates. |
required |
y
|
ndarray
|
Array of y coordinates. |
required |
z
|
ndarray
|
Array of z coordinates. |
required |
shape
|
tuple[int, int, int]
|
3D shape tuple (d0, d1, d2) of the target array. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Flattened indices corresponding to the input coordinates. |
Source code in src/fdtdx/core/conversion/export.py
fdtdx.core.conversion.import_utils.gds_to_numpy(file_path, resolution, layer, datatype=None)
¶
Converts GDSII geometry on a specific layer to a grid-based mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the GDSII file |
required |
resolution
|
float
|
The size of each grid cell in the same units as the GDSII coordinates |
required |
layer
|
int
|
The GDSII layer number to extract |
required |
datatype
|
int | None
|
The GDSII datatype number to extract. Defaults to layer value. |
None
|
Returns:
Type | Description |
---|---|
ndarray[bool_]
|
np.ndarray[np.bool_]: A 2D NumPy array mask where True indicates geometry presence |