Nanosurf Python Library
This library provides a Python interface for controlling Nanosurf atomic force microscopes (AFMs), utilities for processing and handling measurement data, and some simple example applications to get you started.
The library consists of three packages, which can be installed separately:
| Package | Provides |
|---|---|
nanosurf-core |
Python API for controlling Nanosurf atomic force microscopes (AFM) |
nanosurf-utils |
Data processing, file handling, and device drivers for Nanosurf AFM systems |
nanosurf-apps |
Runnable example scripts using the Python API with Nanosurf Studio or Nanosurf MobileS |
Requirements
- To use the Python interface to remotely control a Nanosurf AFM, a running Nanosurf Studio or Nanosurf MobileS session is required.
- Scripting access to low-level Studio functionality can be obtained in different tiers. See documentation, or contact Nanosurf sales for more information.
The library installs on Windows, Linux and macOS, but not every feature is available on every platform:
| Windows | Linux | macOS | |
|---|---|---|---|
| Studio or MobileS functionality via Python | ✅ | – | – |
| Accessory and add-on device control | ✅ | ✅ | – |
| Reading and analysing measurement data | ✅ | ✅ | ✅ |
Installation and updating
To install the full nanosurf library, run the following command from your command
line interface:
pip install nanosurf
To upgrade your nanosurf package installation version ≥ 2.0.0 to the newest version, run the
following command from your command line interface:
pip install -U nanosurf
To upgrade from an existing installed library version < 2.0.0:
pip install -U --force-reinstall nanosurf
Getting started
With a running Studio session:
from nanosurf.studio import Studio, StudioScriptError
studio = Studio()
try:
session = studio.select_measurement_session()
print(f"Instrument: {session.workflow.device.scan_head.name} / "
f"{session.workflow.device.controller.name}")
laser = session.workflow.laser
calibration = session.workflow.probe.cantilever_calibration
imaging = session.workflow.imaging
storage = session.workflow.data.storage
approach = session.workflow.approach
# 1. Laser alignment
print("Aligning laser...")
print(laser.alignment.align_all()['message'])
# 2. Cantilever calibration
calibration.operation_mode = calibration.operation_mode_enum.non_contact
print("Running thermal tune...")
print(calibration.run()['message'])
calibration.apply()
# 3. Set imaging parameters
imaging.scan_range_fast_axis = 2e-6
imaging.scan_range_slow_axis = 2e-6
imaging.points_per_line = 256
imaging.lines_per_frame = 256
imaging.line_rate = 1.0
# 4. Where to save
storage.file_basename = "demo_[DATE]_[INDEX]"
# 5. Approach and acquire an image
print("Approaching...")
print(approach.approach()['message'])
print("Scanning...")
print(imaging.acquire()['message'])
# 6. Withdraw
approach.withdraw()
print("Session complete.")
except StudioScriptError as e:
print(f"Studio error: {e}")
With a running MobileS session:
import time
from nanosurf.com_proxy import SPM
# SPM() auto-detects whichever supported control software is running
# (MobileS, C3000, CoreAFM, CX, etc). Use e.g. nanosurf.MobileS() to target one directly.
spm = SPM()
try:
if not spm.is_connected():
raise RuntimeError("No running Nanosurf MobileS session found.")
if not spm.is_scripting_enabled():
raise RuntimeError("Scripting is not enabled.")
# configure the measurement
scan = spm.application.Scan
scan.ImageWidth = 2e-6
scan.ImageHeight = 2e-6
scan.Points = 200
scan.Lines = 200
# start the measurement
scan.StartFrameUp()
while scan.IsScanning:
time.sleep(0.1)
except Exception as e:
print(f"Connecting to MobileS or imaging failed: {e}")
Documentation
The full documentation for the library and the Studio scripting interface is bundled with Nanosurf Studio starting from version 18.
Version History
See CHANGELOG.txt in the installed package folder.
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanosurf-2.0.7.tar.gz.
File metadata
- Download URL: nanosurf-2.0.7.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc48e6f2387921a646c047538e9a3d779bb859542499402b37bf20e4d8abdf8a
|
|
| MD5 |
97b1c1731bde2008fde3468ca5714385
|
|
| BLAKE2b-256 |
22d0054ba347310fa8bea17ff699d3f6312fb5e3326f8890b5ec150d397fa02e
|
File details
Details for the file nanosurf-2.0.7-py3-none-any.whl.
File metadata
- Download URL: nanosurf-2.0.7-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
448e76247c9b9fd365bcc5297d4ad5e034a0453c63eb554d62d9800ae7796199
|
|
| MD5 |
70a18108db2572003ca26c75c45674d7
|
|
| BLAKE2b-256 |
f7a9db7aa4e89b5123e2e4f6e48a7c94bc3543b88197af4b8f53fdabc95ec38d
|