The APyT configuration module

This module provides functions to load and access user-specific configuration settings for the APyT software package. It automatically manages the location and structure of the configuration file using platform-specific directories, and creates a default configuration file if none is found.

The configuration file is written in TOML format and includes user-defined settings such as database URLs, instrument parameters (e.g. flight length and detector radius), and other metadata needed for data processing.

Configuration files are cached for performance and can be reloaded on demand. Nested configuration settings can be accessed using dot notation.

Configuration file location

The configuration file is stored in a platform-specific user directory. For example:

  • Linux: ~/.config/apyt/config.toml

  • Windows: %USERPROFILE%\AppData\Local\apyt\apyt\config.toml

These locations are determined automatically using the platformdirs package.

Default configuration structure

The default configuration file is written in TOML format and has the following structure:

[devices.metap]
flight_length   = 144.0
detector_radius = 60.0

[devices.micro]
flight_length   = 106.0
detector_radius = 37.5

[devices.tap]
flight_length   = 305.0
detector_radius = 60.0

[database]
url = "https://apt-upload.mp.imw.uni-stuttgart.de"

[localdb]
file = "~/APyT/db.yaml"
data = "~/APyT/data/"

Explanation

  • [devices.<device>] Defines parameters for a specific atom probe device.

    • Required keys:

      • flight_length (float) — the flight path length of the device, i.e. the nominal distance between tip and detector (in mm).

      • detector_radius (float) — the radius of the detector (in mm).

    • Multiple devices can be listed, each under its own section.

  • [database] Contains the URL of the remote SQL database, if remote access is required.

  • [localdb] Configures usage of a local database instead of the SQL backend.

    • file — path to the local YAML database file (see local database module for details).

    • data — directory containing the associated measurement files.

    Hint

    The ~ symbol is expanded to the user’s home directory on both Linux and Windows systems.

List of functions

  • get_setting(): Retrieve a nested setting from the configuration.

  • load_config(): Load configuration from file (or cache if already loaded).

apyt.io.config.get_setting(key_path)[source]

Retrieve a nested setting from the configuration.

Parameters:

key_path (str) – Dot-separated path to the config setting, e.g. "database.url".

Returns:

The requested config value.

Return type:

Any

Raises:

KeyError – If the setting does not exist.

apyt.io.config.load_config(force_reload=False)[source]

Load configuration from file (or cache if already loaded).

Parameters:

force_reload (bool) – Whether to reload the configuration file from disk.

Returns:

The parsed configuration dictionary.

Return type:

dict