-
Notifications
You must be signed in to change notification settings - Fork 122
/
AddSampleLogMultiple.py
101 lines (73 loc) · 3.28 KB
/
AddSampleLogMultiple.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
#pylint: disable=no-init
from mantid.simpleapi import *
from mantid.kernel import *
from mantid.api import *
class AddSampleLogMultiple(PythonAlgorithm):
def category(self):
return 'DataHandling\\Logs'
def summary(self):
return 'Add multiple sample logs to a workspace'
def PyInit(self):
self.declareProperty(WorkspaceProperty('Workspace', '', direction=Direction.InOut),
doc='Workspace to add logs to')
self.declareProperty(StringArrayProperty('LogNames', ''),
doc='Comma separated list of log names')
self.declareProperty(StringArrayProperty('LogValues', ''),
doc='Comma separated list of log values')
self.declareProperty(StringArrayProperty('LogUnits', ''),
doc='Comma separated list of log units')
self.declareProperty('ParseType', True,
doc='Determine the value type by parsing the string')
def PyExec(self):
workspace = self.getPropertyValue('Workspace')
log_names = self.getProperty('LogNames').value
log_values = self.getProperty('LogValues').value
log_units = self.getProperty('LogUnits').value
parse_type = self.getProperty('ParseType').value
if len(log_units) == 0:
log_units = [""]*len(log_names)
for idx in range(0, len(log_names)):
# Get the name, value, and unit
name = log_names[idx]
value = log_values[idx]
unit = log_units[idx]
# Try to get the correct type
value_type = 'String'
if parse_type:
try:
float(value)
value_type = 'Number'
except ValueError:
pass
# Add the log
alg = AlgorithmManager.create('AddSampleLog')
alg.initialize()
alg.setChild(True)
alg.setLogging(False)
alg.setProperty('Workspace', workspace)
alg.setProperty('LogType', value_type)
alg.setProperty('LogName', name)
alg.setProperty('LogText', value)
alg.setProperty('LogUnit', unit)
alg.execute()
def validateInputs(self):
issues = dict()
log_names = self.getProperty('LogNames').value
log_values = self.getProperty('LogValues').value
log_units = self.getProperty('LogUnits').value
num_names = len(log_names)
num_values = len(log_values)
num_units = len(log_units)
# Ensure there is at leats 1 log name
if num_names == 0:
issues['LogNames'] = 'Must have at least one log name'
# Ensure there is at leats 1 log value
if num_values == 0:
issues['LogValues'] = 'Must have at least one log value'
if num_names > 0 and num_values > 0 and num_names != num_values:
issues['LogValues'] = 'Number of log values must match number of log names'
if num_names > 0 and num_units != 0 and num_units != num_names:
issues['LogUnits'] = 'Number of log units must be 0 or match the number of log names'
return issues
# Register algorithm with Mantid
AlgorithmFactory.subscribe(AddSampleLogMultiple)