From d02897d6e9d97ce3cdca92a96f076aa2d1cd0c66 Mon Sep 17 00:00:00 2001
From: "FR@29iduser" <rodolakis@anl.gov>
Date: Thu, 15 Sep 2022 10:25:21 -0500
Subject: [PATCH] debugging

---
 build/lib/iexcode/instruments/FMB_mirrors.py  |  22 +-
 build/lib/iexcode/instruments/IEX_VPU.py      |   2 +-
 build/lib/iexcode/instruments/diagnostics.py  | 249 +++++++++---------
 build/lib/iexcode/instruments/slits.py        |   2 +-
 build/lib/iexcode/instruments/xrays.py        |   6 +-
 build/lib/iexcode/macros/commissioning.py     |   2 +-
 build/lib/iexcode/macros/start_of_the_week.py |  22 +-
 iexcode/instruments/FMB_mirrors.py            |  22 +-
 iexcode/instruments/IEX_VPU.py                |   2 +-
 iexcode/instruments/diagnostics.py            | 249 +++++++++---------
 iexcode/instruments/m3r.py                    |   2 +-
 iexcode/instruments/slits.py                  |  19 +-
 iexcode/instruments/xrays.py                  |   6 +-
 iexcode/macros/commissioning.py               |  23 +-
 iexcode/macros/start_of_the_week.py           |  22 +-
 15 files changed, 333 insertions(+), 317 deletions(-)

diff --git a/build/lib/iexcode/instruments/FMB_mirrors.py b/build/lib/iexcode/instruments/FMB_mirrors.py
index 1c92a07..ca1996f 100644
--- a/build/lib/iexcode/instruments/FMB_mirrors.py
+++ b/build/lib/iexcode/instruments/FMB_mirrors.py
@@ -12,7 +12,7 @@ def _FMB_mirror_ioc(mirror_num):
     returns the ioc name for the given mirror number: 
     miror_num = 0 / 1 / 3  for M0 / M1 /M3R respectively
     """
-    ioc = '29id_'+['M0','M1','','M3R'][mirror_num]+":"
+    ioc = '29id_'+['m0','m1','','m3r'][mirror_num]+":"
     return ioc
 
 def FMB_mirror_status(mirror_num):
@@ -22,7 +22,7 @@ def FMB_mirror_status(mirror_num):
 
     status =1 when positioned
     """
-    ioc = '29id_'+['M0','M1','','M3R'][mirror_num]+":"
+    ioc = '29id_'+['m0','m1','','m3r'][mirror_num]+":"
     pv = _FMB_mirror_ioc(mirror_num)
     status=caget(pv+'SYSTEM_STS')
 
@@ -52,9 +52,9 @@ def FMB_mirror_get(mirror_num,verbose=True):
     for axis in axis_labels:
         rbv,sp = FMB_mirror_axis_position(mirror_num,axis, verbose=False)
         vals.append(round(rbv,3))
-        message =+ "%.3f"+"/" % rbv 
+        message = message + str(round(rbv,3))+"/" 
     if verbose:
-        print(message)
+        print(message[0:-1]) # to not have the last /
     return vals
 
 def FMB_mirror_move(mirror_num,axis,val,verbose=True):
@@ -71,7 +71,7 @@ def FMB_mirror_move(mirror_num,axis,val,verbose=True):
     axes = ['TX','TY','TZ','RX','RY','RZ']
     if axis in axes:
         caput(pv+axis+"_SP.PREC",3)  
-        caput(pv+axis+"_POS_SP")
+        caput(pv+axis+"_POS_SP",val)
         caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000)
         while True:
             if FMB_mirror_status != 1:
@@ -83,7 +83,7 @@ def FMB_mirror_move(mirror_num,axis,val,verbose=True):
     else:
         print_warning_message(axis+' is not a valid axis chose '+axes)
 
-def FMB_mirror_move_all(mirror_num,position_list,verbose=True):
+def FMB_mirror_move_all(mirror_num,position_list,verbose=True,execute=True):
     """
     miror_num = 0 / 1 / 3  for M0 / M1 /M3R respectively
     position_list = [TX,TY,TZ,RX,RY,RZ]
@@ -91,12 +91,14 @@ def FMB_mirror_move_all(mirror_num,position_list,verbose=True):
     "Previously: Move_M0M1
     """  
     pv = _FMB_mirror_ioc(mirror_num)
-    for axis in ['TX','TY','TZ','RX','RY','RZ']:
+    for i, axis in enumerate(['TX','TY','TZ','RX','RY','RZ']):
         caput(pv+axis+"_SP.PREC",3)  
-        caput(pv+axis+"_POS_SP")
-    caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000)
+        caput(pv+axis+"_POS_SP",position_list[i])
+        sleep(.5)
+    if execute:
+        caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000)
     while True:
-        if FMB_mirror_status != 1:
+        if FMB_mirror_status(mirror_num) != 1:
             sleep(.5)
         else:
             break
diff --git a/build/lib/iexcode/instruments/IEX_VPU.py b/build/lib/iexcode/instruments/IEX_VPU.py
index feab470..7094082 100644
--- a/build/lib/iexcode/instruments/IEX_VPU.py
+++ b/build/lib/iexcode/instruments/IEX_VPU.py
@@ -276,7 +276,7 @@ def ID_switch_mode(ID_mode):
             print("Turning ID off...")
             ID_off(verbose=True)
             sleep(10)
-            
+            ID_on(verbose=True)
             print("Switching ID mode, please wait...")
             ID_mode_set(ID_mode) 
             ID_ready()
diff --git a/build/lib/iexcode/instruments/diagnostics.py b/build/lib/iexcode/instruments/diagnostics.py
index 104d793..b72d31b 100644
--- a/build/lib/iexcode/instruments/diagnostics.py
+++ b/build/lib/iexcode/instruments/diagnostics.py
@@ -1,31 +1,62 @@
-from iexcode.instruments.current_amplifiers import Keithley,SRS
 from numpy import nan
 
 from epics import caput, caget
 
 import iexcode.instruments.cfg as iex
