Geometry
Provides functions for manipulating ndarrays of device geometries.
binarize(device_array, eta=0.5, beta=np.inf)
Binarize the input ndarray based on a threshold and a scaling factor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be binarized. |
required |
eta
|
float
|
The threshold value for binarization. Defaults to 0.5. |
0.5
|
beta
|
float
|
The scaling factor for the binarization process. A higher value makes the transition sharper. Defaults to np.inf, which results in a hard threshold. |
inf
|
Returns:
Type | Description |
---|---|
ndarray
|
The binarized array with elements scaled to 0 or 1. |
Source code in prefab/geometry.py
binarize_hard(device_array, eta=0.5)
Apply a hard threshold to binarize the input ndarray. The binarize
function is
generally preferred for most use cases, but it can create numerical artifacts for
large beta values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be binarized. |
required |
eta
|
float
|
The threshold value for binarization. Defaults to 0.5. |
0.5
|
Returns:
Type | Description |
---|---|
ndarray
|
The binarized array with elements set to 0 or 1 based on the threshold. |
Source code in prefab/geometry.py
binarize_monte_carlo(device_array, threshold_noise_std, threshold_blur_std)
Binarize the input ndarray using a Monte Carlo approach with Gaussian blurring.
This function applies a dynamic thresholding technique where the threshold value is determined by a base value perturbed by Gaussian-distributed random noise. The threshold is then spatially varied across the array using Gaussian blurring, simulating a potentially more realistic scenario where the threshold is not uniform across the device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be binarized. |
required |
threshold_noise_std
|
float
|
The standard deviation of the Gaussian distribution used to generate noise for the threshold values. This controls the amount of randomness in the threshold. |
required |
threshold_blur_std
|
float
|
The standard deviation for the Gaussian kernel used in blurring the threshold map. This controls the spatial variation of the threshold across the array. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The binarized array with elements set to 0 or 1 based on the dynamically generated threshold. |
Source code in prefab/geometry.py
binarize_sem(sem_array)
Binarize a grayscale scanning electron microscope (SEM) image.
This function applies Otsu's method to automatically determine the optimal threshold value for binarization of a grayscale SEM image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sem_array
|
ndarray
|
The input SEM image array to be binarized. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The binarized SEM image array with elements scaled to 0 or 1. |
Source code in prefab/geometry.py
blur(device_array, sigma=1.0)
Apply Gaussian blur to the input ndarray and normalize the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be blurred. |
required |
sigma
|
float
|
The standard deviation for the Gaussian kernel. This controls the amount of blurring. Defaults to 1.0. |
1.0
|
Returns:
Type | Description |
---|---|
ndarray
|
The blurred and normalized array with values scaled between 0 and 1. |
Source code in prefab/geometry.py
dilate(device_array, kernel_size)
Dilate the input ndarray using a specified kernel size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array representing the device geometry to be dilated. |
required |
kernel_size
|
int
|
The size of the kernel used for dilation. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The dilated array. |
Source code in prefab/geometry.py
enforce_feature_size(device_array, min_feature_size, strel='disk')
Enforce a minimum feature size on the device geometry.
This function applies morphological operations to ensure that all features in the device geometry are at least the specified minimum size. It uses either a disk or square structuring element for the operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array representing the device geometry. |
required |
min_feature_size
|
int
|
The minimum feature size to enforce, in nanometers. |
required |
strel
|
str
|
The type of structuring element to use. Can be either "disk" or "square". Defaults to "disk". |
'disk'
|
Returns:
Type | Description |
---|---|
ndarray
|
The modified device array with enforced feature size. |
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid structuring element type is specified. |
Source code in prefab/geometry.py
erode(device_array, kernel_size)
Erode the input ndarray using a specified kernel size and number of iterations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array representing the device geometry to be eroded. |
required |
kernel_size
|
int
|
The size of the kernel used for erosion. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The eroded array. |
Source code in prefab/geometry.py
flatten(device_array)
Flatten the input ndarray by summing the vertical layers and normalizing the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be flattened. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The flattened array with values scaled between 0 and 1. |
Source code in prefab/geometry.py
normalize(device_array)
Normalize the input ndarray to have values between 0 and 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be normalized. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The normalized array with values scaled between 0 and 1. |
Source code in prefab/geometry.py
rotate(device_array, angle)
Rotate the input ndarray by a given angle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be rotated. |
required |
angle
|
float
|
The angle of rotation in degrees. Positive values mean counter-clockwise rotation. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The rotated array. |
Source code in prefab/geometry.py
ternarize(device_array, eta1=1 / 3, eta2=2 / 3)
Ternarize the input ndarray based on two thresholds. This function is useful for flattened devices with angled sidewalls (i.e., three segments).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be ternarized. |
required |
eta1
|
float
|
The first threshold value for ternarization. Defaults to 1/3. |
1 / 3
|
eta2
|
float
|
The second threshold value for ternarization. Defaults to 2/3. |
2 / 3
|
Returns:
Type | Description |
---|---|
ndarray
|
The ternarized array with elements set to 0, 0.5, or 1 based on the thresholds. |
Source code in prefab/geometry.py
trim(device_array, buffer_thickness=None)
Trim the input ndarray by removing rows and columns that are completely zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_array
|
ndarray
|
The input array to be trimmed. |
required |
buffer_thickness
|
dict
|
A dictionary specifying the thickness of the buffer to leave around the non-zero elements of the array. Should contain keys 'top', 'bottom', 'left', 'right'. Defaults to None, which means no buffer is added. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
The trimmed array, potentially with a buffer around the non-zero elements. |