Skip to content

Commit

Permalink
Uncommitted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FXI Operator committed Jan 17, 2025
1 parent fc1c2c5 commit b679b39
Show file tree
Hide file tree
Showing 11 changed files with 2,078 additions and 396 deletions.
8 changes: 4 additions & 4 deletions startup/10-area-detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,12 @@ def resume(self):
CAM_RD_CFG = {
"MARANA-4BV6X": {
"rd_time": {
'12-bit (low noise)': 0.011,
'16-bit (high dynamic rang': 0.014,
'11-bit (high speed)': 0.007
'12-bit (low noise)': 0.02327893333333333,
'16-bit (high dynamic rang': 0.013516799999999999,
'11-bit (high speed)': 0.007351242105263158
},
"pxl_encoding": {
'12-bit (low noise)': 'Mono12',
'12-bit (low noise)': 'Mono16',
'16-bit (high dynamic rang': 'Mono16',
'11-bit (high speed)': 'Mono12'},
"image_mode": MaranaU.cam.image_mode.metadata["enum_strs"],
Expand Down
66 changes: 44 additions & 22 deletions startup/18-zebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# will move this definition to motors.py
ROT_BACK_VEL = 30

BIN_FACS = {"Andor": {0: 1, 1: 2, 2: 3, 3: 4, 4: 8}, "MaranaU": {}, "Oryx": {}}
BIN_FACS = {"Andor": {0: 1, 1: 2, 2: 3, 3: 4, 4: 8}, "MaranaU": {0: 1, 1: 2, 2: 3, 3: 4, 4: 8}, "Oryx": {}}


class ZebraPositionCaptureData(Device):
Expand Down Expand Up @@ -286,6 +286,7 @@ class FXITomoFlyer(Device):
}

dft_pulse_wid = {"ms": 0.002, "s": 0.0005, "10s": 0.003} # 0: ms # 1: s # 2: 10s
min_exp = {"MARANA-4BV6X": 0.001, "Neo": 0.001, "Oryx": 0.001}
pc_trig_dir = {1: 0, -1: 1} # 1: positive, -1: negative
rot_var = 0.002
scan_cfg = {}
Expand Down Expand Up @@ -959,8 +960,11 @@ def check_cam_acq_p(det, acq_p, bin_fac):
acq_min = DET_MIN_AP[det.name] / BIN_FACS[det.name][bin_fac]
if cam_model == "MARANA-4BV6X":
full_acq_min = CAM_RD_CFG[cam_model]["rd_time"][det.pre_amp.enum_strs[det.pre_amp.value]]
acq_min = full_acq_min * (det.cam.size.size_y.value / 2048)
acq_p = max(acq_min + 0.002, acq_p) - FXITomoFlyer.rot_var # accounting vel variation in rot vel
acq_min = full_acq_min * (det.cam.size.size_y.value / 2046) + FXITomoFlyer.rot_var # add vel uncertainty tolerance
else:
acq_min = DET_MIN_AP[det.name] / BIN_FACS[det.name][bin_fac]
acq_p = max(acq_min + FXITomoFlyer.min_exp[cam_model], acq_p) # add miminum exposure time
print(f"{full_acq_min=}\n{acq_min=}\n{acq_p=}\n{FXITomoFlyer.rot_var=}")
return acq_p, acq_min

@classmethod
Expand Down Expand Up @@ -1070,7 +1074,7 @@ def compose_scn_cfg(
return scn_cfg

@staticmethod
def do_prime(det):
def _prime_det(det):
if CAM_RD_CFG[det.cam.model.value]["trigger_mode"][det.cam.trigger_mode.value] != "Internal":
yield from abs_set(det.cam.trigger_mode, "Internal", timeout=5, settle_time=1, wait=True)
if CAM_RD_CFG[det.cam.model.value]["image_mode"][det.cam.image_mode.value] != "Fixed":
Expand All @@ -1081,10 +1085,8 @@ def do_prime(det):

@staticmethod
def stop_det(det):
while det.cam.acquire.value != 0:
yield from abs_set(det.cam.acquire, 0, wait=True)
while det.hdf5.capture.value != 0:
yield from abs_set(det.hdf5.capture, 0, wait=True)
yield from abs_set_wait(det.cam.acquire, 0)
yield from abs_set_wait(det.hdf5.capture, 0)

@staticmethod
def bin_det(det, bin_fac):
Expand All @@ -1093,15 +1095,30 @@ def bin_det(det, bin_fac):
if bin_fac is None:
bin_fac = 0
if int(bin_fac) not in [0, 1, 2, 3, 4]:
print('b4')
raise ValueError("binnng must be in [0, 1, 2, 3, 4]")
yield from abs_set(det.binning, bin_fac, wait=True)
return bin_fac
# FXITomoFlyer.do_prime(det)
else:
return bin_fac

@staticmethod
def prime_det(det):
if (det.cam.array_size.array_size_x.value != det.hdf5.array_size.width.value) or (det.cam.array_size.array_size_y.value != det.hdf5.array_size.height.value):
yield from FXITomoFlyer.do_prime(det)
yield from FXITomoFlyer._prime_det(det)

@staticmethod
def set_roi_det(det, roi):
if roi is None:
yield from abs_set_wait(det.cam.size.size_x, det.cam.max_size.max_size_x.value)
yield from abs_set_wait(det.cam.min_x, 1)
yield from abs_set_wait(det.cam.size.size_y, det.cam.max_size.max_size_y.value)
yield from abs_set_wait(det.cam.min_y, 1)
else:
yield from abs_set_wait(det.cam.size.size_x, roi["size_x"])
yield from abs_set_wait(det.cam.min_x, roi["min_x"])
yield from abs_set_wait(det.cam.size.size_y, roi["size_y"])
yield from abs_set_wait(det.cam.min_y, roi["min_y"])

@staticmethod
def def_abs_out_pos(
Expand Down Expand Up @@ -1161,21 +1178,26 @@ def set_mot_r_step_for_scan(scn_cfg):

@staticmethod
def set_cam_mode(cam, stage="pre-scan"):
# if stage == "pre-scan":
# yield from abs_set_wait(cam.cam.image_mode, CAM_RD_CFG[cam.cam.model.value]["image_mode"].index("Fixed"), timeout=5, settle_time=0.5)
# yield from abs_set_wait(cam.cam.trigger_mode, CAM_RD_CFG[cam.cam.model.value]["trigger_mode"].index("External"), timeout=5, settle_time=0.5)
# elif stage == "ref-scan":
# yield from abs_set_wait(cam.cam.image_mode, CAM_RD_CFG[cam.cam.model.value]["image_mode"].index("Fixed"), timeout=5, settle_time=0.5)
# yield from abs_set_wait(cam.cam.trigger_mode, CAM_RD_CFG[cam.cam.model.value]["trigger_mode"].index("Internal"), timeout=5, settle_time=0.5)
# elif stage == "post-scan":
# yield from abs_set_wait(cam.cam.image_mode, CAM_RD_CFG[cam.cam.model.value]["image_mode"].index("Continuous"), timeout=5, settle_time=0.5)
# yield from abs_set_wait(cam.cam.trigger_mode, CAM_RD_CFG[cam.cam.model.value]["trigger_mode"].index("Internal"), timeout=5, settle_time=0.5)
# return
if stage == "pre-scan":
while CAM_RD_CFG[cam.cam.model.value]["image_mode"][cam.cam.image_mode.value] != "Fixed":
yield from abs_set(cam.cam.image_mode, "Fixed", timeout=5, settle_time=0.5, wait=True)
while CAM_RD_CFG[cam.cam.model.value]["trigger_mode"][cam.cam.trigger_mode.value] != "External":
yield from abs_set(cam.cam.trigger_mode, "External", timeout=5, settle_time=0.5, wait=True)
yield from abs_set_wait(cam.cam.image_mode, 0, timeout=5, settle_time=0.5)
yield from abs_set_wait(cam.cam.trigger_mode, 2, timeout=5, settle_time=0.5)
elif stage == "ref-scan":
while CAM_RD_CFG[cam.cam.model.value]["image_mode"][cam.cam.image_mode.value] != "Fixed":
yield from abs_set(cam.cam.image_mode, "Fixed", timeout=5, settle_time=0.5, wait=True)
while CAM_RD_CFG[cam.cam.model.value]["trigger_mode"][cam.cam.trigger_mode.value] != "Internal":
yield from abs_set(cam.cam.trigger_mode, "Internal", timeout=5, settle_time=0.5, wait=True)
yield from abs_set_wait(cam.cam.image_mode, 0, timeout=5, settle_time=0.5)
yield from abs_set_wait(cam.cam.trigger_mode, 0, timeout=5, settle_time=0.5)
elif stage == "post-scan":
while CAM_RD_CFG[cam.cam.model.value]["image_mode"][cam.cam.image_mode.value] != "Continuous":
yield from abs_set(cam.cam.image_mode, "Continuous", timeout=5, settle_time=0.5, wait=True)
while CAM_RD_CFG[cam.cam.model.value]["trigger_mode"][cam.cam.trigger_mode.value] != "Internal":
yield from abs_set(cam.cam.trigger_mode, "Internal", timeout=5, settle_time=0.5, wait=True)
yield from abs_set_wait(cam.cam.image_mode, 1, timeout=5, settle_time=0.5)
yield from abs_set_wait(cam.cam.trigger_mode, 0, timeout=5, settle_time=0.5)
return


Zebra = FXIZebra(
Expand Down
33 changes: 17 additions & 16 deletions startup/40-scan_pre_define.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def _take_image(detectors, motor, num, stream_name="primary"):
def _set_Andor_chunk_size(detectors, chunk_size):
for detector in detectors:
yield from unstage(detector)
yield from abs_set(MaranaU.cam.num_images, chunk_size, wait=True)
yield from abs_set_wait(MaranaU.cam.acquire, 0)
yield from abs_set_wait(MaranaU.cam.image_mode, 0)
yield from abs_set_wait(MaranaU.cam.num_images, chunk_size, wait=True)
for detector in detectors:
yield from stage(detector)

Expand Down Expand Up @@ -94,16 +96,17 @@ def _take_bkg_image(


def _set_andor_param(exposure_time=0.1, period=0.1, chunk_size=1, binning=[1, 1]):
yield from mv(MaranaU.cam.acquire, 0)
yield from mv(MaranaU.cam.acquire, 0)
yield from mv(MaranaU.cam.image_mode, 0)
yield from mv(MaranaU.cam.num_images, chunk_size)
period_cor = max(period, exposure_time+0.013)
for i in range(2):
yield from abs_set_wait(MaranaU.cam.acquire, 0)
yield from bps.sleep(0.2)
for i in range(2):
yield from abs_set_wait(MaranaU.cam.image_mode, 0)
yield from bps.sleep(0.5)
yield from abs_set_wait(MaranaU.cam.num_images, chunk_size)
period_cor = max(period, exposure_time+0.024)

yield from mv(MaranaU.cam.acquire_time, exposure_time)
yield from bps.sleep(1)
yield from abs_set(MaranaU.cam.acquire_period, period_cor)
yield from bps.sleep(1)
yield from abs_set_wait(MaranaU.cam.acquire_time, exposure_time)
yield from abs_set_wait(MaranaU.cam.acquire_period, period_cor)


def _xanes_per_step(
Expand Down Expand Up @@ -152,8 +155,8 @@ def _close_shutter(simu=False):
i = 0
reading = yield from bps.rd(shutter_status)
while not reading: # if 1: closed; if 0: open
yield from abs_set(shutter_close, 1, wait=True)
yield from bps.sleep(3)
yield from abs_set_wait(shutter_close, 1, wait=True)
yield from bps.sleep(1)
i += 1
print(f"try closing {i} time(s) ...")
if i > 20:
Expand All @@ -171,7 +174,7 @@ def _open_shutter(simu=False):
i = 0
reading = yield from bps.rd(shutter_status)
while reading: # if 1: closed; if 0: open
yield from abs_set(shutter_open, 1, wait=True)
yield from abs_set_wait(shutter_open, 1, wait=True)
print(f"try opening {i} time(s) ...")
yield from bps.sleep(1)
i += 1
Expand All @@ -183,9 +186,7 @@ def _open_shutter(simu=False):


def _set_rotation_speed(rs=30):
yield from abs_set(zps.pi_r.velocity, rs)
yield from bps.sleep(0.5)
yield from abs_set(zps.pi_r.velocity, rs)
yield from abs_set_wait(zps.pi_r.velocity, rs)


def _move_sample(x_pos, y_pos, z_pos, r_pos, repeat=1):
Expand Down
128 changes: 128 additions & 0 deletions startup/41-scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,134 @@ def fly_inner_scan():
print(txt)
return uid
'''
def radiography_scan(
exposure_time=0.1,
period_time=0.1,
out_x=-100,
out_y=-100,
out_z=0,
out_r=0,
num_img=10,
take_dark_img=True,
relative_move_flag=1,
rot_first_flag=1,
note="",
simu=False,
md=None,
):
"""
Take multiple images (MaranaU camera)
Input:
------------
exposure_time: float, exposure time for each image
out_x: float(int), relative sample out position for zps.sx
out_y: float(int), relative sampel out position for zps.sy
out_z: float(int), relative sampel out position for zps.sz
out_r: float(int), relative sampel out position for zps.pi_r
num_img: int, number of images to take
"""

yield from _set_andor_param(exposure_time, period_time, 1)

detectors = [MaranaU]
motor_x_ini = zps.sx.position
motor_y_ini = zps.sy.position
motor_z_ini = zps.sz.position
motor_r_ini = zps.pi_r.position

if relative_move_flag:
motor_x_out = motor_x_ini + out_x if not (out_x is None) else motor_x_ini
motor_y_out = motor_y_ini + out_y if not (out_y is None) else motor_y_ini
motor_z_out = motor_z_ini + out_z if not (out_z is None) else motor_z_ini
motor_r_out = motor_r_ini + out_r if not (out_r is None) else motor_r_ini
else:
motor_x_out = out_x if not (out_x is None) else motor_x_ini
motor_y_out = out_y if not (out_y is None) else motor_y_ini
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


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

_md = {
"detectors": ["MaranaU"],
"motors": [mot.name for mot in motors],
"XEng": XEng.position,
"plan_args": {
"exposure_time": exposure_time,
"out_x": out_x,
"out_y": out_y,
"out_z": out_z,
"out_r": out_r,
"num_img": num_img,
"num_bkg": 20,
"note": note if note else "None",
},
"plan_name": "radiography_scan",
"plan_pattern": "linspace",
"plan_pattern_module": "numpy",
"hints": {},
"operator": "FXI",
"note": note if note else "None",
# "motor_pos": wh_pos(print_on_screen=0),
}
_md.update(md or {})
_md["hints"].setdefault("dimensions", [(("time",), "primary")])

@stage_decorator(list(detectors) + motors)
@run_decorator(md=_md)
def inner_scan():

# close shutter, dark images: numer=chunk_size (e.g.20)
if take_dark_img:
print("\nshutter closed, taking dark images...")
yield from _take_dark_image(detectors, motors, num=1, chunk_size=20, stream_name="dark", simu=simu)

yield from _open_shutter(simu=simu)
yield from _set_Andor_chunk_size(detectors, chunk_size=num_img)
yield from _take_image(detectors, motors, num=1, stream_name="primary")


# taking out sample and take background image
print("\nTaking background images...")
yield from _take_bkg_image(
motor_x_out,
motor_y_out,
motor_z_out,
motor_r_out,
detectors,
[],
num=1,
chunk_size=20,
rot_first_flag=rot_first_flag,
stream_name="flat",
simu=simu,
)
if take_dark_img:
yield from _close_shutter(simu=simu)
yield from _move_sample_in(
motor_x_ini,
motor_y_ini,
motor_z_ini,
motor_r_ini,
trans_first_flag=rot_first_flag,
repeat=3,
)

uid = yield from inner_scan()
yield from mv(MaranaU.cam.image_mode, 1)
#yield from _close_shutter(simu=simu)
txt = get_scan_parameter()
insert_text(txt)
print(txt)
return uid


def fly_scan(
exposure_time=0.05,
Expand Down
Loading

0 comments on commit b679b39

Please sign in to comment.