Skip to content

smalldata

Tasks for working with SmallData HDF5 files.

Classes defined in this module provide an interface to extracting data from SmallData files and analyzing it.

Classes:

Name Description
AnalyzeSmallDataXSS

Analyze scattering data for a single detector in a SmallData file.

AnalyzeSmallDataXAS

Analyze absorption data for a single detector in a SmallData file.

AnalyzeSmallDataXES

Analyze emission data for a single detector in a SmallData file.

AnalyzeSmallDataXAS

Bases: AnalyzeSmallData

Task to analyze XAS data stored in a SmallData HDF5 file.

Source code in lute/tasks/smalldata.py
 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
class AnalyzeSmallDataXAS(AnalyzeSmallData):
    """Task to analyze XAS data stored in a SmallData HDF5 file."""

    def __init__(self, *, params: TaskParameters, use_mpi: bool = True) -> None:
        super().__init__(params=params, use_mpi=use_mpi)

    def _pre_run(self) -> None:
        # Currently scattering data is extracted as standard since its used
        # for all analysis types (XSS, XAS, XES,...)
        self._extract_standard_data()
        self._extract_xas(self._task_parameters.xas_detname)

    def _run(self) -> None:
        # XAS returns two sets of binned data
        # Bins raw TR-XAS first, then bins by scan
        diff: Optional[np.ndarray[np.float64]]
        ccm_bins: Optional[np.ndarray[np.float64]]
        laser_on: Optional[np.ndarray[np.float64]]
        laser_off: Optional[np.ndarray[np.float64]]
        ccm_bins, diff, laser_on, laser_off = self._calc_binned_difference_xas()

        # We check None on ccm_bins because the monochromator is not always
        # scanned -> We return None if there aren't enough bins to be worth
        # plotting
        if self._mpi_size > 1 and ccm_bins is not None:
            diff = self._mpi_comm.reduce(diff, op=MPI.SUM)
            laser_on = self._mpi_comm.reduce(laser_on, op=MPI.SUM)
            laser_off = self._mpi_comm.reduce(laser_off, op=MPI.SUM)

        all_plots: List[ElogSummaryPlots] = []
        run: int
        try:
            run = int(self._task_parameters.lute_config.run)
        except ValueError:
            run = 0
        plot_display_name: str
        exp_run: str
        if self._mpi_rank == 0 and ccm_bins is not None:
            # Check None again
            diff /= self._mpi_size
            laser_on /= self._mpi_size
            laser_off /= self._mpi_size
            plots: pn.Tabs = self.plot_all_xas(laser_on, laser_off, ccm_bins, diff)
            exp_run = f"{run:04d}_XAS"
            plot_display_name = f"XAS/{exp_run}"
            all_plots.append(ElogSummaryPlots(plot_display_name, plots))

        scan_bins: Optional[np.ndarray[np.float64]]
        scan_bins, diff, laser_on, laser_off = self._calc_scan_binned_difference_xas()
        if self._mpi_size > 1 and scan_bins is not None:
            diff = self._mpi_comm.reduce(diff, op=MPI.SUM)
            laser_on = self._mpi_comm.reduce(laser_on, op=MPI.SUM)
            laser_off = self._mpi_comm.reduce(laser_off, op=MPI.SUM)

        if self._mpi_rank == 0 and scan_bins is not None:
            plots: pn.Tabs = self.plot_xas_scan_hv(laser_on, laser_off, scan_bins, diff)
            name: str = self._scan_var_name if self._scan_var_name else "By_Event"
            exp_run = f"{run:04d}_{name}_XAS"
            if "lens" in name:
                plot_display_name = f"lens_scans/{exp_run}"
            elif "lxe_opa" in name:
                plot_display_name = f"power_scans/{exp_run}"
            else:
                plot_display_name = f"time_scans/{exp_run}"

            all_plots.append(ElogSummaryPlots(plot_display_name, plots))
        self._result.payload = all_plots

    def _post_run(self) -> None: ...

AnalyzeSmallDataXES

Bases: AnalyzeSmallData

Task to analyze XES data stored in a SmallData HDF5 file.

