tiling.py 4.59 KB
Newer Older
Valentin Valls's avatar
Valentin Valls committed
1
2
3
4
5
import typeguard
import typing
from bliss.scanning.group import Sequence
from bliss.controllers.lima.lima_base import Lima
from .tomoconfig import TomoConfig
6
from .presets import MoveAxisPreset
7
from tomo.helpers.nexuswriter_utils import hdf5_axis_name
Valentin Valls's avatar
Valentin Valls committed
8
9
10
11


@typeguard.typechecked
def tiling(
12
13
    xstart: float,
    xstop: float,
Valentin Valls's avatar
Valentin Valls committed
14
15
16
17
18
19
20
    ystart: float,
    ystop: float,
    zstart: float,
    zstop: float,
    detector: Lima,
    expo_time: float,
    tomoconfig: TomoConfig,
21
22
    n_dark: int = 3,
    n_flat: int = 3,
Valentin Valls's avatar
Valentin Valls committed
23
24
25
26
27
    sleep_time: typing.Optional[float] = None,
):
    """
    Scan a tomo sample stage using full field acquisition as tiled images.

28
    The sequence contains:
29
30
31

    - Few dark
    - Few flat
32
    - A 2D scan at rotation -90 (at this angle scanning sy is like scanning sx at rot 0)
33
    - Few flat
34
35
    - A 2D scan at rotation 0

Valentin Valls's avatar
Valentin Valls committed
36
    Arguments:
37
38
        xstart: X position to start in absolute coordinate of the sample stage (y-axis at -rot90)
        xstop: X position to stop in absolute coordinate of the sample stage (y-axis at -rot90)
Valentin Valls's avatar
Valentin Valls committed
39
40
41
42
43
44
45
46
47
        ystart: Y position to start in absolute coordinate of the sample stage
        ystop: Y position to stop in absolute coordinate of the sample stage
        zstart: Z position to start in absolute coordinate of the sample stage
        zstop: Z position to stop in absolute coordinate of the sample stage
        detector: Lima detector to use
        expo_time: Integration time for the Lima detector
        sleep_time: Time to wait between motor move before taking a new acquisition
        tomoconfig: Description of the tomo sample stage
    """
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    tomo_detector = tomoconfig.detectors.get_tomo_detector(detector)

    technique = {
        "y_axis_name": hdf5_axis_name(tomoconfig.y_axis, False),
        "z_axis_name": hdf5_axis_name(tomoconfig.z_axis, True),
        "sample_y_axis_name": hdf5_axis_name(tomoconfig.sample_y_axis, True),
        "rotation_axis_name": hdf5_axis_name(tomoconfig.rotation_axis, True),
        "exposure_time": expo_time,
        "exposure_time@units": "s",
        "detector_name": detector.name,
        "detector_size": tomo_detector.actual_size,
        "sample_pixel_size": tomo_detector.sample_pixel_size,
        "sample_pixel_size@units": "um",
        "subscans": {
            "scan1": {"type": "tomo:dark"},
            "scan2": {"type": "tomo:flat"},
            "scan3": {
                "type": "tomo:tiling:side",
                "vertical_range": [zstart, zstop],
                "vertical_range@units": "mm",
                "horizontal_range": [xstart, xstop],
                "horizontal_range@units": "mm",
            },
71
72
            "scan4": {"type": "tomo:flat"},
            "scan5": {
73
74
75
76
77
78
79
80
81
82
83
84
                "type": "tomo:tiling:front",
                "vertical_range": [zstart, zstop],
                "vertical_range@units": "mm",
                "horizontal_range": [ystart, ystop],
                "horizontal_range@units": "mm",
            },
        },
    }

    scan_info = {"tomotype": "tilingseq", "technique": technique}
    sequence = Sequence(title="tiling sequence", scan_info=scan_info)

85
86
87
88
89
    srot = tomoconfig.rotation_axis
    # FIXME: It would be better to normalize rot at dial 0 and -90
    rotationAt0 = MoveAxisPreset(srot, 0)
    rotationAt90 = MoveAxisPreset(srot, -90)

Valentin Valls's avatar
Valentin Valls committed
90
91
92
    with sequence.sequence_context() as scan_seq:

        dark_runner = tomoconfig.get_runner("dark")
93
        scan = dark_runner(expo_time, n_dark, detector, run=False)
Valentin Valls's avatar
Valentin Valls committed
94
95
96
97
        scan_seq.add(scan)
        scan.run()

        flat_runner = tomoconfig.get_runner("flat")
98
        scan = flat_runner(expo_time, n_flat, detector, run=False)
Valentin Valls's avatar
Valentin Valls committed
99
100
101
102
        scan_seq.add(scan)
        scan.run()

        tiling_runner = tomoconfig.get_runner("tiling")
103
104
105
106
107
108
109
110
111
112
113
114
115
116
        scan = tiling_runner(
            expo_time=expo_time,
            tomo_detector=tomo_detector,
            zstart=zstart,
            zstop=zstop,
            ystart=xstart,
            ystop=xstop,
            sleep_time=sleep_time,
            run=False,
        )
        scan.add_preset(rotationAt90)
        scan_seq.add(scan)
        scan.run()

117
        flat_runner = tomoconfig.get_runner("flat")
118
        scan = flat_runner(expo_time, n_flat, detector, run=False)
119
120
121
        scan_seq.add(scan)
        scan.run()

122
        tiling_runner = tomoconfig.get_runner("tiling")
Valentin Valls's avatar
Valentin Valls committed
123
124
125
126
127
128
129
130
131
132
        scan = tiling_runner(
            expo_time=expo_time,
            tomo_detector=tomo_detector,
            zstart=zstart,
            zstop=zstop,
            ystart=ystart,
            ystop=ystop,
            sleep_time=sleep_time,
            run=False,
        )
133
        scan.add_preset(rotationAt0)
Valentin Valls's avatar
Valentin Valls committed
134
135
        scan_seq.add(scan)
        scan.run()
136

Valentin Valls's avatar
Valentin Valls committed
137
    return scan