JPK Modules

For decoding and loading .jpk AFM file format into Python Numpy arrays.

get_jpk_channels(file_path: Path | str, config_path: Path | str | None = None) -> dict[str, int]

Get the list of channels available in the .jpk file.

Parameters:

Name Type Description Default
file_path Path | str

Path to the .jpk file.

required
config_path Path | str | None

Path to a configuration file. If ''None'' (default) then the packages default configuration is loaded from ''default_config.yaml''.

None

Returns:

Type Description
dict[str]

Dictionary of available channels.

Source code in AFMReader/jpk.py
def get_jpk_channels(file_path: Path | str, config_path: Path | str | None = None) -> dict[str, int]:
    """
    Get the list of channels available in the .jpk file.

    Parameters
    ----------
    file_path : Path | str
        Path to the .jpk file.
    config_path : Path | str | None
        Path to a configuration file. If ''None'' (default) then the packages
        default configuration is loaded from ''default_config.yaml''.

    Returns
    -------
    dict[str]
        Dictionary of available channels.
    """
    file_path = Path(file_path)
    filename = file_path.stem
    return _get_jpk_channels(file_path, filename, file_path, config_path)

load_jpk(file_path: Path | str, channel: str, config_path: Path | str | None = None, flip_image: bool = True) -> AFMScan

Load image from JPK Instruments .jpk files.

Parameters:

Name Type Description Default
file_path Path | str

Path to the .jpk file.

required
channel str

The channel to extract from the .jpk file.

required
config_path Path | str | None

Path to a configuration file. If ''None'' (default) then the packages default configuration is loaded from ''default_config.yaml''.

None
flip_image bool

Whether to flip the image vertically. Default is True.

True

Returns:

Type Description
AFMScan

An AFMScan object containing the image, its pixel to nanometre scaling value, and z-axis units.

Raises:

Type Description
FileNotFoundError

If the file is not found.

KeyError

If the channel is not found in the file.

Examples:

Load height trace channel from the .jpk file. 'height_trace' is the default channel name.

>>> from AFMReader.jpk import load_jpk
>>> afm_scan = load_jpk(file_path="./my_jpk_file.jpk", channel="height_trace", flip_image=True)
>>> image = afm_scan.image
>>> pixel_to_nanometre_scaling_factor = afm_scan.pixel_to_nanometre_scaling
>>> z_units = afm_scan.z_units
Source code in AFMReader/jpk.py
def load_jpk(
    file_path: Path | str, channel: str, config_path: Path | str | None = None, flip_image: bool = True
) -> AFMScan:
    """
    Load image from JPK Instruments .jpk files.

    Parameters
    ----------
    file_path : Path | str
        Path to the .jpk file.
    channel : str
        The channel to extract from the .jpk file.
    config_path : Path | str | None
        Path to a configuration file. If ''None'' (default) then the packages default configuration is loaded from
        ''default_config.yaml''.
    flip_image : bool
        Whether to flip the image vertically. Default is ``True``.

    Returns
    -------
    AFMScan
        An AFMScan object containing the image, its pixel to nanometre scaling value, and z-axis units.

    Raises
    ------
    FileNotFoundError
        If the file is not found.
    KeyError
        If the channel is not found in the file.

    Examples
    --------
    Load height trace channel from the .jpk file. 'height_trace' is the default channel name.

    >>> from AFMReader.jpk import load_jpk
    >>> afm_scan = load_jpk(file_path="./my_jpk_file.jpk", channel="height_trace", flip_image=True)
    >>> image = afm_scan.image
    >>> pixel_to_nanometre_scaling_factor = afm_scan.pixel_to_nanometre_scaling
    >>> z_units = afm_scan.z_units
    """
    logger.info(f"Loading image from : {file_path}")
    file_path = Path(file_path)
    filename = file_path.stem
    image, pixel_to_nanometre_scaling, units = _load_jpk(
        file=file_path,
        filename=filename,
        channel=channel,
        file_suffix=file_path.suffix,
        config_path=config_path,
        flip_image=flip_image,
    )
    return AFMScan(image=image, pixel_to_nanometre_scaling=pixel_to_nanometre_scaling, z_units=units)