4 Pyafm is a set of tools for controlling atomic force microscopes. It
5 provides control of AFM postition using both short-range (piezo) and
6 long range (stepper) vertical positioning. There are separate modules
7 for controlling the piezo (pypiezo_) and stepper (stepper_), this
8 module mostly contains methods that require the capabilities of both.
10 This module can optionally include temperature sensing via a pypid_
19 I've packaged pyafm for Gentoo. You need layman_ and my `wtk
20 overlay`_. Install with::
22 # emerge -av app-portage/layman
24 # emerge -av sci-physics/pyafm
26 Although it is not strictly required (thanks to `duck typing`_) you'll
27 probably also want my `stepper`_ package or an equivalent
28 stepper implementation.
34 Pyafm requires the following Python modules:
36 * Pycomedi_ (required directly, and via ``pypiezo``)
38 * Stepper_ (or equivalent stepper implementation)
39 * Pypid_ (optional temperature monitoring and control)
46 Pyafm is available as a Git_ repository::
48 $ git clone git://tremily.us/pyafm.git
50 There are also periodic bundled releases. For example, get version
51 0.3 as a gzipped tarball with::
53 $ wget 'http://git.tremily.us/?p=pyafm.git;a=snapshot;h=v0.3;sf=tgz'
54 $ tar -xzvf pyafm-0.1.tar.gz
60 After downloading, change to the source directory and run::
62 $ python setup.py install
64 to install pyafm. Run::
66 $ python setup.py install --help
68 to see a list of installation options you may want to configure.
74 The docstrings include some pretty detailed tests to get you started.
75 ``dir()`` and ``help()`` are your friends ;). One neat feature that
76 I've added recently (2012-03-16) is the ability to store and load
77 complete AFM configurations via h5config_. For example, when you
78 first use pyafm, it may take you a bit to dig up all the necessary
79 calibration constants, etc. and plug them into your config::
81 >>> import pycomedi.constant
82 >>> import pypiezo.config
83 >>> import pyafm.config
84 >>> config = pyafm.config.AFMConfig()
85 >>> config['name'] = '1B3D9'
86 >>> config['main-axis'] = 'z'
87 >>> config['piezo'] = pypiezo.config.PiezoConfig()
88 >>> config['piezo']['name'] = '2253E'
89 >>> config['piezo']['axes'] = [
90 ... pypiezo.config.AxisConfig(), pypiezo.config.AxisConfig()]
91 >>> config['piezo']['axes'][0]['gain'] = 20
92 >>> config['piezo']['axes'][0]['sensitivity'] = 8.8e-9
93 >>> config['piezo']['axes'][0]['channel'] = pypiezo.config.OutputChannelConfig()
94 >>> config['piezo']['axes'][0]['channel']['analog-reference] = pycomedi.constant.AREF.ground
95 >>> config['piezo']['axes'][0]['channel']['analog-reference] = pycomedi.constant.AREF.ground
97 and on, and on ;). Don't worry though, once you finish telling Python
98 about your particular AFM configuration, you can get a working ``AFM``
99 instance quite easily::
102 >>> afm = AFM(config=config, devices=devices)
104 That takes care of opening all the channels and initializing all the
105 pieces you configured above. ``devices`` will end up full of any
106 ``pycomedi.device.Device`` instances that you need. Once you're happy
107 with your setup, make sure the ``config`` object is up-to-date with::
109 >>> afm.setup_config()
111 Which copies any new object state into the ``.config`` attribute
112 (e.g. bit-to-volt conversion polynomials). Then save your
115 >>> import pyafm.storage
116 >>> pyafm.storage.save_afm(afm=afm, filename='whatever', group='/optional')
118 Which will create a HDF5 file at the specified path, and store the AFM
119 configutaion under the specified group. Both ``filename`` and
120 ``group`` are optional. If you leave them out, they will default to
121 ``~/.config/pyafm-default.h5`` and ``/`` respectively.
123 The next time you need to do something with the AFM, just load your
124 old config file. If you used the default location, that's as easy
127 >>> import pyafm.storage
129 >>> afm = pyafm.storage.load_afm(devices=devices)
130 >>> afm.load_from_config()
132 When you're done using them, it's good practice to close any devices
135 >>> for device in devices:
138 Using ``load_afm`` with the default path is a good way to keep your
139 AFM configuration synchronized across several applications. That way,
140 there's only one place you need to update if you recalibrate your
141 piezo or rebuild an amplifier.
144 .. _layman: http://layman.sourceforge.net/
145 .. _wtk overlay: http://blog.tremily.us/posts/Gentoo_overlay/
146 .. _duck typing: http://en.wikipedia.org/wiki/Duck_typing
147 .. _pycomedi: http://blog.tremily.us/posts/pycomedi/
148 .. _pypiezo: http://blog.tremily.us/posts/pypiezo/
149 .. _stepper: http://blog.tremily.us/posts/stepper/
150 .. _pypid: http://blog.tremily.us/posts/pypid/
151 .. _h5config: http://blog.tremily.us/posts/h5config/
152 .. _SciPy: http://www.scipy.org/
153 .. _Git: http://git-scm.com/