layout.readers — reading layout files
tempura/layout/readers.py reads gate geometry from layout files and normalizes
it into a single typed payload. load_layout_data(...) and
load_layout_polygons(...) are the supported entry points; the per-format
readers behind them are an implementation detail.
What it does
A reader returns a LayoutData (see layout.models)
carrying the polygons grouped by layer plus the file's unit metadata. The format
is chosen from the file suffix:
- GDS / GDSII and OAS are read with
gdstk, which reports the file's unit scale and precision directly. Layer names are normalized toL{layer}D{datatype}. - DXF is parsed by a small hand-rolled state machine over the file's
group-code/value pairs, collecting closed
POLYLINEentities per layer and reading the$INSUNITSheader to recover a physical scale when present. DXF layers keep their original names.
Unit metadata
Each LayoutData records whether units are known (units_known), the scale to
meters (unit_scale_m), and the source format. This metadata is what lets
prepare_layout trust the file's physical size in
size_mode="layout_size", or fall back to an explicit length when the units are
missing or unreliable.
API
readers
Layout file readers returning polygons grouped by layer.
load_layout_data(path)
Load polygons and available unit metadata from GDS/GDSII/OAS/DXF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the layout file. |
required |
Returns:
| Type | Description |
|---|---|
LayoutData
|
Normalized layout payload produced by the suffix-specific reader. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the file suffix is not one of the supported layout formats. |
Source code in tempura/layout/readers.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
load_layout_polygons(path)
Load polygons by layer from GDS/GDSII/OAS/DXF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the layout file. |
required |
Returns:
| Type | Description |
|---|---|
PolygonMap
|
Mapping from layer name to the polygons read from |
Source code in tempura/layout/readers.py
294 295 296 297 298 299 300 301 302 303 | |
read_dxf_layout(path)
Read closed DXF POLYLINE entities and any unit metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the DXF file. |
required |
Returns:
| Type | Description |
|---|---|
LayoutData
|
Normalized layout payload containing polygons grouped by DXF layer |
LayoutData
|
name plus any recognized |
Source code in tempura/layout/readers.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
read_dxf_polylines(path)
Read closed DXF POLYLINE entities grouped by DXF layer name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the DXF file. |
required |
Returns:
| Type | Description |
|---|---|
PolygonMap
|
Mapping from DXF layer name to closed polyline polygons. |
Source code in tempura/layout/readers.py
330 331 332 333 334 335 336 337 338 339 | |
read_gds_layout(path)
Read polygons and unit metadata from a GDS/GDSII layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the GDS or GDSII file. |
required |
Returns:
| Type | Description |
|---|---|
LayoutData
|
Normalized layout payload containing polygons grouped by layer plus the |
LayoutData
|
unit metadata reported by the GDS library. |
Source code in tempura/layout/readers.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
read_gds_polygons(path)
Read polygons from a GDS/GDSII layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the GDS or GDSII file. |
required |
Returns:
| Type | Description |
|---|---|
PolygonMap
|
Mapping from layer name to polygons read from |
Source code in tempura/layout/readers.py
306 307 308 309 310 311 312 313 314 315 | |
read_oas_layout(path)
Read polygons and unit metadata from an OASIS layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the OASIS file. |
required |
Returns:
| Type | Description |
|---|---|
LayoutData
|
Normalized layout payload containing polygons grouped by layer plus the |
LayoutData
|
unit metadata reported by the OASIS library. |
Source code in tempura/layout/readers.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
read_oas_polygons(path)
Read polygons from an OASIS layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the OASIS file. |
required |
Returns:
| Type | Description |
|---|---|
PolygonMap
|
Mapping from layer name to polygons read from |
Source code in tempura/layout/readers.py
318 319 320 321 322 323 324 325 326 327 | |