From 3175719ae850047c3c0985fc3be68e3e98c9c317 Mon Sep 17 00:00:00 2001
From: "FR@29iduser" <rodolakis@anl.gov>
Date: Tue, 13 Sep 2022 09:57:42 -0500
Subject: [PATCH] debugging xrays

---
 build/lib/iexcode/instruments/ARPES.py   |   8 +-
 build/lib/iexcode/instruments/IEX_VPU.py | 218 +++++++++++------------
 build/lib/iexcode/instruments/Kappa.py   |  19 +-
 build/lib/iexcode/instruments/scalers.py |   6 +-
 build/lib/iexcode/instruments/xrays.py   |  21 ++-
 iexcode.egg-info/SOURCES.txt             |   1 +
 iexcode/instruments/IEX_VPU.py           |  13 +-
 iexcode/instruments/xrays.py             |  21 ++-
 8 files changed, 157 insertions(+), 150 deletions(-)

diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py
index ee2f19b..5a172a0 100644
--- a/build/lib/iexcode/instruments/ARPES.py
+++ b/build/lib/iexcode/instruments/ARPES.py
@@ -105,7 +105,7 @@ def ARPES_init(*userName,**kwargs):
 ##############################################################################################################
 ##############################             ARPES detectors and motors         ##############################
 ##############################################################################################################
-def _ARPES_detector_list():
+def _ARPES_ca_list():
     """
     list of detectors to trigger 
 
@@ -354,7 +354,7 @@ def _ARPES_scan_before_sequence(**kwargs):
     caput(before_scan_pv+".DESC","Before Scan")
 
     #sequence put CAs in passive
-    ca_list = _ARPES_detector_list()
+    ca_list = _ARPES_ca_list()
     for (i,ca) in enumerate(ca_list):
         ca_pv = _Keithley_pv(ca[0], ca[1])+':read.SCAN PP NMS'
         caput(before_scan_pv+".LNK" +str(i+1),ca_pv)
@@ -367,7 +367,7 @@ def _ARPES_ca_live_sequence(**kwargs):
     """
     kwargs.setdefault('seq_num',7)
 
-    ca_live_sequence_proc = _ca_live_sequence(iex.BL.ioc,kwargs['seq_num'],_ARPES_detector_list())
+    ca_live_sequence_proc = _ca_live_sequence(iex.BL.ioc,kwargs['seq_num'],_ARPES_ca_list())
     return ca_live_sequence_proc
 
 def _ARPES_scan_after_sequence(**kwargs):
@@ -434,7 +434,7 @@ def _ARPES_detector_triggers_sequence(**kwargs):    # do we need to add 29idb:ca
     userStringSeq_clear(scan_ioc,seq_num=kwargs['seq_num'])
     caput(detector_triggers_pv+".DESC","ARPES_Trigger1")
     
-    ca_list = _ARPES_detector_list()
+    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'
diff --git a/build/lib/iexcode/instruments/IEX_VPU.py b/build/lib/iexcode/instruments/IEX_VPU.py
index 45ddf3a..142e4fc 100644
--- a/build/lib/iexcode/instruments/IEX_VPU.py
+++ b/build/lib/iexcode/instruments/IEX_VPU.py
@@ -16,14 +16,36 @@ IDcal_path="/home/beams22/29IDUSER/Documents/User_Macros/Macros_29id/IEX_Diction
 ################################             ID limits and calibration             ##############################
 ##############################################################################################################
 
