-
Notifications
You must be signed in to change notification settings - Fork 122
/
RefLview.py
171 lines (137 loc) · 5.7 KB
/
RefLview.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""*WIKI*
Liquids Reflectometer (REFL) NeXus viewer
This routine will display some of the metadata defined by the IS
for a given run or set of runs.
*WIKI*"""
from MantidFramework import *
from mantidsimple import *
from numpy import zeros, shape, arange
import math
import sfCalculator
class RefLview(PythonAlgorithm):
def category(self):
return "Reflectometry"
def name(self):
return "RefLview"
def version(self):
return 1
def PyInit(self):
self.declareListProperty("RunNumbers", [0],
Validator=ArrayBoundedValidator(Lower=0),
Description="List of run numbers to process")
def PyExec(self):
import os
import numpy
import math
from reduction.instruments.reflectometer import wks_utility
from mantid import mtd
#remove all previous workspaces
list_mt = mtd.getObjectNames()
for _mt in list_mt:
if _mt.find('_scaled') != -1:
mtd.remove(_mt)
if _mt.find('_reflectivity') != -1:
mtd.remove(_mt)
from mantidsimple import mtd
bDebug = False
if bDebug:
print '====== Running in mode DEBUGGING ======='
run_numbers = self.getProperty("RunNumbers")
if bDebug:
print 'run_numbers (before getSequenceRuns): '
print str(run_numbers)
print
run_numbers = wks_utility.getSequenceRuns(run_numbers)
if bDebug:
print 'run_numbers (after getSequenceRuns): '
print str(run_numbers)
print
for _run in run_numbers:
#make sure we are working with integer
_run = int(_run)
print '********* Working with run: ' + str(_run) + ' *********'
#Pick a good workspace name
ws_name = "refl%d" % _run
ws_event_data = ws_name+"_evt"
_File = FileFinder.findRuns("REF_L%d" %_run)
if len(_File)>0 and os.path.isfile(_File[0]):
data_file = _File[0]
if bDebug:
print 'DEBUG: full file name is ' + _File[0]
else:
msg = "RefLReduction: could not find run %d\n" % _run
msg += "Add your data folder to your User Data Directories in the File menu"
if bDebug:
print 'DEBUG: file name could not be found !'
raise RuntimeError(msg)
if not mtd.workspaceExists(ws_event_data):
LoadEventNexus(Filename=data_file,
OutputWorkspace=ws_event_data)
#retrieve list of metadata
mt_run = mtd[ws_event_data].getRun()
#run_title
run_title = mt_run.getProperty('run_title').value
_line = ' Run title: ' + run_title
print _line
#run_start
run_start = mt_run.getProperty('run_start').value
_line = ' Run start: ' + run_start
print _line
#duration
duration_value = mt_run.getProperty('duration').value
duration_units = mt_run.getProperty('duration').units
_line = ' Duration: {0:.2f}'.format(duration_value)
_line += ' ' + duration_units
print _line
#Lambda Requested
lambda_request_value = mt_run.getProperty('LambdaRequest').value[0]
lambda_request_units = mt_run.getProperty('LambdaRequest').units
_line = ' Lambda requested: {0:.2f}'.format(lambda_request_value)
_line += ' ' + lambda_request_units
print _line
#tthd
tthd_value = mt_run.getProperty('tthd').value[0]
tthd_units = mt_run.getProperty('tthd').units
_line = ' tthd: {0:.4f}'.format(tthd_value)
_line += ' ' + tthd_units
print _line
#thi
thi_value = mt_run.getProperty('thi').value[0]
thi_units = mt_run.getProperty('thi').units
_line = ' thi: {0:.4f}'.format(thi_value)
_line += ' ' + thi_units
print _line
#(tthd-thi)/2
_cal = (float(tthd_value)-float(thi_value))/2.
_line = ' (tthd-thi)/2: {0:.2f}'.format(_cal)
_line += ' ' + thi_units
print _line
#ths
ths_value = mt_run.getProperty('ths').value[0]
ths_units = mt_run.getProperty('ths').units
_line = ' ths: {0:.4f}'.format(ths_value)
_line += ' ' + ths_units
print _line
#s1h
s1h_value, s1h_units = wks_utility.getS1h(mtd[ws_event_data])
_line = ' s1h: {0:.4f}'.format(s1h_value)
_line += ' ' + s1h_units
print _line
#s2h
s2h_value, s2h_units = wks_utility.getS2h(mtd[ws_event_data])
_line = ' s2h: {0:.4f}'.format(s2h_value)
_line += ' ' + s2h_units
print _line
#s1w
s1w_value, s1w_units = wks_utility.getS1w(mtd[ws_event_data])
_line = ' s1w: {0:.4f}'.format(s1w_value)
_line += ' ' + s1w_units
print _line
#s2w
s2w_value, s2w_units = wks_utility.getS2w(mtd[ws_event_data])
_line = ' s2w: {0:.4f}'.format(s2w_value)
_line += ' ' + s2w_units
print _line
print '********************************'
print
mtd.registerPyAlgorithm(RefLview())