Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 59 additions & 34 deletions startup/98-user_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def user_fly_scan(
motor_r_out = motor_r_ini + out_r
"""
motor_r_ini = zps.pi_r.position
motor = [zps.sx, zps.sy, zps.sz, zps.pi_r, zps.pi_x]
motors = [zps.sx, zps.sy, zps.sz, zps.pi_r, zps.pi_x]

detectors = [Andor, ic3]
offset_angle = -2.0 * rs
Expand All @@ -277,7 +277,7 @@ def user_fly_scan(
# target_rot_angle = current_rot_angle + relative_rot_angle
_md = {
"detectors": ["Andor"],
"motors": [mot.name for mot in motor],
"motors": [mot.name for mot in motors],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
Expand Down Expand Up @@ -312,13 +312,13 @@ def user_fly_scan(

print("set rotation speed: {} deg/sec".format(rs))

@stage_decorator(list(detectors) + motor)
@stage_decorator(list(detectors) + motors)
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def inner_scan():
# close shutter, dark images: numer=chunk_size (e.g.20)
print("\nshutter closed, taking dark images...")
yield from _take_dark_image(detectors, motor, num_dark=1, simu=simu)
yield from _take_dark_image(detectors, motors, num_dark=1, simu=simu)

yield from mv(zps.pi_x, 0)
yield from mv(zps.pi_r, -50)
Expand All @@ -330,15 +330,15 @@ def inner_scan():
status = yield from abs_set(zps.pi_r, 50, wait=False)
yield from bps.sleep(2)
while not status.done:
yield from trigger_and_read(list(detectors) + motor)
yield from trigger_and_read(list(detectors) + motors)
# bkg images
print("\nTaking background images...")
yield from _set_rotation_speed(rs=30)
yield from mv(zps.pi_r, 0)

yield from mv(zps.pi_x, 12)
yield from mv(zps.pi_r, 70)
yield from trigger_and_read(list(detectors) + motor)
yield from trigger_and_read(list(detectors) + motors)

yield from _close_shutter(simu=simu)
yield from mv(zps.pi_r, 0)
Expand Down Expand Up @@ -728,7 +728,7 @@ def fly_scan2(
motor_z_out = out_z if not (out_z is None) else motor_z_ini
motor_r_out = out_r if not (out_r is None) else motor_r_ini

motor = [zps.sx, zps.sy, zps.sz, zps.pi_r]
motors = [zps.sx, zps.sy, zps.sz, zps.pi_r]

detectors = [Andor, ic3]
offset_angle = -2 * rs
Expand All @@ -737,7 +737,7 @@ def fly_scan2(
target_rot_angle = current_rot_angle + relative_rot_angle
_md = {
"detectors": ["Andor"],
"motors": [mot.name for mot in motor],
"motors": [mot.name for mot in motors],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
Expand Down Expand Up @@ -790,7 +790,9 @@ def fly_scan2(
yield from _set_rotation_speed(rs=rs)
print("set rotation speed: {} deg/sec".format(rs))

@stage_decorator(list(detectors) + motor)
# We manually stage the Andor detector below. See there for why....
# Stage everything else here in the usual way.
@stage_decorator([ic3] + motors])
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def fly_inner_scan():
Expand All @@ -799,6 +801,21 @@ def fly_inner_scan():
yield from mv(flt, 1)
yield from mv(flt, 1)
yield from abs_set(Andor.cam.num_images, chunk_size, wait=True)

# Manually stage the Andor. This creates a Resource document that
# continas the path to the HDF5 file where the detector writes. It also
# encodes the so-called 'frame_per_point' which here is what this plan
# calls chunk_size. The chunk_size CANNOT BE CHANGED later in the scan
# unless we unstage and re-stage the detector and generate a new
# Resource document.

# This approach imposes some unfortunate overhead (closing the HDF5
# file, opening a new one, going through all the steps to set the Area
# Detector's filepath PV, etc.). A better approach has been sketched
# in https://github.com/bluesky/area-detector-handlers/pull/11. It
# allows a single HDF5 file to contain multiple chunk_sizes.

yield from bps.stage(Andor)
yield from bps.sleep(1)

# open shutter, tomo_images
Expand All @@ -808,20 +825,26 @@ def fly_inner_scan():
status = yield from abs_set(zps.pi_r, target_rot_angle, wait=False)
yield from bps.sleep(2)
while not status.done:
yield from trigger_and_read(list(detectors) + motor)
yield from trigger_and_read(list(detectors) + motors)

# bkg images
print("\nTaking background images...")
yield from _set_rotation_speed(rs=rot_back_velo)
yield from abs_set(Andor.cam.num_images, 20, wait=True)

# Now that the new chunk_size has been set (20) create a new Resource
# document by unstage and re-staging the detector.
yield from bps.unstage(Andor)
yield from bps.stage(Andor)

yield from bps.sleep(1)
yield from _take_bkg_image(
motor_x_out,
motor_y_out,
motor_z_out,
motor_r_out,
detectors,
motor,
motors,
num_bkg=1,
simu=False,
traditional_sequence_flag=rot_first_flag,
Expand All @@ -830,7 +853,9 @@ def fly_inner_scan():
# dark images
yield from _close_shutter(simu=simu)
print("\nshutter closed, taking dark images...")
yield from _take_dark_image(detectors, motor, num_dark=1, simu=simu)
yield from _take_dark_image(detectors, motors, num_dark=1, simu=simu)

yield from bps.unstage(Andor)

# restore fliters
yield from _move_sample_in(
Expand Down Expand Up @@ -886,7 +911,7 @@ def dummy_scan( exposure_time=0.1,
motor_z_out = out_z if not (out_z is None) else motor_z_ini
motor_r_out = out_r if not (out_r is None) else motor_r_ini

motor = [zps.sx, zps.sy, zps.sz, zps.pi_r]
motors = [zps.sx, zps.sy, zps.sz, zps.pi_r]

detectors = [Andor, ic3]
offset_angle = -2 * rs
Expand All @@ -905,7 +930,7 @@ def dummy_scan( exposure_time=0.1,
yield from _set_rotation_speed(rs=rs)
print("set rotation speed: {} deg/sec".format(rs))

@stage_decorator(motor)
@stage_decorator(motors)
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def fly_inner_scan():
Expand Down Expand Up @@ -944,12 +969,12 @@ def radiographic_record(exp_t=0.1, period=0.1, t_span=10, stop=True,
motor_z_out = out_z if not (out_z is None) else motor_z_ini
motor_r_out = out_r if not (out_r is None) else motor_r_ini

motor = [zps.sx, zps.sy, zps.sz, zps.pi_r]
motors = [zps.sx, zps.sy, zps.sz, zps.pi_r]

detectors = [Andor, ic3]
_md = {
"detectors": ["Andor"],
# "motors": [mot.name for mot in motor],
# "motors": [mot.name for mot in motors],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
Expand Down Expand Up @@ -2207,7 +2232,7 @@ def user_fly_scan(
motor_z_out = out_z if out_z else motor_z_ini
motor_r_out = out_r if out_r else motor_r_ini

motor = [zps.sx, zps.sy, zps.sz, zps.pi_r]
motors = [zps.sx, zps.sy, zps.sz, zps.pi_r]

detectors = [Andor, ic3]
offset_angle = -0.5 * rs
Expand All @@ -2216,7 +2241,7 @@ def user_fly_scan(
target_rot_angle = current_rot_angle + relative_rot_angle
_md = {
"detectors": ["Andor"],
"motors": [mot.name for mot in motor],
"motors": [mot.name for mot in motors],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
Expand Down Expand Up @@ -2259,7 +2284,7 @@ def user_fly_scan(
yield from _set_rotation_speed(rs=rs)
print("set rotation speed: {} deg/sec".format(rs))

@stage_decorator(list(detectors) + motor)
@stage_decorator(list(detectors) + motors)
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def fly_inner_scan():
Expand All @@ -2268,7 +2293,7 @@ def fly_inner_scan():
yield from _set_andor_param(
exposure_time=exposure_time, period=period, chunk_size=20
)
yield from _take_dark_image(detectors, motor, num_dark=1, simu=simu)
yield from _take_dark_image(detectors, motors, num_dark=1, simu=simu)
yield from bps.sleep(1)
yield from _set_andor_param(
exposure_time=exposure_time, period=period, chunk_size=chunk_size
Expand All @@ -2281,7 +2306,7 @@ def fly_inner_scan():
status = yield from abs_set(zps.pi_r, target_rot_angle, wait=False)
yield from bps.sleep(1)
while not status.done:
yield from trigger_and_read(list(detectors) + motor)
yield from trigger_and_read(list(detectors) + motors)
# bkg images
print("\nTaking background images...")
yield from _set_rotation_speed(rs=30)
Expand All @@ -2299,7 +2324,7 @@ def fly_inner_scan():
motor_z_out,
motor_r_out,
detectors,
motor,
motors,
num_bkg=1,
simu=False,
traditional_sequence_flag=traditional_sequence_flag,
Expand Down Expand Up @@ -2343,7 +2368,7 @@ def user_fly_only(
motor_z_ini = zps.sz.position
motor_r_ini = zps.pi_r.position

motor = [zps.sx, zps.sy, zps.sz, zps.pi_r]
motors = [zps.sx, zps.sy, zps.sz, zps.pi_r]

detectors = [Andor, ic3]
# offset_angle = 0 #-0.5 * rs * np.sign(relative_rot_angle)
Expand All @@ -2352,7 +2377,7 @@ def user_fly_only(
target_rot_angle = end_rot_angle
_md = {
"detectors": ["Andor"],
"motors": [mot.name for mot in motor],
"motors": [mot.name for mot in motors],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
Expand Down Expand Up @@ -2390,14 +2415,14 @@ def user_fly_only(
yield from _set_rotation_speed(rs=rs)
print("set rotation speed: {} deg/sec".format(rs))

@stage_decorator(list(detectors) + motor)
@stage_decorator(list(detectors) + motors)
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def fly_inner_scan():
yield from _open_shutter(simu=simu)
status = yield from abs_set(zps.pi_r, target_rot_angle, wait=False)
while not status.done:
yield from trigger_and_read(list(detectors) + motor)
yield from trigger_and_read(list(detectors) + motors)

uid = yield from fly_inner_scan()
yield from mv(Andor.cam.image_mode, 1)
Expand Down Expand Up @@ -2431,7 +2456,7 @@ def user_dark_only(exposure_time=0.1, chunk_size=20, note="", simu=False, md=Non
global ZONE_PLATE
period = exposure_time # default to exposure time for backgrounds
detectors = [Andor, ic3]
motor = []
motors = []

_md = {
"detectors": ["Andor"],
Expand Down Expand Up @@ -2465,13 +2490,13 @@ def user_dark_only(exposure_time=0.1, chunk_size=20, note="", simu=False, md=Non
exposure_time=exposure_time, period=period, chunk_size=chunk_size
)

@stage_decorator(list(detectors) + motor)
@stage_decorator(list(detectors) + motors)
@run_decorator(md=_md)
def inner_scan():
yield from _set_andor_param(
exposure_time=exposure_time, period=period, chunk_size=chunk_size
)
yield from _take_dark_image(detectors, motor, num_dark=1, simu=simu)
yield from _take_dark_image(detectors, motors, num_dark=1, simu=simu)

uid = yield from inner_scan()
yield from mv(Andor.cam.image_mode, 1)
Expand Down Expand Up @@ -2547,14 +2572,14 @@ def user_bkg_only(
motor_z_out = out_z if out_z else motor_z_ini
motor_r_out = out_r if out_r else motor_r_ini

motor = [zps.sx, zps.sy, zps.sz, zps.pi_r]
motors = [zps.sx, zps.sy, zps.sz, zps.pi_r]

detectors = [Andor, ic3]
current_rot_angle = zps.pi_r.position

_md = {
"detectors": ["Andor"],
"motors": [mot.name for mot in motor],
"motors": [mot.name for mot in motors],
"XEng": XEng.position,
"ion_chamber": ic3.name,
"plan_args": {
Expand Down Expand Up @@ -2589,7 +2614,7 @@ def user_bkg_only(

# yield from _set_andor_param(exposure_time=exposure_time, period=period, chunk_size=chunk_size)

@stage_decorator(list(detectors) + motor)
@stage_decorator(list(detectors) + motors)
@bpp.monitor_during_decorator([zps.pi_r])
@run_decorator(md=_md)
def fly_inner_scan():
Expand All @@ -2603,7 +2628,7 @@ def fly_inner_scan():
motor_z_out,
motor_r_out,
detectors,
motor,
motors,
num_bkg=1,
simu=False,
traditional_sequence_flag=traditional_sequence_flag,
Expand Down