-def ID_calc_SP(mono_grating,ID_mode,hv_eV,QP_ratio):    # Mode = state (0=RCP,1=LCP,2=V,3=H)
+pv = 'ID29:'
+pvs={'AccessSecurity':pv+'AccessSecurity.VAL',
+    'mode_rbv':pv+'ActualMode',
+    'mode_val':pv+'DesiredMode.VAL',
+    'check_ready':pv+'feedback.VAL',
+    'check_busy':pv+'BusyRecord',
+    'busy_reset':pv+'Busy.VAL',
+    'main_power':pv+'Main_on_off.VAL',
+    'energy_rbv':pv+'Energy.VAL',
+    'energy_sp':pv+'EnergySet.VAL',
+    'start_ramp':pv+'StartRamp.VAL',
+    'energy_eV_rbv':pv+'EnergyRBV',
+    'energy_eV_sp':pv+'EnergyScanSet.VAL',
+    'scan_eV_rbv':pv+'EnergyScanSeteV',
+    'scan_eV_val':pv+'EnergySetRBV',
+    'table_dir':pv+'TableDirection',
+    'By_q':pv+'ByqRdbk',
+    'Bx_q':pv+'BxqRdbk',
+    'Vcoil':pv+'ByRdbk.VAL',
+    'Hcoil':pv+'BxRdbk.VAL',
+        'QP_ratio':pv+'QuasiRatio.RVAL',}
+
+
+
+def ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio):    # Mode = state (0=RCP,1=LCP,2=V,3=H)
     """Calculate the ID SP for a given polarization mode and energy;
     with Mode = 0 (RCP),1 (LCP), 2 (V), 3 (H)
     
     Previously: ID_Calc
-    """
-    
-    
+    """   
     if type(ID_mode)== str:
         ID_state=ID_state_mode(ID_mode)
     try:
@@ -32,7 +54,7 @@ def ID_calc_SP(mono_grating,ID_mode,hv_eV,QP_ratio):    # Mode = state (0=RCP,1=
     except KeyError:
         message_string='Not a valid ID mode!'+"\nValid Modes: "+str(ID_mode_list())
         print_warning_message(message_string)
-        ID=caget("ID29:EnergySeteV")
+        ID=caget(pvs['energy_rbv'])
     return round(ID,1)
 
 ##############################################################################################################
@@ -48,7 +70,7 @@ def ID_wait_for_permission():
     Previously: WaitForPermission
     """
     while True:
-        ID_Access=caget("ID29:AccessSecurity.VAL")
+        ID_Access=caget(pvs['AccessSecurity'])
         if (ID_Access!=0):
             print("Checking ID permission, please wait..."+dateandtime())
             sleep(30)
@@ -66,8 +88,8 @@ def ID_get_all(verbose=False):
     vals={    
         "ID_mode":ID_mode_get(verbose=False),
         "ID_QP_ratio":ID_QP_ratio_get(verbose=False),
-        "ID_sp":ID_SP_get_eV(verbose=False),
-        "ID_rbv":ID_rbv_get_eV(verbose=False)
+        "ID_sp":caget(pvs['energy_sp']),
+        "ID_rbv":ID_get_eV(verbose=False)
     }
 
     if verbose:
@@ -77,21 +99,28 @@ def ID_get_all(verbose=False):
 
 def ID_energy_range(ID_mode=None):  
     """
-    Returns the ID_min_SP, ID_max_SP for a given ID mode
+    Returns the ID_min_SP, ID_max_SP in keV for a given ID mode
     
     Previously: ID_Range
     """
     if ID_mode == None:
-        ID_state=caget("ID29:ActualMode")
+        ID_state=caget(pvs['mode_rbv'])
     else:
         ID_state = ID_state_mode(ID_mode)
     #       RCP,LCP, V , H , HN
-    ID_min_SP = [400,400,440,250,250]
-    ID_max_SP = 3800
-    #hv_min=[390,390,430,245,245]
-
+    ID_min_SP = [.400,.400,.440,.250,.250]
+    ID_max_SP = 3.800
     return ID_min_SP[ID_state],ID_max_SP
 
+def ID_energy_range_eV(ID_mode=None):
+    """
+    Returns the ID_min_SP, ID_max_SP in eV for a given ID mode
+    
+    Previously: ID_Range
+    """
+    ID_min_keV, ID_max_keV = ID_energy_range(ID_mode)
+    return ID_min_keV*1000.0, ID_max_keV*1000.0
+
 def ID_mode_list():
     """
     returns the ID_mode_List
@@ -120,14 +149,14 @@ def ID_state_get():
     """
     Returns the current ID state
     """
-    ID_state = caget("ID29:ActualMode")
+    ID_state = caget(pvs['mode_rbv'])
     return ID_state
 
 def ID_mode_get(verbose=True):
     """
     Returns the current ID mode
     """
-    ID_state = caget("ID29:ActualMode")
+    ID_state =ID_state_get()
     ID_mode = ID_mode_list()[ID_state]
 
     if verbose:
@@ -138,7 +167,7 @@ def ID_mode_set(ID_mode):
     """
     writes the desired mode to the correct ID pv
     """
-    caput("ID29:DesiredMode.VAL",ID_mode,wait=True,timeout=18000)     # RCP
+    caput(pvs['mode_val'],ID_mode,wait=True,timeout=18000)     # RCP
 
 
 def ID_ready(verbose=True):
@@ -148,13 +177,13 @@ def ID_ready(verbose=True):
     Previously: ID_Ready
     """
     while True:
-        RBV=caget("ID29:Energy.VAL")
-        checkready=caget("ID29:feedback.VAL")
-        checkbusy=caget("ID29:BusyRecord")
+        RBV=caget(pvs['energy_rbv'])
+        checkready=caget(pvs['check_ready'])
+        checkbusy=caget(pvs['check_busy'])
         if (checkready!="Ready") or (RBV < 3.7):
             sleep(2)
         elif ((checkready=="Ready") and (RBV > 3.7)) and (checkbusy=="Busy"):
-            caput("ID29:Busy.VAL",0)
+            caput(pvs['busy_reset'],0)
         else:
             if verbose:
                 print("ID Ready")      
@@ -164,7 +193,7 @@ def ID_power_status():
     """
     gets if the ID power supplies are On or Off
     """
-    ID_OnOff=caget('ID29:Main_on_off.VAL')
+    ID_OnOff=caget(pvs['main_power'])
     if ID_OnOff == 1: 
         return 'Off'
     elif ID_OnOff == 0:
@@ -175,7 +204,7 @@ def ID_off(verbose=True):
     waits for permission then turns on the main coils OFF    
     """
     ID_wait_for_permission()
-    caput("ID29:Main_on_off.VAL",1,wait=True,timeout=18000)
+    caput(pvs['main_power'],1,wait=True,timeout=18000)
     sleep(5)
     if verbose:
         print("ID is now off")
@@ -185,12 +214,13 @@ def ID_on(verbose=True):
     """
     waits for permission then turns on the main coils On
     """
+    
     ID_wait_for_permission()
     if verbose:
         print("Starting ID  -  "+dateandtime())
     
-    caput("ID29:EnergySet.VAL",3.8)
-    caput("ID29:Main_on_off.VAL",0,wait=True,timeout=18000)
+    caput(pvs['energy_sp'],3.8)
+    caput(pvs['main_power'],0,wait=True,timeout=18000)
 
 def ID_start(ID_mode='RCP',QP_ratio=None, verbose=True):
     """
@@ -241,58 +271,40 @@ def ID_switch_mode(ID_mode):
     except:
         print_warning_message("Not a valid ID mode")
 
-def ID_SP_get(verbose=False):
-    """
-    returns the ID setpoint in keV
-    """
-    ID_SP = caget("ID29:EnergyScanSet.VAL")
-    if verbose:
-        print("ID_SP: ", ID_SP)
-    return ID_SP
-
-def ID_SP_get_eV(verbose=False):
-    """
-    returns the ID setpoint in eV
-    """
-    ID_SP = ID_SP_get(verbose=False)
-    if verbose:
-        print("ID_SP: ", ID_SP)
-    return ID_SP
-
-def ID_rbv_get(verbose=False):
+def ID_get(verbose=False):
     """
     returns the readback value for the 
     """
