magni.afm.types._util module

Module providing the common functionality of the subpackage.

class magni.afm.types._util.BaseClass(attrs)[source]

Bases: object

Base class of every magni.afm.types data class.

The present class validates the attributes passed to its constructor against the allowed attributes of the class of the given instance and exposes these attributes through a read-only dictionary property, attrs. Furthermore, the present class exposes the allowed attributes of the class of the given instance through a read-only dictionary static property, params.

Parameters:attrs (dict) – The desired attributes of the instance.
attrs

magni.utils.types.ReadOnlyDict – The attributes of the instance.

params

magni.utils.types.ReadOnlyDict – The allowed attributes of the instance.

Examples

An example could be the subclass, ‘Person’ which allows only the string attribute, name:

>>> from magni.afm.types._util import BaseClass
>>> class Person(BaseClass):
...     def __init__(self, attrs):
...         BaseClass.__init__(self, attrs)
...     _params = {'name': str}

This class can then be initiated with a name:

>>> person = Person({'name': 'Murphy'})
>>> print('{!r}'.format(person.attrs['name']))
'Murphy'

Any other attributes, than ‘name’, passed to the class are ignored:

>>> person = Person({'name': 'Murphy', 'age': 42})
>>> for name in person.attrs.keys():
...     print('{!r}'.format(name))
'name'
attrs
params = ReadOnlyDict()
class magni.afm.types._util.File(attrs, buffers)[source]

Bases: magni.afm.types._util.BaseClass

Base class of the magni.afm.types file classes.

The present class specifies the allowed file-level attributes and exposes the read-only property, buffers which all .mi files have. Furthermore, the present class provides a method for accessing buffers by their ‘bufferLabel’ attribute.

Parameters:
  • attrs (list or tuple) – The desired attributes of the file.
  • buffers (list or tuple) – The buffers of the file.
buffers

tuple – The buffers of the file.

See also

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):
...     file_ = 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 file_.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'

If only, for example, buffers with ‘bufferLabel’ equal to ‘Topography’ are desired, the method, get_buffer can be called:

>>> if os.path.isfile(path):
...     buffers = len(file_.get_buffer('Topography'))
...     print("Buffers with 'bufferLabel' == 'Topography': {}"
...            .format(buffers))
... else:
...     print("Buffers with 'bufferLabel' == 'Topography': 2")
Buffers with 'bufferLabel' == 'Topography': 2
buffers
get_buffer(label)[source]

Get the buffers that have the specified buffer label.

Parameters:label (str) – The desired buffer label of the buffer.
Returns:buffers (list) – The buffers that have the desired buffer label.
class magni.afm.types._util.FileCollection(files, paths)[source]

Bases: magni.afm.types._util.BaseClass

Data class for collections of File instances with identical settings.

The settings are the following attributes: ‘fileType’, ‘mode’, ‘xPixels’, ‘yPixels’, ‘xOffset’, ‘yOffset’, ‘xLength’, ‘yLength’, ‘scanSpeed’, ‘acMac’, ‘acACMode’, ‘plotType’.

The present class exposes the files of the collection through a read-only tuple property, files and the paths of these files through a read-only tuple property, paths.

Parameters:
  • files (list or tuple) – The files of the collection.
  • paths (list or tuple) – The paths of the files of the collection.
files

tuple – The files of the collection.

paths

tuple – The paths of the files of the collection.

See also

BaseClass
Superclass of the present class.

Examples

No example .mi file collection is distributed with magni.

files
paths