Previous topic

gdsii.types — definitions of GDSII data types

Next topic

gdsii.exceptions — GDSII exceptions

This Page

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).

acls

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
check_size(size)

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
check_tag(tag)

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
classmethod iterate(stream)

Generator function for iterating over all records in a GDSII file. Yields Record objects.

Parameters:stream – GDS file opened for reading in binary mode
points

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
classmethod read(stream)

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(stream)

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

Tag name, if known, otherwise tag ID formatted as hex number.

tag_type

Tag data type ID.

tag_type_name

Tag data type name, if known, and formatted number otherwise.

times

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
class gdsii.record.Reader(stream)

Class for buffered reading of Records

current

Last record read from stream.

read_next()

Read and return next record from stream.