-    ID_RBV = caget("ID29:EnergyRBV")
+    ID_RBV = caget(pvs['energy_rbv'])
     if verbose:
         print("ID_RBV: ", ID_RBV)
     return ID_RBV  
 
-def ID_rbv_get_eV(verbose=False):
+def ID_get_eV(verbose=False):
     """
     returns the readback value for the 
     """
-    ID_RBV = ID_rbv_get(verbose=False)
+    ID_RBV = ID_get(verbose=False)*1000
     if verbose:
         print("ID_RBV: ", ID_RBV)
     return ID_RBV 
 
 
-def ID_SP_set(hv_eV,verbose=True):
+def ID_set(keV,verbose=True):
     """
     "Sets the ID set point to a specific value (hv(eV)) which will not likely be optimum"
 
     Previously: SetID_Raw
     """
     def _ID_write_SP_proc(keV):
-        caput("ID29:EnergyScanSet.VAL",keV,wait=True,timeout=18000)
+        caput(pvs['energy_sp'],keV,wait=True,timeout=18000)
         sleep(0.5)
-        caput("ID29:EnergyScanSet.VAL",(keV+0.001),wait=True,timeout=18000)
-        caput('ID29:StartRamp.VAL',1)
+        caput(pvs['start_ramp'],1)
 
-    def _ID_bw_ok(ID_SP):
-        ID_bw = ID_SP*0.095
-        ID_diff = abs(ID_rbv_get()-ID_SP)
+    def _ID_bw_ok(keV,verbose=False):
+        ID_SP = caget(pvs['energy_sp'])
+        ID_bw = ID_SP * 0.095
+        ID_diff = abs(ID_get()-keV)
         if ID_diff > ID_bw:
             return False
         else:
@@ -304,58 +316,33 @@ def ID_SP_set(hv_eV,verbose=True):
 
     #checking if desired is with allowed range, if not printing the nearest allowed value
     ID_max,ID_min = ID_energy_range()
-    ID_SP=min(max(hv_eV,ID_min),ID_max)*1.0
-    if hv_eV < ID_min or hv_eV > ID_max:
+    if keV < ID_min or keV > ID_max:
         message_string="Set point out of BL energy range \nPlease select a different energy."
-        message_string+="\nClosest allowed value is "+str(ID_SP)
+        message_string+="\nClosest allowed value is "+str(min(max(keV,ID_min),ID_max))
         print_warning_message(message_string)
     else:
         #desired energy is within range
