Skip to content

Commit 9bc7a39

Browse files
Merge pull request #55 from rpanderson/example_IMAQdx_remote
Example labscript and analysis scripts for IMAQdxCamera and RemoteBLACS
2 parents 1189334 + 66d0be4 commit 9bc7a39

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import lyse
2+
from pathlib import Path
3+
import matplotlib.pyplot as plt
4+
5+
# Is this script being run from within an interactive lyse session?
6+
if lyse.spinning_top:
7+
# If so, use the filepath of the current shot
8+
h5_path = lyse.path
9+
else:
10+
# If not, get the filepath of the last shot of the lyse DataFrame
11+
df = lyse.data()
12+
h5_path = df.filepath.iloc[-1]
13+
14+
# Instantiate a lyse.Run object for this shot
15+
run = lyse.Run(h5_path)
16+
17+
# Get a dictionary of the global variables used in this shot
18+
run_globals = run.get_globals()
19+
20+
# Extract the images 'before' and 'after' generated from camera.expose
21+
before, after = run.get_images('camera', 'comparison', 'before', 'after')
22+
23+
# Compute the difference of the two images, after casting them to signed integers
24+
# (otherwise negative differences wrap to 2**16 - 1 - diff)
25+
diff = after.astype('int16') - before.astype('int16')
26+
27+
# Plot the row-wise mean of each image
28+
plt.plot(before.mean(axis=0), label='before')
29+
plt.plot(after.mean(axis=0), label='after')
30+
plt.xlabel('pixel coordinate (column)')
31+
plt.ylabel('counts')
32+
33+
# Label the plot with a unique string representing the shot
34+
plt.title(Path(run.h5_path).name)
35+
36+
# Plot adornments
37+
plt.legend(loc='lower left')
38+
plt.grid()
39+
40+
# Show the plot
41+
plt.show()
42+
43+
# Compute a result based on the image processing and save it to the 'results' group of
44+
# the shot file
45+
result = diff.std()
46+
run.save_result('foobar', result)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from labscript import start, stop, add_time_marker, Trigger, RemoteBLACS
2+
from labscript_devices.DummyPseudoclock.labscript_devices import DummyPseudoclock
3+
from labscript_devices.DummyIntermediateDevice import DummyIntermediateDevice
4+
from labscript_devices.IMAQdxCamera.labscript_devices import IMAQdxCamera
5+
6+
# Use a virtual ('dummy') device for the psuedoclock
7+
DummyPseudoclock(name='pseudoclock')
8+
9+
# An output of this DummyPseudoclock is its 'clockline' attribute, which we use
10+
# to trigger children devices
11+
DummyIntermediateDevice(name='intermediate_device', parent_device=pseudoclock.clockline)
12+
13+
# Instantiate a labscript.Trigger instance used to trigger the camera exposure
14+
# This will be specified as the camera's parent device later
15+
Trigger(
16+
name='camera_trigger', parent_device=intermediate_device, connection='port0/line0'
17+
)
18+
19+
# On the host specified below, start the RemoteBLACS server by running the following:
20+
# $ python - m labscript_utils.remote
21+
RemoteBLACS(name='test_remote', host='localhost')
22+
23+
# We then initiate an IMAQdxCamera using this RemoteBLACS instance
24+
# using mock=True to bypass any attempts to commmunicate with an
25+
# actual camera, and generate fake data at the end of the shot
26+
IMAQdxCamera(
27+
name='camera',
28+
parent_device=camera_trigger,
29+
connection='trigger',
30+
serial_number=0xDEADBEEF,
31+
worker=test_remote,
32+
mock=True,
33+
)
34+
35+
# Begin issuing labscript primitives
36+
# start() elicits the commencement of the shot
37+
start()
38+
39+
# Stop the experiment shot with stop()
40+
stop(1.0)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from labscript import start, stop, add_time_marker, Trigger, RemoteBLACS
2+
from labscript_devices.DummyPseudoclock.labscript_devices import DummyPseudoclock
3+
from labscript_devices.DummyIntermediateDevice import DummyIntermediateDevice
4+
from labscript_devices.IMAQdxCamera.labscript_devices import IMAQdxCamera
5+
6+
# Use a virtual ('dummy') device for the psuedoclock
7+
DummyPseudoclock(name='pseudoclock')
8+
9+
# An output of this DummyPseudoclock is its 'clockline' attribute, which we use
10+
# to trigger children devices
11+
DummyIntermediateDevice(name='intermediate_device', parent_device=pseudoclock.clockline)
12+
13+
# Instantiate a labscript.Trigger instance used to trigger the camera exposure
14+
# This will be specified as the camera's parent device later
15+
Trigger(
16+
name='camera_trigger', parent_device=intermediate_device, connection='port0/line0'
17+
)
18+
19+
# On the host specified below, start the RemoteBLACS server by running the following:
20+
# $ python - m labscript_utils.remote
21+
RemoteBLACS(name='test_remote', host='localhost')
22+
23+
# We then initiate an IMAQdxCamera using this RemoteBLACS instance
24+
# using mock=True to bypass any attempts to commmunicate with an
25+
# actual camera, and generate fake data at the end of the shot
26+
IMAQdxCamera(
27+
name='camera',
28+
parent_device=camera_trigger,
29+
connection='trigger',
30+
serial_number=0xDEADBEEF,
31+
worker=test_remote,
32+
mock=True,
33+
)
34+
35+
# Begin issuing labscript primitives
36+
# A timing variable t is used for convenience
37+
# start() elicits the commencement of the shot
38+
t = 0
39+
add_time_marker(t, "Start", verbose=True)
40+
start()
41+
42+
t += 1
43+
add_time_marker(t, "Exposure: 'before' image", verbose=True)
44+
camera.expose(t, name='comparison', frametype='before', trigger_duration=0.2)
45+
46+
t += 0.5
47+
add_time_marker(t, "Exposure: 'after' image", verbose=True)
48+
camera.expose(t, name='comparison', frametype='after', trigger_duration=0.2)
49+
50+
t += 0.5
51+
stop(t)

0 commit comments

Comments
 (0)