Tools.py 3.7 KB
Newer Older
1
import os
2
3
4
from bliss.setup_globals import *
from bliss.shell.cli.user_dialog import *
from bliss.shell.cli.pt_widgets import BlissDialog
bliss administrator's avatar
bliss administrator committed
5
from bliss.config.static import get_config
6
7
8
9
10
11
12
13
from bliss.shell.standard import mv as bliss_mv
from bliss.shell.standard import umv as bliss_umv
from bliss.shell.standard import mvr as bliss_mvr
from bliss.shell.standard import umvr as bliss_umvr
from bliss.common.scans.ct import ct as bliss_ct
from bliss.shell.cli.user_dialog import *
from bliss.shell.cli.pt_widgets import BlissDialog
from bliss.config.static import get_config
bliss administrator's avatar
bliss administrator committed
14
from bliss import setup_globals
15
16
from bliss.common.logtools import *

17

18
_TOMO = None
19
def init_tomo(tomo):
20
21
22
23
24
25
26
27
28
29
30
31
    global _TOMO
    _TOMO = tomo
  
_UPDATE_ON = False

def update_on():
    global _UPDATE_ON
    _UPDATE_ON = True
    
def update_off():
    global _UPDATE_ON
    _UPDATE_ON = False
32
    
bliss administrator's avatar
bliss administrator committed
33
34
35
36
def update_is_on():
    global _UPDATE_ON
    return _UPDATE_ON == True
    
37
38
39
40
41
42
43
def select_tomo():
    dlg_tomo = UserInput(label="Enter name of tomo object you want to use (ex: hrtomo)")
    ret = BlissDialog( [[dlg_tomo]] , title='Tomo Setup').show()
    if ret != False:
        tomo = get_config().get(ret[dlg_tomo])
        init_tomo(tomo)

44
45
46
47
48
49
50
51
52
53
54
55
56
57
def mv(*args):
    bliss_mv(*args)
    if _UPDATE_ON:
        ct()
        
def mvr(*args):
    bliss_mvr(*args)
    if _UPDATE_ON:
        ct()
        
def umv(*args):
    bliss_umv(*args)
    if _UPDATE_ON:
        ct()
58

59
60
61
62
def umvr(*args):
    bliss_umvr(*args)
    if _UPDATE_ON:
        ct()
63

64
65
66
67
def ct(exposure_time=None, *args):
    if _UPDATE_ON:
        global _TOMO
        if _TOMO is not None:
bliss administrator's avatar
bliss administrator committed
68
69
            if exposure_time is not None:
                bliss_ct(exposure_time, *args)
70
            else:
bliss administrator's avatar
bliss administrator committed
71
72
73
74
                if _TOMO.parameters.exposure_time != 0:
                    bliss_ct(_TOMO.parameters.exposure_time, *args)
                else:
                    print(f"WARNING TOMO.parameters.exposure_time is 0")
75
        else:
76
            print('No tomo exists in the session. Please use select_tomo() to define one')
77
    else:
78
79
        if exposure_time is None:
            exposure_time = 1
80
        bliss_ct(exposure_time, *args)
bliss administrator's avatar
bliss administrator committed
81

82
def set_accumulation(detector):
bliss administrator's avatar
bliss administrator committed
83
    setup_globals.DEFAULT_CHAIN.set_settings(setup_globals.default_acq_chain_acc['chain_config'])
bliss administrator's avatar
bliss administrator committed
84
    
bliss administrator's avatar
bliss administrator committed
85
    det_def_chain = setup_globals.DEFAULT_CHAIN._settings.get(detector)
86
    if det_def_chain is None:
bliss administrator's avatar
bliss administrator committed
87
        setup_globals.DEFAULT_CHAIN.set_settings(setup_globals.default_acq_chain['chain_config'])
bliss administrator's avatar
bliss administrator committed
88
89
90
        raise Exception(f'{detector.name} is not configured in default chain for accumulation') 

def unset_accumulation(detector):
bliss administrator's avatar
bliss administrator committed
91
    setup_globals.DEFAULT_CHAIN.set_settings(setup_globals.default_acq_chain['chain_config'])
bliss administrator's avatar
bliss administrator committed
92
    
bliss administrator's avatar
bliss administrator committed
93
    det_def_chain = setup_globals.DEFAULT_CHAIN._settings.get(detector)
bliss administrator's avatar
bliss administrator committed
94
95
96
97
    if det_def_chain is None:
        raise Exception(f'{detector.name} is not configured in default chain') 


98
99
100
101
102
103
104
def shopen():
    _TOMO.shutter.beam_shutter_open()

def shclose():
    _TOMO.shutter.beam_shutter_close()
    
def feopen():
105
    setup_globals.frontend.open()
106
107

def feclose():
108
    setup_globals.frontend.close()
109

110
111
def psp():
    print(f'sx {setup_globals.sx.position}  sy {setup_globals.sy.position}  sz {setup_globals.sz.position}   yrot {setup_globals.yrot.position}')   
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130


def start_synchro_lbs():
    os.system("ssh lbs191 sudo /root/dockerStart.sh")
    
def stop_synchro_lbs():
    os.system("ssh lbs191 sudo /root/dockerStop.sh")
    
def lbs_free_space():
    process = os.popen('df -h /lbsram')
    result = process.readlines()
    process.close()
    mem_use = [item[:-1] for item in result[1].split(' ') if '%' in item]
    mem_use = int(mem_use[0])
    

    mem_available = 100 - mem_use
    msg = f"\n\033[1mIt remains {mem_available}% of free space on lbs\033[0m\n"
    print(msg)