-        ID_SP_RBV=round(caget("ID29:EnergySet.VAL"),3)*1000
-        ID_RBV=caget("ID29:EnergyRBV")
-        if ID_SP == ID_SP_RBV:
-            #ID is already at the SP energy
-            if verbose:
-                print("ID SET : "+"%.1f" % ID_SP, "eV")
-                print("ID RBV : "+"%.1f" % ID_RBV, "eV")
-                print(caget('ID29:TableDirection',as_string=True))
-             
-        else:
-            # ID not at energy
-            ready = ID_ready(verbose=False)
-            if ready:
-                #set the energy
-                _ID_write_SP_proc(ID_SP/1000)
-
-                while not ID_ready(verbose=False):
-                    sleep(20)
-
-                #is ID within some bandwidth
-                if _ID_bw_ok(ID_SP) == False:
-                    sleep(20)
-                    if _ID_bw_ok(ID_SP) == False:
-                        print("\nID RBV : "+"%.1f" % ID_RBV, "eV")
-                        ID_start(ID_mode_get())
-                        if ID_ready(verbose=False):
-                            #set the energy
-                            _ID_write_SP_proc(ID_SP/1000)
-               
-    if verbose:
-        print("\nID SET : "+"%.1f" % ID_SP, "eV") 
-        print("ID RBV : "+"%.1f" % ID_RBV, "eV")
-        print(caget('ID29:TableDirection',as_string=True))    
-
-        if ID_QP_ratio_get()[0] < 100:
-            #check ratio
-            Byq=caget("ID29:ByqRdbk")
-            Vcoil=caget("ID29:ByRdbk.VAL")
-            ratio=Byq/Vcoil
-            ratio_RBV=caget("ID29:QuasiRatio.RVAL")
-            if verbose:
-                print("QP ratio =", round(ratio,3)*100,"%")
-                print("QP RBV   =", ratio_RBV,"%")    
-
-def ID_energy_set(hv_eV,QP_ratio=None):
+        _ID_write_SP_proc(keV)
+        # ID not at energy
+        ready = ID_ready(verbose=False)
+        if ready:
+            #set the energy
+            _ID_write_SP_proc(ID_SP/1000)
+            while not ID_ready(verbose=False):
+                sleep(20)
+            #is ID within some bandwidth
+            if _ID_bw_ok(ID_SP,verbose=verbose):
+                if verbose:
+                    ID_SP = caget(pvs['energy_sp'])
+                    ID_RBV = ID_get()
+                    print("ID SET : "+"%.1f" % ID_SP, "eV")
+                    print("ID RBV : "+"%.1f" % ID_RBV, "eV")
+                    print(caget(pvs['table_dir'],as_string=True))
+            else:
+                ID_QP_ratio_get(verbose)
+ 
+
+def ID_energy_set_eV(hv_eV,QP_ratio=None,verbose=True):
     """
     Sets optimum ID set point for hv(eV) (max intensity)
     and opens the main shutter
@@ -366,8 +353,8 @@ def ID_energy_set(hv_eV,QP_ratio=None):
     """
     ID_mode = ID_mode_list()[ID_state_get()]
     mono_grating = mono_grating_get()
-    ID_SP = ID_calc_SP(mono_grating,ID_mode,hv_eV,QP_ratio)
-    ID_SP_set(ID_SP)
+    keV = ID_calc_eV(mono_grating,ID_mode,hv_eV,QP_ratio)/1000.0
+    ID_set(keV)
 
     
 def ID_QP_ratio_get(verbose=True):
@@ -376,13 +363,14 @@ def ID_QP_ratio_get(verbose=True):
     calculate the QP ratio
 
     """
-    Byq=caget("ID29:ByqRdbk")
-    Vcoil=caget("ID29:ByRdbk.VAL")
-    ratio_calc=Byq/Vcoil
-    ratio_RBV=caget("ID29:QuasiRatio.RVAL")
+    Byq=caget(pvs['By_q'])
+    Vcoil=caget(pvs['Vcoil'])
+    ratio_calc=round(Byq/Vcoil,3)*100
+    ratio_RBV=caget(pvs['QP_ratio'])
     if verbose:
-        print("QP ratio =", round(ratio_RBV,3)*100,"%")
         print("QP RBV   =", ratio_RBV,"%")
+        print("QP calculated ratio =", ratio_calc ,"%")
+        
 
     if abs(ratio_RBV-ratio_calc)>1:
         message_string="QP RBV and QP calc do not agree \nCheck Interlocks"
@@ -479,9 +467,9 @@ def ID_scan_pvs():
     """ 
     returns the rbv and val for scanning 
     """
-    val_pv="ID29:EnergyScanSeteV"
-    rbv_pv="ID29:EnergySetRBV"
-    return val_pv, rbv_pv
+    val_pv=pvs['scan_eV_val']
+    rbv_pv=pvs['scan_eV_rbv']
+    return rbv_pv, val_pv
 
 def ID_scan_fillin(mda,scan_dim,start,stop,step,**kwargs):
     """
