This module contains classes for low-level GDSII I/O.
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'
Element data.
Element tag (int).
Convert data to list of acls (GID, UID, ACCESS). Useful for LIBSECUR.
>>> 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
Checks if data size equals to the given size. Raises DataSizeError otherwise. For example:
>>> rec = Record(tags.DATATYPE, (0,))
>>> rec.check_size(1)
>>> rec.check_size(5)
Traceback (most recent call last):
...
DataSizeError: 3586
Checks if current record has the same tag as the given one. Raises MissingRecord exception 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
Generator function for iterating over all records in a GDSII file. Yields Record objects.
Parameters: | stream – GDS file opened for reading in binary mode |
---|
Convert data to list of points. Useful for XY record. Raises DataSizeError if 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
Read a GDSII record from file.
Parameters: | stream – GDS file opened for reading in binary mode |
---|---|
Returns: | a new Record instance |
Raises : | UnsupportedTagType if data cannot be parsed |
Raises : | EndOfFileError if end of file is reached |
Save record to a GDS file.
Parameters: | stream – file opened for writing in binary mode |
---|---|
Raises : | UnsupportedTagType if tag type is not supported |
Raises : | FormatError on incorrect data sizes, etc |
Raises : | whatever struct.pack() can raise |
Tag name, if known, otherwise tag ID formatted as hex number.
Tag data type ID.
Tag data type name, if known, and formatted number otherwise.
Convert data to tuple (modification time, access time). Useful for BGNLIB and BGNSTR.
>>> 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