Skip to main content

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

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanosurf-2.0.7.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanosurf-2.0.7-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

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

Hashes for nanosurf-2.0.7.tar.gz
Algorithm Hash digest
SHA256 fc48e6f2387921a646c047538e9a3d779bb859542499402b37bf20e4d8abdf8a
MD5 97b1c1731bde2008fde3468ca5714385
BLAKE2b-256 22d0054ba347310fa8bea17ff699d3f6312fb5e3326f8890b5ec150d397fa02e

See more details on using hashes here.

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

Hashes for nanosurf-2.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 448e76247c9b9fd365bcc5297d4ad5e034a0453c63eb554d62d9800ae7796199
MD5 70a18108db2572003ca26c75c45674d7
BLAKE2b-256 f7a9db7aa4e89b5123e2e4f6e48a7c94bc3543b88197af4b8f53fdabc95ec38d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.7 This release

2 files

1.14.1

2 files

1.14.0

2 files

1.13.7

2 files

1.13.6

2 files

1.13.5

2 files

1.13.4

2 files

1.13.3

2 files

1.13.2

2 files

1.13.1

2 files

1.13.0

2 files

1.12.3

2 files

1.12.2

2 files

1.12.1

2 files

1.12.0

2 files

1.11.0

2 files

1.10.1

2 files

1.10.0

2 files

1.9.5

2 files

1.9.4

2 files

1.9.3

2 files

1.9.2

2 files

1.9.1

2 files

1.9.0

2 files

1.8.6

2 files

1.8.5

2 files

1.8.4

2 files

1.8.3

2 files

1.8.2

2 files

1.8.1

2 files

1.8.0

2 files

1.7.2

2 files

1.7.1

2 files

1.7.0

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.1

2 files

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.4

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.6

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page