@@ -491,7 +479,7 @@ def ID_scan_fillin(mda,scan_dim,start,stop,step,**kwargs):
     """
     #Setting up the ScanRecord for ID in Table mode
     val_pv, rbv_pv = ID_scan_pvs()
-    mda.fillin(scan_dim,val_pv,rbv_pv,start,stop,step,**kwargs)
+    mda.fillin(scan_dim,rbv_pv,val_pv,start,stop,step,**kwargs)
 
 
 def ID_scan_fillin_table(mda,scan_dim,ID_array,**kwargs):
@@ -501,8 +489,8 @@ def ID_scan_fillin_table(mda,scan_dim,ID_array,**kwargs):
     **kwargs => scanRecord.fillin kwargs
     """
     #Setting up the ScanRecord for ID in Table mode
-    val_pv, rbv_pv = ID_scan_pvs()
-    mda.fillin.table(scan_dim,val_pv,rbv_pv,ID_array,**kwargs)
+    rbv_pv, val_pv = ID_scan_pvs()
+    mda.fillin.table(scan_dim,rbv_pv,val_pv,ID_array,**kwargs)
 
 ##############################################################################################################
 ##############################             ID direction table        ##############################
diff --git a/build/lib/iexcode/instruments/Kappa.py b/build/lib/iexcode/instruments/Kappa.py
index 972b016..175c368 100644
--- a/build/lib/iexcode/instruments/Kappa.py
+++ b/build/lib/iexcode/instruments/Kappa.py
@@ -9,22 +9,24 @@ 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.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv
+from iexcode.instruments.Logfile import Logfile
 from iexcode.instruments.staff import staff_detector_dictionary
-from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda
-from iexcode.instruments.staff import staff_detector_dictionary
-from iexcode.instruments.xrays import _xrays_detector_dictionary,_xrays_reset,xrays_get_all
+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, userCalcOut_clear
+from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs
 
 from iexcode.instruments.Motors import Motors
-from iexcode.instruments.current_amplifiers import SRS, ca_reset_all, _Keithley_pv
+from iexcode.instruments.current_amplifiers import Keithley, _Keithley_pv, ca_reset_all, _ca_live_sequence
+
 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
+
 #endstation specific
 from iexcode.instruments.kappa_det import Kappa_Detector
 from iexcode.instruments.scalers import scaler_cts
@@ -80,7 +82,6 @@ def kappa_init(*userName,**kwargs):
         iex.BL.mda.log('kappa',user_name,_kappa_log_header(),_kappa_log_entries)
 
     #global detectors
-    
     tey = SRS("29idMZ0:scaler1.S2", '29idd:A1')
     d3 = SRS("29idMZ0:scaler1.S3", '29idd:A2')
     d4 = SRS("29idMZ0:scaler1.S4", '29idd:A3')
@@ -103,7 +104,7 @@ def kappa_init(*userName,**kwargs):
 ##############################################################################################################
 ##############################                    detectors and motors                ##############################
 ##############################################################################################################
-def _kappa_detector_list():
+def _kappa_ca_list():
     """
     list of detectors to trigger 
 
@@ -496,12 +497,12 @@ def _kappa_detector_triggers_sequence(scan_ioc,scan_dim,**kwargs):    # do we ne
     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_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'
diff --git a/build/lib/iexcode/instruments/scalers.py b/build/lib/iexcode/instruments/scalers.py
index 7face9f..2c17c47 100644
--- a/build/lib/iexcode/instruments/scalers.py
+++ b/build/lib/iexcode/instruments/scalers.py
@@ -10,10 +10,12 @@ def scaler_cts(time_seconds=0.1,verbose=True):
     'For new endstation modify here:'
     if iex.BL.endstation_name == 'kappa':
         Kappa_scaler(time_seconds,verbose=verbose)
+    elif iex.BL.endstation_name == 'Octupole':
+        Octupole_scaler(time_seconds,verbose)
     else:
         pass
 
-def Kappa_scaler(time_seconds=0.1,verbose=True):
+def Kappa_scaler(time_seconds,verbose):
     """
     Sets the integration time for the scalers in the Kappa chamber
     and mpa filter num if mpa is running
