Last active
March 23, 2017 02:32
-
-
Save chiahaoliu/bcfcc13d1e2e7ab4fa22dc67b8461116 to your computer and use it in GitHub Desktop.
170322_Ben_support: cryostat with expo changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import numpy as np | |
| from itertools import product | |
| from xpdacq.beamtime import _configure_area_det | |
| import bluesky.plans as bp | |
| from bluesky.plans import (scan, subs_wrapper, abs_set, count, list_scan, | |
| adaptive_scan, reset_positions_wrapper) | |
| from bluesky.callbacks import LiveTable, LivePlot | |
| from bluesky.plan_tools import print_summary | |
| def two_motor_plan(motor1, motor2, motor1_setpoint, motor2_setpoint, | |
| motor1_delay=1, motor2_delay=1, totExpTime=5, num_exp=1, delay=0): | |
| """ | |
| move two motors to desired grids (motor1_pos1, motor_pos2) and execute "count" scan with desired total exposure time, | |
| number of exposures and delay between exposures. | |
| Parameters | |
| ---------- | |
| motor1 : ophyd.Device | |
| python representation of motor, usally set to slow motor. | |
| For example, temperature controller. | |
| motor2 : ophyd.Device | |
| python representation of motor, usually is a fast motor. | |
| For example, sample stage mover. | |
| motor1_setpoint : float | |
| setpoint of motor1 | |
| motor2_setpoint : float | |
| setpoint of motor2 | |
| motor1_delay : float, optional | |
| wait time for motor1 after it reaches the setpoint. default to 1.0s | |
| motor2_delay : float, optional | |
| wait time for motor2 after it reaches the setpoint. default to 1.0s | |
| totExpTime : float, optional | |
| total exposure time per frame in seconds. Dafault value is 5 sec | |
| num_exp : int, optional | |
| number of images/exposure, default is 1 | |
| delay : float, optional | |
| delay time between exposures in sec, default to 0 | |
| Example | |
| ------- | |
| """ | |
| ## move motors to designed location | |
| yield from abs_set(motor1, motor1_setpoint, wait=True) | |
| yield from bp.sleep(motor1_delay) | |
| yield from abs_set(motor2, motor2_setpoint, wait=True) | |
| yield from bp.sleep(motor2_delay) | |
| ## configure the exposure time first | |
| _configure_area_det(totExpTime) | |
| ## ScanPlan you need | |
| plan = bp.count([pe1c, motor1, motor2], num=num_exp, delay=delay) | |
| plan = bp.subs_wrapper(plan, LiveTable([xpd_configuration['area_det'], motor1, motot2])) | |
| yield from plan | |
| def run_and_save_two_motor_plan(motor_scanplan_func, motor1, motor2, | |
| motor1_pos_list, motor2_pos_list, | |
| motor1_delay, motot2_delay, | |
| exposure_time_list, sample_num_list, | |
| dryrun=True, *args, **kwargs): | |
| """helper function to execute xrun from combinations between elements from | |
| a list of motor positions and elements from a list of sample number | |
| motor_scanplan_func : func | |
| a function that returns valid scanplan | |
| motor1 : ophyd.Device | |
| python representation of motor, usally set to slow motor. | |
| For example, temperature controller. | |
| motor2 : ophyd.Device | |
| python representation of motor, usually is a fast motor. | |
| For example, sample stage mover. | |
| motor1_pos_list : list | |
| list of setpoints for motor1 | |
| motor2_pos_list : list | |
| list of setpoints for motor2 | |
| motor1_delay : float, optional | |
| wait time for motor1 after it reaches the setpoint. | |
| motor2_delay : float, optional | |
| wait time for motor2 after it reaches the setpoint. | |
| exposure_time_list : list | |
| list of exposure time | |
| sample_num_list : list | |
| a list of sample index from ```bt.list()``. | |
| dryrun : bool, optional | |
| option of dry run. if it's True, only the (motor1_pos, motor2_pos, exposure_time) | |
| pairs will be printed. default to True | |
| args : | |
| positional arguments motor_scanplan_func | |
| kargs : | |
| keyword arguments to motor_scanplan_func | |
| Example | |
| -------- | |
| In[]: %run -i /home/documents/scripts/***.py # Note: this depends on the path to this script | |
| In[]: crystat_taj = np.arange(300, 200, -5) # ramping from 300k to 200k with -5k step | |
| In[]: ss_stg2_x_traj = [1.5, 2.5, 3.5] # move ss_stg2_x motor to 1.5, 2.5, 3.5 at each temperature | |
| In[]: expo_time_list = [60, 3, 60] # expose 60s, 3s and 60s repectively at three ss_stg2_x positions | |
| In[]: sample_num_list = [15, 1, 16] # sample indices for sample at at three ss_stg2_x positions | |
| In[]: cryostat_delay = 0. # no extra delay after cryostat moves to desired temperature | |
| In[]: ss_stg2_x_delay = 1. # 1s extra delay after ss_stag2_x moves to desired position. | |
| In[]: run_and_save_two_motorplan(two_motor_plan, cryostat, ss_stg2_x, | |
| crystat_taj, ss_stg2_x_traj, cryostat_delay, ss_stg2_x_delay, | |
| expo_time_list, sample_num_list, dryrun=True) # dryrun to check | |
| In[]: run_and_save_two_motorplan(two_motor_plan, cryostat, ss_stg2_x, | |
| crystat_taj, ss_stg2_x_traj, cryostat_delay, ss_stg2_x_delay, | |
| expo_time_list, sample_num_list, dryrun=False) # real scan | |
| """ | |
| data_dir = "/direct/XF28ID1/pe2_data/xpdUser/tiff_base/" | |
| combinations = list(product(motor1_pos_list, zip(motor2_pos_list, exposure_time_list, sample_num_list))) | |
| total_num = len(list(product(motor1_pos_list, motor2_pos_list))) | |
| for comb in combinations: | |
| m1, meta = comb # separate long trajectory | |
| m2, expo, sample_num = meta # separate inner loop | |
| if dryrun: | |
| print("==== At motor1 position = {}, motor2 position = {}\n====" | |
| "==== xrun on sample_num = {} with exposure = {}s ====" | |
| .format(m1, m2, sample_num, expo)) | |
| else: | |
| _plan = motor_scanplan_func(motor1, motor2, m1, m2, | |
| motor1_delay, motor2_delay,totExpTime=expo) | |
| xrun(sample_num, _plan) | |
| integrate_and_save_last() | |
| ### note: this code block gives you separate small tables on each scan | |
| """" | |
| file_name = data_dir + "sample_num_" + str(sample_num) + ".csv" | |
| tb = db.get_table(db[-1]) | |
| tb.to_csv() | |
| """" | |
| ### note: this code block gives you a huge tables on all of your scans | |
| file_name = data_dir + "sample_num_list{}.csv".format(sample_num_list) | |
| tb = db.get_table(db[-total_num:]) | |
| tb.to_csv() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment