diff --git a/build/lib/iexcode/instruments/scanRecord.py b/build/lib/iexcode/instruments/scanRecord.py index d9e015ba41aa72f619f837c6f7831af9d3e3c564..07ff5d0c75c9ffab5ea17a14690c43c39511305b 100644 --- a/build/lib/iexcode/instruments/scanRecord.py +++ b/build/lib/iexcode/instruments/scanRecord.py @@ -43,29 +43,57 @@ class ScanRecord: before_scan_pv: pv to be proc'ed be for the start of a scan after_scan_pv: pv to be proc'ed be for the start of a scan - **kwargs + + **kwargs: + if a kwargs is not specified then it will not modify that field of the scanRecord + + empty = True + kwargs = { + 'detector_dictionary':'{}', + 'trigger_dictionary':'{}', + 'before_scan_pv':"", + 'after_scan_pv':"" + } + detector_dictionary trigger_dictionary before_scan_pv after_scan_pv - """ - self.ioc = scan_ioc + if 'empty' in kwargs: + if kwargs['empty']: + kwargs = { + 'detector_dictionary':'{}', + 'trigger_dictionary':'{}', + 'before_scan_pv':"", + 'after_scan_pv':"" + } if 'detector_dictionary' in kwargs: self.detector_dictionary = kwargs['detector_dictionary'] + if 'trigger_dictionary' in kwargs: self.trigger_dictionary = kwargs['trigger_dictionary'] + if 'before_scan_pv' in kwargs: self.before_scan_pv = kwargs['before_scan_pv'] + if 'after_scan_pv' in kwargs: - self.after_scan_pv = kwargs['after_scan_pv'] + self.before_scan_pv = kwargs['after_scan_pv'] + if 'default_detector_settling_time' in kwargs: + self.default_detector_settling_time = kwargs['default_detector_settling_time'] + else: + self.default_detector_settling_time = default_detector_settling_time + if 'default_positioner_settling_time' in kwargs: + self.default_positioner_settling_time = kwargs['default_positioner_settling_time'] else: - pass + self.default_positioner_settling_time = default_positioner_settling_time + + pass @@ -146,36 +174,30 @@ class ScanRecord: ### before and after scans - def _before_after_scan_set(self,**kwargs): + def _before_after_scan_set(self,scan_dim,**kwargs): """ Clears the before_scan and after_scan in all dims Fills in the before_scan and after_after pv for kwargs['scan_dim'] only **kwargs - scan_dim = 1 (default) before_scan_pv after_scan_pv """ - kwargs.setdefault('scan_dim',1) + + scan_pv = self.ioc+"scan"+str(scan_dim) if 'before_scan_pv' in kwargs: self.before_scan_pv = kwargs['before_scan_pv'] + caput(scan_pv+".BSPV",self.before_scan_pv) + caput(scan_pv+".BSCD",1) + caput(scan_pv+".BSWAIT","Wait") + if 'after_scan_pv' in kwargs: self.before_scan_pv = kwargs['after_scan_pv'] + caput(scan_pv+".ASPV",self.after_scan_pv) + caput(scan_pv+".ASCD",1) + caput(scan_pv+".ASWAIT","Wait") - #Clearing all Before/Afters in all dims - for dim in [1,2,3,4]: - caput(self.ioc+"scan"+str(dim)+".BSPV","") - caput(self.ioc+"scan"+str(dim)+".ASPV","") - scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - - caput(scan_pv+".BSPV",self.before_scan_pv) - caput(scan_pv+".BSCD",1) - caput(scan_pv+".BSWAIT","Wait") - - caput(scan_pv+".ASPV",self.after_scan_pv) - caput(scan_pv+".ASCD",1) - caput(scan_pv+".ASWAIT","Wait") def default_after_scan_seq(self,**kwargs): """ @@ -224,14 +246,14 @@ class ScanRecord: caput(after_scan_pv+".LNK4",scan_pv+'.DDLY'+" PP NMS") caput(after_scan_pv+".DO4",settling_time) - return after_scan_pv+"+PROC" + return after_scan_pv+".PROC" ### Resetting: def reset_scan_dim(self,scan_dim,**kwargs): """ Resets all the scanRecords (scanDIM=1,2,3,4) for a given IOC uses Reset_Scan() - **kwargs + **kwargs: detector_dictionary trigger_dictionary before_scan_pv @@ -239,40 +261,54 @@ class ScanRecord: Previously: Reset_ScanAll """ - self.detectors_clear(scan_dim) - self.triggers_clear(scan_dim) + + #clearing + self.detectors_clear(scan_dim,{}) + self.triggers_clear(scan_dim,{}) self.positioners_clear(scan_dim) + #resetting if 'detector_dictionary' in kwargs: self.detectors_set(scan_dim,kwargs['detector_dictionary']) - if 'trigger_dictionary' in kwargs: self.triggers_set(scan_dim,kwargs['trigger_dictionary']) - self._before_after_scan_set(self,kwargs.update({'scan_dim':scan_dim})) + self._before_after_scan_set(scan_dim,**kwargs) - self.detector_settling_time(scan_dim) - self.positioner_settling_time(scan_dim) + #settling time + kwargs.setdefault('scan_dim',scan_dim) + self.detector_settling_time(**kwargs) + self.positioner_settling_time(**kwargs) - def reset_all(self): + def reset_all(self,**kwargs): """ Resets all the scanRecords (scanDIM=1,2,3,4) for a given IOC - uses Reset_Scan() + + **kwargs - scaler='y', only for Kappa ioc + detector_dictionary + trigger_dictionary + before_scan_pv + after_scan_pv + + Note that for scan_dim = 1; default values are those that were set to attributes Previously: Reset_ScanAll """ - + if hasattr(self, 'detector_dictionary'): + kwargs.setdefault('detector_dictionary',self.detector_dictionary) + if hasattr(self, 'trigger_dictionary'): + kwargs.setdefault('trigger_dictionary',self.trigger_dictionary) + if hasattr(self, 'before_scan_pv'): + kwargs.setdefault('before_scan_pv',self.before_scan_pv) + if hasattr(self, 'after_scan_pv'): + kwargs.setdefault('after_scan_pv',self.after_scan_pv) + + #clearing all for scan_dim in range(4,1): self.reset_scan_dim(scan_dim,{},{},'','') - kwargs = { - 'detector_dictionary':self.detector_dictionary, - 'trigger_dictionary':self.trigger_dictionary, - 'before_scan_pv':self.before_scan_pv, - 'after_scan_pv':self.after_scan_pv - } + #setting to defaults self.reset_scan_dim(1,**kwargs) ### default setting @@ -282,8 +318,8 @@ class ScanRecord: Previous: Reset_Scan """ - scan_pv = self.ioc+"scan"+str(scan_dim) - + kwargs.setdefault('scan_dim',scan_dim) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) self.positioner_absolute_mode(absolute=True,**kwargs) # Absolute position self.positioner_after_scan(after="PRIOR POS",**kwargs) # After scan: prior position self.positioner_settling_time(**kwargs)# Positioner Settling time => default @@ -304,14 +340,14 @@ class ScanRecord: caput(scan_pv+".CMND",3) # Clear all Positionners if verbose: - print("\nAll extra positionners cleared") + print("\nAll extra positionners cleared") def positioner_settling_time(self,**kwargs): """ sets the positioner settling time """ kwargs.setdefault('scan_dim',1) - kwargs.setdefault('positioner_settling_time',self.default_positioner_settling_time()) + kwargs.setdefault('positioner_settling_time',self.default_positioner_settling_time) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) @@ -368,10 +404,9 @@ class ScanRecord: kwargs.setdefault('detector_settling_time',default_detector_settling_time) kwargs.setdefault('positioner_settling_time',default_positioner_settling_time) - scan_dim = kwargs['scan_dim'] - self.progress(scan_dim) + self.progress(kwargs['scan_dim']) - scan_pv = self.ioc+"scan"+str(scan_dim) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) posNum = kwargs['positioner_num'] caput(scan_pv+".P"+str(posNum)+"PV",val_pv) @@ -379,16 +414,17 @@ class ScanRecord: caput(scan_pv+".P"+str(posNum)+"SP",start*1.0) caput(scan_pv+".P"+str(posNum)+"EP",stop*1.0) if kwargs['positioner_num'] == 1: - if kwargs['num_points'] : - caput(scan_pv+".NPTS",steps_points) + if 'num_points' in kwargs: + if kwargs['num_points'] : + caput(scan_pv+".NPTS",steps_points) else: caput(scan_pv+".P1SI",steps_points*1.0) - self.detector_settling_time(scan_dim,kwargs['detector_settling_time']) - self.positioner_settling_time(scan_dim,kwargs['positioner_settling_time']) + self.detector_settling_time(**kwargs) + self.positioner_settling_time(**kwargs) #checking that PVs and positioner limits are good - self._check(scan_dim) + self.check(kwargs['scan_dim']) ### detectors and detector settling time @@ -412,18 +448,15 @@ class ScanRecord: detector_dictionary = {detNum:pv} """ scan_pv = self.ioc+"scan"+str(scan_dim) - - if detector_dictionary != None: - for det_num in detector_dictionary.keys(): - det_pv=caget(scan_pv+".D"+det_num+"PV") - caput(det_pv,detector_dictionary[det_num]) + for det_num in detector_dictionary.keys(): + det_pv=caget(scan_pv+".D"+det_num+"PV") + caput(det_pv,detector_dictionary[det_num]) def detector_settling_time(self,**kwargs): """ set the detector settling time """ - kwargs.setdefault('scan_dim',1) - kwargs.setdefault('detector_settling_time',self.default_detector_settling_time()) + kwargs.setdefault('detector_settling_time',self.default_detector_settling_time) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) @@ -439,10 +472,9 @@ class ScanRecord: Previously: Clear_Scan_Triggers """ scan_pv = self.ioc+"scan"+str(scan_dim) - if trigger_dictionary != None: - if len(trigger_dictionary.keys())>0: - for tigger_num in trigger_dictionary.keys(): - caput(scan_pv+".T"+str(tigger_num)+"PV",trigger_dictionary[tigger_num]) + if len(trigger_dictionary.keys())>0: + for tigger_num in trigger_dictionary.keys(): + caput(scan_pv+".T"+str(tigger_num)+"PV",trigger_dictionary[tigger_num]) def triggers_clear(self,scan_dim,trigger_dictionary,verbose=True): """ @@ -519,7 +551,7 @@ class ScanRecord: scan_pv = self.ioc+"scan"+str(scan_dim) caput(scan_pv+'.CMND',1) time.sleep(.5) - SMSG = caget(scan_pv+'SMSG',as_string=True) + SMSG = caget(scan_pv+'.SMSG',as_string=True) if len(SMSG) > 0: print_warning_message('Positioner out of limits \n '+SMSG) limits_ok = False @@ -557,13 +589,13 @@ class ScanRecord: caput(scan_pv+".P"+str(posNum)+"PA",myarray) caput(scan_pv+'.NPTS',len(myarray)) - self.detector_settling_time(scan_dim,kwargs['detector_settling_time']) - self.positioner_settling_time(scan_dim,kwargs['positioner_settling_time']) + self.detector_settling_time(**kwargs) + self.positioner_settling_time(**kwargs) #checking that PVs and positioner limits are good self.check(scan_dim) - def table_reset_after(self,scan_dim): + def table_reset_after(self,**kwargs): """ resets positioner settling time 0.1 sets all positionitonser to linear @@ -572,14 +604,14 @@ class ScanRecord: Previously: Scan_Reset_AfterTable """ #Setting everything back - scan_pv = self.ioc+"scan"+str(scan_dim) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - self.detector_settling_time(self.ioc,scan_dim) + self.detector_settling_time(**kwargs) for i in range(1,5): caput(scan_pv+".P"+str(i)+"SM","LINEAR") - self.positioners_clear(self.ioc,scan_dim) + self.positioners_clear(self.ioc,kwargs['scan_dim']) ############################################################################################################## ############################# progress, go and abort ############################## diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py index 77abe5ac44e27399c6e212747862798ecd19c0ee..30cf6095a9a50842ebe7cf576f68bd546be979c3 100644 --- a/iexcode/instruments/scanRecord.py +++ b/iexcode/instruments/scanRecord.py @@ -43,29 +43,57 @@ class ScanRecord: before_scan_pv: pv to be proc'ed be for the start of a scan after_scan_pv: pv to be proc'ed be for the start of a scan - **kwargs + + **kwargs: + if a kwargs is not specified then it will not modify that field of the scanRecord + + empty = True + kwargs = { + 'detector_dictionary':'{}', + 'trigger_dictionary':'{}', + 'before_scan_pv':"", + 'after_scan_pv':"" + } + detector_dictionary trigger_dictionary before_scan_pv after_scan_pv - """ - self.ioc = scan_ioc + if 'empty' in kwargs: + if kwargs['empty']: + kwargs = { + 'detector_dictionary':'{}', + 'trigger_dictionary':'{}', + 'before_scan_pv':"", + 'after_scan_pv':"" + } if 'detector_dictionary' in kwargs: self.detector_dictionary = kwargs['detector_dictionary'] + if 'trigger_dictionary' in kwargs: self.trigger_dictionary = kwargs['trigger_dictionary'] + if 'before_scan_pv' in kwargs: self.before_scan_pv = kwargs['before_scan_pv'] + if 'after_scan_pv' in kwargs: - self.after_scan_pv = kwargs['after_scan_pv'] + self.before_scan_pv = kwargs['after_scan_pv'] + if 'default_detector_settling_time' in kwargs: + self.default_detector_settling_time = kwargs['default_detector_settling_time'] + else: + self.default_detector_settling_time = default_detector_settling_time + if 'default_positioner_settling_time' in kwargs: + self.default_positioner_settling_time = kwargs['default_positioner_settling_time'] else: - pass + self.default_positioner_settling_time = default_positioner_settling_time + + pass @@ -146,36 +174,30 @@ class ScanRecord: ### before and after scans - def _before_after_scan_set(self,**kwargs): + def _before_after_scan_set(self,scan_dim,**kwargs): """ Clears the before_scan and after_scan in all dims Fills in the before_scan and after_after pv for kwargs['scan_dim'] only **kwargs - scan_dim = 1 (default) before_scan_pv after_scan_pv """ - kwargs.setdefault('scan_dim',1) + + scan_pv = self.ioc+"scan"+str(scan_dim) if 'before_scan_pv' in kwargs: self.before_scan_pv = kwargs['before_scan_pv'] + caput(scan_pv+".BSPV",self.before_scan_pv) + caput(scan_pv+".BSCD",1) + caput(scan_pv+".BSWAIT","Wait") + if 'after_scan_pv' in kwargs: self.before_scan_pv = kwargs['after_scan_pv'] + caput(scan_pv+".ASPV",self.after_scan_pv) + caput(scan_pv+".ASCD",1) + caput(scan_pv+".ASWAIT","Wait") - #Clearing all Before/Afters in all dims - for dim in [1,2,3,4]: - caput(self.ioc+"scan"+str(dim)+".BSPV","") - caput(self.ioc+"scan"+str(dim)+".ASPV","") - - scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - caput(scan_pv+".BSPV",self.before_scan_pv) - caput(scan_pv+".BSCD",1) - caput(scan_pv+".BSWAIT","Wait") - - caput(scan_pv+".ASPV",self.after_scan_pv) - caput(scan_pv+".ASCD",1) - caput(scan_pv+".ASWAIT","Wait") def default_after_scan_seq(self,**kwargs): """ @@ -231,7 +253,7 @@ class ScanRecord: """ Resets all the scanRecords (scanDIM=1,2,3,4) for a given IOC uses Reset_Scan() - **kwargs + **kwargs: detector_dictionary trigger_dictionary before_scan_pv @@ -239,40 +261,54 @@ class ScanRecord: Previously: Reset_ScanAll """ - self.detectors_clear(scan_dim) - self.triggers_clear(scan_dim) + + #clearing + self.detectors_clear(scan_dim,{}) + self.triggers_clear(scan_dim,{}) self.positioners_clear(scan_dim) + #resetting if 'detector_dictionary' in kwargs: self.detectors_set(scan_dim,kwargs['detector_dictionary']) - if 'trigger_dictionary' in kwargs: self.triggers_set(scan_dim,kwargs['trigger_dictionary']) - self._before_after_scan_set(self,kwargs.update({'scan_dim':scan_dim})) + self._before_after_scan_set(scan_dim,**kwargs) - self.detector_settling_time(scan_dim) - self.positioner_settling_time(scan_dim) + #settling time + kwargs.setdefault('scan_dim',scan_dim) + self.detector_settling_time(**kwargs) + self.positioner_settling_time(**kwargs) - def reset_all(self): + def reset_all(self,**kwargs): """ Resets all the scanRecords (scanDIM=1,2,3,4) for a given IOC - uses Reset_Scan() + + **kwargs - scaler='y', only for Kappa ioc + detector_dictionary + trigger_dictionary + before_scan_pv + after_scan_pv + + Note that for scan_dim = 1; default values are those that were set to attributes Previously: Reset_ScanAll """ - + if hasattr(self, 'detector_dictionary'): + kwargs.setdefault('detector_dictionary',self.detector_dictionary) + if hasattr(self, 'trigger_dictionary'): + kwargs.setdefault('trigger_dictionary',self.trigger_dictionary) + if hasattr(self, 'before_scan_pv'): + kwargs.setdefault('before_scan_pv',self.before_scan_pv) + if hasattr(self, 'after_scan_pv'): + kwargs.setdefault('after_scan_pv',self.after_scan_pv) + + #clearing all for scan_dim in range(4,1): self.reset_scan_dim(scan_dim,{},{},'','') - kwargs = { - 'detector_dictionary':self.detector_dictionary, - 'trigger_dictionary':self.trigger_dictionary, - 'before_scan_pv':self.before_scan_pv, - 'after_scan_pv':self.after_scan_pv - } + #setting to defaults self.reset_scan_dim(1,**kwargs) ### default setting @@ -282,8 +318,8 @@ class ScanRecord: Previous: Reset_Scan """ - scan_pv = self.ioc+"scan"+str(scan_dim) - + kwargs.setdefault('scan_dim',scan_dim) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) self.positioner_absolute_mode(absolute=True,**kwargs) # Absolute position self.positioner_after_scan(after="PRIOR POS",**kwargs) # After scan: prior position self.positioner_settling_time(**kwargs)# Positioner Settling time => default @@ -304,14 +340,14 @@ class ScanRecord: caput(scan_pv+".CMND",3) # Clear all Positionners if verbose: - print("\nAll extra positionners cleared") + print("\nAll extra positionners cleared") def positioner_settling_time(self,**kwargs): """ sets the positioner settling time """ kwargs.setdefault('scan_dim',1) - kwargs.setdefault('positioner_settling_time',self.default_positioner_settling_time()) + kwargs.setdefault('positioner_settling_time',self.default_positioner_settling_time) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) @@ -368,10 +404,9 @@ class ScanRecord: kwargs.setdefault('detector_settling_time',default_detector_settling_time) kwargs.setdefault('positioner_settling_time',default_positioner_settling_time) - scan_dim = kwargs['scan_dim'] - self.progress(scan_dim) + self.progress(kwargs['scan_dim']) - scan_pv = self.ioc+"scan"+str(scan_dim) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) posNum = kwargs['positioner_num'] caput(scan_pv+".P"+str(posNum)+"PV",val_pv) @@ -379,16 +414,17 @@ class ScanRecord: caput(scan_pv+".P"+str(posNum)+"SP",start*1.0) caput(scan_pv+".P"+str(posNum)+"EP",stop*1.0) if kwargs['positioner_num'] == 1: - if kwargs['num_points'] : - caput(scan_pv+".NPTS",steps_points) + if 'num_points' in kwargs: + if kwargs['num_points'] : + caput(scan_pv+".NPTS",steps_points) else: caput(scan_pv+".P1SI",steps_points*1.0) - self.detector_settling_time(scan_dim,kwargs['detector_settling_time']) - self.positioner_settling_time(scan_dim,kwargs['positioner_settling_time']) + self.detector_settling_time(**kwargs) + self.positioner_settling_time(**kwargs) #checking that PVs and positioner limits are good - self._check(scan_dim) + self.check(kwargs['scan_dim']) ### detectors and detector settling time @@ -412,18 +448,15 @@ class ScanRecord: detector_dictionary = {detNum:pv} """ scan_pv = self.ioc+"scan"+str(scan_dim) - - if detector_dictionary != None: - for det_num in detector_dictionary.keys(): - det_pv=caget(scan_pv+".D"+det_num+"PV") - caput(det_pv,detector_dictionary[det_num]) + for det_num in detector_dictionary.keys(): + det_pv=caget(scan_pv+".D"+det_num+"PV") + caput(det_pv,detector_dictionary[det_num]) def detector_settling_time(self,**kwargs): """ set the detector settling time """ - kwargs.setdefault('scan_dim',1) - kwargs.setdefault('detector_settling_time',self.default_detector_settling_time()) + kwargs.setdefault('detector_settling_time',self.default_detector_settling_time) scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) @@ -439,10 +472,9 @@ class ScanRecord: Previously: Clear_Scan_Triggers """ scan_pv = self.ioc+"scan"+str(scan_dim) - if trigger_dictionary != None: - if len(trigger_dictionary.keys())>0: - for tigger_num in trigger_dictionary.keys(): - caput(scan_pv+".T"+str(tigger_num)+"PV",trigger_dictionary[tigger_num]) + if len(trigger_dictionary.keys())>0: + for tigger_num in trigger_dictionary.keys(): + caput(scan_pv+".T"+str(tigger_num)+"PV",trigger_dictionary[tigger_num]) def triggers_clear(self,scan_dim,trigger_dictionary,verbose=True): """ @@ -519,8 +551,8 @@ class ScanRecord: scan_pv = self.ioc+"scan"+str(scan_dim) caput(scan_pv+'.CMND',1) time.sleep(.5) - SMSG = caget(scan_pv+'SMSG',as_string=True) - if len(SMSG) > 0: + SMSG = caget(scan_pv+'.SMSG',as_string=True) + if SMSG != 'SCAN Values within limits !!!!!': print_warning_message('Positioner out of limits \n '+SMSG) limits_ok = False else: @@ -557,13 +589,13 @@ class ScanRecord: caput(scan_pv+".P"+str(posNum)+"PA",myarray) caput(scan_pv+'.NPTS',len(myarray)) - self.detector_settling_time(scan_dim,kwargs['detector_settling_time']) - self.positioner_settling_time(scan_dim,kwargs['positioner_settling_time']) + self.detector_settling_time(**kwargs) + self.positioner_settling_time(**kwargs) #checking that PVs and positioner limits are good self.check(scan_dim) - def table_reset_after(self,scan_dim): + def table_reset_after(self,**kwargs): """ resets positioner settling time 0.1 sets all positionitonser to linear @@ -572,14 +604,14 @@ class ScanRecord: Previously: Scan_Reset_AfterTable """ #Setting everything back - scan_pv = self.ioc+"scan"+str(scan_dim) + scan_pv = self.ioc+"scan"+str(kwargs['scan_dim']) - self.detector_settling_time(self.ioc,scan_dim) + self.detector_settling_time(**kwargs) for i in range(1,5): caput(scan_pv+".P"+str(i)+"SM","LINEAR") - self.positioners_clear(self.ioc,scan_dim) + self.positioners_clear(self.ioc,kwargs['scan_dim']) ############################################################################################################## ############################# progress, go and abort ############################## @@ -642,14 +674,21 @@ class ScanRecord: ############################################################################################################## - def empty_scan(self,**kwargs): + def empty_scan(self,npts=1,**kwargs): """ starts a scan with out a drive + npts = number of points + + **kwargs: + execute = True/False (default=True) + Previously: Scan_Empty_Go """ kwargs.setdefault('execute',True) - self.fillin("","",0,1,1,**kwargs) + kwargs.setdefault('num_points',True) + num_points + self.fillin("","",0,npts,1,**kwargs) if kwargs['execute']: self.go(**kwargs)