forked from NSLS-II/lsdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runSpotFinder4syncW.py
executable file
·88 lines (75 loc) · 3.01 KB
/
runSpotFinder4syncW.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/opt/conda_envs/lsdc-server-2023-2-latest/bin/python
import time
import os
import sys
import db_lib
from daq_utils import getBlConfig
import xmltodict
import ispybLib
from config_params import *
baseDirectory = os.environ["PWD"]
directory = sys.argv[1]
cbfDir = directory+"/cbf"
comm_s = "mkdir -p " + cbfDir
os.system(comm_s)
filePrefix = sys.argv[2]
request_id = sys.argv[3]
seqNum = int(sys.argv[4])
beamline = os.environ["BEAMLINE_ID"]
node = getBlConfig("SynchWebSpotNode")
ispybDCID = int(sys.argv[5])
request=db_lib.getRequestByID(request_id)
reqObj = request["request_obj"]
img_width = reqObj["img_width"]
sweep_start = reqObj["sweep_start"]
sweep_end = reqObj["sweep_end"]
range_degrees = abs(sweep_end-sweep_start)
numimages = round(range_degrees/img_width)
numstart = reqObj["file_number_start"]
dialsComm = getBlConfig("dialsComm")
dialsTuneLowRes = getBlConfig(RASTER_TUNE_LOW_RES)
dialsTuneHighRes = getBlConfig(RASTER_TUNE_HIGH_RES)
dialsTuneIceRingFlag = getBlConfig(RASTER_TUNE_ICE_RING_FLAG)
dialsTuneResoFlag = getBlConfig(RASTER_TUNE_RESO_FLAG)
dialsTuneIceRingWidth = getBlConfig(RASTER_TUNE_ICE_RING_WIDTH)
if (dialsTuneIceRingFlag):
iceRingParams = " ice_rings.filter=true ice_rings.width=" + str(dialsTuneIceRingWidth)
else:
iceRingParams = ""
if (dialsTuneResoFlag):
resoParams = " d_min=" + str(dialsTuneLowRes) + " d_max=" + str(dialsTuneHighRes)
else:
resoParams = ""
dialsCommWithParams = dialsComm + resoParams + iceRingParams
print(dialsCommWithParams)
for i in range (numstart,numimages,10):
comm_s = f"ssh -q {node} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}eiger2cbf.sh {request_id} {i} {i} 0 {seqNum}\""
os.system(comm_s)
retry = 3
localDialsResultDict = {}
while(1):
resultString = "<data>\n"+os.popen(comm_s).read()+"</data>\n"
localDialsResultDict = xmltodict.parse(resultString)
if (localDialsResultDict["data"] == None and retry>0):
print("ERROR \n" + resultString + " retry = " + str(retry))
retry = retry - 1
if (retry==0):
localDialsResultDict["data"]={}
localDialsResultDict["data"]["response"]=[]
localDialsResultDict["data"]["response"].append({'d_min': '-1.00','d_min_method_1': '-1.00','d_min_method_2': '-1.00','image': '','spot_count': '0','spot_count_no_ice': '0','total_intensity': '0'})
break
else:
break
logfile = open(cbfDir + "/spotLog.txt","a+")
for i in range (0,len(localDialsResultDict["data"]["response"])):
spotTotal = localDialsResultDict["data"]["response"][i]['spot_count']
goodBraggCandidates = localDialsResultDict["data"]["response"][i]['spot_count_no_ice']
method2Res = localDialsResultDict["data"]["response"][i]['d_min_method_2']
totalIntegratedSignal = localDialsResultDict["data"]["response"][i]['total_intensity']
logfile.write(str(i*10) + " " + str(goodBraggCandidates)+"\n")
try:
ispybLib.insertPlotResult(ispybDCID,i*10,spotTotal,goodBraggCandidates,method2Res,totalIntegratedSignal)
except Exception as e:
print(f'exception during insertPlotResult:{e}')
logfile.close()
os.system("rm " + cbfDir + "/*.cbf")