Access Scan Data¶
A guide to accessing scan data after acquisition. This guide assumes you are comfortable with running a simple scan and observing the live data.
Goal
Learn how to access the data from your scans after they have finished.
Steps¶
0. Run a scan¶
For an intro to running scans, see the example linked above. We will use the scan from that example, but assign it to a variable in our console:
scan_report = scans.line_scan(dev.samx, -1, 1, steps=5, exp_time=0.1, relative=False)
1. Inspect the output from a scan you have just run¶
Having run the scan above, we can see inspect its status:
scan_report
ScanReport:
--------------------
Status: COMPLETED
Start time: ...
End time: ...
Elapsed time: ... s
Scan ID: ...
Scan number: ...
Number of points: 5
File: ...
2. Inspect the latest scan from history¶
Fetch the most recent scan history entry:
latest = bec.history[-1]
latest
ScanDataContainer:
Start time: ...
End time: ...
Elapsed time: ... s
Scan ID: ...
Scan number: ...
Scan name: line_scan
Status: closed
Number of points (monitored): 5
File: ...
This gives you a handle to the scan data after execution.
Scan history is a list of all past scans
bec.history behaves like a normal Python list. Index 0 accesses the first stored scan, while negative indices such as -1
access entries from the end, so bec.history[-1] gives you the most recent scan.
3. Read one signal from the stored result¶
For example, inspect the recorded motor values for samx:
This returns arrays of timestamps and values collected during the scan, which you can use for further analysis:
latest.devices.samx.samx.read()
{'timestamp': array([1.77496343e+09, 1.77496343e+09, 1.77496343e+09, 1.77496344e+09,
1.77496344e+09]),
'value': array([-0.99140924, -0.49119309, -0.00282538, 0.49814051, 0.99329906])}
Each entry represents one sampled point from the scan, so history is not just a final snapshot. It preserves the full recorded series for later plotting, fitting, or custom analysis workflows.
4. Access the stored data¶
For each scan, an HDF5 file is written containing all the recorded signals and additional metadata about the scan which
was run. It can be found in the File: entry in the scan report, both for an active scan and one obtained from the
history. You can open this file with your preferred HDF5 viewer, or with h5py in Python. For an introduction to working with the BEC HDF5 file structure, see Open BEC HDF5 files with h5py and Open BEC HDF5 files with silx for a GUI-based approach.
Success
You have successfully accessed previous scans through bec.history, and know how to access the recorded data from your scans after they have finished. You can now use this data for further analysis, plotting, or custom workflows.