{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# -*- coding: utf-8 -*-\n", "# Copyright 2024 United Kingdom Research and Innovation\n", "# Copyright 2024 The University of Manchester\n", "#\n", "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", "# http://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License.\n", "#\n", "# Authored by: Hannah Robarts (UKRI-STFC)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load and visualise data with NikonDataReader\n", "This how-to shows how to use the `NikonDataReader` to load data from Nikon .xtekct files and quickly visualise the data and geometry\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get the example dataset `dataexample.KORN` using `download_data()`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from cil.utilities import dataexample\n", "dataexample.KORN.download_data(data_dir='../data', prompt=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now set up the `NikonDataReader()` to read an .xtekct file." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from cil.io import NikonDataReader\n", "file_name = '../data/korn/Korn i kasse/47209 testscan korn01_recon.xtekct'\n", "data_reader = NikonDataReader(file_name=file_name)\n", "data = data_reader.read()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check the data has been loaded correctly by viewing the geometry with `show_geometry()` to display information about the source and detector setup." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from cil.utilities.display import show_geometry\n", "show_geometry(data.geometry)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And view a central projection of the data with `show2D()`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from cil.utilities.display import show2D\n", "show2D(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default the `NikonDataReader` argument `normalise` is `True`, which means all projections are loaded and normalised by the detector white level, which is stored in the .xtekct file as WhiteLevel. If you want to load the data without normalisation, specify `normalise=False`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "file_name = '../data/korn/Korn i kasse/47209 testscan korn01_recon.xtekct'\n", "data_reader = NikonDataReader(file_name=file_name, normalise=False)\n", "data = data_reader.read()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "show2D(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the `roi` argument to load a subset of the data. `roi`should be passed as a dictionary e.g. `{'axis_labels_1': (start, end, step),'axis_labels_2': (start, end, step)}` with axis labels that describe the data dimension labels\n", "\n", "To load a cropped subset of the data, change the start and end values. 'axis_label': -1 is a shortcut to load all elements along the axis." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = {'horizontal':(120, 870, 1), 'vertical':-1}\n", "data_reader = NikonDataReader(file_name=file_name, roi=roi)\n", "data = data_reader.read()\n", "show2D(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To load a binned subset of the data, change the step value. Here we use different binning for the horizontal and vertical dimensions which results in a different aspect ratio" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "roi = {'horizontal':(None, None, 4), 'vertical':(None, None, 2)}\n", "data_reader = NikonDataReader(file_name=file_name, roi=roi)\n", "data = data_reader.read()\n", "show2D(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also use the argument `fliplr=True` to flip all projections in the vertical axis. If we enable this option we see that the projection is flipped in the left-right direction/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_reader = NikonDataReader(file_name=file_name, fliplr=True)\n", "data = data_reader.read()\n", "show2D(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sometimes we might want to load the geometry from the Nikon file without loading the data, for example if we want to load the raw data files separately and use the geometry from the .xtekct file. We can do this by instantiating the data reader and calling `get_geometry()`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_reader = NikonDataReader(file_name=file_name)\n", "ag = data_reader.get_geometry()\n", "show_geometry(ag)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Uncomment the cell below to delete the dataset and its folder" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# import shutil\n", "# shutil.rmtree('../data/korn')" ] } ], "metadata": { "kernelspec": { "display_name": "cil_demos", "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.12.7" } }, "nbformat": 4, "nbformat_minor": 2 }