@@ -31,7 +33,7 @@ def Kappa_scaler(time_seconds=0.1,verbose=True):
         print("Integration time set to:", str(time_seconds))
 
 
-def Octupole_scaler(time_seconds=0.1,verbose=True):
+def Octupole_scaler(time_seconds,verbose):
     """
     Sets the integration time for the scalers in the Kappa chamber
     and mpa filter num if mpa is running
diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py
index f6c1beb..b105234 100644
--- a/build/lib/iexcode/instruments/xrays.py
+++ b/build/lib/iexcode/instruments/xrays.py
@@ -3,6 +3,7 @@ functions related to using x-rays
 
 """
 import numpy as np
+#import math
 from time import sleep
 
 from epics import caget,caput
@@ -29,9 +30,12 @@ mpa = iex.mpa
 def _xrays_reset(verbose=True):
     if verbose:
         print("resetting the mono limits")
+
     mono_limits_reset()
+
     if verbose:
         print("resetting beamline encoders")
+
     xray_motor_encoder_sync()
 
 
@@ -239,7 +243,7 @@ def energy(hv_eV,slit_coeff=1,m3r=True,QP_ratio=100,verbose=True):
         print_warning_message(message_string)
 
 
-    ID_energy_set(hv_eV,QP_ratio,verbose=verbose)
+    ID_energy_set_eV(hv_eV,QP_ratio,verbose=verbose)
     mono_energy_set(hv_eV,verbose=verbose)
     apertures_set(c_2B=slit_coeff,c_1A=1,verbose=verbose)
 
@@ -250,10 +254,10 @@ def _energy_range_min_max():
     """
     returns the min,max energies for the current grating/ID setting
     """
-    ID_min, ID_max = ID_energy_range()
+    ID_min, ID_max = ID_energy_range_eV()
     mono_min, mono_max = mono_energy_range()
-    hv_max = np.min(ID_max, mono_max)
-    hv_min = np.max(ID_min, mono_min)
+    hv_max = min(ID_max, mono_max)
+    hv_min = max(ID_min, mono_min)
     return hv_min,hv_max
 
 def _energy_range_check(hv):
@@ -264,8 +268,8 @@ def _energy_range_check(hv):
     Previously: SetRange()
     """
     hv_min,hv_max = _energy_range_min_max()
-    hv = np.min(hv_max,hv)
-    hv = np.max(hv_min,hv)
+    hv = min(hv_max,hv)
+    hv = max(hv_min,hv)
     return hv
 
 def qp(QP_ratio):
@@ -294,9 +298,8 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True):
 
     Previously: SetSlit_BL
     """
-    mono_vals=mono_get_all()
-    hv_rbv = mono_vals['ENERGY_MON']
-    grt  = mono_vals['GRT']
+    hv_rbv = mono_energy_get()
+    grt  = mono_grating_get
     
     # slit were defined for the range: 500 - 2000
     hv = max(hv_rbv,500)
diff --git a/iexcode.egg-info/SOURCES.txt b/iexcode.egg-info/SOURCES.txt
index 28247ed..514373e 100644
--- a/iexcode.egg-info/SOURCES.txt
+++ b/iexcode.egg-info/SOURCES.txt
@@ -16,6 +16,7 @@ iexcode/instruments/ARPES.py
 iexcode/instruments/FMB_mirrors.py
 iexcode/instruments/IEX_BL_config.py
 iexcode/instruments/IEX_VPU.py
+iexcode/instruments/IEX_VPU_backup.py
 iexcode/instruments/IEX_cameras.py
 iexcode/instruments/Kappa.py
 iexcode/instruments/Kappa_det.py
diff --git a/iexcode/instruments/IEX_VPU.py b/iexcode/instruments/IEX_VPU.py
index f368beb..142e4fc 100644
--- a/iexcode/instruments/IEX_VPU.py
+++ b/iexcode/instruments/IEX_VPU.py
@@ -99,7 +99,7 @@ def ID_get_all(verbose=False):
 
 def ID_energy_range(ID_mode=None):  
     """
-    Returns the ID_min_SP, ID_max_SP for a given ID mode
+    Returns the ID_min_SP, ID_max_SP in keV for a given ID mode
     
     Previously: ID_Range
     """
@@ -112,6 +112,15 @@ def ID_energy_range(ID_mode=None):
     ID_max_SP = 3.800
     return ID_min_SP[ID_state],ID_max_SP
 
+def ID_energy_range_eV(ID_mode=None):
+    """
+    Returns the ID_min_SP, ID_max_SP in eV for a given ID mode
+    
+    Previously: ID_Range
+    """
+    ID_min_keV, ID_max_keV = ID_energy_range(ID_mode)
+    return ID_min_keV*1000.0, ID_max_keV*1000.0
+
 def ID_mode_list():
     """
     returns the ID_mode_List
@@ -333,7 +342,7 @@ def ID_set(keV,verbose=True):
                 ID_QP_ratio_get(verbose)
  
 
-def ID_energy_set(hv_eV,QP_ratio=None):
+def ID_energy_set_eV(hv_eV,QP_ratio=None,verbose=True):
     """
     Sets optimum ID set point for hv(eV) (max intensity)
     and opens the main shutter
diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py
index f6c1beb..b105234 100644
--- a/iexcode/instruments/xrays.py
+++ b/iexcode/instruments/xrays.py
@@ -3,6 +3,7 @@ functions related to using x-rays
 
 """
 import numpy as np
+#import math
 from time import sleep
 
 from epics import caget,caput
@@ -29,9 +30,12 @@ mpa = iex.mpa
 def _xrays_reset(verbose=True):
     if verbose:
         print("resetting the mono limits")
+
     mono_limits_reset()
+
     if verbose:
         print("resetting beamline encoders")
+
     xray_motor_encoder_sync()
 
 
@@ -239,7 +243,7 @@ def energy(hv_eV,slit_coeff=1,m3r=True,QP_ratio=100,verbose=True):
         print_warning_message(message_string)
 
 
-    ID_energy_set(hv_eV,QP_ratio,verbose=verbose)
+    ID_energy_set_eV(hv_eV,QP_ratio,verbose=verbose)
     mono_energy_set(hv_eV,verbose=verbose)
     apertures_set(c_2B=slit_coeff,c_1A=1,verbose=verbose)
 
@@ -250,10 +254,10 @@ def _energy_range_min_max():
     """
     returns the min,max energies for the current grating/ID setting
     """
-    ID_min, ID_max = ID_energy_range()
+    ID_min, ID_max = ID_energy_range_eV()
     mono_min, mono_max = mono_energy_range()
-    hv_max = np.min(ID_max, mono_max)
-    hv_min = np.max(ID_min, mono_min)
+    hv_max = min(ID_max, mono_max)
+    hv_min = max(ID_min, mono_min)
     return hv_min,hv_max
 
 def _energy_range_check(hv):
@@ -264,8 +268,8 @@ def _energy_range_check(hv):
     Previously: SetRange()
     """
     hv_min,hv_max = _energy_range_min_max()
-    hv = np.min(hv_max,hv)
-    hv = np.max(hv_min,hv)
+    hv = min(hv_max,hv)
+    hv = max(hv_min,hv)
     return hv
 
 def qp(QP_ratio):
@@ -294,9 +298,8 @@ def apertures_set(c_2B=1,c_1A=1,verbose=True):
 
     Previously: SetSlit_BL
     """
-    mono_vals=mono_get_all()
-    hv_rbv = mono_vals['ENERGY_MON']
-    grt  = mono_vals['GRT']
+    hv_rbv = mono_energy_get()
+    grt  = mono_grating_get
     
     # slit were defined for the range: 500 - 2000
     hv = max(hv_rbv,500)
-- 
GitLab