-
+from iexcode.instruments.current_amplifiers import Keithley,SRS
+from iexcode.instruments.utilities import print_warning_message
 ##############################################################################################################
 ################################            default positions             ##############################
 ##############################################################################################################
-def diagnostics_go2(diag_name,preset_name):
-    pv = _diagnostics_preset_pv(diag_name,preset_name)
-    caput(pv+'_Trigger.PROC',1)
-
-def diagnostics_sp_read(diag_name,preset_name):
-    pv = _diagnostics_preset_pv(diag_name,preset_name)
-    caget(pv+'_Setpoint.VAL')
+def _diagnostics_presets():
+    presets={
+        'H-wire':['OUT','Start'],
+        'V-wire':['OUT','Start'],
+        'H-Diagon':['OUT','Si-2800','ML-400','ML-460'],
+        'V-Diagon':['OUT','Si-2800','ML-400','ML-460'],
+        'D1A':['OUT','Mesh'],
+        'D2B':['OUT','Mesh','YAG'],
+        'D3B':['OUT','YAG'],
+        'D4C':['OUT','Mesh','YAG'],
+        'gas-cell':['OUT','Diode1','Diode2'],
+        'D4D':['OUT','Mesh','YAG'],
+        'D5D':['OUT','Mesh','YAG','Diode'],
+    }
+    return presets
 
-def _diagnostics_sp_write(diag_name,preset_name):
-    pv = _diagnostics_preset_pv(diag_name,preset_name)
-    caget(pv+'_Setpoint.VAL')
+#For new endstation modify here:
+def _diagnostics_inout_dict():
+    """
+    dictionary to convert quick_name to preset_names
+    """
+    #quick_name: (diag_name, preset_in,preset_out)
+    d={
+        'mesh_W':('D1A','Mesh','OUT'),
+        'mesh_c':('D4C','Mesh','OUT'),
+        'mesh_d':('D4D','Mesh','OUT'),
+        'diode_c':('gas-cell','Diode1','OUT'),
+        'diode_d':('gas-D4D','Diode','OUT'),
+        }
+
+    return d
+
+#For new endstation modify here:
+def _diagnostic_CA_dict():
+    CA_dict={
+        'diode_c':Keithley('b',15),
+        'mesh_d':SRS("29idMZ0:scaler1.S14", '29idd:A4'),
+    }
+    return CA_dict
 
+##############################################################################################################
+################################            access presets            ##############################
+##############################################################################################################
 def _diagnostics_preset_pv(diag_name,preset_name):
     """
     dictionary of the motor pvs for the beamline diagnostics
     """
     ioc = '29idb:'
-    d = _diagnostics_get_presets()
+    d = _diagnostics_presets()
     pv=None
     
     if diag_name.casefold() in (key.casefold() for key in list(d.keys())):
@@ -47,130 +78,96 @@ def _diagnostics_preset_pv(diag_name,preset_name):
     
     return pv
 
-def _diagnostics_get_presets():
-    presets={
-        'H-wire':['OUT','Start'],
-        'V-wire':['OUT','Start'],
-        'H-Diagon':['OUT','Si-2800','ML-400','ML-460'],
-        'V-Diagon':['OUT','Si-2800','ML-400','ML-460'],
-        'D1A':['OUT','Mesh'],
-        'D2B':['OUT','Mesh','YAG'],
-        'D3B':['OUT','YAG'],
-        'D4C':['OUT','Mesh','YAG'],
-        'gas-cell':['OUT','Diode1','Diode2'],
-        'D4D':['OUT','Mesh','YAG'],
-        'D5D':['OUT','Mesh','YAG'],
-    }
-    return presets
-    
+def diagnostics_go2(diag_name,preset_name):
+    pv = _diagnostics_preset_pv(diag_name,preset_name)
+    caput(pv+'_Trigger.PROC',1)
 
-###### We should make pvs in the 29idb ioc to hold these values:
-def _diagnostics_dict():
-    """
-    Dictionary of Diagnostic positions In and Out by either motor number or name
-    WARNING: When updating motor values, also update the following screens:
-        - 29id_BL_Layout.ui               (for MeshD and DiodeC)
-        - 29id_Diagnostic.ui
-        - 29idd_graphic
-    usage:       
-        diagnostics_dict()['name'] returns dictionary motor:name
-        diagnostics_dict()['motor'] returns dictionary name:motor   
-        diagnostics_dict()['In'] returns dictionary motor:In position  (where val can be a list for multiple position)  
-        diagnostics_dict()['Out'] returns dictionary motor:In position  
-                motor=diagnostics_dict()['motor']['gas-cell']
-                pos_in=diagnostics_dict()['In'][motor]
-                
-    WARNING: When updating MeshD (D5D) value: update value in the dictionnary + caQtdM (29id_BL_Diag.ui + 29idd_graphic.ui + Diagnostic.ui)
-    
-    Previously: AllDiag_dict
-    """
-    diag={}
-    diag["In"]  = {                5:-55, 6:-46,          17:-56, 20:-30, 25:-56, 28:[-3,-3]}
-                                                                                    
-    diag["Out"] = {1:-4, 2:-10, 3:-4, 4:-4, 5:-20, 6:-20, 7:-20, 17:-20, 20:-21, 25:-20, 28:-3}    
-    diag["name"]= {1:"H-wire", 2:"V-wire", 3:"H-Diagon", 4:"V-Diagon", 5:"W-mesh",
-     6:"D2B", 7:"D3B", 17:"D4C/pre-slit", 20:"gas-cell", 25:"D4D/pre-slit", 28:"D5D/pre-RSXS"}
-    diag["motor"]= {"H-wire":1, "V-wire":2, "H-Diagon":3, "V-Diagon":4,"W-mesh":5,
-     "D2B":6, "D3B":7, "D4C":17, "gas-cell":20,"D4D":25,"D5D":28}
-    return diag
+def diagnostics_sp_read(diag_name,preset_name):
+    pv = _diagnostics_preset_pv(diag_name,preset_name)
+    caget(pv+'_Setpoint.VAL')
 
