diff --git a/iexcode/__init__.py b/iexcode/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f6b952099eb3dd409346085a870f8b63984aa3b3 100644 --- a/iexcode/__init__.py +++ b/iexcode/__init__.py @@ -0,0 +1,42 @@ +import iexcode.instruments.cfg as iex +from iexcode.instruments.bakeout import * #not tested +from iexcode.instruments.ARPES import * +from iexcode.instruments.bakeout import * #not tested +from iexcode.instruments.conversions_constants import * +from iexcode.instruments.Keithley_current_amplifiers import * +from iexcode.instruments.SRS_current_amplifiers import * +from iexcode.instruments.diagnostics import * +from iexcode.instruments.electron_analyzer import * #didn't test, but not much changed +from iexcode.instruments.encoders import * #didn't test encoder reset +from iexcode.instruments.files_and_folders import * +from iexcode.instruments.FMB_mirrors import * +from iexcode.instruments.hxp_mirrors import * +from iexcode.instruments.IEX_cameras import * +from iexcode.instruments.IEX_VPU import * #need to test with ID +from iexcode.instruments.kappa_angle_calcs import * +from iexcode.instruments.Kappa_det import * +from iexcode.instruments.Kappa import * +from iexcode.instruments.Lakeshore_335 import *#didnt' test mostly hardcoded +from iexcode.instruments.Logfile import * # +from iexcode.instruments.m3r import * +from iexcode.instruments.Motors import * +from iexcode.instruments.MPA import * +from iexcode.instruments.Octupole import * +from iexcode.instruments.remote_controlers import * +from iexcode.instruments.resolution import * +from iexcode.instruments.s29_temp_cntl import * +from iexcode.instruments.scalers import * +from iexcode.instruments.scanRecord import * +from iexcode.instruments.Scienta import * +from iexcode.instruments.shutters import * #didn't do main shutter +from iexcode.instruments.slits import * +from iexcode.instruments.spec_stuff import * +from iexcode.instruments.staff import * +from iexcode.instruments.storage_ring import * +from iexcode.instruments.userCalcs import * +from iexcode.instruments.utilities import * +from iexcode.instruments.valves import * +from iexcode.instruments.VLS_PGM import * +from iexcode.instruments.utilities import * +from iexcode.instruments.vortex import * +from iexcode.instruments.xrays import * diff --git a/iexcode/instruments/AD_utilities.py b/iexcode/instruments/AD_utilities.py index ae1f3646562bed8f0e60cc7af9bab049b636a74e..89ca8e7e6d1d739b580bc396b3b026111dcc179b 100644 --- a/iexcode/instruments/AD_utilities.py +++ b/iexcode/instruments/AD_utilities.py @@ -16,6 +16,7 @@ from epics import caget, caput import iexcode.instruments.cfg as iex from iexcode.instruments.files_and_folders import get_next_fileNumber +from iexcode.instruments.scanRecord import mda_filepath, mda_ioc def AD_exposure_time(ADplugin,exp_time,**kwargs): """ @@ -95,7 +96,7 @@ def AD_SaveFileSetup(ADplugin,**kwargs): FileTemplate="%s%s_%4.4d."+ext; format for filename first %s = filepath, second %s = prefix """ - kwargs.setdefault("userpath",os.path.dirname(iex.BL.mda.filepath())) + kwargs.setdefault("userpath",os.path.dirname(mda_filepath())) kwargs.setdefault("subfolder",ADplugin.split(":")[-2][:-1]) kwargs.setdefault("prefix",ADplugin.split(":")[-2][:-1]) @@ -267,7 +268,7 @@ def AD_ScanTrigger(ADplugin,**kwargs): kwargs.setdefault("R","cam1:") kwargs.setdefault("detTrig",2) - scanPV=iex.BL.mda.ioc+"scan"+str(kwargs["scanDIM"]) + scanPV=mda_ioc()+"scan"+str(kwargs["scanDIM"]) trigger=".T"+str(kwargs["detTrig"])+"PV" caput(scanPV+trigger,kwargs["P"]+kwargs["R"]+"Acquire",wait=True,timeout=5*60) @@ -306,8 +307,8 @@ def ADplugin_ScanSetup(ADplugin, **kwargs): AD_SaveFileSetup(ADplugin,**kwargs) AD_ScanTrigger(ADplugin, **kwargs) - trigger=".T"+str(kwargs["detTrig"])+"PV" - scanPV=iex.BL.mda.ioc+"scan"+str(kwargs["scanDIM"]) + trigger = ".T"+str(kwargs["detTrig"])+"PV" + scanPV = mda_ioc()+"scan"+str(kwargs["scanDIM"]) print("WARNING: you need to need to disable saving and clear the trigger by hand after the scan") print("\tAD_FreeRun("+ADplugin+"); caput("+scanPV+trigger+",'')") diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py index 82954d19b7c0da98021641a083223c6ab2ecde2f..de0a103dbe23cb35ffc07b5368e7fbb7fbbc4c90 100644 --- a/iexcode/instruments/ARPES.py +++ b/iexcode/instruments/ARPES.py @@ -1,16 +1,17 @@ import os from re import A from time import sleep -from iexcode.instruments.scanRecord import * + import numpy as np from epics import caget,caput import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config from iexcode.instruments.IEX_cameras import _enable_endstation_cameras +from iexcode.instruments.scanRecord import * from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv -from iexcode.instruments.Logfile import Logfile +from iexcode.instruments.Logfile import Logfile, log_name_set from iexcode.instruments.staff import staff_detector_dictionary from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all, xrays_log_dictionary @@ -35,7 +36,7 @@ default_ioc = '29idARPES:' def ARPES_init(*userName,**kwargs): """ used to intialize the Endstation class which carries scanRecord, logging ... parameters - returns global detectors relavent to this endstation (tey,ca15) + returns global detectors relavent to this endstation *userName is an optional parameter, will be prompted if set_folders=True @@ -52,7 +53,7 @@ def ARPES_init(*userName,**kwargs): kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('xrays',True) kwargs.setdefault('mode','user') - kwargs.setdefault('set_folders',True) + kwargs.setdefault('set_folders',False) kwargs.setdefault('reset',False) #motors @@ -77,11 +78,14 @@ def ARPES_init(*userName,**kwargs): user_name = userName[0] print(user_name) folders_ARPES(user_name,**kwargs) + else: user_name = mda_user_name() - - #update for default scanRecord advanced parameters + + #logging iex.BL.mda.log=Logfile('ARPES',user_name,_ARPES_log_dictionary,set_file=False) + if kwargs['set_folders']: + log_name_set() #EA if EA.connected: @@ -101,7 +105,7 @@ def ARPES_init(*userName,**kwargs): ca15 = Keithley('b',15) #default scan settings - ARPES_default_scan_setting() + ARPES_default_scan_settings() #resetting everything if kwargs['reset']: @@ -233,7 +237,7 @@ def folders_ARPES(user_name,**kwargs): else: print_warning_message("EA ioc is not running, h5 folder not set") -def ARPES_default_scan_setting(): +def ARPES_default_scan_settings(): """ default setting for scan record Note: only get set if ARPES_reset is run @@ -249,8 +253,6 @@ def ARPES_default_scan_setting(): iex.BL.mda.after_scan_pv = _ARPES_scan_after_sequence() iex.BL.mda.snake_set = ARPES_snake_set #sending the function, no parenthesis - #set the logfile name - iex.BL.mda.log.name_set() def ARPES_reset(): """ @@ -294,6 +296,7 @@ def ARPES_get_all(verbose=True): vals={} if verbose: print("\n===========================================================") + #sample position motor_dictionary = _ARPES_motor_dictionary() for motor in motor_dictionary.keys(): @@ -424,7 +427,6 @@ def _ARPES_scan_after_sequence(**kwargs): #clear and write the after scan user sequence after_scan_pv,after_scan_proc = _ARPES_scan_after_pvs(clear=True,**kwargs) - caput(after_scan_pv+".DESC","After Scan") ## Put All relevant CA back in live mode @@ -468,7 +470,7 @@ def _ARPES_detector_triggers_sequence(**kwargs): ca_list = _ARPES_ca_list() last = len(ca_list) for i,ca in enumerate(ca_list): - ca_pv = _Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS' + ca_pv = _Keithley_pv(ca[0], ca[1])+':read.PROC PP NMS' caput(detector_triggers_pv+".LNK" +str(i+1),ca_pv) caput(detector_triggers_pv+".WAIT"+str(i+1),"After"+str(last)) @@ -494,7 +496,7 @@ def _ARPES_snake_userCalc(**kwargs): kwargs.setdefault('scan_dim',1) seq_num=kwargs['seq_num'] - scan_ioc = iex.BL.ioc + scan_ioc = mda_ioc() userCalc_clear(scan_ioc,seq_num) snake_userCalc_pv,snake_userCalc_proc = userCalcs_pvs(scan_ioc, seq_num) @@ -514,7 +516,7 @@ def ARPES_snake_set(snake,**kwargs): used for snake scanning """ kwargs.setdefault('scan_dim',1) - scan_ioc = iex.BL.mda.ioc + scan_ioc = mda_ioc() after_scan_pv,after_scan_proc = _ARPES_scan_after_pvs() scan_step_pv = scan_ioc+'scan'+str(kwargs['scan_dim'])+'.P1SI NP NMS' @@ -793,4 +795,3 @@ def ARPES_map_sample(y_start=-2,y_stop=2,y_step=0.5,z_start=12,z_stop=16,z_step= """ kwargs.setdefault('snake',True) ARPES_Motors.scan_2D(["y",y_start,y_stop,y_step],["z",z_start,z_stop,z_step],**kwargs) - diff --git a/iexcode/instruments/FMB_mirrors.py b/iexcode/instruments/FMB_mirrors.py index 5af10702dc9fc621863cb0b57556b199f8c3f8b6..a34e03dc3e3560cb82250b7b2609a1f306bd797b 100644 --- a/iexcode/instruments/FMB_mirrors.py +++ b/iexcode/instruments/FMB_mirrors.py @@ -4,6 +4,7 @@ from epics import caget, caput import iexcode.instruments.cfg as iex from iexcode.instruments.utilities import read_dict, print_warning_message +from iexcode.instruments.scanRecord import scan_fillin M0M1_fpath="/home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Dictionaries/Dict_IDCal.txt" @@ -136,7 +137,7 @@ def FMB_mirror_scan(mirror_num,start,stop,step): # database sets .PREC==0. We want more digits than that. caput(pv+"_SP.PREC",3) - iex.BL.mda.fillin(pv+"_SP",pv+"_MON",start,stop,step) + scan_fillin(pv+"_SP",pv+"_MON",start,stop,step) diff --git a/iexcode/instruments/IEX_VPU.py b/iexcode/instruments/IEX_VPU.py index 9f850fdf9c2647375a9d8b690e180a2e7ae350fb..142091ad9abdc02a477006e3382c4a00e78c74c0 100644 --- a/iexcode/instruments/IEX_VPU.py +++ b/iexcode/instruments/IEX_VPU.py @@ -6,6 +6,7 @@ import numpy.polynomial.polynomial as poly from epics import caget, caput import iexcode.instruments.cfg as iex +from iexcode.instruments.scanRecord import scan_fillin, scan_fillin_table from iexcode.instruments.userCalcs import userCalcOut_clear from iexcode.instruments.utilities import dateandtime, print_warning_message, read_dict from iexcode.instruments.VLS_PGM import mono_grating_get @@ -172,6 +173,7 @@ def ID_mode_set(ID_mode): """ writes the desired mode to the correct ID pv """ + ID_mode = ID_mode.upper() if ID_mode in ID_mode_list(): ID_state = ID_mode_list().index(ID_mode) caput(ID_pvs()['mode_val'],ID_state,wait=True,timeout=18000) @@ -532,7 +534,7 @@ def ID_scan_fillin(start,stop,step,**kwargs): """ #Setting up the ScanRecord for ID in Table mode val_pv, rbv_pv = ID_scan_pvs() - iex.BL.mda.fillin(val_pv,rbv_pv,start,stop,step,**kwargs) + scan_fillin(val_pv,rbv_pv,start,stop,step,**kwargs) def ID_scan_fillin_table(ID_array,**kwargs): @@ -543,7 +545,7 @@ def ID_scan_fillin_table(ID_array,**kwargs): """ #Setting up the ScanRecord for ID in Table mode val_pv, rbv_pv = ID_scan_pvs() - iex.BL.mda.fillin_table(val_pv,rbv_pv,ID_array,**kwargs) + scan_fillin_table(val_pv,rbv_pv,ID_array,**kwargs) ############################################################################################################## ############################## ID direction table ############################## diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py index cb565d1633d08e3922fbd990af567de242f27d5d..73bac38c1136e983e623d252b05baaf3ad56a8a5 100644 --- a/iexcode/instruments/Kappa.py +++ b/iexcode/instruments/Kappa.py @@ -8,41 +8,41 @@ from epics import caget, caput,PV import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config from iexcode.instruments.IEX_cameras import _enable_endstation_cameras +from iexcode.instruments.scanRecord import * from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv -from iexcode.instruments.Logfile import Logfile +from iexcode.instruments.Logfile import Logfile,log_name_set from iexcode.instruments.staff import staff_detector_dictionary from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all from iexcode.instruments.conversions_constants import * from iexcode.instruments.utilities import * -from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs +from iexcode.instruments.userCalcs import * from iexcode.instruments.Motors import Motors -from iexcode.instruments.SRS_current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence -from iexcode.instruments.SRS_current_amplifiers import SRS +from iexcode.instruments.Keithley_current_amplifiers import * +from iexcode.instruments.SRS_current_amplifiers import * from iexcode.instruments.valves import branch_valve_close from iexcode.instruments.shutters import branch_shutter_close #branch specific from iexcode.instruments.slits import slit3D_get +from iexcode.instruments.m3r import m3r_centroid #endstation specific -from iexcode.instruments.kappa_det import Kappa_Detector -from iexcode.instruments.scalers import scaler_cts -from iexcode.instruments.MPA import MPA, mpa_ROI_reset +from iexcode.instruments.Kappa_det import Kappa_Detector +from iexcode.instruments.scalers import scaler_cts,Scaler +from iexcode.instruments.MPA import MPA from iexcode.instruments.spec_stuff import folders_spec default_ioc = '29idKappa:' -global tey,d3,d4,mesh,kappa_scaler_pv,tth_pv,tthdet - ############################################################################# def kappa_init(*userName,**kwargs): """ used to intialize the Endstation class which carries scanRecord, logging ... parameters - returns global detectors relavent to this endstation (tey,d3,d4,mesh,kappa_scaler_pv,tth_pv,tthdet) + returns global detectors relavent to this endstation *userName is an optional parameter, will be prompted if set_folders=True @@ -51,12 +51,17 @@ def kappa_init(*userName,**kwargs): reset: to reset the detectors in the IOC, etc (default => True) xrays: sets global variable and detectors for x-ray (default => True) mode: used sets the detectors 'user ' / 'staff' (default => 'user' ) + + usage: + tey,d3,d4,mesh,tth_pv,tthdet = kappa_init('user_name) + tey,d3,d4,mesh,tth_pv,tthdet = kappa_init(mode='staff') + """ kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('xrays',True) kwargs.setdefault('mode','user') - kwargs.setdefault('set_folders',True) - kwargs.setdefault('reset',True) + kwargs.setdefault('set_folders',False) + kwargs.setdefault('reset',False) #motors physical_motors = ['x','y','z','tth','kth','kap','kphi'] @@ -66,11 +71,13 @@ def kappa_init(*userName,**kwargs): #endstation iex.BL = Beamline_Config('kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['mode'],kappa_Motors) + iex.BL.safe_state = kappa_safe_state + iex.BL.endstation_get = kappa_get_all #setting folders if kwargs['set_folders']: if iex.BL.mode == 'staff': - user_name = 'staff' + user_name = 'Staff' else: if len(userName)==0: user_name = input('user name: ') @@ -79,32 +86,51 @@ def kappa_init(*userName,**kwargs): print(user_name) folders_kappa(user_name,**kwargs) - #update for default scanRecord advanced parameters - iex.BL.mda.log('kappa',user_name,_kappa_log_header(),_kappa_log_entries) + else: + user_name = mda_user_name() + print('user_name:',user_name) + + #logging + iex.BL.mda.log=Logfile('kappa',user_name,_kappa_log_dictionary,set_file=False) + if kwargs['set_folders']: + log_name_set() + + #MPA + iex.mpa = MPA() + global tth_pv,tthdet + tthdet = Kappa_Detector(kappa_Motors) + tth_pv = _kappa_motor_dictionary('tth')[3] #global detectors + global tey,d3,d4,mesh tey = SRS("29idMZ0:scaler1.S2", '29idd:A1') d3 = SRS("29idMZ0:scaler1.S3", '29idd:A2') d4 = SRS("29idMZ0:scaler1.S4", '29idd:A3') mesh = SRS("29idMZ0:scaler1.S14", '29idd:A4') - kappa_scaler_pv = '29idMZ0:scaler1.CNT' - tth_pv = _kappa_motor_dictionary('tth')[3] - iex.mpa = MPA() - tthdet = Kappa_Detector(kappa_Motors) + #default scan settings + kappa_default_scan_settings() + #resetting everything if kwargs['reset']: kappa_reset(**kwargs) - #enable cameras + #enable cameras - m3r + endstation _enable_endstation_cameras() - print ('kappa initalized') + print ('\nkappa initalized') #return any detectors or other parameters that you want access to from jupyter - return tey,d3,d4,mesh,kappa_scaler_pv,tth_pv,tthdet + return tey,d3,d4,mesh,tth_pv,tthdet + ############################################################################################################## ############################## detectors and motors ############################## ############################################################################################################## +def kappa_scaler_pv(): + """ + returns the scaler count pv + """ + return '29idMZ0:scaler1.CNT' + def _kappa_ca_list(): """ list of detectors to trigger @@ -260,6 +286,7 @@ def folders_kappa(user_name,**kwargs): """ kwargs.setdefault('set_folders',False) kwargs.setdefault('run',check_run()) + kwargs.setdefault('vortex',False) kwargs.setdefault('ftp',False) kwargs.setdefault('debug',False) @@ -275,9 +302,6 @@ def folders_kappa(user_name,**kwargs): if kwargs["set_folders"]: # Set up MDA folder: folder_mda(run,iex.BL.folder,user_name,iex.BL.prefix,iex.BL.ioc) - #logfile_name_set(iex.BL.endstation) - #logfile_header(iex.BL.endstation,iex.BL.ioc,kappa_log_header()) - # Set up SPEC folder: folders_spec(run,iex.BL.folder,user_name) @@ -289,34 +313,42 @@ def folders_kappa(user_name,**kwargs): if 'reset': kappa_reset() -def kappa_reset(): +def kappa_default_scan_settings(**kwargs): """ - resets scanRecord, current amplifiers, mono limits and lakeshore + default setting for scan record + Note: only get set if ARPES_reset is run """ #writing default parameters to iex.BL.mda + iex.BL.mda.detector_dictionary = _kappa_detector_dictionary(**kwargs) if iex.BL.mode=='staff': - iex.BL.mda.detector_dictionary = staff_detector_dictionary() - else: - iex.BL.mda.detector_dictionary = _kappa_detector_dictionary() + iex.BL.mda.detector_dictionary.update(staff_detector_dictionary()) + iex.BL.mda.trigger_dictionary = _kappa_trigger_dictionary() iex.BL.mda.scan_before_sequence = _kappa_scan_before_sequence() iex.BL.mda.scan_after_sequence = _kappa_scan_after_sequence() + iex.BL.mda.snake_set = kappa_snake_set #sending the function, no parenthesis + + +def kappa_reset(**kwargs): + """ + resets scanRecord, current amplifiers, mono limits and lakeshore + **kwargs: + reset_MPA_ROIs = False (default) + """ + kwargs.setdefault('reset_MPA_ROIs',False) + #resetting the scanRecord print("resetting the scanRecord - "+iex.BL.ioc) - iex.BL.mda.reset_all() + mda_reset() #resetting the MPA ROIs - if iex.BL.xray: - mpa_ROI_reset() - - - #resetting mono and anyother beamline stuff - if iex.BL.xrays: - _xrays_reset() + if kwargs['reset_MPA_ROIs']: + MPA.mpa_ROI_reset() #resetting mono and other beamline stuff if iex.BL.xrays: + ca_reset_all() _xrays_reset() #motors home and sync @@ -333,78 +365,64 @@ def kappa_get_all(verbose=True): returns a dictionary with the current status of the kappa endstation and exit slit """ vals = {} - if verbose: print("\n===========================================================") + #sample postion motor_dictionary = _kappa_motor_dictionary() for motor in motor_dictionary.keys(): vals[motor]=kappa_Motors.get(motor,verbose=False) + #endstation/branch pvs extra_pvs = kappa_extra_pvs() for key in extra_pvs.keys(): vals.update(key,caget(extra_pvs[key])) if iex.BL.xrays: vals.update('exit_slit',slit3D_get()) - vals.update({'mesh':mesh.current_Amp}) - if verbose: - for key in vals: - print(key+" = "+vals[key]) + mesh.get() + vals.update({'mesh':mesh.current_Amp}) #beamline info if iex.BL.xray: beamline_info = xrays_get_all() vals.update(beamline_info) - if verbose: - print("-----------------------------------------------------------") - for key in beamline_info: - print(key+" = "+vals[key]) - print("-----------------------------------------------------------") - if verbose: - print("\n===========================================================") + + if verbose: + print("-----------------------------------------------------------") + for key in vals: + print(key+" = "+vals[key]) + print("-----------------------------------------------------------") return vals + ############################################################################################################## ############################## logging ############################## ############################################################################################################## -def _kappa_log_header(): - """ - header for the log file - """ - h = "scan,motor,start,stop,step,x,y,z,tth,kth,kap,kphi,TA,TB," - h += "hv,exit_slit,GRT,ID_SP,ID_RBV,ID_Mode,ID_QP,TEY,mesh,det_name,mpa_HV,m3r_centroid,time,comment" - header_list = {'kappa':h} - return header_list - -def _kappa_log_entries(): +def _kappa_log_dictionary(): """ enstation info for log file Previously: scanlog """ - vals = kappa_get_all(verbose=False) - x = vals['x'] - y = vals['y'] - z = vals['z'] - tth = vals['tth'] - kth = vals['kth'] - kap = vals['kap'] - kphi = vals['kphi'] - - TA = vals['TA'] - TB = vals['TB'] - mesh.get() - tey_current = tey.current_Amp - mesh_current = mesh.current_Amp - det_name = tthdet.name - mpa_HV = iex.mpa.HV_get() - m3r_cent = m3r_centroid() - - entry_list = ["x","y","z","tth","kth","kap","kphi","TA","TB","TEY","mesh","det_name","mpa_HV","m3r_centroid"] - pv_list = [ x, y, z, tth, kth, kap,kphi, TA, TB,tey_current,mesh_current,det_name,mpa_HV,m3r_centroid] - format_list = [".2f",".2f",".2f",".2f",".2f",".2f",".2f",".2f",".2f","1.2e","1.2e","s",".0f",".0f"] - - return entry_list,pv_list,format_list + #header: pv, format + + d={ + "x":(kappa_Motors.get('x'),".2f"), + "y":(kappa_Motors.get('y'),".2f"), + "z":(kappa_Motors.get('z'),".2f"), + "tth":(kappa_Motors.get('tth'),".2f"), + "kth":(kappa_Motors.get('kth'),".2f"), + "kap":(kappa_Motors.get('kap'),".2f"), + "kphi":(kappa_Motors.get('kphi'),".2f"), + "TA":(caget(kappa_extra_pvs()['TA']),".2f"), + "TB":(caget(kappa_extra_pvs()['TB']),".2f"), + "TEY":(tey.current,".2f"), + "mesh":(mesh.current,".2f"), + "det_name":(Kappa_Detector.get()[0],"s"), + "mpa_HV":(MPA.HV_get(),".0f"), + "m3r_centroid":(m3r_centroid()[0],".0f"), + } + return d ############################################################################################################## ############################## kappa scanRecord ############################## @@ -436,6 +454,21 @@ def _kappa_scan_before_sequence(scan_ioc,scan_dim,**kwargs): return before_scan_proc +def _kappa_scan_after_pvs(clear=False,**kwargs): + """ + _Octupole_scan_after_sequence pv + """ + kwargs.setdefault('seq_num',10) + seq_num = kwargs['seq_num'] + + scan_ioc = iex.BL.ioc + + after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) + + if clear: + userStringSeq_clear(scan_ioc,seq_num) + return after_scan_pv,after_scan_proc + def _kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs): """ writes the user string sequence to happen at the end of a scan @@ -447,26 +480,17 @@ def _kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs): Previously: AfterScan_StrSeq """ - kwargs.setdefault('seq_num',10) - kwargs.setdefault('snake',False) - seq_num=kwargs['seq_num'] + kwargs.setdefault('scan_dim',1) + scan_dim = kwargs['scan_dim'] - if 'scan_ioc' in kwargs: - scan_ioc = kwargs['scan_ioc'] - try: - iex.BL.ioc = kwargs['scan_ioc'] - except: - error = 'undefined' - else: - scan_ioc = iex.BL.ioc + scan_ioc = iex.BL.ioc - after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) - #clear and write the after scan user sequence - userStringSeq_clear(scan_ioc,seq_num) + after_scan_pv,after_scan_proc = _kappa_scan_after_pvs(clear=True,**kwargs) caput(after_scan_pv+".DESC","After Scan") scan_pv = iex.BL.ioc+"scan"+str(scan_dim) + ## Put scan record back in absolute mode caput(after_scan_pv+".LNK2",scan_pv+".P1AR") caput(after_scan_pv+".STR2","ABSOLUTE") @@ -478,37 +502,39 @@ def _kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs): ## Clear DetTriggers 2 to 4: caput(after_scan_pv+".LNK4",scan_pv+".T2PV NPP NMS") #remove trigger 2 (used for EA) after scan - if kwargs['snake']: - snake_dim = scan_dim - 1 - #snake_proc= kappa_snake_pv(snake_dim,enable=True) - #caput(after_scan_pv+".LNK10",kappa_snake_pv()+"PP NMS") - #caput(after_scan_pv+".D10",1) + ##Snake goes in LNKA (10) return after_scan_proc def _kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs): # do we need to add 29idb:ca5 ??? """ + sets the trigger sequence for the endstation """ - kwargs.setdefault(seq_num,8) + kwargs.setdefault('seq_num',8) seq_num=kwargs['seq_num'] + scan_ioc = iex.BL.ioc + detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(iex.BL.ioc, seq_num) #clear the userStringSeq userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num']) caput(detector_triggers_pv+".DESC","kappa_Trigger1") - scaler_pv = kappa_scaler_pv - - caput(detector_triggers_pv+".LNK" +str(1),scaler_pv) - caput(detector_triggers_pv+".WAIT"+str(1),"After"+str(last)) - + #trigger Keithleys if any ca_list = _kappa_ca_list() last = len(ca_list) - for i,ca in enumerate(ca_list): - ca_pv = _Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS' - caput(detector_triggers_pv+".LNK" +str(i+2),ca_pv) - caput(detector_triggers_pv+".WAIT"+str(i+2),"After"+str(last)) + if last !=0: + for i,ca in enumerate(ca_list): + ca_pv = _Keithley_pv(ca[0], ca[1])+':read.PROC PP NMS' + caput(detector_triggers_pv+".LNK" +str(i+2),ca_pv) + caput(detector_triggers_pv+".WAIT"+str(i+2),"After"+str(last)) + + #trigger scaler if any + last+=1 + scaler_pv = kappa_scaler_pv() + caput(detector_triggers_pv+".LNK" +str(1),scaler_pv)+" PP" + caput(detector_triggers_pv+"STR"+str(1),'Count') return detector_triggers_proc @@ -521,7 +547,46 @@ def _kappa_trigger_dictionary(scan_ioc,scan_dim,**kwargs): } return trigger_dictionary +def _kappa_snake_userCalc(**kwargs): + """ + used to flip the sign of the step after a scan + snake scans as opposed to typewriter scans + """ + kwargs.setdefault('seq_num',10) + kwargs.setdefault('scan_dim',1) + seq_num=kwargs['seq_num'] + scan_ioc = iex.BL.ioc + + userCalc_clear(scan_ioc,seq_num) + snake_userCalc_pv,snake_userCalc_proc = userCalcs_pvs(scan_ioc, seq_num) + + scan_step_pv = scan_ioc+'scan'+str(kwargs['scan_dim'])+'.P1SI NP NMS' + + caput(snake_userCalc_pv+'.DESC','snake_calc'), + caput(snake_userCalc_pv+'.SCAN','I/O Intr'), + caput(snake_userCalc_pv+'.INAN',scan_step_pv) + caput(snake_userCalc_pv+'.B',"-1") + caput(snake_userCalc_pv+'.CALC$',"A*B") + + return snake_userCalc_pv+'.VAL' + +def kappa_snake_set(snake,**kwargs): + """ + used for snake scanning + """ + kwargs.setdefault('scan_dim',1) + scan_ioc = mda_ioc() + after_scan_pv,after_scan_proc = _kappa_scan_after_pvs() + + scan_step_pv = scan_ioc+'scan'+str(kwargs['scan_dim'])+'.P1SI NP NMS' + + if snake: + caput(after_scan_pv+".LNKA",scan_step_pv) + caput(after_scan_pv+".DOLA",_kappa_snake_userCalc()+" NP") + else: + caput(after_scan_pv+".LNKA","") + caput(after_scan_pv+".DOA","") ############################################################################################################## @@ -690,26 +755,26 @@ def th2th_scan_sensitivity(th_table,gain_num_table,gain_unit_table,**kwargs): tth_table = 2*th_table kwargs.update("positioner_num",1) - iex.BL.mda.fillin_table(kth_val,kth_rbv,kth_table,**kwargs) + scan_fillin_table(kth_val,kth_rbv,kth_table,**kwargs) kwargs.update("positioner_num",2) - iex.BL.mda.fillin_table(tth_val,tth_rbv,tth_table,**kwargs) + scan_fillin_table(tth_val,tth_rbv,tth_table,**kwargs) kwargs.update("positioner_num",3) - iex.BL.mda.fillin_table(gain_num_pv,"",gain_num_table,**kwargs) + scan_fillin_table(gain_num_pv,"",gain_num_table,**kwargs) kwargs.update("positioner_num",4) - iex.BL.mda.fillin_table(gain_unit_pv,"",gain_unit_table,**kwargs) + scan_fillin_table(gain_unit_pv,"",gain_unit_table,**kwargs) print("\nDon't forget to clear extra positionners at the end of the scan if you were to abort the script using the function:") print(" Clear_Scan_Positioners('kappa',1)") scaler_cts(kwargs['cts'],verbose=False) if kwargs['execute']: - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) #clean up after scan - iex.BL.mda.table_reset_after(**kwargs) + scan_after_table_reset(**kwargs) scaler_cts(verbose=False) def scanth2th(tth_start,tth_stop,tth_step,th_offset,**kwargs): @@ -739,14 +804,14 @@ def scanth2th(tth_start,tth_stop,tth_step,th_offset,**kwargs): kwargs.update("positioner_num",2) - iex.BL.mda.fillin(th_val,th_rbv,th_start,th_stop,th_step,**kwargs) + scan_fillin(th_val,th_rbv,th_start,th_stop,th_step,**kwargs) kwargs.update("positioner_num",1) - iex.BL.mda.fillin(tth_val,tth_rbv,tth_start,tth_stop,tth_step,**kwargs) + scan_fillin(tth_val,tth_rbv,tth_start,tth_stop,tth_step,**kwargs) scaler_cts(kwargs['cts'],verbose=False) if kwargs['execute']: - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) #clean up after scan scaler_cts(verbose=False) @@ -790,21 +855,20 @@ def scanth2th_table(tth_table,th_offset, **kwargs): tth_val,tth_rbv,tth_spmg,tth_pv = _kappa_motor_dictionary['tth'] kwargs.update("positioner_num",1) - iex.BL.mda.fillin_table(tth_val,tth_rbv,tth_table,**kwargs) + scan_fillin_table(tth_val,tth_rbv,tth_table,**kwargs) kwargs.update("positioner_num",2) - iex.BL.mda.fillin_table(th_val,th_rbv,th_table,**kwargs) - iex.BL.mda.positioner_after_scan(after="STAY") - + scan_fillin_table(th_val,th_rbv,th_table,**kwargs) + scan_positioner_after_set(after="STAY") scaler_cts(kwargs['cts'],verbose=False,**kwargs) if kwargs['execute']: - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) #clean up after scan - iex.BL.mda.table_reset_after() + scan_after_table_reset() scaler_cts(verbose=False) - iex.BL.mda.positioner_after_scan(after="PRIOR POS",**kwargs) + scan_positioner_after_set(after="PRIOR POS") #JM here @@ -816,14 +880,14 @@ def _kappaTransfer_StrSeq(): #User= [ DESC, x, y, z, tth, kth, kap, kphi] User = ["kappa Transfer",0, -2650, -650, 0, 57, 0, -88] n=4 - _kappaPreset_StrSeq(n,User) + #_kappaPreset_StrSeq(n,User) def _kappaGrazing_StrSeq(): #Need to determine positions and then add to the kappa graphic #Dial= [ DESC, x, y, z, tth, kth, kap, kphi] User = ["kappa Grazing",0, 0, 0, 0, 57.045, 134.76,57.045] n=3 - _kappaPreset_StrSeq(n,User) + #_kappaPreset_StrSeq(n,User) def kappa_ResetPreset(): _kappaGrazing_StrSeq() @@ -864,7 +928,7 @@ def kappa_temperature_pressure_scan(scan_dim=1): Previously: kappa_ScanTempPres """ - pv="29id"+iex.BL.mda.ioc+":scan"+str(scan_dim) + pv=mda_ioc()+":scan"+str(scan_dim) #Clear all scan pvs caput(pv+".CMND",6) #Set detectors diff --git a/iexcode/instruments/Kappa_det.py b/iexcode/instruments/Kappa_det.py index 5ea9e9e8f9f10625ad1cb901a8f28125d8688b9c..b03fe847c641be18510e00eba7cf534e856889c5 100644 --- a/iexcode/instruments/Kappa_det.py +++ b/iexcode/instruments/Kappa_det.py @@ -28,7 +28,7 @@ class Kappa_Detector: det_name = caget(det_set_pv) self.name = det_name tth_val = self.motors.get('tth') - return self.name, tth_val + return det_name, tth_val def set(self,det_name,move=True): """ diff --git a/iexcode/instruments/Logfile.py b/iexcode/instruments/Logfile.py index c7ae335c49e2df3071903e3ecd440fcad261b3e8..509afc25fd0406af9c13effbd56f3275f3e0cf50 100644 --- a/iexcode/instruments/Logfile.py +++ b/iexcode/instruments/Logfile.py @@ -26,15 +26,16 @@ def log_update(d=None,**kwargs): updates the log file with the last scan info d = dictionary of {header:[data,format]} """ - #try: - iex.BL.mda.log.update(d,**kwargs) + try: + iex.BL.mda.log.update(d,**kwargs) - #except: - # print('No logfile written') + except: + print('No logfile written') def log_name_set(file_name): try: iex.BL.mda.log.name_set(filename=file_name) + iex.BL.mda.filename = file_name except: print('No logfile name change') @@ -55,11 +56,8 @@ class Logfile: self.filepath = self._fpath() self.log_dictionary = log_dictionary - if set_file: - self.name_set() - else: - print('\n log_filename = '+caget(self._name_pv(),as_string=True)) - print('\tuse log_name_set to change') + print('\n log_filename = '+caget(self._name_pv(),as_string=True)) + print('\tuse log_name_set to change') def _name_pv(self): """ @@ -185,7 +183,7 @@ class Logfile: header_list.append(key) data_list.append(val[0]) format_list.append(val[1]) - print(data_list) + return header_list,data_list,format_list def _intit_log(self,header_list): diff --git a/iexcode/instruments/MPA.py b/iexcode/instruments/MPA.py index 539c975c5c7d417947a5cbdf34ea4343a1d23c73..d328e8f943b7f7027c8d84f7494ecdf69ddd0d34 100644 --- a/iexcode/instruments/MPA.py +++ b/iexcode/instruments/MPA.py @@ -1,8 +1,9 @@ from time import sleep -from os.path import dirname, join,exists,mkdir +from os import mkdir +from os.path import dirname,join,exists import socket -from epics import caget, caput +from epics import caget, caput, PV import iexcode.instruments.cfg as iex from iexcode.instruments.files_and_folders import get_next_fileNumber diff --git a/iexcode/instruments/Motors.py b/iexcode/instruments/Motors.py index 475e3627837c70aed74aa8d24d72576e1904e1eb..5ab6f5762cdd243c8dcfa298d3f8d7b04f7fd4d7 100644 --- a/iexcode/instruments/Motors.py +++ b/iexcode/instruments/Motors.py @@ -2,8 +2,7 @@ import time from epics import caget, caput -import iexcode.instruments.cfg as iex - +from iexcode.instruments.scanRecord import * from iexcode.instruments.utilities import print_warning_message from iexcode.instruments.scalers import scaler_cts @@ -183,11 +182,10 @@ class Motors: abs_start = start abs_stop = stop - scaler_cts(kwargs['cts'],verbose=True) - iex.BL.mda.fillin(val_pv,rbv_pv,abs_start,abs_stop,step,**kwargs) + scan_fillin(val_pv,rbv_pv,abs_start,abs_stop,step,**kwargs) if kwargs['execute']: - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) def scan_2D(self,inner_loop_list,outer_loop_list,**kwargs): @@ -242,12 +240,11 @@ class Motors: outer_loop_list[2]=round(current_value1+outer_loop_list[2],3) outer_loop_list[3]=round(current_value1+outer_loop_list[3],3) - scaler_cts(kwargs['cts'],verbose=True) - iex.BL.mda.fillin_2D(inner_loop_list,outer_loop_list,**kwargs) + scan_fillin_2D(inner_loop_list,outer_loop_list,**kwargs) if kwargs['execute']: kwargs.update({'scan_dim':kwargs['outer_scan_dim']}) - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) diff --git a/iexcode/instruments/Octupole.py b/iexcode/instruments/Octupole.py index fc723148fb377a038b865d4ffc0f252c1dfdf8d7..6bd38371aa2676320119c2938b022f5f0b5789e7 100644 --- a/iexcode/instruments/Octupole.py +++ b/iexcode/instruments/Octupole.py @@ -7,10 +7,10 @@ from epics import caget, caput,PV import iexcode.instruments.cfg as iex from iexcode.instruments.IEX_BL_config import Beamline_Config from iexcode.instruments.IEX_cameras import _enable_endstation_cameras - +from iexcode.instruments.scanRecord import * from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv -from iexcode.instruments.Logfile import Logfile +from iexcode.instruments.Logfile import Logfile,log_name_set from iexcode.instruments.staff import staff_detector_dictionary from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all @@ -33,13 +33,12 @@ from iexcode.instruments.scalers import scaler_cts,Scaler from iexcode.instruments.spec_stuff import folders_spec default_ioc = '29ide:' -global tey,tfy,pd,mesh,diag,kbh,kbv ############################################################################# def Octupole_init(*userName,**kwargs): """ used to intialize the Endstation class which carries scanRecord, logging ... parameters - returns global detectors relavent to this endstation (tey,d3,d4,mesh,Kappa_scaler_pv,tth_pv,tthdet) + returns global detectors relavent to this endstation *userName is an optional parameter, will be prompted if set_folders=True @@ -56,7 +55,7 @@ def Octupole_init(*userName,**kwargs): kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('xrays',True) kwargs.setdefault('mode','user') - kwargs.setdefault('set_folders',True) + kwargs.setdefault('set_folders',False) kwargs.setdefault('reset',False) #motors @@ -67,6 +66,8 @@ def Octupole_init(*userName,**kwargs): #endstation iex.BL = Beamline_Config('Octupole',kwargs['scan_ioc'],kwargs['xrays'],kwargs['mode'],Octupole_Motors) + iex.BL.safe_state = Octupole_safe_state + iex.BL.endstation_get = Octupole_get_all #setting folders if kwargs['set_folders']: @@ -81,14 +82,17 @@ def Octupole_init(*userName,**kwargs): folders_Octupole(user_name,**kwargs) else: - user_name = iex.BL.mda.user_name() - print('else statement:',user_name) - + user_name = mda_user_name() + print('user_name:',user_name) - #update for default scanRecord advanced parameters + #logging iex.BL.mda.log=Logfile('Octupole',user_name,_Octupole_log_dictionary) + if kwargs['set_folders']: + log_name_set() + #global detectors + global tey,tfy,pd,mesh,diag,kbh,kbv mesh = SRS("29ide:scaler1.S2", '29idd:A4') diag = SRS("29ide:scaler1.S6", '29ide:SR570_1:') kbh = SRS("29ide:scaler1.S7", '29ide:SR570_2:') @@ -98,21 +102,27 @@ def Octupole_init(*userName,**kwargs): pd = SRS("29ide:scaler1.S5", '29ide:SR570_5:') #default scan settings - Octupole_default_scan_setting() + Octupole_default_scan_settings() #resetting everything if kwargs['reset']: Octupole_reset() + #enable cameras - need m3r camera + _enable_endstation_cameras() + print ('\nOctupole initalized') #return any detectors or other parameters that you want access to from jupyter return tey,tfy,pd,mesh,diag,kbh,kbv + ############################################################################################################## ############################## detectors and motors ############################## ############################################################################################################## def Octupole_scaler_pv(): - scaler_pv = '29ide:scaler1.CNT' - return scaler_pv + """ + returns the scaler count pv + """ + return '29ide:scaler1.CNT' def _Octupole_ca_list(): """ @@ -221,7 +231,8 @@ def Octupole_extra_pvs(): """ d={ - "TA":"29ide:LS340:LS340_1:Control", + "TA":"29ide:LS340:LS340_1:Control", + "centroid":'29id_ps6:Stats1:CentroidX_RBV' } return d @@ -245,10 +256,10 @@ def folders_Octupole(user_name,**kwargs): """ kwargs.setdefault('set_folders',False) kwargs.setdefault('run',check_run()) + kwargs.setdefault('vortex',False) kwargs.setdefault('ftp',False) kwargs.setdefault('debug',False) - kwargs.setdefault('vortex',False) - + run = kwargs['run'] if kwargs['debug']: @@ -266,7 +277,7 @@ def folders_Octupole(user_name,**kwargs): if 'reset': Octupole_reset(**kwargs) -def Octupole_default_scan_setting(**kwargs): +def Octupole_default_scan_settings(**kwargs): """ default setting for scan record Note: only get set if ARPES_reset is run @@ -281,8 +292,6 @@ def Octupole_default_scan_setting(**kwargs): iex.BL.mda.scan_after_sequence = _Octupole_scan_after_sequence() iex.BL.mda.snake_set = Octupole_snake_set #sending the function, no parenthesis - #set the logfile name - iex.BL.mda.log.name_set() def Octupole_reset(**kwargs): """ @@ -290,18 +299,11 @@ def Octupole_reset(**kwargs): """ #resetting the scanRecord print("resetting the scanRecord - "+iex.BL.ioc) - iex.BL.mda.reset_all() - - #resetting the current amplifiers - if iex.BL.xrays: - ca_reset_all() - + mda_reset() + #resetting mono and anyother beamline stuff if iex.BL.xrays: - _xrays_reset() - - #resetting mono and other beamline stuff - if iex.BL.xrays: + ca_reset_all() _xrays_reset() @@ -313,7 +315,9 @@ def Octupole_get_all(verbose=True): returns a dictionary with the current status of the Octupole endstation and exit slit """ vals = {} - + if verbose: + print("\n===========================================================") + #sample postion motor_dictionary = _Octupole_motor_dictionary() for motor in motor_dictionary.keys(): @@ -325,15 +329,14 @@ def Octupole_get_all(verbose=True): vals.update(key,caget(extra_pvs[key])) if iex.BL.xrays: vals.update('exit_slit',slit3D_get()) + mesh.get() + vals.update({'mesh':mesh.current}) #beamline info if iex.BL.xray: beamline_info = xrays_get_all() vals.update(beamline_info) - mesh.get() - vals.update({'mesh':mesh.current}) - if verbose: print("-----------------------------------------------------------") for key in vals: @@ -350,7 +353,8 @@ def _Octupole_log_dictionary(): Previously: scanlog """ - + tey.get(verbose=False) + mesh.get(verbose=False) #header: pv, format d={ "x":(Octupole_Motors.get('x'),".2f"), @@ -359,11 +363,12 @@ def _Octupole_log_dictionary(): "th":(Octupole_Motors.get('th'),".2f"), "tth":(Octupole_Motors.get('tth'),".2f"), "TA":(caget(Octupole_extra_pvs()['TA']),".2f"), - "tey_current":(tey.current,".2f"), - "mesh_current":(mesh.current,".2f"), - "m3r_centroid":(m3r_centroid(),".0f") , + "tey_current":(tey.current_Amp,".2E"), + "mesh_current":(mesh.current_Amp,".2E"), + "m3r_centroid":(m3r_centroid()[0],".0f") , } return d + ############################################################################################################## ############################## Octupole scanRecord ############################## ############################################################################################################## @@ -426,11 +431,8 @@ def _Octupole_scan_after_sequence(**kwargs): scan_ioc = iex.BL.ioc - after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) - #clear and write the after scan user sequence after_scan_pv,after_scan_proc = _Octupole_scan_after_pvs(clear=True,**kwargs) - caput(after_scan_pv+".DESC","After Scan") scan_pv = iex.BL.ioc+"scan"+str(scan_dim) @@ -443,11 +445,7 @@ def _Octupole_scan_after_sequence(**kwargs): caput(after_scan_pv+".LNK3",scan_pv+".PDLY NPP NMS") caput(after_scan_pv+".DO3",0.1) -<<<<<<< HEAD - ## Clear DetTriggers 2: -======= ## Clear DetTriggers 2 : ->>>>>>> 95226a1fe706ac74c0a7efeef77197a87c943634 caput(after_scan_pv+".LNK4",scan_pv+".T2PV NPP NMS") #remove trigger 2 (used for EA) after scan ##Snake goes in LNKA (10) @@ -456,7 +454,7 @@ def _Octupole_scan_after_sequence(**kwargs): def _Octupole_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 ??? """ - + sets the trigger sequence for the endstation """ kwargs.setdefault('seq_num',8) seq_num=kwargs['seq_num'] @@ -474,16 +472,16 @@ def _Octupole_detector_triggers_sequence(**kwargs): # do we need to add 29idb last = len(ca_list) if last !=0: for i,ca in enumerate(ca_list): - ca_pv = _Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS' + ca_pv = _Keithley_pv(ca[0], ca[1])+':read.PROC PP NMS' caput(detector_triggers_pv+".LNK" +str(i+2),ca_pv) caput(detector_triggers_pv+".WAIT"+str(i+2),"After"+str(last)) #trigger scaler if any last+=1 scaler_pv = Octupole_scaler_pv() - caput(detector_triggers_pv+".LNK" +str(1),scaler_pv) - caput(detector_triggers_pv+".WAIT"+str(1),"After"+str(last)) - + caput(detector_triggers_pv+".LNK" +str(1),scaler_pv+" PP") + caput(detector_triggers_pv+".STR"+str(1),'Count') + return detector_triggers_proc def _Octupole_trigger_dictionary(**kwargs): @@ -525,7 +523,7 @@ def Octupole_snake_set(snake,**kwargs): used for snake scanning """ kwargs.setdefault('scan_dim',1) - scan_ioc = iex.BL.mda.ioc + scan_ioc = mda_ioc() after_scan_pv,after_scan_proc = _Octupole_scan_after_pvs() scan_step_pv = scan_ioc+'scan'+str(kwargs['scan_dim'])+'.P1SI NP NMS' @@ -553,10 +551,10 @@ def Octupole_light(ON_OFF): """ Previously:light """ - light_pv = '29ide:Unidig1Bo0' - if ON_OFF.lower() == 'on': + light_pv = '29ide:9440:1:bo_1.VAL' + if ON_OFF.lower() == 'off': light=0 - elif ON_OFF.lower() == 'off': + elif ON_OFF.lower() == 'on': light=1 caput(light_pv,light) print(("Turning light "+ON_OFF+".")) diff --git a/iexcode/instruments/VLS_PGM.py b/iexcode/instruments/VLS_PGM.py index 095ac21879db6c91ab89c2ac39bf9d7fd684420a..0481388f84504f10010a485724768a4899e1b837 100644 --- a/iexcode/instruments/VLS_PGM.py +++ b/iexcode/instruments/VLS_PGM.py @@ -525,10 +525,10 @@ def mono_scan(hv_start,hv_stop,hv_step,**kwargs): #Setting up the ScanRecord for Mono in Table mode val_pv, rbv_pv = mono_scan_pvs() - iex.BL.mda.fillin(val_pv,rbv_pv,hv_start,hv_stop,hv_step,**kwargs) + scan_fillin(val_pv,rbv_pv,hv_start,hv_stop,hv_step,**kwargs) #mono needs to stay and have a longer settling time - iex.BL.mda.positioner_after_scan("STAY") + scan_positioner_after_set(positioner_after_scan="STAY") def mono_scan_table(hv_array,**kwargs): @@ -542,22 +542,22 @@ def mono_scan_table(hv_array,**kwargs): """ kwargs.setdefault('positioner_settling_time',0.2) + kwargs.setdefault('positioner_after_scan',"STAY") - #Setting up the ScanRecord for Mono in Table mode + #Setting up the ScanRecord for Mono in Table modes val_pv, rbv_pv = mono_scan_pvs() scan_fillin_table(val_pv,rbv_pv,hv_array,**kwargs) #mono needs to stay and have a longer settling time - iex.BL.mda.positioner_settling_time(**kwargs) - iex.BL.mda.positioner_after_scan("STAY") + scan_positioner_settling_time_set(**kwargs) + scan_positioner_after_set() def mono_scan_after(**kwargs): """ resets mda after scanning the mono """ - after_scan_pv = iex.BL.mda.default_after_scan_seq() - caput(after_scan_pv+".PROC",1) - iex.BL.mda.positioner_after_scan("PRIOR POS",**kwargs) + kwargs.setdefault('positioner_after_scan',"PRIOR POS") + scan_positioner_after_set(**kwargs) ############################################################################################################## @@ -592,7 +592,7 @@ def mono_motor_scan(motor,start,stop,step,**kwargs): val_pv,rbv_pv = mono_motor_scan_pvs(motor) caput(val_pv+".PREC",3) # database sets .PREC==0. We want more digits than that. - iex.BL.mda.fillin(val_pv,rbv_pv,start,stop,step,**kwargs) + scan_fillin(val_pv,rbv_pv,start,stop,step,**kwargs) def mono_zero_order(angle): """ diff --git a/iexcode/instruments/electron_analyzer.py b/iexcode/instruments/electron_analyzer.py index d3aa577ebc2e90331ad3dbe7bae6dbca67a45224..de246eda4ce0810e3d048920dc4b5e3dc6cddfe2 100644 --- a/iexcode/instruments/electron_analyzer.py +++ b/iexcode/instruments/electron_analyzer.py @@ -171,7 +171,7 @@ def EA_log_dictionary(): 'lens_mode':[EA.LensMode,"s"], 'PE':[EA.PassEnergy,".0f"], "KE":[EA.KineticEnergy,".0f"], - "sweeps":[caget(iex.BL.mda.ioc+'scan1.NPTS'),".0f"], + "sweeps":[caget(mda_ioc()+'scan1.NPTS'),".0f"], "frames":[EA.Frames,".0f"] } return d @@ -261,9 +261,9 @@ def _scanEATrigger(EAlist,before_after,**kwargs): _scanEAPrefix(kwargs["prefix"],**kwargs) #set det trigger mda_kwargs={'scan_dim':kwargs['scan_dim'],'trigger_dictionary':{kwargs['detTrig']:''}} - iex.BL.mda.trigger_set(mda_kwargs) + scan_triggers_set(mda_kwargs) #remove scanNum as detector - iex.BL.mda.detectors_set(detector_dictionary={20:''}) + scan_detectors_set(detector_dictionary={20:''}) if kwargs["debug"]: print("mda_kwargs",mda_kwargs) @@ -288,8 +288,8 @@ def _scanEAPrefix(ptype,**kwargs): print(ptype) if ptype == "mda": - fpath = iex.BL.mda.filepath()[0:-3]+EA.dtype - nextMDA = iex.BL.mda.fileNum() + fpath = mda_filepath()[0:-3]+EA.dtype + nextMDA = mda_fileNum() prefix = "MDAscan"+str.zfill(str(nextMDA),kwargs["nzeros"]) else: prefix = ptype @@ -332,7 +332,7 @@ def scanEA_reset(**kwargs): kwargs.setdefault("scan_dim",1) _scanEATrigger([],"after",**kwargs) - iex.BL.mda.positioners_clear(kwargs["scan_dim"]) + scan_positioners_clear(kwargs["scan_dim"]) def scanEA(EAlist,**kwargs): """ @@ -416,7 +416,7 @@ def scanEA(EAlist,**kwargs): if kwargs['debug']: print("Clearing scan positioners and filling in sweeps") #Fill in Sweeps scan - iex.BL.mda.positioners_clear(**kwargs) + scan_positioners_clear(**kwargs) VAL="" RBV="" scan_fillin(VAL,RBV,1,sweeps,1,**kwargs) @@ -441,7 +441,7 @@ def scanEA(EAlist,**kwargs): #After scan EAlog_update() scanEA_reset(**kwargs) - iex.BL.mda.table_reset_after(**kwargs) + scan_after_table_reset(**kwargs) else: return EAparms @@ -468,10 +468,10 @@ def scanFM(EAlist,thList,RoughPositions,**kwargs): if kwargs['debug']: print(x,y,z,th,chi,phi) - iex.BL.mda.fillin_table(EA.Motors._motor_dictionary["th"][1],EA.Motors._motor_dictionary["th"][0],th,positioner_num=1) - iex.BL.mda.fillin_table(EA.Motors._motor_dictionary["x"][1],EA.Motors._motor_dictionary["x"][0],x,positioner_num=2) - iex.BL.mda.fillin_table(EA.Motors._motor_dictionary["y"][1],EA.Motors._motor_dictionary["y"][0],y,positioner_num=3) - iex.BL.mda.fillin_table(EA.Motors._motor_dictionary["z"][1],EA.Motors._motor_dictionary["z"][0],z,positioner_num=4) + scan_fillin_table(EA.Motors._motor_dictionary["th"][1],EA.Motors._motor_dictionary["th"][0],th,positioner_num=1) + scan_fillin_table(EA.Motors._motor_dictionary["x"][1],EA.Motors._motor_dictionary["x"][0],x,positioner_num=2) + scan_fillin_table(EA.Motors._motor_dictionary["y"][1],EA.Motors._motor_dictionary["y"][0],y,positioner_num=3) + scan_fillin_table(EA.Motors._motor_dictionary["z"][1],EA.Motors._motor_dictionary["z"][0],z,positioner_num=4) #setting up EA EAkwargs={ @@ -600,10 +600,10 @@ def scanEA_hv(EAlist,hv_lists,**kwargs): energy(mono_array[0]) #Scanning EA.put(mono_array[0]-EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) #After scan scanEA_reset(**kwargs) - iex.BL.mda.table_reset_after(**kwargs) + scan_after_table_reset(**kwargs) def scanEA_y(EAlist, y_start,y_stop,y_step,mode='absolute',**kwargs): scanEA_motor(EAlist,'y',y_start,y_stop,y_step,mode=mode,**kwargs) @@ -651,7 +651,7 @@ def scanEA_motor(EAlist, motor,start,stop,step,mode='absolute',**kwargs): if kwargs["execute"]==True: #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) - iex.BL.mda.go(kwargs["scanIOC"],scan_dim) + scan_go(kwargs["scanIOC"],scan_dim) EAlog_update() #After scan scanEA_reset(**kwargs) @@ -698,7 +698,7 @@ def scanEA_map_sample(EAlist,y_list,z_list,**kwargs): if kwargs['execute']: #Scanning EA.put(EAlist[1],EAparms['PassEnergy'],LensMode="Angular",Frames=EAparms['Frames'],**kwargs) - iex.BL.mda.go(scan_dim=outer_scan_dim) + scan_go(scan_dim=outer_scan_dim) EAlog_update() #After scan diff --git a/iexcode/instruments/m3r.py b/iexcode/instruments/m3r.py index 04aef80dfdf60c9b02794b78a0cf99afec6f1975..4f3cb029141474299583d00d9d38d3495a27a6f5 100644 --- a/iexcode/instruments/m3r.py +++ b/iexcode/instruments/m3r.py @@ -116,22 +116,22 @@ def m3r_switch_branch(branch,verbose=True): ################################ M3R alignment ############################## ############################################################################################################## -def m3r_centroid(t=None,q=1): +def m3r_centroid(acq_time=None,verbose=False): ''' Return position of centroid, sigma, m3r:RY (mirror pitch) Optional argument t to set camera intergration time. ''' - if t is not None: - caput(M3R_cam1+'AcquireTime',t) + if acq_time is not None: + caput(M3R_cam1+'AcquireTime',acq_time) else: - t=caget(M3R_cam1+'AcquireTime') + acq_time=caget(M3R_cam1+'AcquireTime') position = round(caget(M3R_stats+'CentroidX_RBV'),2) sigma = round(caget(M3R_stats+'SigmaX_RBV'),2) intensity = round(caget(M3R_stats+'CentroidTotal_RBV'),2) m3rRY = round(caget(M3R_pitch),4) - if q != None: + if verbose: print('(position, sigma, total intensity, integration time (s), mirror pitch):') - return position,sigma,intensity,t,m3rRY + return position,sigma,intensity,acq_time,m3rRY def _m3r_align_start(pxl=None): if pxl == None: @@ -151,6 +151,6 @@ def m3r_align(pxl=None): sleep(1) min_m3r=caget(M3R_align_pv+'motor_min') if m3r_RY_pos_sp_get() == min_m3r: - align_m3r_epics() + _m3r_align_start() except: print('Unable to align; check camera settings.') \ No newline at end of file diff --git a/iexcode/instruments/scalers.py b/iexcode/instruments/scalers.py index 705710f3bce187e746b4e09743c83870d4b1512b..16895989ba7a4d2c2ad4a8603c693725969cab69 100644 --- a/iexcode/instruments/scalers.py +++ b/iexcode/instruments/scalers.py @@ -1,5 +1,5 @@ from math import floor -from epics import caput,PV +from epics import caput,caget,PV import iexcode.instruments.cfg as iex @@ -8,6 +8,8 @@ def scaler_cts(time_seconds=0.1,verbose=True): sets the scalers counting for the endstation defined in BL """ 'For new endstation modify here:' + if verbose: + print(iex.BL.endstation_name," scaler") if iex.BL.endstation_name == 'kappa': Kappa_scaler(time_seconds,verbose=verbose) elif iex.BL.endstation_name == 'Octupole': diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py index 0658ba59cb65f20cfb538e90ccc8e990c6899266..f6942ea8ad30afbae08dfee33c749dd471d90277 100644 --- a/iexcode/instruments/scanRecord.py +++ b/iexcode/instruments/scanRecord.py @@ -9,6 +9,7 @@ from iexcode.instruments.utilities import dateandtime, print_warning_message from iexcode.instruments.userCalcs import userStringSeq_pvs,userStringSeq_clear from iexcode.instruments.shutters import shutter_check from iexcode.instruments.Logfile import log_update +from iexcode.instruments.scalers import scaler_cts def scan_fillin(VAL,RBV,start,stop,steps_points,**kwargs): """ @@ -19,6 +20,9 @@ def scan_fillin(VAL,RBV,start,stop,steps_points,**kwargs): except: print("IEX_endstations has not been initialized") +def scan_fillin_2D(inner_loop_list,outer_loop_list,**kwargs): + iex.mda.scan_fillin_2D(inner_loop_list,outer_loop_list,**kwargs) + def scan_fillin_table(VAL,RBV,my_table,**kwargs): """ fills in the scan record for the curretn beamline ioc @@ -28,6 +32,33 @@ def scan_fillin_table(VAL,RBV,my_table,**kwargs): except: print("IEX_endstations has not been initialized") +def scan_after_table_reset(**kwargs): + """ + resets the scanRecord after a table scan + """ + iex.BL.mda.table_reset_after(**kwargs) + +def scan_positioners_clear(**kwargs): + iex.BL.mda.positioners_clear(**kwargs) + +def scan_positioner_after_set(**kwargs): + iex.BL.mda.positioner_after_scan_set(**kwargs) + +def scan_positioner_settling_time_set(**kwargs): + iex.BL.mda.positioner_settling_time_set(**kwargs) + +def scan_triggers_set(**kwargs): + iex.BL.mda.trigger_set(**kwargs) + +def scan_triggers_clear(**kwargs): + iex.BL.mda.triggers_clear(**kwargs) + +def scan_detectors_set(**kwargs): + iex.BL.mda.detectors_set(**kwargs) + + + + def scan_go(**kwargs): """ Starts a scan @@ -42,6 +73,11 @@ def scan_go(**kwargs): except: print("IEX_endstations has not been initialized") +def mda_fileNum(): + """ + returns the next fileNum + """ + return iex.BL.mda.fileNum() def last_mda(): """ @@ -72,18 +108,25 @@ def mda_user_name(): """ return iex.BL.mda.user_name() -def mda_user_name(): +def mda_run_cycle(): """ returns the run cycle form the mda filepath """ return iex.BL.mda.run_cycle() +def mda_ioc(): + """ + returns the ioc for the current mda ioc + """ + return iex.BL.mda.ioc + def mda_reset(): """ resets the scanRecord to the default settings """ iex.BL.mda.reset_all() + def saveData_get_all(ioc_pv): """ returns saveData info: @@ -460,6 +503,7 @@ class ScanRecord: positioner_settling_time detector_settling_time trigger_dictionary + scaler_cts: to change scaler dwell time Previously: Scan_FillIn """ @@ -475,10 +519,12 @@ class ScanRecord: if kwargs['debug']: print('fillin: ',val_pv,rbv_pv,start,stop,steps_points) - #clear positioners - self.positioners_clear(**kwargs) + if posNum ==1: + #clear positioners + self.positioners_clear(**kwargs) + #set to linear mode + caput(scan_pv+".P"+str(posNum)+"SM","LINEAR") #write new positioners - caput(scan_pv+".P"+str(posNum)+"SM","LINEAR") caput(scan_pv+".P"+str(posNum)+"PV",val_pv) caput(scan_pv+".R"+str(posNum)+"PV",rbv_pv) caput(scan_pv+".P"+str(posNum)+"SP",start*1.0) @@ -499,6 +545,8 @@ class ScanRecord: self.positioner_settling_time_set(**kwargs) if 'trigger_dictionary' in kwargs: self.triggers_set(**kwargs) + if 'scaler_cts' in kwargs: + scaler_cts(kwargs['scaler_cts']) #checking that PVs and positioner limits are good time.sleep(.1) @@ -754,6 +802,7 @@ class ScanRecord: """ kwargs.setdefault("scan_dim",1) kwargs.setdefault("positioner_num",1) + kwargs.setdefault('debug',False) self.progress(kwargs['scan_dim']) @@ -761,15 +810,19 @@ class ScanRecord: posNum = kwargs['positioner_num'] if kwargs['debug']: - print('fillin: ',val_pv,rbv_pv,myarray[0],myarray[-1],myarray.shape()[0]) + print('fillin: ',val_pv,rbv_pv,myarray[0],myarray[-1]) - #clear positioners - self.positioners_clear(**kwargs) - #write new positioners and set to table mode - caput(scan_pv+".P"+str(posNum)+"SM","TABLE") + if posNum == 1: + #clear positioners + self.positioners_clear(**kwargs) + #set to table mode + caput(scan_pv+".P"+str(posNum)+"SM","TABLE") + #write new positioners caput(scan_pv+".P"+str(posNum)+"PV",val_pv) #Drive caput(scan_pv+".R"+str(posNum)+"PV",rbv_pv) #Read caput(scan_pv+".P"+str(posNum)+"PA",myarray) + caput(scan_pv+".P"+str(posNum)+"SP",myarray[0]*1.0) + caput(scan_pv+".P"+str(posNum)+"EP",myarray[-1]*1.0) #set the number of points caput(scan_pv+'.NPTS',len(myarray)) diff --git a/iexcode/instruments/slits.py b/iexcode/instruments/slits.py index 1b8da8715131f6cc714346eff7d888302865bdaf..e4e394caaebefc4d68378a819444a45a84b6a7b7 100644 --- a/iexcode/instruments/slits.py +++ b/iexcode/instruments/slits.py @@ -2,7 +2,7 @@ from numpy import inf,nan from epics import caget, caput -import iexcode.instruments.cfg as iex +from iexcode.instruments.scanRecord import * from iexcode.instruments.shutters import main_shutter_close from iexcode.instruments.utilities import print_warning_message from iexcode.instruments.encoders import encoders_reset_zero, _encoder_dictionary,encoder_sync @@ -234,9 +234,9 @@ def slits_scan_size(slit_name,direction,start,stop,step,**kwargs): #set slit center slits_set_center(slit_name,kwargs['center']) #scan - iex.BL.mda.fillin(size_rbv,size_val,start,stop,step,**kwargs) + scan_fillin(size_rbv,size_val,start,stop,step,**kwargs) if kwargs['execute']: - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) def slits_scan_center(slit_name,direction,start,stop,step,**kwargs): """ @@ -261,9 +261,9 @@ def slits_scan_center(slit_name,direction,start,stop,step,**kwargs): #set slit center slits_set_size(slit_name,kwargs['size']) #scan - iex.BL.mda.fillin(center_rbv,center_val,start,stop,step,**kwargs) + scan_fillin(center_rbv,center_val,start,stop,step,**kwargs) if kwargs['execute']: - iex.BL.mda.go(**kwargs) + scan_go(**kwargs) def slit1A_scribe_marks(): diff --git a/iexcode/instruments/vortex.py b/iexcode/instruments/vortex.py index aa7143586c0c3848bd6c56e65ef0c2721003370b..cc34eb8e23e434fd12bdb7a1c519c19d1a04baec 100644 --- a/iexcode/instruments/vortex.py +++ b/iexcode/instruments/vortex.py @@ -1,8 +1,7 @@ from time import sleep from epics import caput, caget -import iexcode.instruments.cfg as iex -from iexcode.instruments.scanRecord import saveData_get_all +from iexcode.instruments.scanRecord import * vortex_pv = "29idVORTEX:" scaler_pv = '29idMZ0:scaler1.TP' @@ -53,7 +52,7 @@ def mca_on(): print('Vortex power ON') def _mca_file_setup(): - mda_saveData=saveData_get_all(iex.BL.mda.ioc) + mda_saveData=saveData_get_all(mda_ioc()) caput(vortex_pv+'saveData_fileSystem',mda_saveData['fileSystem']) caput(vortex_pv+'saveData_subDir', '/'+ mda_saveData['subDir']+'/S'+str(mda_saveData['scanNumber'])) caput(vortex_pv+'saveData_scanNumber',1) @@ -92,16 +91,16 @@ def scanmca(add_mca=True,save_image=False,**kwargs): trig_num = 2 if add_mca: #add trigger and detectors - iex.BL.mda.triggers_set(_vortex_trigger_dictionary(save_image,trig_num)) - iex.BL.mda.detectors_set(_vortex_detector_dictionary(add_mca)) + scan_triggers_set(_vortex_trigger_dictionary(save_image,trig_num)) + scan_detectors_set(_vortex_detector_dictionary(add_mca)) sleep(1) if save_image: _mca_file_setup() mca_check_save() else: #remove vortex trigger and detectors - iex.BL.mda.triggers_clear() - iex.BL.mda.detectors_set(_vortex_detector_dictionary(add_mca)) + scan_triggers_clear() + scan_detectors_set(_vortex_detector_dictionary(add_mca)) sleep(1) def mca_check_save(**kwargs): @@ -113,7 +112,7 @@ def mca_check_save(**kwargs): """ kwargs.setdefault('scan_dim',1) kwargs.setdefault('trig_num',2) - d=iex.BL.mda.triggers_get(kwargs['scan_dim']) + d=scan_triggers_set(kwargs['scan_dim']) if d[kwargs['trig_num']] == vortex_pv+'scanH.EXSC': print('Saving mca files') _mca_file_setup() diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py index 76a00cc28a3a6590a11e2451af28ed3af9b65aca..3ec1eb15de7d1f1b7624a7b5b4bc959a07b58f16 100644 --- a/iexcode/instruments/xrays.py +++ b/iexcode/instruments/xrays.py @@ -10,7 +10,7 @@ from epics import caget,caput import iexcode.instruments.cfg as iex from iexcode.instruments.SRS_current_amplifiers import * -from iexcode.instruments.Keithlys import * +from iexcode.instruments.Keithley_current_amplifiers import * from iexcode.instruments.diagnostics import * from iexcode.instruments.FMB_mirrors import FMB_mirror_get from iexcode.instruments.IEX_VPU import * @@ -395,7 +395,7 @@ def scanXAS(hv_list,ID_tracking=False, **kwargs): **kwargs: scan_dim = 1 (default) - ID_eV: sets the ID, only works if ID_tracking is False + ID_eV: sets the ID, if ID_tracking=True, this is ignored average_pnts: if using Keithlys this set the averaging; None for no averaging m3r: if True the mirror is optimized before the start of the scan mcp @@ -407,7 +407,6 @@ def scanXAS(hv_list,ID_tracking=False, **kwargs): - If in the C-branch we use the slit blades for normalization (ca13) """ kwargs.setdefault("scan_dim",1) - kwargs.setdefault("average_pnts",1) kwargs.setdefault("m3r",True) kwargs.setdefault("mcp",True) kwargs.setdefault('execute',True) @@ -424,17 +423,21 @@ def scanXAS(hv_list,ID_tracking=False, **kwargs): if ID_tracking == True: kwargs.update({'positioner_num':2}) ID_scan_fillin_table(ID_array,**kwargs) - energy(ID_array[0],m3r=kwargs["m3r"]) + if kwargs['execute']: + energy(ID_array[0],m3r=kwargs["m3r"]) else: - if ID_eV != None: + if 'ID_eV' in kwargs: #Setting the beamline energy - energy(ID_eV,m3r=kwargs["m3r"]) + if kwargs['execute']: + energy(kwargs['ID_eV'],m3r=kwargs["m3r"]) #Averaging and Normalization - ca_average(kwargs['average_pnts']) + if 'average_pnts' in kwargs: + ca_average(kwargs['average_pnts']) + if iex.BL.branch=="d": mesh_d("In") - print_warning_message('MeshD is not automatically removed') + #print_warning_message('MeshD is not automatically removed') #mpa if iex.BL.endstation_name == "Kappa" and kwargs["mcp"]: