{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SPM Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "# Import the load_spm from AFMReader\n",
    "from AFMReader.spm import load_spm\n",
    "from AFMReader.logging import logger\n",
    "\n",
    "logger.enable(__package__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the SPM file as an image and pixel to nm scaling factor\n",
    "FILE = \"../tests/resources/sample_0.spm\"\n",
    "image, pixel_to_nm_scaling = load_spm(FILE, channel=\"Height\")\n",
    "logger.info(f\"Loaded a {image.shape} image with a pixel to nm scaling factor of {pixel_to_nm_scaling} nm/pixel.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot the image\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# GWY Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "# Import the load_gwy from AFMReader\n",
    "from AFMReader.gwy import load_gwy\n",
    "from AFMReader.logging import logger\n",
    "\n",
    "logger.enable(__package__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the GWY file as an image and pixel to nm scaling factor\n",
    "FILE = Path(\"../tests/resources/sample_0.gwy\")\n",
    "image, pixel_to_nm_scaling = load_gwy(FILE, channel=\"Height\")\n",
    "logger.info(f\"Loaded a {image.shape} image with a pixel to nm scaling factor of {pixel_to_nm_scaling} nm/pixel.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ASD Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the load_asd from AFMReader\n",
    "from AFMReader.asd import load_asd, create_animation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the ASD file as a list of frames, the pixel to nm scaling factor and the metadata\n",
    "FILE = \"../tests/resources/sample_0.asd\"\n",
    "frames, pixel_to_nm_scaling, metadata = load_asd(file_path=FILE, channel=\"TP\")\n",
    "logger.info(f\"Loaded {len(frames)} frames from {FILE}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot a frame\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "frame_number = 55\n",
    "plt.imshow(frames[frame_number], cmap=\"afmhot\")\n",
    "plt.title(f\"Frame {frame_number}\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a gif of the frames using the create_animation function. This is slow for large files.\n",
    "create_animation(file_name=\"sample_0\", frames=frames, file_format=\".gif\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# JPK Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the load_jpk function from AFMReader\n",
    "from AFMReader.jpk import load_jpk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the JPK file as an image and pixel to nm scaling factor\n",
    "FILE = \"../tests/resources/sample_0.jpk\"\n",
    "image, pixel_to_nm_scaling = load_jpk(file_path=FILE, channel=\"height_trace\", flip_image=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot the image\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# H5-JPK Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the load_jpk function from AFMReader\n",
    "from AFMReader.h5_jpk import load_h5jpk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the JPK file as an image and pixel to nm scaling factor\n",
    "FILE = \"../tests/resources/sample_0.h5-jpk\"\n",
    "frames, pixel_to_nm_scaling, timestamps = load_h5jpk(file_path=FILE, channel=\"height_trace\", flip_image=True)\n",
    "logger.info(f\"Loaded {len(frames)} frames from {FILE}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot the image\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# IBW Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the load_ibw function from AFMReader\n",
    "from AFMReader.ibw import load_ibw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the IBW file as an image and pixel to nm scaling factor\n",
    "FILE = \"../tests/resources/sample_0.ibw\"\n",
    "image, pixel_to_nm_scaling = load_ibw(file_path=FILE, channel=\"HeightTracee\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot the image\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TopoStats Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the load_ibw function from AFMReader\n",
    "from AFMReader.topostats import load_topostats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the TopoStats file as an image, pixel to nm scaling factor, and metadata\n",
    "FILE = \"../tests/resources/sample_0_1.topostats\"\n",
    "image, pixel_to_nm_scaling, metadata = load_topostats(file_path=FILE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot the image\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# STP Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the load_stp function from AFMReader\n",
    "from AFMReader.stp import load_stp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the STP file as an image and pixel to nm scaling factor\n",
    "FILE = \"../tests/resources/sample_0.stp\"\n",
    "image, pixel_to_nm_scaling = load_stp(file_path=FILE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot the image\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TOP Files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the load_top function from AFMReader\n",
    "from AFMReader.top import load_top"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the TOP file as an image and pixel to nm scaling factor\n",
    "FILE = \"../tests/resources/sample_0.top\"\n",
    "image, pixel_to_nm_scaling = load_top(file_path=FILE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Plot the image\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.imshow(image, cmap=\"afmhot\")\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "afmreader",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
