Important

You can run this notebook in a live session Binder or view it on nbviewer or GitHub.

Supplemental Data

In this notebook you will:

  • Run some simulated experiments including supplemental baseline readings and an asynchronously monitored signal.

  • Access the saved data.

Configuration

Below, we will connect to EPICS IOC(s) controlling simulated hardware in lieu of actual motors, detectors. The IOCs should already be running in the background. Run this command to verify that they are running: it should produce output with RUNNING on each line. In the event of a problem, edit this command to replace status with restart all and run again.

[1]:
!supervisorctl -c supervisor/supervisord.conf status
decay                            RUNNING   pid 4872, uptime 0:04:20
mini_beamline                    RUNNING   pid 4873, uptime 0:04:20
random_walk                      RUNNING   pid 4874, uptime 0:04:20
random_walk_horiz                RUNNING   pid 4875, uptime 0:04:20
random_walk_vert                 RUNNING   pid 4876, uptime 0:04:20
simple                           RUNNING   pid 4877, uptime 0:04:20
thermo_sim                       RUNNING   pid 4878, uptime 0:04:20
trigger_with_pc                  RUNNING   pid 4879, uptime 0:04:20
[2]:
%run scripts/beamline_configuration.py
[3]:
sd
[3]:
SupplementalData(baseline=[], monitors=[], flyers=[])

Baseline Readings

Now, at the beginning and end of every run, record the positions of these motors.

[4]:
sd.baseline = [mtr_spotx, mtr_spoty]
[5]:
# run a similar scan as other exercises
plt.figure('ph_det vs motor_ph')
RE(scan([ph], motor_ph, -1, 1, 5))


Transient Scan ID: 28     Time: 2020-06-05 15:47:37
Persistent Unique Scan ID: '353b0b99-3ba1-4548-a487-7a1c8335307d'
New stream: 'baseline'
Start-of-run baseline readings:
+--------------------------------+--------------------------------+
|                    motor_spotx | 1.0                            |
|                    motor_spoty | 0.0                            |
+--------------------------------+--------------------------------+
New stream: 'primary'
+-----------+------------+------------+------------+
|   seq_num |       time |   motor_ph |     ph_det |
+-----------+------------+------------+------------+
|         1 | 15:47:37.6 |     -1.000 |     102613 |
|         2 | 15:47:37.6 |     -0.500 |     104431 |
|         3 | 15:47:37.7 |      0.000 |     104346 |
|         4 | 15:47:37.7 |      0.500 |     104036 |
|         5 | 15:47:37.7 |      1.000 |     102796 |
+-----------+------------+------------+------------+
generator scan ['353b0b99'] (scan num: 28)
End-of-run baseline readings:
+--------------------------------+--------------------------------+
|                    motor_spotx | 1.0                            |
|                    motor_spoty | 0.0                            |
+--------------------------------+--------------------------------+



[5]:
('353b0b99-3ba1-4548-a487-7a1c8335307d',)

Notice

New stream: 'baseline'

as well as the boxes of readings. How can we access that data later? It doesn’t show up in the table!

[6]:
# Let's show the plot again so you can refer back to it when looking at the tables.
plt.gcf()
[6]:
_images/Supplemental_Data_8_0.png
[7]:
db[-1].table()
[7]:
time motor_ph ph_det
seq_num
1 2020-06-05 15:47:37.674469948 -1.0 102613.0
2 2020-06-05 15:47:37.689902067 -0.5 104431.0
3 2020-06-05 15:47:37.702738285 0.0 104346.0
4 2020-06-05 15:47:37.745059252 0.5 104036.0
5 2020-06-05 15:47:37.782876968 1.0 102796.0
[8]:
db[-1].table('primary')  # the default
[8]:
time motor_ph ph_det
seq_num
1 2020-06-05 15:47:37.674469948 -1.0 102613.0
2 2020-06-05 15:47:37.689902067 -0.5 104431.0
3 2020-06-05 15:47:37.702738285 0.0 104346.0
4 2020-06-05 15:47:37.745059252 0.5 104036.0
5 2020-06-05 15:47:37.782876968 1.0 102796.0
[9]:
db[-1].table('baseline')
[9]:
time motor_spotx motor_spoty
seq_num
1 2020-06-05 15:47:37.613499165 1.0 0.0
2 2020-06-05 15:47:37.817860126 1.0 0.0

If the table gets too wide, it’s handy to know how to take the transpose of a DataFrame.

[10]:
db[-1].table('baseline').T
[10]:
seq_num 1 2
time 2020-06-05 15:47:37.613499165 2020-06-05 15:47:37.817860126
motor_spotx 1 1
motor_spoty 0 0

Asynchronous Monitoring

[11]:
sd.monitors = [I]
[12]:
RE(scan([ph], motor_ph, -1, 1, 10))


Transient Scan ID: 29     Time: 2020-06-05 15:47:38
Persistent Unique Scan ID: 'f0376e2d-bd57-471e-8f02-851740924a4d'
New stream: 'baseline'
Start-of-run baseline readings:
+--------------------------------+--------------------------------+
|                    motor_spotx | 1.0                            |
|                    motor_spoty | 0.0                            |
+--------------------------------+--------------------------------+
New stream: 'I_monitor'
New stream: 'primary'
+-----------+------------+------------+------------+
|   seq_num |       time |   motor_ph |     ph_det |
+-----------+------------+------------+------------+
|         1 | 15:47:38.5 |     -1.000 |     100164 |
|         2 | 15:47:38.6 |     -0.778 |      99927 |
|         3 | 15:47:38.6 |     -0.556 |     100469 |
|         4 | 15:47:38.6 |     -0.333 |     100520 |
|         5 | 15:47:38.6 |     -0.111 |     101320 |
|         6 | 15:47:38.6 |      0.111 |     101110 |
|         7 | 15:47:38.7 |      0.333 |     100510 |
|         8 | 15:47:38.7 |      0.556 |     100243 |
|         9 | 15:47:38.7 |      0.778 |      99358 |
|        10 | 15:47:38.8 |      1.000 |      97882 |
+-----------+------------+------------+------------+
generator scan ['f0376e2d'] (scan num: 29)
End-of-run baseline readings:
+--------------------------------+--------------------------------+
|                    motor_spotx | 1.0                            |
|                    motor_spoty | 0.0                            |
+--------------------------------+--------------------------------+



[12]:
('f0376e2d-bd57-471e-8f02-851740924a4d',)

Notice

New stream: 'I_monitor'

and a new figure. But the Best-Effort Callback doesn’t show us the numbers from monitor readings. (There’s just not enough room.)

[13]:
h = db[-1]
h.table('I_monitor')
[13]:
time I
seq_num
1 2020-06-05 15:47:38.450299025 513.404551
2 2020-06-05 15:47:38.452636480 513.404551
3 2020-06-05 15:47:38.465982437 509.921099
4 2020-06-05 15:47:38.553429604 506.182499
5 2020-06-05 15:47:38.652632713 502.311770
6 2020-06-05 15:47:38.757848740 498.355962

What streams do we have? Another good Header method to know:

[14]:
h.stream_names
[14]:
['baseline', 'primary', 'I_monitor']

Exercises

  1. Add mtr_slit to the list of things to be recorded as baseline readings.

[ ]:

[15]:
%load solutions/add_baseline_device.py
  1. Remove mtr_slit from the list of things to be recorded as baseline readings.

[ ]:

[16]:
%load solutions/remove_baseline_device.py
  1. Empty the list of things to be monitored.

[ ]:

[17]:
%load solutions/clear_supplemental_monitors.py