/usr/bin/diff_tomo is in pyfai 0.13.0+dfsg-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | #!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Project: Azimuthal integration
# https://github.com/kif/pyFAI
#
# Copyright (C) European Synchrotron Radiation Facility, Grenoble, France
#
# Authors: Jérôme Kieffer (Jerome.Kieffer@ESRF.eu)
# Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
diff_tomo
A tool for fast processing of diffraction tomography
"""
__author__ = "Jerome Kieffer"
__contact__ = "Jerome.Kieffer@ESRF.eu"
__license__ = "GPLv3+"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "27/11/2015"
__satus__ = "Production"
import logging
import os
import sys
import glob
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("diff_tomo")
from pyFAI import version as PyFAI_VERSION
from pyFAI import date as PyFAI_DATE
from pyFAI.diffmap import DiffMap
try:
from argparse import ArgumentParser
except ImportError:
from pyFAI.third_party.argparse import ArgumentParser
if sys.version_info[0] < 3:
bytes = str
from urlparse import urlparse
else:
from urllib.parse import urlparse
class DiffTomo(DiffMap):
"""
Basic class for diffraction tomography experiment using pyFAI.
"""
def __init__(self, nTrans=1, nRot=1, nDiff=1000):
"""
Constructor of the class
@param nTrans: number of translations
@param nRot: number of translations
@param nDiff: number of points in diffraction pattern
"""
DiffMap.__init__(self, npt_slow=nRot, npt_fast=nTrans, npt_rad=nDiff)
self.hdf5path = "diff_tomo/data/sinogram"
self.experiment_title = "Diffraction Tomography"
self.slow_motor_name = "rotation"
self.fast_motor_name = "translation"
def parse(self, *args, **kwargs):
"""
parse options from command line
"""
description = """Azimuthal integration for diffraction tomography.
Diffraction tomography is an experiment where 2D diffraction patterns are recorded
while performing a 2D scan, one (the slowest) in rotation around the sample center
and the other (the fastest) along a translation through the sample.
Diff_tomo is a script (based on pyFAI and h5py) which allows the reduction of this
4D dataset into a 3D dataset containing the rotations angle (hundreds), the translation step (hundreds)
and the many diffraction angles (thousands).
The resulting dataset can be opened using the PyMca ROItool
where the 1d dataset has to be selected as last dimension.
The output file aims at being NeXus compliant.
This tool can be used for mapping experiments if one considers the slow scan
direction as the rotation. but the *diff_map* tool provides in addition a graphical
user interface.
"""
epilog = """If the number of files is too large, use double quotes "*.edf" """
usage = """diff_tomo [options] -p ponifile imagefiles*"""
version = "diff_tomo from pyFAI version %s: %s" % (PyFAI_VERSION, PyFAI_DATE)
parser = ArgumentParser(usage=usage, description=description, epilog=epilog)
parser.add_argument("-V", "--version", action='version', version=version)
parser.add_argument("args", metavar="FILE", help="List of files to calibrate", nargs='+')
parser.add_argument("-o", "--output", dest="outfile",
help="HDF5 File where processed sinogram was saved, by default diff_tomo.h5",
metavar="FILE", default="diff_tomo.h5")
parser.add_argument("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="switch to verbose/debug mode, defaut: quiet")
parser.add_argument("-P", "--prefix", dest="prefix",
help="Prefix or common base for all files",
metavar="FILE", default="", type=str)
parser.add_argument("-e", "--extension", dest="extension",
help="Process all files with this extension",
default="")
parser.add_argument("-t", "--nTrans", dest="nTrans",
help="number of points in translation. Mandatory", default=None)
parser.add_argument("-r", "--nRot", dest="nRot",
help="number of points in rotation. Mandatory", default=None)
parser.add_argument("-c", "--nDiff", dest="nDiff",
help="number of points in diffraction powder pattern, Mandatory",
default=None)
parser.add_argument("-d", "--dark", dest="dark", metavar="FILE",
help="list of dark images to average and subtract",
default=None)
parser.add_argument("-f", "--flat", dest="flat", metavar="FILE",
help="list of flat images to average and divide",
default=None)
parser.add_argument("-m", "--mask", dest="mask", metavar="FILE",
help="file containing the mask, no mask by default", default=None)
parser.add_argument("-p", "--poni", dest="poni", metavar="FILE",
help="file containing the diffraction parameter (poni-file), Mandatory",
default=None)
parser.add_argument("-O", "--offset", dest="offset",
help="do not process the first files", default=None)
parser.add_argument("-g", "--gpu", dest="gpu", action="store_true",
help="process using OpenCL on GPU ", default=False)
parser.add_argument("-S", "--stats", dest="stats", action="store_true",
help="show statistics at the end", default=False)
options = parser.parse_args()
args = options.args
if options.verbose:
logger.setLevel(logging.DEBUG)
self.hdf5 = options.outfile
if options.dark:
dark_files = [os.path.abspath(urlparse(f).path)
for f in options.dark.split(",")
if os.path.isfile(urlparse(f).path)]
if dark_files:
self.dark = dark_files
else:
raise RuntimeError("No such dark files")
if options.flat:
flat_files = [os.path.abspath(urlparse(f).path)
for f in options.flat.split(",")
if os.path.isfile(urlparse(f).path)]
if flat_files:
self.flat = flat_files
else:
raise RuntimeError("No such flat files")
self.use_gpu = options.gpu
self.inputfiles = []
for fn in args:
f = urlparse(fn).path
if os.path.isfile(f) and f.endswith(options.extension):
self.inputfiles.append(os.path.abspath(f))
elif os.path.isdir(f):
self.inputfiles += [os.path.abspath(os.path.join(f, g)) for g in os.listdir(f) if g.endswith(options.extension) and g.startswith(options.prefix)]
else:
self.inputfiles += [os.path.abspath(f) for f in glob.glob(f)]
self.inputfiles.sort(key=self.to_tuple)
if not self.inputfiles:
raise RuntimeError("No input files to process, try --help")
if options.mask:
mask = urlparse(options.mask).path
if os.path.isfile(mask):
logger.info("Reading Mask file from: %s" % mask)
self.mask = os.path.abspath(mask)
else:
logger.warning("No such mask file %s" % mask)
if options.poni:
if os.path.isfile(options.poni):
logger.info("Reading PONI file from: %s" % options.poni)
self.poni = options.poni
else:
logger.warning("No such poni file %s" % options.poni)
if options.nTrans is not None:
self.npt_fast = int(options.nTrans)
if options.nRot is not None:
self.npt_slow = int(options.nRot)
if options.nDiff is not None:
self.npt_rad = int(options.nDiff)
if options.offset is not None:
self.offset = int(options.offset)
else:
self.offset = 0
self.stats = options.stats
return options
if __name__ == "__main__":
dt = DiffTomo()
dt.parse()
dt.setup_ai()
dt.makeHDF5()
dt.process()
dt.show_stats()
|