-def _diagnostic_CA_dict():
-    CA_dict={
-        'diode_c':Keithley('b',15),
-        'mesh_d':SRS("29idMZ0:scaler1.S14", '29idd:A4'),
-    }
-    return CA_dict
+def _diagnostics_sp_write(diag_name,preset_name):
+    pv = _diagnostics_preset_pv(diag_name,preset_name)
+    caget(pv+'_Setpoint.VAL')
+    
 
-def diagnostics_list_all():
+##############################################################################################################
+################################            quick names            ##############################
+##############################################################################################################
+def diagnostics_list_all(verbose=True):
     """
     lists all diagnostics
     """
-    d = _diagnostics_dict()
-    for key in d.keys():
-        print(key)
+    d = _diagnostics_presets()
+    if verbose:
+        for key in d.keys():
+            print(key)
+    return list(d.keys())
 
-def diagnostic(diagnostic_name,in_out):
-    "Inserts/retracts a diagnostic(motor number or name) either = \"In\" or \"Out\""
-    diag=_diagnostics_dict()
-    if type(diagnostic_name) is int:
-        motor=diagnostic_name
-        name=diag['name'][motor]
+def diagnostic(name,in_out):
+    '''
+    Inserts/retracts a diagnostic(motor number or name) either = "In" or "Out"
+    
+    '''
+    d_quick = _diagnostics_inout_dict()
+    if name in d_quick.keys():
+        diag_name, preset_in,preset_out = d_quick[name]
+        if in_out.lower() == "in":
+            preset_name = preset_in
+        elif in_out.lower() == "out":
+            preset_name = preset_in
+        diagnostics_go2(diag_name,preset_name)
+        print("\n"+name+": "+ in_out)
     else:
-        name=diagnostic_name
-        motor=diag["motor"][name]
-    position=diag[in_out][motor]
-
-    caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-    print("\n"+name+": "+ in_out)
+        message = 'name = '+name+' is not a valid diagnostic name'
+        message +='\n valid names are '+diagnostics_list_all(verbose=False)
+        print_warning_message(message)
 
-def diagnostics_all_out(diode_stay_in=False):
+def diagnostics_all_out(diode_stay_in=False,mesh_stay_in=False):
     """
-    Retracts all diagnostic
-    diode_to_stay_in = True / False (checks beamline)
+    Retracts all diagnostic unless
+        diode_stay_in = True => leaves diode_c/diode_d In
+        mesh_stay_in = True => leaves mesh_c/mesh_d In
 
     Previously: AllDiagOut
     """
-    diag=_diagnostics_dict()
-    text=""
+    message = "All diagnostics out"
+    d_quick = _diagnostics_inout_dict()
 
-    #which motor is Diode of interest
+    diag_list = list(_diagnostics_presets().keys())
+
+    #if staying remove diag_name from list
     if diode_stay_in:
         branch = iex.BL.branch
-
-    if branch == 'c':
-        diode_motor=diag["motor"]["gas-cell"]
-    elif branch == 'd':
-        diode_motor=diag["motor"]["D5D"]
-    else:
-        diode_motor=None
-
-    #Taking out the diagnostic
-    for motor in list(diag["Out"].keys()):
-        if motor is diode_motor:
-            text=' except Diode-'+iex.BL.branch
-            #putting Diode In if not already in -JM
-            position=diag["In"][motor]
-            caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-        else:
-            position=diag["Out"][motor]
-            caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-    text="All diagnostics out"+text
-    print("\n",text)
-
-def diagnostics_all_in():
-    """
-    Inserts all diagnostic (meshes and diodes) for pinhole scans
+        if branch == 'c':
+            diode_stay_name = d_quick['diode_c'][0]
+            message += '\ndiode_c => In'
+        elif branch == 'd':
+            diode_stay_name = d_quick['diode_d'][0]
+            message += '\ndiode_d => In'
+        diag_list.pop(diode_stay_name) 
+
+    if mesh_stay_in:
+        branch = iex.BL.branch
+        if branch == 'c':
+            mesh_stay_name = d_quick['mesh_c'][0]
+            message += '\nmesh_c => In'
+        elif branch == 'd':
+            mesh_stay_name = d_quick['mesh_d'][0]
+            message += '\nmesh_d => In'
+        diag_list.pop(mesh_stay_name) 
+
+    #moving the diagnostics in list
+    for diag_name in diag_list:
+        diagnostics_go2(diag_name,'OUT')
     
-    Previously: AllDiagIn and AllMeshIn()
-    """
-    diag=_diagnostics_dict()
-    for motor in list(diag["In"].keys()):
-        position=diag["In"][motor]
-        if type(position) == list:
-            position=position[0]
-        caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-        print('m'+str(motor)+' = '+str(position))
-    print("All diagnostics in (meshes and diodes) for pinhole scans")
+    #putting stays in if not already in
+    if diode_stay_in:
+        diagnostics_go2(diode_stay_name,'Diode')
+    if mesh_stay_name:
+        diagnostics_go2(mesh_stay_name,'Mesh')
+
+    print("\n",message)
 
 def mesh_W(In_Out):
     """
@@ -239,28 +236,28 @@ def diagnostic_read(diode_name, verbose=True):
         print(diode_name,val, "(pv = "+diode_pv+")")
     return val
 
-def diode_c_read(quiet=True):
+def diode_c_read(verbose=True):
     """
     reads the current amplifier and returns the value
     quiet = False to pring
     """ 
-    val = diagnostic_read('diode_d',quiet)
+    val = diagnostic_read('diode_d',verbose)
     return val
 
-def diode_d_read(quiet=True):
+def diode_d_read(verbose=True):
     """
     reads the current amplifier and returns the value
     quiet = False to pring
     """ 
-    val = diagnostic_read('diode_d',quiet)
+    val = diagnostic_read('diode_d',verbose)
     return val
 
-def mesh_d_read(quiet=True):
+def mesh_d_read(verbose=True):
     """
     reads the current amplifier and returns the value
     quiet = False to pring
     """ 
-    val = diagnostic_read('diode_d',quiet)
+    val = diagnostic_read('diode_d',verbose)
     return val
 
 
diff --git a/build/lib/iexcode/instruments/slits.py b/build/lib/iexcode/instruments/slits.py
index 612bb84..ea616f0 100644
--- a/build/lib/iexcode/instruments/slits.py
+++ b/build/lib/iexcode/instruments/slits.py
@@ -114,7 +114,7 @@ def slits_get_all(verbose=True):
     vals = {}
     for slit_name in ['slit1A','slit2B','slit3C','slit3D']:
         vals[slit_name+'_size'], vals[slit_name+'_center'] = slits_get(slit_name,verbose=verbose)
-
+    return vals
 
 def slits_set(slit_name,size,center,verbose=True,wait=True):
     """
diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py
index e61e120..f80bed6 100644
--- a/build/lib/iexcode/instruments/xrays.py
+++ b/build/lib/iexcode/instruments/xrays.py
@@ -107,9 +107,9 @@ def xrays_get_all(verbose=True):
     if verbose:
         print("-----------------------------------------------------------")
     vals.update(slits_get_all(verbose=verbose))
-    vals.update(FMB_mirror_get(0,verbose=verbose))
-    vals.update(FMB_mirror_get(1,verbose=verbose))
-    vals.update(FMB_mirror_get(3,verbose=verbose))
+    vals.update({"M0":FMB_mirror_get(0,verbose=verbose)})
+    vals.update({"M1":FMB_mirror_get(1,verbose=verbose)})
+    vals.update({"M3":FMB_mirror_get(3,verbose=verbose)})
     if verbose:
         print("-----------------------------------------------------------")
 
diff --git a/build/lib/iexcode/macros/commissioning.py b/build/lib/iexcode/macros/commissioning.py
index 5400079..76741dd 100644
--- a/build/lib/iexcode/macros/commissioning.py
+++ b/build/lib/iexcode/macros/commissioning.py
@@ -563,7 +563,7 @@ def ID_beam_profile(grt,slit_list,c_slit=1,c_energy=1,**kwargs):
         c_energy = scaling of mono step size ( c=1   eV step = 2)
         with c_slit=1 and c_energy = 1   Each slit ~ 1:10 min
 
-        Previously
+        Previously BeamProfile
     """
     grating(grt)
     grt_density = mono_grating_density_get()
diff --git a/build/lib/iexcode/macros/start_of_the_week.py b/build/lib/iexcode/macros/start_of_the_week.py
index ec9555c..beb866c 100644
--- a/build/lib/iexcode/macros/start_of_the_week.py
+++ b/build/lib/iexcode/macros/start_of_the_week.py
@@ -1,8 +1,10 @@
 import datetime
+from re import A
 import matplotlib.pyplot as plt
 
 import iexcode.instruments.cfg as iex
-from iexcode.instruments.staff import staff_init
+from iexcode.instruments.ARPES import ARPES_init
+from iexcode.instrumetns.kappa import kappa_init
 
 from iexcode.instruments.diagnostics import _diagnostics_dict, diagnostics_all_out, diagnostics_all_in,diode_c,diode_d
 from iexcode.instruments.current_amplifiers import *
@@ -44,15 +46,19 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs):
     kwargs.setdefault('extended_range',False)
 
     branch=branch.lower()
-    if iex.BL == None or kwargs['repeat']==False:
+    if iex.BL == None:
         if branch == 'c':
-            staff_init('ARPES')
-            switch_branch(branch)
+            BL_init=ARPES_init
         else:
-            staff_init('kappa')
-            switch_branch(branch)
-    FileName='StartOfTheWeek_log.txt'
-    log_name_set(FileName)
+            BL_init=kappa_init
+
+    if kwargs['repeat']==False: #reset folders/detectors/...
+        BL_init('staff')
+    else:
+        BL_init('staff',reset=False,set_folders=False)
+        switch_branch(branch)
+        FileName='StartOfTheWeek_log.txt'
+        log_name_set(FileName)
             
     for scan in kwargs['scanType']: 
         if scan not in ['slit1','wire','flux','monoVslit']:
diff --git a/iexcode/instruments/FMB_mirrors.py b/iexcode/instruments/FMB_mirrors.py
index 1c92a07..ca1996f 100644
--- a/iexcode/instruments/FMB_mirrors.py
+++ b/iexcode/instruments/FMB_mirrors.py
@@ -12,7 +12,7 @@ def _FMB_mirror_ioc(mirror_num):
     returns the ioc name for the given mirror number: 
     miror_num = 0 / 1 / 3  for M0 / M1 /M3R respectively
     """
-    ioc = '29id_'+['M0','M1','','M3R'][mirror_num]+":"
+    ioc = '29id_'+['m0','m1','','m3r'][mirror_num]+":"
     return ioc
 
 def FMB_mirror_status(mirror_num):
