Read
Provides functions to create Devices from various data sources.
from_gds(gds_path, cell_name, gds_layer=(1, 0), bounds=None, **kwargs)
Create a Device from a GDS cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gds_path |
str
|
The file path to the GDS file. |
required |
cell_name |
str
|
The name of the cell within the GDS file to be converted into a Device object. |
required |
gds_layer |
tuple[int, int]
|
A tuple specifying the layer and datatype to be used from the GDS file. Defaults to (1, 0). |
(1, 0)
|
bounds |
tuple[tuple[int, int], tuple[int, int]]
|
A tuple specifying the bounds for cropping the cell before conversion, formatted as ((min_x, min_y), (max_x, max_y)), in units of the GDS file. If None, the entire cell is used. |
None
|
**kwargs |
Additional keyword arguments to be passed to the Device constructor. |
{}
|
Returns:
Type | Description |
---|---|
Device
|
A Device object representing the specified cell from the GDS file, after processing based on the specified layer. |
Source code in prefab/read.py
from_gdstk(gdstk_cell, gds_layer=(1, 0), bounds=None, **kwargs)
Create a Device from a gdstk cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdstk_cell |
Cell
|
The gdstk.Cell object to be converted into a Device object. |
required |
gds_layer |
tuple[int, int]
|
A tuple specifying the layer and datatype to be used. Defaults to (1, 0). |
(1, 0)
|
bounds |
tuple[tuple[int, int], tuple[int, int]]
|
A tuple specifying the bounds for cropping the cell before conversion, formatted as ((min_x, min_y), (max_x, max_y)), in units of the GDS file. If None, the entire cell is used. |
None
|
**kwargs |
Additional keyword arguments to be passed to the Device constructor. |
{}
|
Returns:
Type | Description |
---|---|
Device
|
A Device object representing the gdstk.Cell, after processing based on the specified layer. |
Source code in prefab/read.py
from_img(img_path, img_width_nm=None, binarize=True, **kwargs)
Create a Device from an image file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_path |
str
|
The path to the image file to be converted into a Device object. |
required |
img_width_nm |
int
|
The desired width of the device in nanometers. If specified, the image will be resized to this width while maintaining aspect ratio. If None, no resizing is performed. |
None
|
binarize |
bool
|
If True, the image will be binarized (converted to binary values) before conversion to a Device object. This is useful for converting grayscale images into binary masks. Defaults to True. |
True
|
**kwargs |
Additional keyword arguments to be passed to the Device constructor. |
{}
|
Returns:
Type | Description |
---|---|
Device
|
A Device object representing the processed image, after optional resizing and binarization. |
Source code in prefab/read.py
from_ndarray(ndarray, resolution=1, binarize=True, **kwargs)
Create a Device from an ndarray.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ndarray |
ndarray
|
The input array representing the device layout. |
required |
resolution |
int
|
The resolution of the ndarray in nanometers per pixel, defaulting to 1 nm per pixel. If specified, the input array will be resized based on this resolution to match the desired physical size. |
1
|
binarize |
bool
|
If True, the input array will be binarized (converted to binary values) before conversion to a Device object. This is useful for processing grayscale images into binary masks. Defaults to True. |
True
|
**kwargs |
Additional keyword arguments to be passed to the Device constructor. |
{}
|
Returns:
Type | Description |
---|---|
Device
|
A Device object representing the input array, after optional resizing and binarization. |
Source code in prefab/read.py
from_sem(sem_path, sem_resolution=None, sem_resolution_key=None, binarize=True, bounds=None, **kwargs)
Create a Device from a scanning electron microscope (SEM) image file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sem_path |
str
|
The file path to the SEM image. |
required |
sem_resolution |
float
|
The resolution of the SEM image in nanometers per pixel. If not provided, it
will be extracted from the image metadata using the |
None
|
sem_resolution_key |
str
|
The key to look for in the SEM image metadata to extract the resolution.
Required if |
None
|
binarize |
bool
|
If True, the SEM image will be binarized (converted to binary values) before conversion to a Device object. This is needed for processing grayscale images into binary masks. Defaults to True. |
True
|
bounds |
tuple[tuple[int, int], tuple[int, int]]
|
A tuple specifying the bounds for cropping the image before conversion, formatted as ((min_x, min_y), (max_x, max_y)). If None, the entire image is used. |
None
|
**kwargs |
Additional keyword arguments to be passed to the Device constructor. |
{}
|
Returns:
Type | Description |
---|---|
Device
|
A Device object representing the processed SEM image. |
Raises:
Type | Description |
---|---|
ValueError
|
If neither |
Source code in prefab/read.py
get_sem_resolution(sem_path, sem_resolution_key)
Extracts the resolution of a scanning electron microscope (SEM) image from its metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sem_path |
str
|
The file path to the SEM image. |
required |
sem_resolution_key |
str
|
The key to look for in the SEM image metadata to extract the resolution. |
required |
Returns:
Type | Description |
---|---|
float
|
The resolution of the SEM image in nanometers per pixel. |
Raises:
Type | Description |
---|---|
ValueError
|
If the resolution key is not found in the SEM image metadata. |