File: __init__.py

package info (click to toggle)
python-fabio 0.14.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,068 kB
  • sloc: python: 20,053; ansic: 1,085; makefile: 217; sh: 215
file content (93 lines) | stat: -rw-r--r-- 3,306 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python
# coding: utf-8
#
#    Copyright (C) European Synchrotron Radiation Facility, Grenoble, France
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

"""Benchmark for file reading"""

__author__ = "Jérôme Kieffer"
__date__ = "03/04/2020"
__license__ = "MIT"
__copyright__ = "2016-2020 European Synchrotron Radiation Facility, Grenoble, France"

import json
import sys
import time
import timeit
import os
import platform
import subprocess
import numpy
import fabio
import os.path as op
import logging

# To use use the locally build version of PyFAI, use ../bootstrap.py
try:
    from .. import open as fabio_open, version, date
except ImportError:
    from fabio import open as fabio_open, version, date
from ..test import utilstest

datasets = ["mb_LP_1_001.img",
            "Cr8F8140k103.0026",
            "run2_1_00148.cbf",
            "F2K_Seb_Lyso0675.edf",
            "fit2d_click.msk",
            "GE_aSI_detector_image_1529",
            "i01f0001.kcd",
            "example.mar2300",
            "corkcont2_H_0089.mccd",
            "b191_1_9_1.img",
            "image0001.pgm",
            "mgzn-20hpt.img",
            "oPPA_5grains_0001.tif",
            "XSDataImage.xml", ]

setup = """
import fabio
"""
stmt = "data = fabio.open(r'%s').data"


def run_benchmark(number=10, repeat=3):
    """
    :param number: Measure timimg over number of executions
    :param repeat: number of measurement, takes the best of them

    """
    print("Averaging over %i repetitions (best of %s)." % (number, repeat))
    print("Python %s" % sys.version)
    print("FabIO %s (%s)" % (version, date))
    print("#" * 80)
    print("     Module           filename        \t file size \t image size \t read time (ms) \t ms/Mpix")
    for img in datasets:
        fn = utilstest.UtilsTest.getimage(img)
        fimg = fabio_open(fn)
        file_size = os.stat(fn).st_size / 1.0e6  # MB
        img_size = fimg.data.size / 1.0e6  # Mpix
        timer = timeit.Timer(stmt % fn, setup + (stmt % fn))
        tmin = min([i / (0.001 * number) for i in timer.repeat(repeat=repeat, number=number)])
        print("%13s %25s %.3f Mb \t %.3f Mpix \t  %.3f ms \t %.3f ms/Mpix" %
              (fimg.__class__.__name__, img, file_size, img_size, tmin, tmin / img_size))


run = run_benchmark