magni.afm.types.image module¶
Module providing data container classes for .mi image files.
The classes of this module can be used either directly or indirectly through
the magni.afm.io
subpackage by loading an .mi image file.
Routine listings¶
- Buffer(magni.afm.types.BaseClass)
- Data class of the .mi image file buffers.
- Image(magni.afm.types.File)
- Data class of the .mi image files.
See also
magni.afm.io
- .mi file loading.
-
class
magni.afm.types.image.
Buffer
(attrs, data)[source]¶ Bases:
magni.afm.types._util.BaseClass
Data class of the .mi image file buffers.
Parameters: - attrs (dict) – The attributes of the buffer.
- data (numpy.ndarray) – The 2D data of the buffer.
-
apply_clipping
¶ bool
A flag indicating if clipping should be applied to the data.
-
data
¶ numpy.ndarray
The 2D data of the buffer.
See also
magni.utils.types.BaseClass
- Superclass of the present class.
Examples
A subclass of the present class is implicitly instantiated when loading, for example, the .mi file provided with the package:
>>> import os, magni >>> path = magni.utils.split_path(magni.__path__[0])[0] >>> path = path + 'examples' + os.sep + 'example.mi' >>> if os.path.isfile(path): ... image = magni.afm.io.read_mi_file(path) ... buffer_ = image.buffers[0]
This buffer can have a number of attributes including ‘bufferLabel’:
>>> if os.path.isfile(path): ... print('{!r}'.format(buffer_.attrs['bufferLabel'])) ... else: ... print("'Topography'") 'Topography'
The primary purpose of this class is, however, to contain the 2D data of a buffer:
>>> if os.path.isfile(path): ... print('Buffer data shape: {!r}'.format( ... tuple(int(s) for s in buffer_.data.shape))) ... else: ... print('Buffer data shape: (256, 256)') Buffer data shape: (256, 256)
-
apply_clipping
Get the apply_clipping property of the buffer.
The clipping is specified by the ‘DisplayOffset’, ‘DisplayRange’, and ‘filter’ attributes of the buffer.
Returns: apply_clipping (bool) – A flag indicating if clipping should be applied to the data.
-
data
Get the data property of the buffer.
If
apply_clipping
is False, the data is returned as-is. Otherwise, the filtering specified by the ‘filter’ attribute of the buffer and the clipping specified by the ‘DisplayOffset’ and ‘DisplayRange’ attributes of the buffer are applied to the data before it is returned.Returns: data (numpy.ndarray) – The 2D data of the buffer.
-
class
magni.afm.types.image.
Image
(attrs, buffers)[source]¶ Bases:
magni.afm.types._util.File
Data class of the .mi image files.
Parameters: - attrs (dict) – The attributes of the image.
- buffers (list or tuple) – The buffers of the image.
See also
magni.utils.types.File
- Superclass of the present class.
Examples
The present class is implicitly instantiated when loading, for example, the .mi file provided with the package:
>>> import os, magni >>> path = magni.utils.split_path(magni.__path__[0])[0] >>> path = path + 'examples' + os.sep + 'example.mi' >>> if os.path.isfile(path): ... image = magni.afm.io.read_mi_file(path)
This file has a number of buffers which each has the ‘bufferLabel’ attribute:
>>> if os.path.isfile(path): ... for buffer_ in image.buffers[::2][:3]: ... label = buffer_.attrs['bufferLabel'] ... print("Buffer with 'bufferLabel': {!r}".format(label)) ... else: ... for label in ('Topography', 'Deflection', 'Friction'): ... print("Buffer with 'bufferLabel': {!r}".format(label)) Buffer with 'bufferLabel': 'Topography' Buffer with 'bufferLabel': 'Deflection' Buffer with 'bufferLabel': 'Friction'