@@ -22,7 +22,7 @@ def FMB_mirror_status(mirror_num):
 
     status =1 when positioned
     """
-    ioc = '29id_'+['M0','M1','','M3R'][mirror_num]+":"
+    ioc = '29id_'+['m0','m1','','m3r'][mirror_num]+":"
     pv = _FMB_mirror_ioc(mirror_num)
     status=caget(pv+'SYSTEM_STS')
 
@@ -52,9 +52,9 @@ def FMB_mirror_get(mirror_num,verbose=True):
     for axis in axis_labels:
         rbv,sp = FMB_mirror_axis_position(mirror_num,axis, verbose=False)
         vals.append(round(rbv,3))
-        message =+ "%.3f"+"/" % rbv 
+        message = message + str(round(rbv,3))+"/" 
     if verbose:
-        print(message)
+        print(message[0:-1]) # to not have the last /
     return vals
 
 def FMB_mirror_move(mirror_num,axis,val,verbose=True):
@@ -71,7 +71,7 @@ def FMB_mirror_move(mirror_num,axis,val,verbose=True):
     axes = ['TX','TY','TZ','RX','RY','RZ']
     if axis in axes:
         caput(pv+axis+"_SP.PREC",3)  
-        caput(pv+axis+"_POS_SP")
+        caput(pv+axis+"_POS_SP",val)
         caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000)
         while True:
             if FMB_mirror_status != 1:
@@ -83,7 +83,7 @@ def FMB_mirror_move(mirror_num,axis,val,verbose=True):
     else:
         print_warning_message(axis+' is not a valid axis chose '+axes)
 
-def FMB_mirror_move_all(mirror_num,position_list,verbose=True):
+def FMB_mirror_move_all(mirror_num,position_list,verbose=True,execute=True):
     """
     miror_num = 0 / 1 / 3  for M0 / M1 /M3R respectively
     position_list = [TX,TY,TZ,RX,RY,RZ]
