{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2: SpecsScan loading\n", "This is an example showcasing the loading of trARPES data as collected using the Phoibos detector at FHI Berlin.\n", "\n", "The band dispersion is loaded as a xarray dataframe demonstrating different modes of operation " ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "First, the SpecsScan class is imported which has the scan loader as its class method." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "from specsscan import SpecsScan\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "%matplotlib widget" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Here, a SpecsScan class instance is created as per the configuration provided in [config.yaml](../tests/data/config.yaml). The user may set the entries in config.yaml file, for example, the data path and conversion parameters as per the requirements before creating this instance.\n", "\n", "In addition to the provided config files, config files from different locations are optionally included as well (see documentation)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sps = SpecsScan(config=\"../tests/data/config.yaml\", user_config={}, system_config={})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Loading data" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The load_scan method loads the scan as an xarray of the data converted into angular/energy coordinates along with the metadata of the scan." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "path = \"../tests/data/\" # Path to the test data set\n", "# The path may be changed to point to the scan folder of the data of interest (for example, on a server drive)\n", "res_xarray = sps.load_scan(\n", " scan=4450, # Scan number for an example mirror scan\n", " path = path,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The data are from a mirror scan, showing the mirror position as third dimension:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "res_xarray.dims" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can plot, e.g., selected steps of the scan:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.figure()\n", "res_xarray[:,:,0].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Cropping data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The image contains data beyond the boundaries given by the illuminated area of the MCP, which should be removed. For this, the ``crop`` option of the converter can be used:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "res_xarray = sps.load_scan(\n", " scan=4450, # Scan number for an example mirror scan\n", " path = path,\n", " crop=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The loader has given a warning saying that the cropping parameters do not exist yet. Therefore, an interactive cropping tool can be used to crop the data while also saving the crop ranges into a class attribute for later scans. Pressing ``crop`` applies the cropping to the test image, and stores the cropping information in the class.\n", "\n", "One can provide relative cropping ranges either as keyword parameters, or in the config file, and optionally directly apply the settings to make the tool non-interactive." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sps.crop_tool(\n", " ek_range_min=0.08,\n", " ek_range_max=0.88,\n", " ang_range_min=0.15,\n", " ang_range_max=0.85,\n", " apply=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the scan again to apply it to all images:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "res_xarray = sps.load_scan(\n", " scan=4450, # Scan number for an example mirror scan\n", " path = path,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Removal of Mesh Artifact" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to remove the meshgrid artifact present in the data, an fft filtering is applied already in the data loaded previously. For this, parameters of the fft peaks corresponding to the grid are required which can be provided in the config file. Alternatively, one can also interactively optimize the parameters using the fft tool" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sps.fft_tool(\n", " amplitude=1,\n", " pos_x=82,\n", " pos_y=116,\n", " sigma_x=15,\n", " sigma_y=23,\n", " apply=True # Use apply=False for interactive mode\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the scan again for the new changes to apply to all the images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "res_xarray = sps.load_scan(\n", " scan=4450,\n", " path=path,\n", " apply_fft_filter=True\n", ")\n", "\n", "plt.figure()\n", "res_xarray[:,:,0].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can e.g. also get a plot along the third dimension, by integrating along the first.\n", "\n", "One can also access the conversion result from a class accessor:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.figure()\n", "sps.result.loc[{\"Angle\": slice(-5, 5)}].sum(axis=0).plot()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The metadata associated with the scan is added as an attribute to the xarray" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sps.result.attrs[\"metadata\"].keys()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Loading with selected iterations" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "3D scans, where the images are recorded as a function of a third parameter (generally delay or in this case, mirrorX), can also be loaded with an option to average only the given iterations passed as a list or slice object. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plt.figure()\n", "sps.load_scan(\n", " scan=4450,\n", " path=path,\n", " iterations=np.s_[0, 1:2],\n", ").sum(axis=2).plot()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Another useful functionality is to load a 3D scan as a function of iterations averaged over the scan parameter (in this case, mirrorX). This is done using the check_scan method" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "res_xarray_check = sps.check_scan(\n", " scan=4450,\n", " delays=0, # for a fixed delay of index, 1\n", " path=path,\n", ")\n", "plt.figure()\n", "res_xarray_check.loc[{\"Angle\": slice(-5, 5)}].sum(axis=(0)).plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Saving\n", "Data can be saved, e.g., as hdf5 files including metadata for convenient processing in other notebooks or software." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sps.load_scan(\n", " scan=4450, # Scan number for an example mirror scan\n", " path = path,\n", ")\n", "sps.save(\"example_data.h5\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "python3", "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.8.12" }, "vscode": { "interpreter": { "hash": "a164666994e9db75450cd7016dd7e51d42ea6e7c1e5e8017af1f8068ca906367" } } }, "nbformat": 4, "nbformat_minor": 2 }