Source code in lute/tasks/smalldata.py
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
class AnalyzeSmallDataXES(AnalyzeSmallData):
    """Task to analyze XES data stored in a SmallData HDF5 file."""

    def __init__(self, *, params: TaskParameters, use_mpi: bool = True) -> None:
        super().__init__(params=params, use_mpi=use_mpi)

    def _pre_run(self) -> None:
        # Currently scattering data is extracted as standard since its used
        # for all analysis types (XSS, XAS, XES,...)
        self._extract_standard_data()
        self._extract_xes(self._task_parameters.xes_detname)

    def _run(self) -> None:
        # XES returns two sets of data
        # Average TR-XES first, then bins by scan variable
        diff: np.ndarray[np.float64]
        laser_on: np.ndarray[np.float64]
        laser_off: np.ndarray[np.float64]
        diff, laser_on, laser_off = self._calc_avg_difference_xes()

        if self._mpi_size > 1:
            diff = self._mpi_comm.reduce(diff, op=MPI.SUM)
            laser_on = self._mpi_comm.reduce(laser_on, op=MPI.SUM)
            laser_off = self._mpi_comm.reduce(laser_off, op=MPI.SUM)

        all_plots: List[ElogSummaryPlots] = []
        run: int
        try:
            run = int(self._task_parameters.lute_config.run)
        except ValueError:
            run = 0
        plot_display_name: str
        exp_run: str
        if self._mpi_rank == 0:
            diff /= self._mpi_size
            laser_on /= self._mpi_size
            laser_off /= self._mpi_size
            energy_bins: Optional[np.ndarray[np.float64]] = None
            plots: pn.Tabs = self.plot_xes_hv(laser_on, laser_off, energy_bins, diff)
            exp_run = f"{run:04d}_XES"
            plot_display_name = f"XES/{exp_run}"
            all_plots.append(ElogSummaryPlots(plot_display_name, plots))

        scan_bins: np.ndarray[np.float64]
        scan_bins, diff, laser_on, laser_off = self._calc_scan_binned_difference_xes()
        if self._mpi_size > 1:
            diff = self._mpi_comm.reduce(diff, op=MPI.SUM)
            laser_on = self._mpi_comm.reduce(laser_on, op=MPI.SUM)
            laser_off = self._mpi_comm.reduce(laser_off, op=MPI.SUM)

        if self._mpi_rank == 0:
            plots: pn.Tabs = self.plot_xes_scan_hv(laser_on, laser_off, scan_bins, diff)
            name: str = self._scan_var_name if self._scan_var_name else "By_Event"
            exp_run = f"{run:04d}_{name}_XES"
            if "lens" in name:
                plot_display_name = f"lens_scans/{exp_run}"
            elif "lxe_opa" in name:
                plot_display_name = f"power_scans/{exp_run}"
            else:
                plot_display_name = f"time_scans/{exp_run}"

            all_plots.append(ElogSummaryPlots(plot_display_name, plots))
        self._result.payload = all_plots

    def _post_run(self) -> None: ...

AnalyzeSmallDataXSS

Bases: AnalyzeSmallData

Task to analyze XSS profiles stored in a SmallData HDF5 file.

Source code in lute/tasks/smalldata.py
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
class AnalyzeSmallDataXSS(AnalyzeSmallData):
    """Task to analyze XSS profiles stored in a SmallData HDF5 file."""

    def __init__(self, *, params: TaskParameters, use_mpi: bool = True) -> None:
        super().__init__(params=params, use_mpi=use_mpi)

    def _pre_run(self) -> None:
        # Currently scattering data is extracted as standard since its used
        # for all analysis types (XSS, XAS, XES,...)
        self._extract_standard_data()

    def _run(self) -> None:
        diff: np.ndarray[np.float64]
        bins: np.ndarray[np.float64]
        laser_on: np.ndarray[np.float64]
        bins, diff, laser_on = self._calc_scan_binned_difference_xss()

        if self._mpi_size > 1:
            diff = self._mpi_comm.reduce(diff, op=sum_diff)
            laser_on = self._mpi_comm.reduce(laser_on, op=laser_on_mean)
        else:
            laser_on = np.nansum(laser_on, axis=0)

        if self._mpi_rank == 0:
            diff /= self._mpi_size
            laser_on /= self._total_num_events
            name: str = self._scan_var_name if self._scan_var_name else "By_Event"
            plots: pn.Tabs = self.plot_all_xss(laser_on, bins, diff, name)
            plot_display_name: str
            run: int
            try:
                run = int(self._task_parameters.lute_config.run)
            except ValueError:
                run = 0
            exp_run: str = f"{run:04d}_{name}_XSS"
            if "lens" in name:
                plot_display_name = f"lens_scans/{exp_run}"
            else:
                plot_display_name = f"time_scans/{exp_run}"

            self._result.payload = ElogSummaryPlots(plot_display_name, plots)