{ "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", "# Copyright 2024 Technical University of Denmark\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 (STFC-UKRI)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load and visualise data with ZeissDataReader\n", "This how-to shows how to use the `ZeissDataReader` to load data from Zeiss .txrm files and quickly visualise the data and geometry" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get the example dataset `dataexample.WALNUT` using `download_data()`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from cil.utilities import dataexample\n", "dataexample.WALNUT.download_data(data_dir='../data', prompt=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now load a file from the dataset using the `ZEISSDataReader()`\n", "\n", "We specify the file to load using `file_name = '.walnut/valnut/valnut_2014-03-21_643_28/tomo-A/valnut_tomo-A.txrm\"`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from cil.io import ZEISSDataReader\n", "file_name = \"../data/walnut/valnut/valnut_2014-03-21_643_28/tomo-A/valnut_tomo-A.txrm\"\n", "data_reader = ZEISSDataReader(file_name=file_name)\n", "data = data_reader.read()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "View the geometry with `show_geometry` to display information about the source and detector setup\n" ] }, { "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": [ "View 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": [ "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':(200, 800, 1), 'vertical':-1}\n", "data_reader = ZEISSDataReader(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 = ZEISSDataReader(file_name=file_name, roi=roi)\n", "data = data_reader.read()\n", "show2D(data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sometimes we might want to just read the geometry from a Zeiss file, for example if we want to load the raw TIFF files separately but get the correct geometry from the .txrm file. We can do this by instantiating the data reader and using the `get_geometry()` method" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_reader = ZEISSDataReader(file_name=file_name)\n", "ag = data_reader.get_geometry()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "show_geometry(ag)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Uncomment the cell below to delete the dataset and its folder" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# import shutil\n", "# shutil.rmtree('../data/walnut')" ] } ], "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 }