gdsii.record — GDSII record I/O
This module contains classes for low-level GDSII I/O.
- class gdsii.record.Record(tag, data=None, points=None, times=None, acls=None)
Class for representing a GDSII record with attached data. Example:
>>> r = Record(tags.STRNAME, 'my_structure') >>> '%04x' % r.tag '0606' >>> r.tag_name 'STRNAME' >>> r.tag_type 6 >>> r.tag_type_name 'ASCII' >>> r.data 'my_structure' >>> r = Record(0xffff, 'xxx') # Unknown tag type >>> r.tag_name '0xffff' >>> r.tag_type_name '0xff'
- data
Element data.
- tag
Element tag (
int).
- property acls
Convert data to list of acls
(GID, UID, ACCESS). Useful forLIBSECUR.>>> r = Record(tags.LIBSECUR, [1, 2, 3, 4, 5, 6]) >>> r.acls [(1, 2, 3), (4, 5, 6)] >>> r = Record(tags.LIBSECUR, [1, 2, 3, 4]) # wrong data size >>> r.acls Traceback (most recent call last): ... DataSizeError: 15106
- check_size(size)
Checks if data size equals to the given size. Raises
DataSizeErrorotherwise. For example:>>> rec = Record(tags.DATATYPE, (0,)) >>> rec.check_size(1) >>> rec.check_size(5) Traceback (most recent call last): ... DataSizeError: 3586
- check_tag(tag)
Checks if current record has the same tag as the given one. Raises
MissingRecordexception otherwise. For example:>>> rec = Record(tags.STRNAME, b'struct') >>> rec.check_tag(tags.STRNAME) >>> rec.check_tag(tags.DATATYPE) Traceback (most recent call last): ... MissingRecord: Wanted: 3586, got: STRNAME
- classmethod iterate(stream)
Generator function for iterating over all records in a GDSII file. Yields
Recordobjects.- Parameters:
stream – GDS file opened for reading in binary mode
- property points
Convert data to list of points. Useful for
XYrecord. RaisesDataSizeErrorif data size is incorrect. For example:>>> r = Record(tags.XY, [0, 1, 2, 3]) >>> r.points [(0, 1), (2, 3)] >>> r = Record(tags.XY, []) # not allowed >>> r.points Traceback (most recent call last): ... DataSizeError: 4099 >>> r = Record(tags.XY, [1, 2, 3]) # odd number of coordinates >>> r.points Traceback (most recent call last): ... DataSizeError: 4099
- classmethod read(stream)
Read a GDSII record from file.
- Parameters:
stream – GDS file opened for reading in binary mode
- Returns:
a new
Recordinstance- Raises:
UnsupportedTagTypeif data cannot be parsed- Raises:
EndOfFileErrorif end of file is reached
- save(stream)
Save record to a GDS file.
- Parameters:
stream – file opened for writing in binary mode
- Raises:
UnsupportedTagTypeif tag type is not supported- Raises:
FormatErroron incorrect data sizes, etc- Raises:
whatever
struct.pack()can raise
- property tag_name
Tag name, if known, otherwise tag ID formatted as hex number.
- property tag_type
Tag data type ID.
- property tag_type_name
Tag data type name, if known, and formatted number otherwise.
- property times
Convert data to tuple
(modification time, access time). Useful forBGNLIBandBGNSTR.>>> r = Record(tags.BGNLIB, [100, 1, 1, 1, 2, 3, 110, 8, 14, 21, 10, 35]) >>> print(r.times[0].isoformat()) 2000-01-01T01:02:03 >>> print(r.times[1].isoformat()) 2010-08-14T21:10:35 >>> r = Record(tags.BGNLIB, [100, 1, 1, 1, 2, 3]) # wrong data length >>> r.times Traceback (most recent call last): ... DataSizeError: 258 >>> # invalid day/month/etc >>> r = r = Record(tags.BGNLIB, [100, 0, 1, 1, 2, 3, 110, 8, 32, 21, 10, 35]) >>> print(r.times[0].isoformat()) 1900-01-01T00:00:00 >>> print(r.times[1].isoformat()) 1900-01-01T00:00:00