@@ -91,12 +91,14 @@ def FMB_mirror_move_all(mirror_num,position_list,verbose=True):
     "Previously: Move_M0M1
     """  
     pv = _FMB_mirror_ioc(mirror_num)
-    for axis in ['TX','TY','TZ','RX','RY','RZ']:
+    for i, axis in enumerate(['TX','TY','TZ','RX','RY','RZ']):
         caput(pv+axis+"_SP.PREC",3)  
-        caput(pv+axis+"_POS_SP")
-    caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000)
+        caput(pv+axis+"_POS_SP",position_list[i])
+        sleep(.5)
+    if execute:
+        caput(pv+"MOVE_CMD.PROC",1,wait=True,timeout=18000)
     while True:
-        if FMB_mirror_status != 1:
+        if FMB_mirror_status(mirror_num) != 1:
             sleep(.5)
         else:
             break
diff --git a/iexcode/instruments/IEX_VPU.py b/iexcode/instruments/IEX_VPU.py
index feab470..7094082 100644
--- a/iexcode/instruments/IEX_VPU.py
+++ b/iexcode/instruments/IEX_VPU.py
@@ -276,7 +276,7 @@ def ID_switch_mode(ID_mode):
             print("Turning ID off...")
             ID_off(verbose=True)
             sleep(10)
-            
+            ID_on(verbose=True)
             print("Switching ID mode, please wait...")
             ID_mode_set(ID_mode) 
             ID_ready()
diff --git a/iexcode/instruments/diagnostics.py b/iexcode/instruments/diagnostics.py
index 104d793..b72d31b 100644
--- a/iexcode/instruments/diagnostics.py
+++ b/iexcode/instruments/diagnostics.py
@@ -1,31 +1,62 @@
-from iexcode.instruments.current_amplifiers import Keithley,SRS
 from numpy import nan
 
 from epics import caput, caget
 
 import iexcode.instruments.cfg as iex
-
+from iexcode.instruments.current_amplifiers import Keithley,SRS
+from iexcode.instruments.utilities import print_warning_message
 ##############################################################################################################
 ################################            default positions             ##############################
 ##############################################################################################################
-def diagnostics_go2(diag_name,preset_name):
-    pv = _diagnostics_preset_pv(diag_name,preset_name)
-    caput(pv+'_Trigger.PROC',1)
-
-def diagnostics_sp_read(diag_name,preset_name):
-    pv = _diagnostics_preset_pv(diag_name,preset_name)
-    caget(pv+'_Setpoint.VAL')
+def _diagnostics_presets():
+    presets={
+        'H-wire':['OUT','Start'],
+        'V-wire':['OUT','Start'],
+        'H-Diagon':['OUT','Si-2800','ML-400','ML-460'],
+        'V-Diagon':['OUT','Si-2800','ML-400','ML-460'],
+        'D1A':['OUT','Mesh'],
+        'D2B':['OUT','Mesh','YAG'],
+        'D3B':['OUT','YAG'],
+        'D4C':['OUT','Mesh','YAG'],
+        'gas-cell':['OUT','Diode1','Diode2'],
+        'D4D':['OUT','Mesh','YAG'],
+        'D5D':['OUT','Mesh','YAG','Diode'],
+    }
+    return presets
 
-def _diagnostics_sp_write(diag_name,preset_name):
-    pv = _diagnostics_preset_pv(diag_name,preset_name)
-    caget(pv+'_Setpoint.VAL')
+#For new endstation modify here:
+def _diagnostics_inout_dict():
+    """
+    dictionary to convert quick_name to preset_names
+    """
+    #quick_name: (diag_name, preset_in,preset_out)
+    d={
+        'mesh_W':('D1A','Mesh','OUT'),
+        'mesh_c':('D4C','Mesh','OUT'),
+        'mesh_d':('D4D','Mesh','OUT'),
+        'diode_c':('gas-cell','Diode1','OUT'),
+        'diode_d':('gas-D4D','Diode','OUT'),
+        }
+
+    return d
+
+#For new endstation modify here:
+def _diagnostic_CA_dict():
+    CA_dict={
+        'diode_c':Keithley('b',15),
+        'mesh_d':SRS("29idMZ0:scaler1.S14", '29idd:A4'),
+    }
+    return CA_dict
 
+##############################################################################################################
+################################            access presets            ##############################
+##############################################################################################################
 def _diagnostics_preset_pv(diag_name,preset_name):
     """
     dictionary of the motor pvs for the beamline diagnostics
     """
     ioc = '29idb:'
-    d = _diagnostics_get_presets()
+    d = _diagnostics_presets()
     pv=None
     
     if diag_name.casefold() in (key.casefold() for key in list(d.keys())):
@@ -47,130 +78,96 @@ def _diagnostics_preset_pv(diag_name,preset_name):
     
     return pv
 
-def _diagnostics_get_presets():
-    presets={
-        'H-wire':['OUT','Start'],
-        'V-wire':['OUT','Start'],
-        'H-Diagon':['OUT','Si-2800','ML-400','ML-460'],
-        'V-Diagon':['OUT','Si-2800','ML-400','ML-460'],
-        'D1A':['OUT','Mesh'],
-        'D2B':['OUT','Mesh','YAG'],
-        'D3B':['OUT','YAG'],
-        'D4C':['OUT','Mesh','YAG'],
-        'gas-cell':['OUT','Diode1','Diode2'],
-        'D4D':['OUT','Mesh','YAG'],
-        'D5D':['OUT','Mesh','YAG'],
-    }
-    return presets
-    
+def diagnostics_go2(diag_name,preset_name):
+    pv = _diagnostics_preset_pv(diag_name,preset_name)
+    caput(pv+'_Trigger.PROC',1)
 
-###### We should make pvs in the 29idb ioc to hold these values:
-def _diagnostics_dict():
-    """
-    Dictionary of Diagnostic positions In and Out by either motor number or name
-    WARNING: When updating motor values, also update the following screens:
-        - 29id_BL_Layout.ui               (for MeshD and DiodeC)
-        - 29id_Diagnostic.ui
-        - 29idd_graphic
-    usage:       
-        diagnostics_dict()['name'] returns dictionary motor:name
-        diagnostics_dict()['motor'] returns dictionary name:motor   
-        diagnostics_dict()['In'] returns dictionary motor:In position  (where val can be a list for multiple position)  
-        diagnostics_dict()['Out'] returns dictionary motor:In position  
-                motor=diagnostics_dict()['motor']['gas-cell']
-                pos_in=diagnostics_dict()['In'][motor]
-                
-    WARNING: When updating MeshD (D5D) value: update value in the dictionnary + caQtdM (29id_BL_Diag.ui + 29idd_graphic.ui + Diagnostic.ui)
-    
-    Previously: AllDiag_dict
-    """
-    diag={}
-    diag["In"]  = {                5:-55, 6:-46,          17:-56, 20:-30, 25:-56, 28:[-3,-3]}
-                                                                                    
-    diag["Out"] = {1:-4, 2:-10, 3:-4, 4:-4, 5:-20, 6:-20, 7:-20, 17:-20, 20:-21, 25:-20, 28:-3}    
-    diag["name"]= {1:"H-wire", 2:"V-wire", 3:"H-Diagon", 4:"V-Diagon", 5:"W-mesh",
-     6:"D2B", 7:"D3B", 17:"D4C/pre-slit", 20:"gas-cell", 25:"D4D/pre-slit", 28:"D5D/pre-RSXS"}
-    diag["motor"]= {"H-wire":1, "V-wire":2, "H-Diagon":3, "V-Diagon":4,"W-mesh":5,
-     "D2B":6, "D3B":7, "D4C":17, "gas-cell":20,"D4D":25,"D5D":28}
-    return diag
+def diagnostics_sp_read(diag_name,preset_name):
+    pv = _diagnostics_preset_pv(diag_name,preset_name)
+    caget(pv+'_Setpoint.VAL')
 
-def _diagnostic_CA_dict():
-    CA_dict={
-        'diode_c':Keithley('b',15),
-        'mesh_d':SRS("29idMZ0:scaler1.S14", '29idd:A4'),
-    }
-    return CA_dict
+def _diagnostics_sp_write(diag_name,preset_name):
+    pv = _diagnostics_preset_pv(diag_name,preset_name)
+    caget(pv+'_Setpoint.VAL')
+    
 
-def diagnostics_list_all():
+##############################################################################################################
+################################            quick names            ##############################
+##############################################################################################################
+def diagnostics_list_all(verbose=True):
     """
     lists all diagnostics
     """
-    d = _diagnostics_dict()
-    for key in d.keys():
-        print(key)
+    d = _diagnostics_presets()
+    if verbose:
+        for key in d.keys():
+            print(key)
+    return list(d.keys())
 
-def diagnostic(diagnostic_name,in_out):
-    "Inserts/retracts a diagnostic(motor number or name) either = \"In\" or \"Out\""
-    diag=_diagnostics_dict()
-    if type(diagnostic_name) is int:
-        motor=diagnostic_name
-        name=diag['name'][motor]
+def diagnostic(name,in_out):
+    '''
+    Inserts/retracts a diagnostic(motor number or name) either = "In" or "Out"
+    
+    '''
+    d_quick = _diagnostics_inout_dict()
+    if name in d_quick.keys():
+        diag_name, preset_in,preset_out = d_quick[name]
+        if in_out.lower() == "in":
+            preset_name = preset_in
+        elif in_out.lower() == "out":
+            preset_name = preset_in
+        diagnostics_go2(diag_name,preset_name)
+        print("\n"+name+": "+ in_out)
     else:
-        name=diagnostic_name
-        motor=diag["motor"][name]
-    position=diag[in_out][motor]
-
-    caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-    print("\n"+name+": "+ in_out)
+        message = 'name = '+name+' is not a valid diagnostic name'
+        message +='\n valid names are '+diagnostics_list_all(verbose=False)
+        print_warning_message(message)
 
-def diagnostics_all_out(diode_stay_in=False):
+def diagnostics_all_out(diode_stay_in=False,mesh_stay_in=False):
     """
