{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Read data from an EDF acquisition\n", "\n", "\n", "To create a 'Scan' object from EDF you have to use the :class:`EDFTomoScan` class and provide the path to the acquisition\n", "\n", "WARNING: Browsing EDF files is based on several convention at ESRF.\n", " The most important one is that the acquisition 'identification' - which is the folder name is repeated in the file names.\n", " For example if we have an acquisition names 'acq_0005' we expect edf file prefix to be 'acq_0005' too.\n", "\n", "WARNING: The :class:`EDFTomoScan` has been tested on EDF single frame files. It wouldn't be surprising if it fails on EDF multiple frames files.\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using matplotlib backend: Qt5Agg\n", "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "# %pylab # to use imshow uncomment" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get a simple dataset for test (this dataset is a pure noise)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from tomoscan.tests.datasets import GitlabDataset\n", "import os\n", "\n", "data_dir = GitlabDataset.get_dataset(\"edf_datasets/test10\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## create an instance of `EDFTomoScan`\n", "\n", "`EDFTomoScan` implements the TomoScanBase interface.\n", "This allow you to have a common API for accessing data from EDF or HDF5 regardless of the type of acquisition." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from tomoscan.esrf.scan.edfscan import EDFTomoScan\n", "scan = EDFTomoScan(scan=data_dir)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then from it you can access several information" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### projections" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{3: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100003.edf', data_path=None, data_slice=[0]),\n", " 27: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100027.edf', data_path=None, data_slice=[0]),\n", " 0: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100000.edf', data_path=None, data_slice=[0]),\n", " 31: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100031.edf', data_path=None, data_slice=[0]),\n", " 20: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100020.edf', data_path=None, data_slice=[0]),\n", " 25: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100025.edf', data_path=None, data_slice=[0]),\n", " 7: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100007.edf', data_path=None, data_slice=[0]),\n", " 19: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100019.edf', data_path=None, data_slice=[0]),\n", " 8: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100008.edf', data_path=None, data_slice=[0]),\n", " 5: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100005.edf', data_path=None, data_slice=[0]),\n", " 4: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100004.edf', data_path=None, data_slice=[0]),\n", " 22: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100022.edf', data_path=None, data_slice=[0]),\n", " 26: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100026.edf', data_path=None, data_slice=[0]),\n", " 32: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100032.edf', data_path=None, data_slice=[0]),\n", " 14: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100014.edf', data_path=None, data_slice=[0]),\n", " 18: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100018.edf', data_path=None, data_slice=[0]),\n", " 30: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100030.edf', data_path=None, data_slice=[0]),\n", " 2: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100002.edf', data_path=None, data_slice=[0]),\n", " 16: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100016.edf', data_path=None, data_slice=[0]),\n", " 15: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100015.edf', data_path=None, data_slice=[0]),\n", " 23: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100023.edf', data_path=None, data_slice=[0]),\n", " 11: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100011.edf', data_path=None, data_slice=[0]),\n", " 13: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100013.edf', data_path=None, data_slice=[0]),\n", " 1: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100001.edf', data_path=None, data_slice=[0]),\n", " 17: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100017.edf', data_path=None, data_slice=[0]),\n", " 24: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100024.edf', data_path=None, data_slice=[0]),\n", " 12: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100012.edf', data_path=None, data_slice=[0]),\n", " 9: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100009.edf', data_path=None, data_slice=[0]),\n", " 29: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100029.edf', data_path=None, data_slice=[0]),\n", " 21: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100021.edf', data_path=None, data_slice=[0]),\n", " 28: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100028.edf', data_path=None, data_slice=[0]),\n", " 10: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100010.edf', data_path=None, data_slice=[0]),\n", " 6: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/test100006.edf', data_path=None, data_slice=[0])}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scan.projections" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This return a dictionary of projection index and DataUrl.\n", "You can access the data using `silx.io.utils.get_data function`" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from silx.io.utils import get_data\n", "frame_18_data = get_data(scan.projections[18])\n", "# imshow(frame_28_data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### darks" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scan.darks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### flats" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{20: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/refHST0020.edf', data_path=None, data_slice=[0]),\n", " 10: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/refHST0010.edf', data_path=None, data_slice=[0]),\n", " 0: DataUrl(valid=True, scheme='fabio', file_path='/home/payno/dev/tomo/tomoscan/tomoscan/test/test10/refHST0000.edf', data_path=None, data_slice=[0])}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scan.flats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### energy (in keV)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "19.0" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scan.energy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### pixel size (in )" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.00030199999999999997" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scan.get_pixel_size(unit='cm')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is more information that you can access, to get them all please have a look on the [TomwerScanBase API](https://tomotools.gitlab-pages.esrf.fr/tomoscan/modules/scanbase.html#tomoscan.scanbase.TomoScanBase) and [EDFTomoScan API](https://tomotools.gitlab-pages.esrf.fr/tomoscan/modules/esrf.html#tomoscan.esrf.edfscan.EDFTomoScan)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }