From e0d89221ba6585010919fc04ab34a55c332d0e68 Mon Sep 17 00:00:00 2001 From: Jessica McChesney <jmcchesn@anl.gov> Date: Mon, 22 Aug 2022 16:55:14 -0500 Subject: [PATCH] debugging --- build/lib/iexcode/init_Kapp.py | 2 +- build/lib/iexcode/instruments/ARPES.py | 132 +++++++++++------- .../iexcode/instruments/IEX_endstations.py | 40 ++++-- build/lib/iexcode/instruments/Kappa.py | 42 +++--- build/lib/iexcode/instruments/Scienta.py | 4 + build/lib/iexcode/instruments/cameras.py | 1 - .../iexcode/instruments/current_amplifiers.py | 86 +++++++----- .../iexcode/instruments/files_and_folders.py | 14 +- build/lib/iexcode/instruments/logfile.py | 35 +++-- build/lib/iexcode/instruments/scanRecord.py | 38 +++-- iexcode.egg-info/SOURCES.txt | 2 +- iexcode/instruments/ARPES.py | 132 +++++++++++------- iexcode/instruments/IEX_endstations.py | 40 ++++-- iexcode/instruments/Kappa.py | 42 +++--- iexcode/instruments/Scienta.py | 4 + iexcode/instruments/cameras.py | 1 - iexcode/instruments/current_amplifiers.py | 86 +++++++----- iexcode/instruments/files_and_folders.py | 4 +- iexcode/instruments/logfile.py | 35 +++-- iexcode/instruments/scanRecord.py | 32 +++-- .../instruments/{vortexs29.py => vortex.py} | 0 iexcode/launch_Kappa.py | 2 +- 22 files changed, 478 insertions(+), 296 deletions(-) rename iexcode/instruments/{vortexs29.py => vortex.py} (100%) diff --git a/build/lib/iexcode/init_Kapp.py b/build/lib/iexcode/init_Kapp.py index d2e8127..0ef1a88 100644 --- a/build/lib/iexcode/init_Kapp.py +++ b/build/lib/iexcode/init_Kapp.py @@ -5,7 +5,7 @@ from iexcode.instruments.Kappa_Euler import * from iexcode.instruments.current_amplifiers import * from iexcode.instruments.MPA import * -from iexcode.instruments.vortexs29 import * +from iexcode.instruments.vortexs import * from iexcode.instruments.spec_stuff import * diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py index ccfe14e..d052fc6 100644 --- a/build/lib/iexcode/instruments/ARPES.py +++ b/build/lib/iexcode/instruments/ARPES.py @@ -24,66 +24,65 @@ from iexcode.instruments.shutters import branch_shutter_close from iexcode.instruments.slits import slit3C_get from iexcode.instruments.Lakeshore_335 import Lakeshore_reset -from iexcode.instruments.electron_analyzer import EA_init_Motors, folders_EA,EA +from iexcode.instruments.electron_analyzer import EA_init_Motors,folders_EA,EA global BL global tey,ca15 global ARPES_Motors - +default_ioc = '29idARPES:' ############################################################################# -def ARPES_init(set_folders=True,reset=True,**kwargs): +def ARPES_init(**kwargs): """ kwargs: - set_folders: sets the mda and EA folders; default => False - xrays: sets global variable; default => True + set_folders: sets the mda and EA folders (default => True) + 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' ) """ - kwargs.setdefault('scan_ioc','29idARPES:') + kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('xrays',True) kwargs.setdefault('BL_mode','user') + kwargs.setdefault('set_folders',True) + kwargs.setdefault('reset',True) - #scan - if kwargs['BL_mode']=='staff': - detector_dictionary = staff_detector_dictionary() - else: - detector_dictionary = ARPES_detector_dictionary() - mda_scanRecord = ScanRecord(kwargs['scan_ioc']) - - mda_scanRecord.reset_all(detector_dictionary,ARPES_trigger_dictionary(kwargs['scan_ioc']),ARPES_scan_before_sequence(kwargs['scan_ioc']),ARPES_scan_after_sequence(kwargs['scan_ioc'])) + #motors + physical_motors = ['x','y','z','th','chi','phi'] + psuedo_motors = ['focus'] + global ARPES_Motors + ARPES_Motors = Motors('ARPES',ARPES_motor_dictionary(),physical_motors,psuedo_motors) #endstation - BL=Endstation('ARPES',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],mda_scanRecord, - ARPES_log_header,ARPES_log_entries,ARPES_motor_dictionary) + global BL + BL=Endstation('ARPES',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],ARPES_Motors,ARPES_log_header,ARPES_log_entries) + + #setting folders + if kwargs['set_folders']: + if BL.mode == 'staff': + user_name = 'staff' + else: + user_name = input('user name: ') + folders_ARPES(user_name,**kwargs) #EA - try: + if EA.connected: EA.get() EA_init_Motors(ARPES_Motors) - except: - print("\n\n NOTE: Scienta IOC is not running - start IOC and %run Macros_29id/ScanFunctions_EA.py\n\n") + else: + print("NOTE: Scienta IOC is not running") #global detectors + global tey,ca15 tey = Keithley('c',1) ca15 = Keithley('b',15) - - #setting folders - if 'set_folders': - if BL.mode == 'staff': - user_name = 'staff' - else: - user_name = input('user name: ') - folders_ARPES(user_name,**kwargs) - - #resetting - if 'reset': + + #resetting everything + if kwargs['reset']: ARPES_reset() - - #motors - physical_motors = ['x','y','z','th','chi','phi'] - psuedo_motors = ['focus'] - ARPES_Motors = Motors('ARPES',ARPES_motor_dictionary(),physical_motors,psuedo_motors) - print ('ARPES_init') + print ('ARPES initalized') + + ############################################################################################################## ############################## ARPES detectors and motors ############################## ############################################################################################################## @@ -166,13 +165,15 @@ def folders_ARPES(user_name,**kwargs): """ kwargs.setdefault('set_folders',True) kwargs.setdefault('run',check_run()) + kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('ftp',False) kwargs.setdefault('debug',False) + global BL run = kwargs['run'] if kwargs['debug']: - print("run,folder,user_name,ioc,ftp: ",run,BL.folder,user_name,BL.ioc,kwargs['ftp']) + print("run,folder,user_name,ioc,ftp: ",run,BL.folder,user_name,kwargs['scan_ioc'],kwargs['ftp']) # Create User Folder: make_user_folders(run,BL.folder,user_name,BL.endstation,ftp=kwargs['ftp']) @@ -181,23 +182,35 @@ def folders_ARPES(user_name,**kwargs): if kwargs["set_folders"]: # Set up MDA folder: folder_mda(run,BL.folder,user_name,BL.prefix,BL.ioc) + sleep(5) logfile_name_set(BL.endstation) + sleep(2) logfile_header(BL.endstation,BL.ioc,ARPES_log_header()) #Set up Scienta folders: - try: + if EA.connected: userPath = "/net/s29data/export/data_29id"+BL.folder+"/"+run+"/"+user_name+"/" folders_EA(userPath,filePrefix="EA") - except: - print_warning_message("EA ioc is not running, cannot set folder") + else: + print_warning_message("EA ioc is not running, h5 folder not set") def ARPES_reset(): """ resets scanRecord, current amplifiers, mono limits and lakeshore """ + global BL #resetting the scanRecord - BL.mda.reset() + if BL.mode=='staff': + detector_dictionary = staff_detector_dictionary() + else: + detector_dictionary = ARPES_detector_dictionary() + + trigger_dictionary = ARPES_trigger_dictionary(**kwargs) + scan_before_sequence = ARPES_scan_before_sequence(**kwargs) + scan_after_sequence = ARPES_scan_after_sequence(**kwargs) + + mda_scanRecord.reset_all(detector_dictionary,trigger_dictionary,scan_before_sequence,scan_after_sequence) #resetting the current amplifiers if BL.xray: @@ -298,13 +311,17 @@ def ARPES_scan_before_sequence(**kwargs): Previously: BeforeScan_StrSeq """ - kwargs.setdefault(seq_num,9) + kwargs.setdefault('seq_num',9) seq_num=kwargs['seq_num'] - before_scan_pv,before_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + global BL + + scan_ioc = BL.ioc + + before_scan_pv,before_scan_proc = userStringSeq_pvs(scan_ioc,seq_num) #clear and write the before scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(before_scan_pv+".DESC","Before Scan") #sequence put CAs in passive @@ -320,10 +337,12 @@ def ARPES_ca_live_sequence(**kwargs): """ """ kwargs.setdefault('seq_num',7) + global BL + ca_live_sequence_proc = ca_live_sequence(BL.ioc,kwargs['seq_num'],ARPES_detector_list()) return ca_live_sequence_proc -def ARPES_scan_after_sequence(scan_dim, **kwargs): +def ARPES_scan_after_sequence(**kwargs): """ writes the user string sequence to happen at the end of a scan returns after_scan_pv = pv for userStringSeq for after scan @@ -333,14 +352,19 @@ def ARPES_scan_after_sequence(scan_dim, **kwargs): snake: for snake scanning => False (default) Previously: AfterScan_StrSeq """ - kwargs.setdefault(seq_num,10) + kwargs.setdefault('seq_num',10) kwargs.setdefault('snake',False) + kwargs.setdefault('scan_dim',1) seq_num=kwargs['seq_num'] - after_scan_pv,after_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + global BL + scan_ioc = BL.ioc + scan_dim = kwargs[scan_dim] + + after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear and write the after scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(after_scan_pv+".DESC","After Scan") ## Put All relevant CA back in live mode @@ -375,13 +399,15 @@ def ARPES_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 kwargs.setdefault('seq_num',8) seq_num=kwargs['seq_num'] - detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(kwargs['scan_ioc'], seq_num) + global BL + scan_ioc = BL.ioc + detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear the userStringSeq - userStringSeq_clear(BL.ioc,seq_num=kwargs['seq_num']) + userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num']) caput(detector_triggers_pv+".DESC","ARPES_Trigger1") - ca_list = ARPES_detector_list + ca_list = ARPES_detector_list() last = len(ca_list) for i,ca in enumerate(ca_list): ca_pv = Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS' @@ -395,7 +421,7 @@ def ARPES_trigger_dictionary(**kwargs): need to do something """ trigger_dictionary = { - 1:ARPES_detector_triggers_sequence(**kwargs), + 1:ARPES_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs), } return trigger_dictionary @@ -590,6 +616,8 @@ def ARPES_safe_state(**kwargs): kwargs.setdefault("EA_off",True) kwargs.setdefault("shutter_close",True) kwargs.setdefault("valve_close",True) + + global EA if kwargs["EA_off"]: try: diff --git a/build/lib/iexcode/instruments/IEX_endstations.py b/build/lib/iexcode/instruments/IEX_endstations.py index 6bff704..e35cc5d 100644 --- a/build/lib/iexcode/instruments/IEX_endstations.py +++ b/build/lib/iexcode/instruments/IEX_endstations.py @@ -1,7 +1,12 @@ from math import floor +from re import M import time +from tkinter.messagebox import NO from epics import caput + +from iexcode.instruments.scanRecord import ScanRecord + """ Endstation class is used to contain information about ioc, branch, mode @@ -26,7 +31,7 @@ class Endstation: """ - def __init__(self,endstation_name,scan_ioc,xrays,BL_mode,mda_scanRecord,log_header,log_entries,Motors): + def __init__(self,endstation_name,scan_ioc,xrays,BL_mode,mda_scanRecord=None,Motors=None,log_header=None,log_entries=None): """ intializes the several beamline variables @@ -39,12 +44,27 @@ class Endstation: BL.folder => 'b','c','d' BL.prefix => 'ARPES_','Kappa_' BL.ioc => previously: BL_ioc() - BL.mda_filepath BL.log_header => dictionary with header list BL.log_entries => method to get pvs to be written to log file BL.Motors => motor calls """ + + + + self.endstation = None + self.ioc = scan_ioc + self.folder = None + self.prefix = None + + self.mode = None + self.xrays = xrays + + self.mda = ScanRecord(scan_ioc) + self.Motors = Motors + self.log_entries = log_entries + self.log_header = log_header + global BL endstations_list = ['ARPES','Kappa'] BL_mode_list = ['user','staff'] @@ -56,9 +76,11 @@ class Endstation: print('Endstations: '+endstations_list) return + if BL_mode in BL_mode_list: + self.mode = BL_mode - if BL_mode.lower == 'user': + if BL_mode == 'user': if endstation_name == 'ARPES': self.folder = 'c' self.prefix = 'ARPES_' @@ -67,19 +89,17 @@ class Endstation: self.prefix = 'Kappa_' #elif endstation_name == 'Octupole': #self.folder = 'e' - elif BL_mode.lower == 'staff': + else: + print('folder and prefix not set') + + elif BL_mode == 'staff': self.folder = 'b' #overwrite folder for staff mode + self.prefix = endstation_name+"_" else: print('Not a valid BL_mode choice') print('BL_modes: '+BL_mode_list) return - self.xrays = xrays - self.ioc = scan_ioc - self.mda = mda_scanRecord - self.log_header = log_header - self.log_entries = log_entries - self.Motors = Motors def set_logfile_path(): diff --git a/build/lib/iexcode/instruments/Kappa.py b/build/lib/iexcode/instruments/Kappa.py index dda262f..25ead0a 100644 --- a/build/lib/iexcode/instruments/Kappa.py +++ b/build/lib/iexcode/instruments/Kappa.py @@ -34,6 +34,7 @@ global Kappa_Motors global tey, d3, d4, mesh, Kappa_scaler_pv, mpa global tthdet +default_ioc = '29idKappa:' ############################################################################# def Kappa_init(set_folders=False,reset=False,**kwargs): """ @@ -44,7 +45,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs): xrays: sets global variable; default => True BL_mode: 'user' / 'staff' => used for saving, detectors... """ - kwargs.setdefault('scan_ioc','29idKappa:') + kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('xrays',True) kwargs.setdefault('BL_mode','user') @@ -55,7 +56,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs): detector_dictionary = Kappa_detector_dictionary() mda_scanRecord = ScanRecord(kwargs['scan_ioc'],detector_dictionary, - Kappa_trigger_dictionary(),Kappa_scan_before_sequence(),Kappa_scan_after_sequence()) + Kappa_trigger_dictionary(scan_ioc,scan_dim,),Kappa_scan_before_sequence(scan_ioc,scan_dim),Kappa_scan_after_sequence(scan_ioc,scan_dim)) #endstation BL=Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],mda_scanRecord,Kappa_log_header,Kappa_log_entries) @@ -380,7 +381,7 @@ def Kappa_log_entries(): ############################################################################################################## ############################## Kappa scanRecord ############################## ############################################################################################################## -def Kappa_scan_before_sequence(**kwargs): +def Kappa_scan_before_sequence(scan_ioc,scan_dim,**kwargs): """ writes the user string sequence to happen at the beginning of a scan returns before_scan_pv = pv for userStringSeq for before scan @@ -390,13 +391,13 @@ def Kappa_scan_before_sequence(**kwargs): Previously: BeforeScan_StrSeq """ - kwargs.setdefault(seq_num,9) + kwargs.setdefault('seq_num',9) seq_num=kwargs['seq_num'] - before_scan_pv,before_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + before_scan_pv,before_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear and write the before scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(before_scan_pv+".DESC","Before Scan") #This is where you'd do something if need (CA -> 'Passive', etc) @@ -407,7 +408,7 @@ def Kappa_scan_before_sequence(**kwargs): return before_scan_proc -def Kappa_scan_after_sequence(scan_dim, **kwargs): +def Kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs): """ writes the user string sequence to happen at the end of a scan returns after_scan_pv = pv for userStringSeq for after scan @@ -418,14 +419,23 @@ def Kappa_scan_after_sequence(scan_dim, **kwargs): Previously: AfterScan_StrSeq """ - kwargs.setdefault(seq_num,10) + kwargs.setdefault('seq_num',10) kwargs.setdefault('snake',False) seq_num=kwargs['seq_num'] - after_scan_pv,after_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + if 'scan_ioc' in kwargs: + scan_ioc = kwargs['scan_ioc'] + try: + BL.ioc = kwargs['scan_ioc'] + except: + error = 'undefined' + else: + scan_ioc = BL.ioc + + after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear and write the after scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(after_scan_pv+".DESC","After Scan") scan_pv = BL.ioc+"scan"+str(scan_dim) @@ -448,7 +458,7 @@ def Kappa_scan_after_sequence(scan_dim, **kwargs): return after_scan_proc -def Kappa_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 ??? +def Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs): # do we need to add 29idb:ca5 ??? """ """ kwargs.setdefault(seq_num,8) @@ -457,15 +467,15 @@ def Kappa_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(BL.ioc, seq_num) #clear the userStringSeq - userStringSeq_clear(BL.ioc,seq_num=kwargs['seq_num']) + userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num']) caput(detector_triggers_pv+".DESC","Kappa_Trigger1") - scaler_pv = Kappa_scaler_pv + scaler_pv = Kappa_scaler_pv() caput(detector_triggers_pv+".LNK" +str(1),scaler_pv) caput(detector_triggers_pv+".WAIT"+str(1),"After"+str(last)) - ca_list = Kappa_detector_list + ca_list = Kappa_detector_list() last = len(ca_list) for i,ca in enumerate(ca_list): ca_pv = Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS' @@ -474,12 +484,12 @@ def Kappa_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 return detector_triggers_proc -def Kappa_trigger_dictionary(): +def Kappa_trigger_dictionary(scan_ioc,scan_dim,**kwargs): """ need to do something """ trigger_dictionary = { - 1:Kappa_detector_triggers_sequence(), + 1:Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs), } return trigger_dictionary diff --git a/build/lib/iexcode/instruments/Scienta.py b/build/lib/iexcode/instruments/Scienta.py index e49856e..be0869d 100644 --- a/build/lib/iexcode/instruments/Scienta.py +++ b/build/lib/iexcode/instruments/Scienta.py @@ -77,13 +77,17 @@ class Scienta: self.KineticEnergy = None self.SpectraMode = None + self.connected = None + #Camera Settings self.Frames = None pv = PV(self.PHV+"WorkFunction") if pv.connect(): self.get() + self.connected = True else: + self.connected = False print("Scienta is not connected") return diff --git a/build/lib/iexcode/instruments/cameras.py b/build/lib/iexcode/instruments/cameras.py index 1436d9b..3cfb114 100644 --- a/build/lib/iexcode/instruments/cameras.py +++ b/build/lib/iexcode/instruments/cameras.py @@ -5,7 +5,6 @@ from iexcode.instruments.userCalcs import userStringSeq_clear from iexcode.instruments.AD_utilities import * from iexcode.instruments.IEX_endstations import * - def cam_pv_dictionary(cam_num): """ dictionary of pv names for the beamline cameras diff --git a/build/lib/iexcode/instruments/current_amplifiers.py b/build/lib/iexcode/instruments/current_amplifiers.py index 5df2d30..d021d10 100644 --- a/build/lib/iexcode/instruments/current_amplifiers.py +++ b/build/lib/iexcode/instruments/current_amplifiers.py @@ -44,34 +44,49 @@ def ca_dictionary(): ############################################################################################################## ################################ Keithley ############################## ############################################################################################################## -def Keithley_pv(ca_ioc, ca_num): - return "29id"+ca_ioc+":ca"+str(ca_num)+":" +def Keithley_pv(ca_crate, ca_num): + """ + ca_crate = 'b' / 'c' ... + """ + return "29id"+ca_crate+":ca"+str(ca_num)+":" class Keithley: """ class for Keithley current amplifiers """ - def __init__(self,ca_ioc, ca_num): - self._pv = Keithley_pv(ca_ioc, ca_num) + def __init__(self,ca_crate, ca_num): + """ + ca_crate = 'b' / 'c' ... + + """ + self._pv = Keithley_pv(ca_crate, ca_num) try: - self.name = ca_dictionary()[ca_ioc][ca_num] + self.name = ca_dictionary()[ca_crate][ca_num] except: - self.name = 'CA'+ca_ioc+str(ca_num) + self.name = 'CA'+ca_crate+str(ca_num) - self.current - self.rate - self.filter_num - self.range + self.current = None + self.rate = None + self.filter_num = None + self.range = None - def get(self): + self.get(verbose=False) + + def get(self,verbose=True): """ reads the current SRS and corresponding scaler values + verbose: prints current values True/False """ - self.current = caget(self.pv+"read") - self.range = 'Autoscale' if caget(self.pv+"rangeAuto",as_string=True)=='On' else caget(self.pv+"range",as_string=True) - self.rate = caget(self.pv+"rate") - digital_filter = (self.pv+'digitalFilter') - self.filter_num = 1 if digital_filter == 'On' else (self.pv+'digitalFilterCount') + self.current = caget(self._pv+"read") + self.range = 'Autoscale' if caget(self._pv+"rangeAuto",as_string=True)=='On' else caget(self._pv+"range",as_string=True) + self.rate = caget(self._pv+"rate") + digital_filter = caget(self._pv+'digitalFilter',as_string=True) + self.filter_num = 1 if digital_filter == 'On' else (self._pv+'digitalFilterCount') + + if verbose: + for key, value in vars(self).items(): + if key[0] != '_': + print(key, ' = ', value) def reset(self,rate="Slow"): @@ -80,19 +95,20 @@ class Keithley: Previously: Reset_CA """ - pv = self.pv - caput(pv+":reset.PROC",1) - caput(pv+":digitalFilterSet","Off") - caput(pv+":medianFilterSet","Off") - caput(pv+":zeroCheckSet",0) - caput(pv+":rangeAuto",1) - caput(pv+":rateSet",rate) - caput(pv+":rangeAutoUlimit","20mA") - caput(pv+":read.SCAN",".5 second") + pv = self._pv + caput(pv+"reset.PROC",1) + sleep(5) + caput(pv+"digitalFilterSet","Off") + caput(pv+"medianFilterSet","Off") + caput(pv+"zeroCheckSet",0) + caput(pv+"rangeAuto",1) + caput(pv+"rateSet",rate) + caput(pv+"rangeAutoUlimit","20mA") + caput(pv+"read.SCAN",".5 second") def autoscale(self,On_Off='On',gain=7): """ - ca_ioc = 'b' / 'c' + ca_crate = 'b' / 'c' ca_num = 2 On_Off= 'On' => Turns On the Autoscale; gain is irrelevant. @@ -108,15 +124,15 @@ class Keithley: Previously: CA_Autoscale """ - pv = self.pv - caput(pv+":rangeAutoSet",On_Off) + pv = self._pv + caput(pv+"rangeAutoSet",On_Off) sleep(0.5) - caput(pv+":rangeSet",gain) + caput(pv+"rangeSet",gain) print(pv,"Autoscale",On_Off) if On_Off == 'Off': sleep(1) - print("Gain set to:",caget(pv+":range",as_string=True)) + print("Gain set to:",caget(pv+"range",as_string=True)) @@ -134,7 +150,7 @@ class Keithley: Previously: CA_Filter """ - pv = self.pv + pv = self._pv name=self.name t=0.1 if rate == "Slow": @@ -174,9 +190,9 @@ def ca_reset_all(rate="Slow"): Previously: Reset_CA_all """ ca_dict = ca_dictionary() - for ca_ioc in ca_dict.keys(): - for ca_num in ca_dict[ca_ioc].keys(): - CA = Keithley(ca_ioc,ca_num) + for ca_crate in ca_dict.keys(): + for ca_num in ca_dict[ca_crate].keys(): + CA = Keithley(ca_crate,ca_num) CA.reset() caput("29idb:ca5:read.SCAN","Passive") # CA5 in passive @@ -319,7 +335,7 @@ class SRS: self.gain self.unit self.current - self.get() + self.get(verbose=False) def get(self): """ diff --git a/build/lib/iexcode/instruments/files_and_folders.py b/build/lib/iexcode/instruments/files_and_folders.py index 9710c1b..e1a1266 100644 --- a/build/lib/iexcode/instruments/files_and_folders.py +++ b/build/lib/iexcode/instruments/files_and_folders.py @@ -146,9 +146,9 @@ def folder_mda(run,folder,user_name,file_prefix,ioc,verbose=True): if user_name == 'Staff': user_name="" else: - user_name=user_name+"/" + user_name=user_name+'/' - mda_path="/net/s29data/export/data_29id"+folder+"/"+run+"/"+user_name+"/mda" + mda_path="/net/s29data/export/data_29id"+folder+"/"+run+"/"+user_name+"mda" print("\nMDA folder: " + mda_path) if not (exists(mda_path)): mkdir(mda_path) @@ -226,13 +226,13 @@ def get_next_fileNumber(data_dir, file_prefix,**kwargs): data_dir/file_prefix_filenum kwargs: - debug = False (default); if True then print lo - q = True (default); if False then prints next file number - + verbose = False (default); if True then prints next file number + debug = False (default) Previously: getNextFileNumber """ + kwargs.setdefault("verbose",False) kwargs.setdefault("debug",False) - kwargs.setdefault("q",True) + onlyfiles = [f for f in listdir(data_dir) if isfile(join(data_dir, f)) and f[:len(file_prefix)] == file_prefix] sortedfiles = sorted(onlyfiles, key=_filename_key) @@ -256,7 +256,7 @@ def get_next_fileNumber(data_dir, file_prefix,**kwargs): print("File number =", matchObj.group(2)) print("File extension =", matchObj.group(3)) print("Next File number =", nextFileNumber) - if kwargs["q"] == False: + if kwargs["verbose"] == True: print("Next File Number: ",nextFileNumber) return nextFileNumber diff --git a/build/lib/iexcode/instruments/logfile.py b/build/lib/iexcode/instruments/logfile.py index dc7d7b5..d4b50bd 100644 --- a/build/lib/iexcode/instruments/logfile.py +++ b/build/lib/iexcode/instruments/logfile.py @@ -1,7 +1,7 @@ from os.path import join,isfile from epics import caget, caput -from iexcode.instruments.IEX_endstations import * +from iexcode.instruments.IEX_endstations import BL from iexcode.instruments.utilities import today @@ -12,12 +12,14 @@ def log_print(**kwargs): """ prints a comment to the logfile """ + #global BL logfile_print(BL.endstation_name,BL.ioc,kwargs['comment']) def log_update(): """ updates the log file with the last scan info """ + #global BL try: entry_list,pv_list, format_list = BL.log_entries() logfile_update(BL.endstation_name,BL.ioc,entry_list,pv_list,format_list) @@ -81,21 +83,24 @@ def logfile_name_get(endstation_name): return caget(logfile_name_pv(endstation_name)) -def logfile_fpath(endstation_name,mda_ioc): +def logfile_fpath(endstation_name): """ returns the full path to the logfile based on the current user in the mda scanRecord Previously: logname, logname_generate """ - - try: - filename = logfile_name_get(endstation_name) - user_name = BL.mda.scanRecord_user(mda_ioc) - fpath_with_subfolder = join(user_name,filename) - except: - fpath_with_subfolder = "logfile.txt" - print("Couldn't read log file path, using: "+fpath_with_subfolder) + #global BL + #try: + filename = logfile_name_get(endstation_name) + print('filename = ',logfile_name_get(endstation_name)) + user_name = BL.mda.scanRecord_user() + print('user_name = ',BL.mda.scanRecord_user()) + fpath_with_subfolder = join(user_name,filename) + # except: + # fpath_with_subfolder = "logfile.txt" + # logfile_name_get(endstation_name) + # print("Couldn't read log file path, using: "+fpath_with_subfolder) return fpath_with_subfolder @@ -112,7 +117,7 @@ def logfile_print(endstation_name,mda_ioc,comment=''): logfile_name = logfile_name_get(endstation_name) try: - fpath_with_subfolder=logfile_fpath(endstation_name,mda_ioc) + fpath_with_subfolder=logfile_fpath(endstation_name) if not isfile(fpath_with_subfolder): logfile_header(fpath_with_subfolder,entry=None) with open(fpath_with_subfolder,'a') as myfile: @@ -132,12 +137,12 @@ def logfile_header(endstation_name,mda_ioc,header_list): Previously: SaveFile_Header """ version = '1.4' + #global BL - fpath_with_subfolder=logfile_fpath(endstation_name,mda_ioc) + fpath_with_subfolder=logfile_fpath(endstation_name) with open(fpath_with_subfolder, "w+") as f: f.write('@Log version: '+ version+'\n\n') - file_path = BL.mda.scanRecord_filepath(mda_ioc) - f.write('FilePath '+endstation_name+': '+file_path+'\n') + f.write('FilePath '+endstation_name+': '+fpath_with_subfolder+'\n') for key in header_list.keys(): f.write(key+' Header: '+ header_list[key]+'\n\n') @@ -151,7 +156,7 @@ def logfile_update(endstation_name,mda_ioc,entry_list,pv_list,format_list): Previously: SaveFile """ - fpath_with_subfolder=logfile_fpath(endstation_name,mda_ioc) + fpath_with_subfolder=logfile_fpath(endstation_name) if not isfile(fpath_with_subfolder): logfile_header(endstation_name,mda_ioc,entry_list) diff --git a/build/lib/iexcode/instruments/scanRecord.py b/build/lib/iexcode/instruments/scanRecord.py index f1c12a4..c498425 100644 --- a/build/lib/iexcode/instruments/scanRecord.py +++ b/build/lib/iexcode/instruments/scanRecord.py @@ -13,18 +13,26 @@ def saveData_get_all(ioc_pv): """ returns saveData info: """ - saveData_info = { - 'fileSystem':caget(ioc_pv+"saveData_fileSystem",as_string=True), - 'subDir':caget(ioc_pv+"saveData_subDir",as_string=True), - 'scanNumber':caget(ioc_pv+"saveData_scanNumber"), - 'baseName':caget(ioc_pv+"saveData_baseName",as_string=True), - } - - filepath = join(saveData_info['fileSystem'],saveData_info['subDir']) - filepath=filepath.replace('//','/') - saveData_info['filepath'] = filepath - - return saveData_info + try: + saveData_info = { + 'fileSystem':caget(ioc_pv+"saveData_fileSystem",as_string=True), + 'subDir':caget(ioc_pv+"saveData_subDir",as_string=True), + 'scanNumber':caget(ioc_pv+"saveData_scanNumber"), + 'baseName':caget(ioc_pv+"saveData_baseName",as_string=True), + } + #take care of subDir starting with '/' + f1 = saveData_info['fileSystem'] + f2 = saveData_info['subDir'][1:] if saveData_info['subDir'][0] =='/' else saveData_info['subDir'] + filepath = join(f1,f2) + #take care f filesystem starting with '//' (VME only) + filepath=filepath.replace('//','/') + saveData_info['filepath'] = filepath + return saveData_info + except: + print(ioc_pv+"not connected") + return {} + + default_positioner_settling_time = 0.05 @@ -734,8 +742,10 @@ class ScanRecord: kwargs.update({'detector_settling_time':60.0/step_min}) - stop=duration_min*60.0*step_min - self.fillin("","time",1,stop,1,**kwargs) + stop = duration_min + #num_pnts = duration_min * step_min + dwell = 60/step_min + self.fillin("","time",dwell/60,stop,dwell/60,**kwargs) print("Time scan - Settling time : "+str(step_min)) if kwargs['execute']: diff --git a/iexcode.egg-info/SOURCES.txt b/iexcode.egg-info/SOURCES.txt index 31b3742..b6dad63 100644 --- a/iexcode.egg-info/SOURCES.txt +++ b/iexcode.egg-info/SOURCES.txt @@ -49,7 +49,7 @@ iexcode/instruments/staff.py iexcode/instruments/storage_ring.py iexcode/instruments/userCalcs.py iexcode/instruments/utilities.py -iexcode/instruments/vortexs29.py +iexcode/instruments/vortex.py iexcode/instruments/xrays.py iexcode/macros/ARPES_macros.py iexcode/macros/BL_shutdown.py diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py index ccfe14e..d052fc6 100644 --- a/iexcode/instruments/ARPES.py +++ b/iexcode/instruments/ARPES.py @@ -24,66 +24,65 @@ from iexcode.instruments.shutters import branch_shutter_close from iexcode.instruments.slits import slit3C_get from iexcode.instruments.Lakeshore_335 import Lakeshore_reset -from iexcode.instruments.electron_analyzer import EA_init_Motors, folders_EA,EA +from iexcode.instruments.electron_analyzer import EA_init_Motors,folders_EA,EA global BL global tey,ca15 global ARPES_Motors - +default_ioc = '29idARPES:' ############################################################################# -def ARPES_init(set_folders=True,reset=True,**kwargs): +def ARPES_init(**kwargs): """ kwargs: - set_folders: sets the mda and EA folders; default => False - xrays: sets global variable; default => True + set_folders: sets the mda and EA folders (default => True) + 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' ) """ - kwargs.setdefault('scan_ioc','29idARPES:') + kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('xrays',True) kwargs.setdefault('BL_mode','user') + kwargs.setdefault('set_folders',True) + kwargs.setdefault('reset',True) - #scan - if kwargs['BL_mode']=='staff': - detector_dictionary = staff_detector_dictionary() - else: - detector_dictionary = ARPES_detector_dictionary() - mda_scanRecord = ScanRecord(kwargs['scan_ioc']) - - mda_scanRecord.reset_all(detector_dictionary,ARPES_trigger_dictionary(kwargs['scan_ioc']),ARPES_scan_before_sequence(kwargs['scan_ioc']),ARPES_scan_after_sequence(kwargs['scan_ioc'])) + #motors + physical_motors = ['x','y','z','th','chi','phi'] + psuedo_motors = ['focus'] + global ARPES_Motors + ARPES_Motors = Motors('ARPES',ARPES_motor_dictionary(),physical_motors,psuedo_motors) #endstation - BL=Endstation('ARPES',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],mda_scanRecord, - ARPES_log_header,ARPES_log_entries,ARPES_motor_dictionary) + global BL + BL=Endstation('ARPES',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],ARPES_Motors,ARPES_log_header,ARPES_log_entries) + + #setting folders + if kwargs['set_folders']: + if BL.mode == 'staff': + user_name = 'staff' + else: + user_name = input('user name: ') + folders_ARPES(user_name,**kwargs) #EA - try: + if EA.connected: EA.get() EA_init_Motors(ARPES_Motors) - except: - print("\n\n NOTE: Scienta IOC is not running - start IOC and %run Macros_29id/ScanFunctions_EA.py\n\n") + else: + print("NOTE: Scienta IOC is not running") #global detectors + global tey,ca15 tey = Keithley('c',1) ca15 = Keithley('b',15) - - #setting folders - if 'set_folders': - if BL.mode == 'staff': - user_name = 'staff' - else: - user_name = input('user name: ') - folders_ARPES(user_name,**kwargs) - - #resetting - if 'reset': + + #resetting everything + if kwargs['reset']: ARPES_reset() - - #motors - physical_motors = ['x','y','z','th','chi','phi'] - psuedo_motors = ['focus'] - ARPES_Motors = Motors('ARPES',ARPES_motor_dictionary(),physical_motors,psuedo_motors) - print ('ARPES_init') + print ('ARPES initalized') + + ############################################################################################################## ############################## ARPES detectors and motors ############################## ############################################################################################################## @@ -166,13 +165,15 @@ def folders_ARPES(user_name,**kwargs): """ kwargs.setdefault('set_folders',True) kwargs.setdefault('run',check_run()) + kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('ftp',False) kwargs.setdefault('debug',False) + global BL run = kwargs['run'] if kwargs['debug']: - print("run,folder,user_name,ioc,ftp: ",run,BL.folder,user_name,BL.ioc,kwargs['ftp']) + print("run,folder,user_name,ioc,ftp: ",run,BL.folder,user_name,kwargs['scan_ioc'],kwargs['ftp']) # Create User Folder: make_user_folders(run,BL.folder,user_name,BL.endstation,ftp=kwargs['ftp']) @@ -181,23 +182,35 @@ def folders_ARPES(user_name,**kwargs): if kwargs["set_folders"]: # Set up MDA folder: folder_mda(run,BL.folder,user_name,BL.prefix,BL.ioc) + sleep(5) logfile_name_set(BL.endstation) + sleep(2) logfile_header(BL.endstation,BL.ioc,ARPES_log_header()) #Set up Scienta folders: - try: + if EA.connected: userPath = "/net/s29data/export/data_29id"+BL.folder+"/"+run+"/"+user_name+"/" folders_EA(userPath,filePrefix="EA") - except: - print_warning_message("EA ioc is not running, cannot set folder") + else: + print_warning_message("EA ioc is not running, h5 folder not set") def ARPES_reset(): """ resets scanRecord, current amplifiers, mono limits and lakeshore """ + global BL #resetting the scanRecord - BL.mda.reset() + if BL.mode=='staff': + detector_dictionary = staff_detector_dictionary() + else: + detector_dictionary = ARPES_detector_dictionary() + + trigger_dictionary = ARPES_trigger_dictionary(**kwargs) + scan_before_sequence = ARPES_scan_before_sequence(**kwargs) + scan_after_sequence = ARPES_scan_after_sequence(**kwargs) + + mda_scanRecord.reset_all(detector_dictionary,trigger_dictionary,scan_before_sequence,scan_after_sequence) #resetting the current amplifiers if BL.xray: @@ -298,13 +311,17 @@ def ARPES_scan_before_sequence(**kwargs): Previously: BeforeScan_StrSeq """ - kwargs.setdefault(seq_num,9) + kwargs.setdefault('seq_num',9) seq_num=kwargs['seq_num'] - before_scan_pv,before_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + global BL + + scan_ioc = BL.ioc + + before_scan_pv,before_scan_proc = userStringSeq_pvs(scan_ioc,seq_num) #clear and write the before scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(before_scan_pv+".DESC","Before Scan") #sequence put CAs in passive @@ -320,10 +337,12 @@ def ARPES_ca_live_sequence(**kwargs): """ """ kwargs.setdefault('seq_num',7) + global BL + ca_live_sequence_proc = ca_live_sequence(BL.ioc,kwargs['seq_num'],ARPES_detector_list()) return ca_live_sequence_proc -def ARPES_scan_after_sequence(scan_dim, **kwargs): +def ARPES_scan_after_sequence(**kwargs): """ writes the user string sequence to happen at the end of a scan returns after_scan_pv = pv for userStringSeq for after scan @@ -333,14 +352,19 @@ def ARPES_scan_after_sequence(scan_dim, **kwargs): snake: for snake scanning => False (default) Previously: AfterScan_StrSeq """ - kwargs.setdefault(seq_num,10) + kwargs.setdefault('seq_num',10) kwargs.setdefault('snake',False) + kwargs.setdefault('scan_dim',1) seq_num=kwargs['seq_num'] - after_scan_pv,after_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + global BL + scan_ioc = BL.ioc + scan_dim = kwargs[scan_dim] + + after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear and write the after scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(after_scan_pv+".DESC","After Scan") ## Put All relevant CA back in live mode @@ -375,13 +399,15 @@ def ARPES_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 kwargs.setdefault('seq_num',8) seq_num=kwargs['seq_num'] - detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(kwargs['scan_ioc'], seq_num) + global BL + scan_ioc = BL.ioc + detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear the userStringSeq - userStringSeq_clear(BL.ioc,seq_num=kwargs['seq_num']) + userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num']) caput(detector_triggers_pv+".DESC","ARPES_Trigger1") - ca_list = ARPES_detector_list + ca_list = ARPES_detector_list() last = len(ca_list) for i,ca in enumerate(ca_list): ca_pv = Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS' @@ -395,7 +421,7 @@ def ARPES_trigger_dictionary(**kwargs): need to do something """ trigger_dictionary = { - 1:ARPES_detector_triggers_sequence(**kwargs), + 1:ARPES_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs), } return trigger_dictionary @@ -590,6 +616,8 @@ def ARPES_safe_state(**kwargs): kwargs.setdefault("EA_off",True) kwargs.setdefault("shutter_close",True) kwargs.setdefault("valve_close",True) + + global EA if kwargs["EA_off"]: try: diff --git a/iexcode/instruments/IEX_endstations.py b/iexcode/instruments/IEX_endstations.py index 6bff704..e35cc5d 100644 --- a/iexcode/instruments/IEX_endstations.py +++ b/iexcode/instruments/IEX_endstations.py @@ -1,7 +1,12 @@ from math import floor +from re import M import time +from tkinter.messagebox import NO from epics import caput + +from iexcode.instruments.scanRecord import ScanRecord + """ Endstation class is used to contain information about ioc, branch, mode @@ -26,7 +31,7 @@ class Endstation: """ - def __init__(self,endstation_name,scan_ioc,xrays,BL_mode,mda_scanRecord,log_header,log_entries,Motors): + def __init__(self,endstation_name,scan_ioc,xrays,BL_mode,mda_scanRecord=None,Motors=None,log_header=None,log_entries=None): """ intializes the several beamline variables @@ -39,12 +44,27 @@ class Endstation: BL.folder => 'b','c','d' BL.prefix => 'ARPES_','Kappa_' BL.ioc => previously: BL_ioc() - BL.mda_filepath BL.log_header => dictionary with header list BL.log_entries => method to get pvs to be written to log file BL.Motors => motor calls """ + + + + self.endstation = None + self.ioc = scan_ioc + self.folder = None + self.prefix = None + + self.mode = None + self.xrays = xrays + + self.mda = ScanRecord(scan_ioc) + self.Motors = Motors + self.log_entries = log_entries + self.log_header = log_header + global BL endstations_list = ['ARPES','Kappa'] BL_mode_list = ['user','staff'] @@ -56,9 +76,11 @@ class Endstation: print('Endstations: '+endstations_list) return + if BL_mode in BL_mode_list: + self.mode = BL_mode - if BL_mode.lower == 'user': + if BL_mode == 'user': if endstation_name == 'ARPES': self.folder = 'c' self.prefix = 'ARPES_' @@ -67,19 +89,17 @@ class Endstation: self.prefix = 'Kappa_' #elif endstation_name == 'Octupole': #self.folder = 'e' - elif BL_mode.lower == 'staff': + else: + print('folder and prefix not set') + + elif BL_mode == 'staff': self.folder = 'b' #overwrite folder for staff mode + self.prefix = endstation_name+"_" else: print('Not a valid BL_mode choice') print('BL_modes: '+BL_mode_list) return - self.xrays = xrays - self.ioc = scan_ioc - self.mda = mda_scanRecord - self.log_header = log_header - self.log_entries = log_entries - self.Motors = Motors def set_logfile_path(): diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py index dda262f..25ead0a 100644 --- a/iexcode/instruments/Kappa.py +++ b/iexcode/instruments/Kappa.py @@ -34,6 +34,7 @@ global Kappa_Motors global tey, d3, d4, mesh, Kappa_scaler_pv, mpa global tthdet +default_ioc = '29idKappa:' ############################################################################# def Kappa_init(set_folders=False,reset=False,**kwargs): """ @@ -44,7 +45,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs): xrays: sets global variable; default => True BL_mode: 'user' / 'staff' => used for saving, detectors... """ - kwargs.setdefault('scan_ioc','29idKappa:') + kwargs.setdefault('scan_ioc',default_ioc) kwargs.setdefault('xrays',True) kwargs.setdefault('BL_mode','user') @@ -55,7 +56,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs): detector_dictionary = Kappa_detector_dictionary() mda_scanRecord = ScanRecord(kwargs['scan_ioc'],detector_dictionary, - Kappa_trigger_dictionary(),Kappa_scan_before_sequence(),Kappa_scan_after_sequence()) + Kappa_trigger_dictionary(scan_ioc,scan_dim,),Kappa_scan_before_sequence(scan_ioc,scan_dim),Kappa_scan_after_sequence(scan_ioc,scan_dim)) #endstation BL=Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],mda_scanRecord,Kappa_log_header,Kappa_log_entries) @@ -380,7 +381,7 @@ def Kappa_log_entries(): ############################################################################################################## ############################## Kappa scanRecord ############################## ############################################################################################################## -def Kappa_scan_before_sequence(**kwargs): +def Kappa_scan_before_sequence(scan_ioc,scan_dim,**kwargs): """ writes the user string sequence to happen at the beginning of a scan returns before_scan_pv = pv for userStringSeq for before scan @@ -390,13 +391,13 @@ def Kappa_scan_before_sequence(**kwargs): Previously: BeforeScan_StrSeq """ - kwargs.setdefault(seq_num,9) + kwargs.setdefault('seq_num',9) seq_num=kwargs['seq_num'] - before_scan_pv,before_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + before_scan_pv,before_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear and write the before scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(before_scan_pv+".DESC","Before Scan") #This is where you'd do something if need (CA -> 'Passive', etc) @@ -407,7 +408,7 @@ def Kappa_scan_before_sequence(**kwargs): return before_scan_proc -def Kappa_scan_after_sequence(scan_dim, **kwargs): +def Kappa_scan_after_sequence(scan_ioc,scan_dim,**kwargs): """ writes the user string sequence to happen at the end of a scan returns after_scan_pv = pv for userStringSeq for after scan @@ -418,14 +419,23 @@ def Kappa_scan_after_sequence(scan_dim, **kwargs): Previously: AfterScan_StrSeq """ - kwargs.setdefault(seq_num,10) + kwargs.setdefault('seq_num',10) kwargs.setdefault('snake',False) seq_num=kwargs['seq_num'] - after_scan_pv,after_scan_proc = userStringSeq_pvs(BL.ioc, seq_num) + if 'scan_ioc' in kwargs: + scan_ioc = kwargs['scan_ioc'] + try: + BL.ioc = kwargs['scan_ioc'] + except: + error = 'undefined' + else: + scan_ioc = BL.ioc + + after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num) #clear and write the after scan user sequence - userStringSeq_clear(BL.ioc,seq_num) + userStringSeq_clear(scan_ioc,seq_num) caput(after_scan_pv+".DESC","After Scan") scan_pv = BL.ioc+"scan"+str(scan_dim) @@ -448,7 +458,7 @@ def Kappa_scan_after_sequence(scan_dim, **kwargs): return after_scan_proc -def Kappa_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 ??? +def Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs): # do we need to add 29idb:ca5 ??? """ """ kwargs.setdefault(seq_num,8) @@ -457,15 +467,15 @@ def Kappa_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(BL.ioc, seq_num) #clear the userStringSeq - userStringSeq_clear(BL.ioc,seq_num=kwargs['seq_num']) + userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num']) caput(detector_triggers_pv+".DESC","Kappa_Trigger1") - scaler_pv = Kappa_scaler_pv + scaler_pv = Kappa_scaler_pv() caput(detector_triggers_pv+".LNK" +str(1),scaler_pv) caput(detector_triggers_pv+".WAIT"+str(1),"After"+str(last)) - ca_list = Kappa_detector_list + ca_list = Kappa_detector_list() last = len(ca_list) for i,ca in enumerate(ca_list): ca_pv = Keithley_pv(ca[0], ca[1])+':read.PROC CA NMS' @@ -474,12 +484,12 @@ def Kappa_detector_triggers_sequence(**kwargs): # do we need to add 29idb:ca5 return detector_triggers_proc -def Kappa_trigger_dictionary(): +def Kappa_trigger_dictionary(scan_ioc,scan_dim,**kwargs): """ need to do something """ trigger_dictionary = { - 1:Kappa_detector_triggers_sequence(), + 1:Kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs), } return trigger_dictionary diff --git a/iexcode/instruments/Scienta.py b/iexcode/instruments/Scienta.py index e49856e..be0869d 100644 --- a/iexcode/instruments/Scienta.py +++ b/iexcode/instruments/Scienta.py @@ -77,13 +77,17 @@ class Scienta: self.KineticEnergy = None self.SpectraMode = None + self.connected = None + #Camera Settings self.Frames = None pv = PV(self.PHV+"WorkFunction") if pv.connect(): self.get() + self.connected = True else: + self.connected = False print("Scienta is not connected") return diff --git a/iexcode/instruments/cameras.py b/iexcode/instruments/cameras.py index 1436d9b..3cfb114 100644 --- a/iexcode/instruments/cameras.py +++ b/iexcode/instruments/cameras.py @@ -5,7 +5,6 @@ from iexcode.instruments.userCalcs import userStringSeq_clear from iexcode.instruments.AD_utilities import * from iexcode.instruments.IEX_endstations import * - def cam_pv_dictionary(cam_num): """ dictionary of pv names for the beamline cameras diff --git a/iexcode/instruments/current_amplifiers.py b/iexcode/instruments/current_amplifiers.py index 5df2d30..d021d10 100644 --- a/iexcode/instruments/current_amplifiers.py +++ b/iexcode/instruments/current_amplifiers.py @@ -44,34 +44,49 @@ def ca_dictionary(): ############################################################################################################## ################################ Keithley ############################## ############################################################################################################## -def Keithley_pv(ca_ioc, ca_num): - return "29id"+ca_ioc+":ca"+str(ca_num)+":" +def Keithley_pv(ca_crate, ca_num): + """ + ca_crate = 'b' / 'c' ... + """ + return "29id"+ca_crate+":ca"+str(ca_num)+":" class Keithley: """ class for Keithley current amplifiers """ - def __init__(self,ca_ioc, ca_num): - self._pv = Keithley_pv(ca_ioc, ca_num) + def __init__(self,ca_crate, ca_num): + """ + ca_crate = 'b' / 'c' ... + + """ + self._pv = Keithley_pv(ca_crate, ca_num) try: - self.name = ca_dictionary()[ca_ioc][ca_num] + self.name = ca_dictionary()[ca_crate][ca_num] except: - self.name = 'CA'+ca_ioc+str(ca_num) + self.name = 'CA'+ca_crate+str(ca_num) - self.current - self.rate - self.filter_num - self.range + self.current = None + self.rate = None + self.filter_num = None + self.range = None - def get(self): + self.get(verbose=False) + + def get(self,verbose=True): """ reads the current SRS and corresponding scaler values + verbose: prints current values True/False """ - self.current = caget(self.pv+"read") - self.range = 'Autoscale' if caget(self.pv+"rangeAuto",as_string=True)=='On' else caget(self.pv+"range",as_string=True) - self.rate = caget(self.pv+"rate") - digital_filter = (self.pv+'digitalFilter') - self.filter_num = 1 if digital_filter == 'On' else (self.pv+'digitalFilterCount') + self.current = caget(self._pv+"read") + self.range = 'Autoscale' if caget(self._pv+"rangeAuto",as_string=True)=='On' else caget(self._pv+"range",as_string=True) + self.rate = caget(self._pv+"rate") + digital_filter = caget(self._pv+'digitalFilter',as_string=True) + self.filter_num = 1 if digital_filter == 'On' else (self._pv+'digitalFilterCount') + + if verbose: + for key, value in vars(self).items(): + if key[0] != '_': + print(key, ' = ', value) def reset(self,rate="Slow"): @@ -80,19 +95,20 @@ class Keithley: Previously: Reset_CA """ - pv = self.pv - caput(pv+":reset.PROC",1) - caput(pv+":digitalFilterSet","Off") - caput(pv+":medianFilterSet","Off") - caput(pv+":zeroCheckSet",0) - caput(pv+":rangeAuto",1) - caput(pv+":rateSet",rate) - caput(pv+":rangeAutoUlimit","20mA") - caput(pv+":read.SCAN",".5 second") + pv = self._pv + caput(pv+"reset.PROC",1) + sleep(5) + caput(pv+"digitalFilterSet","Off") + caput(pv+"medianFilterSet","Off") + caput(pv+"zeroCheckSet",0) + caput(pv+"rangeAuto",1) + caput(pv+"rateSet",rate) + caput(pv+"rangeAutoUlimit","20mA") + caput(pv+"read.SCAN",".5 second") def autoscale(self,On_Off='On',gain=7): """ - ca_ioc = 'b' / 'c' + ca_crate = 'b' / 'c' ca_num = 2 On_Off= 'On' => Turns On the Autoscale; gain is irrelevant. @@ -108,15 +124,15 @@ class Keithley: Previously: CA_Autoscale """ - pv = self.pv - caput(pv+":rangeAutoSet",On_Off) + pv = self._pv + caput(pv+"rangeAutoSet",On_Off) sleep(0.5) - caput(pv+":rangeSet",gain) + caput(pv+"rangeSet",gain) print(pv,"Autoscale",On_Off) if On_Off == 'Off': sleep(1) - print("Gain set to:",caget(pv+":range",as_string=True)) + print("Gain set to:",caget(pv+"range",as_string=True)) @@ -134,7 +150,7 @@ class Keithley: Previously: CA_Filter """ - pv = self.pv + pv = self._pv name=self.name t=0.1 if rate == "Slow": @@ -174,9 +190,9 @@ def ca_reset_all(rate="Slow"): Previously: Reset_CA_all """ ca_dict = ca_dictionary() - for ca_ioc in ca_dict.keys(): - for ca_num in ca_dict[ca_ioc].keys(): - CA = Keithley(ca_ioc,ca_num) + for ca_crate in ca_dict.keys(): + for ca_num in ca_dict[ca_crate].keys(): + CA = Keithley(ca_crate,ca_num) CA.reset() caput("29idb:ca5:read.SCAN","Passive") # CA5 in passive @@ -319,7 +335,7 @@ class SRS: self.gain self.unit self.current - self.get() + self.get(verbose=False) def get(self): """ diff --git a/iexcode/instruments/files_and_folders.py b/iexcode/instruments/files_and_folders.py index cbcb410..e1a1266 100644 --- a/iexcode/instruments/files_and_folders.py +++ b/iexcode/instruments/files_and_folders.py @@ -146,9 +146,9 @@ def folder_mda(run,folder,user_name,file_prefix,ioc,verbose=True): if user_name == 'Staff': user_name="" else: - user_name=user_name+"/" + user_name=user_name+'/' - mda_path="/net/s29data/export/data_29id"+folder+"/"+run+"/"+user_name+"/mda" + mda_path="/net/s29data/export/data_29id"+folder+"/"+run+"/"+user_name+"mda" print("\nMDA folder: " + mda_path) if not (exists(mda_path)): mkdir(mda_path) diff --git a/iexcode/instruments/logfile.py b/iexcode/instruments/logfile.py index dc7d7b5..e7481db 100644 --- a/iexcode/instruments/logfile.py +++ b/iexcode/instruments/logfile.py @@ -1,7 +1,7 @@ from os.path import join,isfile from epics import caget, caput -from iexcode.instruments.IEX_endstations import * +from iexcode.instruments.IEX_endstations import from iexcode.instruments.utilities import today @@ -12,12 +12,14 @@ def log_print(**kwargs): """ prints a comment to the logfile """ + global BL logfile_print(BL.endstation_name,BL.ioc,kwargs['comment']) def log_update(): """ updates the log file with the last scan info """ + global BL try: entry_list,pv_list, format_list = BL.log_entries() logfile_update(BL.endstation_name,BL.ioc,entry_list,pv_list,format_list) @@ -81,21 +83,24 @@ def logfile_name_get(endstation_name): return caget(logfile_name_pv(endstation_name)) -def logfile_fpath(endstation_name,mda_ioc): +def logfile_fpath(endstation_name): """ returns the full path to the logfile based on the current user in the mda scanRecord Previously: logname, logname_generate """ - - try: - filename = logfile_name_get(endstation_name) - user_name = BL.mda.scanRecord_user(mda_ioc) - fpath_with_subfolder = join(user_name,filename) - except: - fpath_with_subfolder = "logfile.txt" - print("Couldn't read log file path, using: "+fpath_with_subfolder) + global BL + #try: + filename = logfile_name_get(endstation_name) + print('filename = ',logfile_name_get(endstation_name)) + user_name = BL.mda.scanRecord_user() + print('user_name = ',BL.mda.scanRecord_user()) + fpath_with_subfolder = join(user_name,filename) + # except: + # fpath_with_subfolder = "logfile.txt" + # logfile_name_get(endstation_name) + # print("Couldn't read log file path, using: "+fpath_with_subfolder) return fpath_with_subfolder @@ -112,7 +117,7 @@ def logfile_print(endstation_name,mda_ioc,comment=''): logfile_name = logfile_name_get(endstation_name) try: - fpath_with_subfolder=logfile_fpath(endstation_name,mda_ioc) + fpath_with_subfolder=logfile_fpath(endstation_name) if not isfile(fpath_with_subfolder): logfile_header(fpath_with_subfolder,entry=None) with open(fpath_with_subfolder,'a') as myfile: @@ -132,12 +137,12 @@ def logfile_header(endstation_name,mda_ioc,header_list): Previously: SaveFile_Header """ version = '1.4' + global BL - fpath_with_subfolder=logfile_fpath(endstation_name,mda_ioc) + fpath_with_subfolder=logfile_fpath(endstation_name) with open(fpath_with_subfolder, "w+") as f: f.write('@Log version: '+ version+'\n\n') - file_path = BL.mda.scanRecord_filepath(mda_ioc) - f.write('FilePath '+endstation_name+': '+file_path+'\n') + f.write('FilePath '+endstation_name+': '+fpath_with_subfolder+'\n') for key in header_list.keys(): f.write(key+' Header: '+ header_list[key]+'\n\n') @@ -151,7 +156,7 @@ def logfile_update(endstation_name,mda_ioc,entry_list,pv_list,format_list): Previously: SaveFile """ - fpath_with_subfolder=logfile_fpath(endstation_name,mda_ioc) + fpath_with_subfolder=logfile_fpath(endstation_name) if not isfile(fpath_with_subfolder): logfile_header(endstation_name,mda_ioc,entry_list) diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py index 2fd9113..c498425 100644 --- a/iexcode/instruments/scanRecord.py +++ b/iexcode/instruments/scanRecord.py @@ -13,18 +13,26 @@ def saveData_get_all(ioc_pv): """ returns saveData info: """ - saveData_info = { - 'fileSystem':caget(ioc_pv+"saveData_fileSystem",as_string=True), - 'subDir':caget(ioc_pv+"saveData_subDir",as_string=True), - 'scanNumber':caget(ioc_pv+"saveData_scanNumber"), - 'baseName':caget(ioc_pv+"saveData_baseName",as_string=True), - } - - filepath = join(saveData_info['fileSystem'],saveData_info['subDir']) - filepath=filepath.replace('//','/') - saveData_info['filepath'] = filepath - - return saveData_info + try: + saveData_info = { + 'fileSystem':caget(ioc_pv+"saveData_fileSystem",as_string=True), + 'subDir':caget(ioc_pv+"saveData_subDir",as_string=True), + 'scanNumber':caget(ioc_pv+"saveData_scanNumber"), + 'baseName':caget(ioc_pv+"saveData_baseName",as_string=True), + } + #take care of subDir starting with '/' + f1 = saveData_info['fileSystem'] + f2 = saveData_info['subDir'][1:] if saveData_info['subDir'][0] =='/' else saveData_info['subDir'] + filepath = join(f1,f2) + #take care f filesystem starting with '//' (VME only) + filepath=filepath.replace('//','/') + saveData_info['filepath'] = filepath + return saveData_info + except: + print(ioc_pv+"not connected") + return {} + + default_positioner_settling_time = 0.05 diff --git a/iexcode/instruments/vortexs29.py b/iexcode/instruments/vortex.py similarity index 100% rename from iexcode/instruments/vortexs29.py rename to iexcode/instruments/vortex.py diff --git a/iexcode/launch_Kappa.py b/iexcode/launch_Kappa.py index 747c8c6..cc00a4f 100644 --- a/iexcode/launch_Kappa.py +++ b/iexcode/launch_Kappa.py @@ -5,7 +5,7 @@ from iexcode.instruments.Kappa_Euler import * from iexcode.instruments.current_amplifiers import * from iexcode.instruments.MPA import * -from iexcode.instruments.vortexs29 import * +from iexcode.instruments.vortexs import * from iexcode.instruments.spec_stuff import * -- GitLab