-    Retracts all diagnostic
-    diode_to_stay_in = True / False (checks beamline)
+    Retracts all diagnostic unless
+        diode_stay_in = True => leaves diode_c/diode_d In
+        mesh_stay_in = True => leaves mesh_c/mesh_d In
 
     Previously: AllDiagOut
     """
-    diag=_diagnostics_dict()
-    text=""
+    message = "All diagnostics out"
+    d_quick = _diagnostics_inout_dict()
 
-    #which motor is Diode of interest
+    diag_list = list(_diagnostics_presets().keys())
+
+    #if staying remove diag_name from list
     if diode_stay_in:
         branch = iex.BL.branch
-
-    if branch == 'c':
-        diode_motor=diag["motor"]["gas-cell"]
-    elif branch == 'd':
-        diode_motor=diag["motor"]["D5D"]
-    else:
-        diode_motor=None
-
-    #Taking out the diagnostic
-    for motor in list(diag["Out"].keys()):
-        if motor is diode_motor:
-            text=' except Diode-'+iex.BL.branch
-            #putting Diode In if not already in -JM
-            position=diag["In"][motor]
-            caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-        else:
-            position=diag["Out"][motor]
-            caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-    text="All diagnostics out"+text
-    print("\n",text)
-
-def diagnostics_all_in():
-    """
-    Inserts all diagnostic (meshes and diodes) for pinhole scans
+        if branch == 'c':
+            diode_stay_name = d_quick['diode_c'][0]
+            message += '\ndiode_c => In'
+        elif branch == 'd':
+            diode_stay_name = d_quick['diode_d'][0]
+            message += '\ndiode_d => In'
+        diag_list.pop(diode_stay_name) 
+
+    if mesh_stay_in:
+        branch = iex.BL.branch
+        if branch == 'c':
+            mesh_stay_name = d_quick['mesh_c'][0]
+            message += '\nmesh_c => In'
+        elif branch == 'd':
+            mesh_stay_name = d_quick['mesh_d'][0]
+            message += '\nmesh_d => In'
+        diag_list.pop(mesh_stay_name) 
+
+    #moving the diagnostics in list
+    for diag_name in diag_list:
+        diagnostics_go2(diag_name,'OUT')
     
-    Previously: AllDiagIn and AllMeshIn()
-    """
-    diag=_diagnostics_dict()
-    for motor in list(diag["In"].keys()):
-        position=diag["In"][motor]
-        if type(position) == list:
-            position=position[0]
-        caput("29idb:m"+str(motor)+".VAL",position,wait=True,timeout=18000)
-        print('m'+str(motor)+' = '+str(position))
-    print("All diagnostics in (meshes and diodes) for pinhole scans")
+    #putting stays in if not already in
+    if diode_stay_in:
+        diagnostics_go2(diode_stay_name,'Diode')
+    if mesh_stay_name:
+        diagnostics_go2(mesh_stay_name,'Mesh')
+
+    print("\n",message)
 
 def mesh_W(In_Out):
     """
@@ -239,28 +236,28 @@ def diagnostic_read(diode_name, verbose=True):
         print(diode_name,val, "(pv = "+diode_pv+")")
     return val
 
-def diode_c_read(quiet=True):
+def diode_c_read(verbose=True):
     """
     reads the current amplifier and returns the value
     quiet = False to pring
     """ 
-    val = diagnostic_read('diode_d',quiet)
+    val = diagnostic_read('diode_d',verbose)
     return val
 
-def diode_d_read(quiet=True):
+def diode_d_read(verbose=True):
     """
     reads the current amplifier and returns the value
     quiet = False to pring
     """ 
-    val = diagnostic_read('diode_d',quiet)
+    val = diagnostic_read('diode_d',verbose)
     return val
 
-def mesh_d_read(quiet=True):
+def mesh_d_read(verbose=True):
     """
     reads the current amplifier and returns the value
     quiet = False to pring
     """ 
-    val = diagnostic_read('diode_d',quiet)
+    val = diagnostic_read('diode_d',verbose)
     return val
 
 
diff --git a/iexcode/instruments/m3r.py b/iexcode/instruments/m3r.py
index fe8d151..9619e8d 100644
--- a/iexcode/instruments/m3r.py
+++ b/iexcode/instruments/m3r.py
@@ -137,7 +137,7 @@ def _m3r_align_start(pxl=None):
     caput(M3R_align_pv+'startAlign',1,wait=True,timeout=180)
 
 def m3r_align(pxl=None):
-    if iex.BL.branch() == 'd':
+    if iex.BL.branch == 'd':
         print('\nalign_m3r()')
         try:
             _m3r_align_start()
diff --git a/iexcode/instruments/slits.py b/iexcode/instruments/slits.py
index 612bb84..460734f 100644
--- a/iexcode/instruments/slits.py
+++ b/iexcode/instruments/slits.py
@@ -114,7 +114,7 @@ def slits_get_all(verbose=True):
     vals = {}
     for slit_name in ['slit1A','slit2B','slit3C','slit3D']:
         vals[slit_name+'_size'], vals[slit_name+'_center'] = slits_get(slit_name,verbose=verbose)
-
+    return vals
 
 def slits_set(slit_name,size,center,verbose=True,wait=True):
     """
@@ -350,7 +350,7 @@ def slit3C_set(size,verbose=True):
     center = None
     slits_set(slit_name,size,center, verbose=verbose)
 
-def slit3C_get(size,verbose=True):
+def slit3C_get(verbose=True):
     """
     gets slit-3C (ARPES resolution defining slit)
     returns size, position
@@ -409,9 +409,9 @@ def slit3D_encoders_reset(Vcenter):
     encoders_reset_zero(slit_name)
     slits_synch(slit_name)
 
