hyperspy.io_plugins.semper_unf module

class hyperspy.io_plugins.semper_unf.SemperFormat(data, title='', offsets=(0.0, 0.0, 0.0), scales=(1.0, 1.0, 1.0), units=(<undefined>, <undefined>, <undefined>), metadata=None)

Bases: object

Class for importing and exporting SEMPER .unf-files.

The SemperFormat class represents a SEMPER binary file format with a header, which holds additional information. .unf-files can be saved and read from files.

data

ndarray (N=3) – The phase map or magnetization information in a 3D array (with one slice).

title

string – Title of the file (not to be confused with the filename).

offsets

tuple (N=3) of floats – Offset shifts (in nm) of the grid origin (does not have to start at 0) in x, y, z.

scales

tuple (N=3) of floats – Grid spacing (nm per pixel) in x, y, z.

units

tuple (N=3) of strings – Units of the grid in x, y, z.

metadata

dictionary – A dictionary of all flags and metadata present in the .unf-file.

HEADER_DTYPES = [('NCOL', '<i2'), ('NROW', '<i2'), ('NLAY', '<i2'), ('ICLASS', '<i2'), ('IFORM', '<i2'), ('IFLAG', '<i2'), ('IFORM', '<i2')]
ICLASS_DICT = {1: 'image', 2: 'macro', 3: 'fourier', 4: 'spectrum', 5: 'correlation', 6: <undefined>, 7: 'walsh', 8: 'position list', 9: 'histogram', 10: 'display look-up table'}
ICLASS_DICT_INV = {'image': 1, 'macro': 2, 'fourier': 3, 'spectrum': 4, 'correlation': 5, <undefined>: 6, 'walsh': 7, 'position list': 8, 'histogram': 9, 'display look-up table': 10}
IFORM_DICT = {0: <class 'numpy.int8'>, 1: <class 'numpy.int16'>, 2: <class 'numpy.float32'>, 3: <class 'numpy.complex64'>, 4: <class 'numpy.int32'>}
IFORM_DICT_INV = {<class 'numpy.int8'>: 0, <class 'numpy.int16'>: 1, <class 'numpy.float32'>: 2, <class 'numpy.complex64'>: 3, <class 'numpy.int32'>: 4}
LABEL_DTYPES = [('SEMPER', ('<i2', 6)), ('NCOL', ('<i2', 2)), ('NROW', ('<i2', 2)), ('NLAY', ('<i2', 2)), ('ICCOLN', ('<i2', 2)), ('ICROWN', ('<i2', 2)), ('ICLAYN', ('<i2', 2)), ('ICLASS', '<i2'), ('IFORM', '<i2'), ('IWP', '<i2'), ('DATE', ('<i2', 6)), ('NCRANG', '<i2'), ('RANGE', ('<i2', 27)), ('IPLTYP', '<i2'), ('NCOLH', '<i2'), ('NROWH', '<i2'), ('NLAYH', '<i2'), ('ICCOLNH', '<i2'), ('ICROWNH', '<i2'), ('ICLAYNH', '<i2'), ('REALCO', '<i2'), ('NBLOCK', '<i2'), ('FREE', ('<i2', 3)), ('DATAV6', ('<i2', 4)), ('DATAV7', ('<i2', 4)), ('DZV5', ('<i2', 4)), ('Z0V4', ('<i2', 4)), ('DYV3', ('<i2', 4)), ('Y0V2', ('<i2', 4)), ('DXV1', ('<i2', 4)), ('X0V0', ('<i2', 4)), ('NTITLE', '<i2'), ('TITLE', ('<i2', 144)), ('XUNIT', ('<i2', 4)), ('YUNIT', ('<i2', 4)), ('ZUNIT', ('<i2', 4))]
classmethod from_signal(signal)

Import a SemperFormat object from a Signal object.

Parameters:signal (Signal) – The signal which should be imported.
Returns:
Return type:None
classmethod load_from_unf(filename, lazy=False)

Load a .unf-file into a SemperFormat object.

Parameters:filename (string) – The name of the unf-file from which to load the data. Standard format is ‘*.unf’.
Returns:semper – SEMPER file format object containing the loaded information.
Return type:SemperFormat (N=1)
log_info()

log important flag information of the SemperFormat object.

Parameters:None
Returns:
Return type:None
save_to_unf(filename='semper.unf', skip_header=False)

Save a SemperFormat to a file.

Parameters:
  • filename (string, optional) – The name of the unf-file to which the data should be written.
  • skip_header (boolean, optional) – Determines if the header, title and label should be skipped (useful for some other programs). Default is False.
Returns:

Return type:

None

to_signal(lazy=False)

Export a SemperFormat object to a Signal object.

Parameters:None
Returns:signal – The exported signal.
Return type:Signal
hyperspy.io_plugins.semper_unf.file_reader(filename, **kwds)
hyperspy.io_plugins.semper_unf.file_writer(filename, signal, **kwds)
hyperspy.io_plugins.semper_unf.pack_to_intbytes(fmt, value)

Pack a value into a byte list using format fmt and represent it as int (range 0-255).

hyperspy.io_plugins.semper_unf.unpack_from_intbytes(fmt, byte_list)

Read in a list of bytes (as int with range 0-255) and unpack them with format fmt.