-def exit_slit(size, verbose=True):
+def exit_slit_set(size, verbose=True):
     """
-    verbose used to supress printing
+    sets the size for the iex.BL.branch exit slit
 
     Previously: SetExitSlit
     """
@@ -421,6 +421,17 @@ def exit_slit(size, verbose=True):
     elif branch == "d":
         slit3D_set(size, verbose)
 
+def exit_slit_get(verbose=True):
+    """
+    gets the size for the iex.BL.branch exit slit 
+    """
+    branch = iex.BL.branch
+    if branch == "c":
+        slit_size,slit_center = slit3C_get(verbose=False)
+    elif branch == "d":
+        slit_size,slit_center = slit3D_get(verbose=False)
+   
+    return slit_size,slit_center
 
 
 ##############################################################################################################
diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py
index e61e120..f80bed6 100644
--- a/iexcode/instruments/xrays.py
+++ b/iexcode/instruments/xrays.py
@@ -107,9 +107,9 @@ def xrays_get_all(verbose=True):
     if verbose:
         print("-----------------------------------------------------------")
     vals.update(slits_get_all(verbose=verbose))
-    vals.update(FMB_mirror_get(0,verbose=verbose))
-    vals.update(FMB_mirror_get(1,verbose=verbose))
-    vals.update(FMB_mirror_get(3,verbose=verbose))
+    vals.update({"M0":FMB_mirror_get(0,verbose=verbose)})
+    vals.update({"M1":FMB_mirror_get(1,verbose=verbose)})
+    vals.update({"M3":FMB_mirror_get(3,verbose=verbose)})
     if verbose:
         print("-----------------------------------------------------------")
 
diff --git a/iexcode/macros/commissioning.py b/iexcode/macros/commissioning.py
index 5400079..1499dcc 100644
--- a/iexcode/macros/commissioning.py
+++ b/iexcode/macros/commissioning.py
@@ -18,33 +18,28 @@ from iexcode.instruments.electron_analyzer import scanEA
 from iexcode.instruments.Logfile import log_name_set,log_print
 from iexcode.instruments.cameras import *
 
-
-
-
-
-
-
-
 from .quick_plot import fit_mda, mda_1D
 
-
-
 ##############################################################################################################
 ################################            checking alignment             ##############################
 ##############################################################################################################
 
 def check_flux(hv=500,ID_mode='RCP',stay=False):
     """
-    puts the diode in
+    puts the diode in in the branch defined my position of m3r
     measures flux at energy ID_mode specified
-    stay: diode position after the scan
+    stay = True => leaves the diode in
 
     Previously: CheckFlux
     """
     ID_switch_mode(ID_mode)
     energy(hv)
+    
+    ring_current=round(caget("S:SRcurrentAI.VAL"),2)
+
     diagnostics_all_out(diode_to_stay_in=m3r_branch())
-    SR=round(caget("S:SRcurrentAI.VAL"),2)
+    exit_slit()
+
     if m3r_branch() == "c":
         current_slit=caget('29idb:Slit3CFit.A')
         diode_c('In')
@@ -60,7 +55,7 @@ def check_flux(hv=500,ID_mode='RCP',stay=False):
     flux=current2flux(diode)
     print("\n----- Current on diode   : %.3e" % diode, "A")
     print("----- Corresponding flux: %.3e" % flux, "ph/s \n")
-    print("----- Storage ring current: %.2f" % SR, "mA")
+    print("----- Storage ring current: %.2f" % ring_current, "mA")
     print("\nFlux at hv=500 as off Feb 2019 for RCP and HEG:  ~3.3e-06 A = ~1.5e+11 ph/s")
     
     if not stay:
@@ -563,7 +558,7 @@ def ID_beam_profile(grt,slit_list,c_slit=1,c_energy=1,**kwargs):
         c_energy = scaling of mono step size ( c=1   eV step = 2)
         with c_slit=1 and c_energy = 1   Each slit ~ 1:10 min
 
-        Previously
+        Previously BeamProfile
     """
     grating(grt)
     grt_density = mono_grating_density_get()
diff --git a/iexcode/macros/start_of_the_week.py b/iexcode/macros/start_of_the_week.py
index ec9555c..beb866c 100644
--- a/iexcode/macros/start_of_the_week.py
+++ b/iexcode/macros/start_of_the_week.py
@@ -1,8 +1,10 @@
 import datetime
+from re import A
 import matplotlib.pyplot as plt
 
 import iexcode.instruments.cfg as iex
-from iexcode.instruments.staff import staff_init
+from iexcode.instruments.ARPES import ARPES_init
+from iexcode.instrumetns.kappa import kappa_init
 
 from iexcode.instruments.diagnostics import _diagnostics_dict, diagnostics_all_out, diagnostics_all_in,diode_c,diode_d
 from iexcode.instruments.current_amplifiers import *
@@ -44,15 +46,19 @@ def StartOfTheWeek(GRT,branch,wait=False,**kwargs):
     kwargs.setdefault('extended_range',False)
 
     branch=branch.lower()
-    if iex.BL == None or kwargs['repeat']==False:
+    if iex.BL == None:
         if branch == 'c':
-            staff_init('ARPES')
-            switch_branch(branch)
+            BL_init=ARPES_init
         else:
-            staff_init('kappa')
-            switch_branch(branch)
-    FileName='StartOfTheWeek_log.txt'
-    log_name_set(FileName)
+            BL_init=kappa_init
+
+    if kwargs['repeat']==False: #reset folders/detectors/...
+        BL_init('staff')
+    else:
+        BL_init('staff',reset=False,set_folders=False)
+        switch_branch(branch)
+        FileName='StartOfTheWeek_log.txt'
+        log_name_set(FileName)
             
     for scan in kwargs['scanType']: 
         if scan not in ['slit1','wire','flux','monoVslit']:
-- 
GitLab