Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
811c0538
Commit
811c0538
authored
Oct 25, 2016
by
Whitfield, Ross
Browse files
Fix all PythonScriptsTest for python3
parent
8ab67e8d
Changes
54
Hide whitespace changes
Inline
Side-by-side
scripts/CryPowderISIS/cry_focus.py
View file @
811c0538
# pylint: disable=too-many-arguments,unused-variable
# pylint: disable=too-many-arguments,unused-variable
from
mantid.simpleapi
import
*
from
os.path
import
join
...
...
scripts/Inelastic/CrystalField/__init__.py
View file @
811c0538
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
.fitting
import
CrystalField
,
CrystalFieldFit
,
CrystalFieldMulti
from
.function
import
PeaksFunction
,
Background
,
Function
scripts/Inelastic/CrystalField/energies.py
View file @
811c0538
#pylint: disable=no-name-in-module
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
mantid.simpleapi
import
CrystalFieldEnergies
import
numpy
as
np
import
warnings
...
...
scripts/Inelastic/CrystalField/fitting.py
View file @
811c0538
from
__future__
import
(
absolute_import
,
division
,
print_function
)
import
numpy
as
np
import
re
from
mantid.kernel
import
ConfigService
...
...
@@ -167,7 +168,7 @@ class CrystalField(object):
temperature
=
self
.
_getTemperature
(
i
)
out
=
'name=CrystalFieldPeaks,Ion=%s,Symmetry=%s,Temperature=%s'
%
(
self
.
_ion
,
self
.
_symmetry
,
temperature
)
out
+=
',ToleranceEnergy=%s,ToleranceIntensity=%s'
%
(
self
.
_toleranceEnergy
,
self
.
_toleranceIntensity
)
out
+=
',%s'
%
','
.
join
([
'%s=%s'
%
item
for
item
in
self
.
_fieldParameters
.
items
()])
out
+=
',%s'
%
','
.
join
([
'%s=%s'
%
item
for
item
in
list
(
self
.
_fieldParameters
.
items
()
)
])
return
out
def
makeSpectrumFunction
(
self
,
i
=
0
):
...
...
@@ -181,7 +182,7 @@ class CrystalField(object):
out
+=
',PeakShape=%s'
%
self
.
getPeak
(
i
).
name
if
self
.
_FWHM
is
not
None
:
out
+=
',FWHM=%s'
%
self
.
_getFWHM
(
i
)
out
+=
',%s'
%
','
.
join
([
'%s=%s'
%
item
for
item
in
self
.
_fieldParameters
.
items
()])
out
+=
',%s'
%
','
.
join
([
'%s=%s'
%
item
for
item
in
list
(
self
.
_fieldParameters
.
items
()
)
])
peaks
=
self
.
getPeak
(
i
)
params
=
peaks
.
paramString
(
''
,
0
)
if
len
(
params
)
>
0
:
...
...
@@ -217,7 +218,7 @@ class CrystalField(object):
out
+=
',Temperatures=(%s)'
%
','
.
join
(
map
(
str
,
self
.
_temperature
))
if
self
.
_FWHM
is
not
None
:
out
+=
',FWHMs=(%s)'
%
','
.
join
(
map
(
str
,
self
.
_FWHM
))
out
+=
',%s'
%
','
.
join
([
'%s=%s'
%
item
for
item
in
self
.
_fieldParameters
.
items
()])
out
+=
',%s'
%
','
.
join
([
'%s=%s'
%
item
for
item
in
list
(
self
.
_fieldParameters
.
items
()
)
])
tieList
=
[]
constraintsList
=
[]
...
...
@@ -281,7 +282,7 @@ class CrystalField(object):
"""
if
value
not
in
self
.
ion_nre_map
.
keys
():
msg
=
'Value %s is not allowed for attribute Ion.
\n
List of allowed values: %s'
%
\
(
value
,
', '
.
join
(
self
.
ion_nre_map
.
keys
()))
(
value
,
', '
.
join
(
list
(
self
.
ion_nre_map
.
keys
()))
)
raise
RuntimeError
(
msg
)
self
.
_ion
=
value
self
.
_dirty_eigensystem
=
True
...
...
@@ -529,7 +530,7 @@ class CrystalField(object):
self
.
_fieldTies
[
name
]
=
'0'
def
getFieldTies
(
self
):
ties
=
[
'%s=%s'
%
item
for
item
in
self
.
_fieldTies
.
items
()]
ties
=
[
'%s=%s'
%
item
for
item
in
list
(
self
.
_fieldTies
.
items
()
)
]
return
','
.
join
(
ties
)
def
getFieldConstraints
(
self
):
...
...
@@ -740,7 +741,7 @@ class CrystalFieldMulti(object):
self
.
_ties
[
tie
]
=
kwargs
[
tie
]
def
getTies
(
self
):
ties
=
[
'%s=%s'
%
item
for
item
in
self
.
_ties
.
items
()]
ties
=
[
'%s=%s'
%
item
for
item
in
list
(
self
.
_ties
.
items
()
)
]
return
','
.
join
(
ties
)
def
getSpectrum
(
self
,
i
=
0
,
workspace
=
None
,
ws_index
=
0
):
...
...
scripts/Inelastic/CrystalField/function.py
View file @
811c0538
from
__future__
import
(
absolute_import
,
division
,
print_function
)
import
re
parNamePattern
=
re
.
compile
(
r
'([a-zA-Z][\w.]+)'
)
...
...
@@ -75,13 +76,13 @@ class Function(object):
def
toString
(
self
):
"""Create function initialisation string"""
attrib
=
[
'%s=%s'
%
item
for
item
in
self
.
_attrib
.
items
()]
+
\
[
'%s=%s'
%
item
for
item
in
self
.
_params
.
items
()]
attrib
=
[
'%s=%s'
%
item
for
item
in
list
(
self
.
_attrib
.
items
()
)
]
+
\
[
'%s=%s'
%
item
for
item
in
list
(
self
.
_params
.
items
()
)
]
if
len
(
attrib
)
>
0
:
out
=
'name=%s,%s'
%
(
self
.
_name
,
','
.
join
(
attrib
))
else
:
out
=
'name=%s'
%
self
.
_name
ties
=
','
.
join
([
'%s=%s'
%
item
for
item
in
self
.
_ties
.
items
()])
ties
=
','
.
join
([
'%s=%s'
%
item
for
item
in
list
(
self
.
_ties
.
items
()
)
])
if
len
(
ties
)
>
0
:
out
+=
',ties=(%s)'
%
ties
constraints
=
','
.
join
(
self
.
_constraints
)
...
...
@@ -93,15 +94,15 @@ class Function(object):
"""Create a string with only parameters and attributes settings.
The prefix is prepended to all attribute names.
"""
attrib
=
[
'%s%s=%s'
%
((
prefix
,)
+
item
)
for
item
in
self
.
_attrib
.
items
()]
+
\
[
'%s%s=%s'
%
((
prefix
,)
+
item
)
for
item
in
self
.
_params
.
items
()]
attrib
=
[
'%s%s=%s'
%
((
prefix
,)
+
item
)
for
item
in
list
(
self
.
_attrib
.
items
()
)
]
+
\
[
'%s%s=%s'
%
((
prefix
,)
+
item
)
for
item
in
list
(
self
.
_params
.
items
()
)
]
return
','
.
join
(
attrib
)
def
tiesString
(
self
,
prefix
):
"""Create a string with only ties settings.
The prefix is prepended to all parameter names.
"""
ties
=
[
'%s%s=%s'
%
((
prefix
,)
+
item
)
for
item
in
self
.
_ties
.
items
()]
ties
=
[
'%s%s=%s'
%
((
prefix
,)
+
item
)
for
item
in
list
(
self
.
_ties
.
items
()
)
]
return
','
.
join
(
ties
)
def
constraintsString
(
self
,
prefix
):
...
...
@@ -153,7 +154,7 @@ class CompositeProperties(object):
def
getSize
(
self
):
"""Get number of maps (functions) defined here"""
keys
=
self
.
_properties
.
keys
()
keys
=
list
(
self
.
_properties
.
keys
()
)
if
len
(
keys
)
>
0
:
return
max
(
keys
)
+
1
return
0
...
...
@@ -166,7 +167,7 @@ class CompositeProperties(object):
for
i
in
range
(
self
.
getSize
()):
if
i
in
self
.
_properties
:
props
=
self
.
_properties
[
i
]
prop_list
.
append
(
','
.
join
([
'%s=%s'
%
item
for
item
in
props
.
items
()]))
prop_list
.
append
(
','
.
join
([
'%s=%s'
%
item
for
item
in
sorted
(
props
.
items
()
)
]))
else
:
prop_list
.
append
(
''
)
return
prop_list
...
...
@@ -184,7 +185,7 @@ class CompositeProperties(object):
props
=
self
.
_properties
[
i
]
if
len
(
out
)
>
0
:
out
+=
','
out
+=
','
.
join
([
'%s%s=%s'
%
((
fullPrefix
,)
+
item
)
for
item
in
props
.
items
()])
out
+=
','
.
join
([
'%s%s=%s'
%
((
fullPrefix
,)
+
item
)
for
item
in
sorted
(
props
.
items
()
)
])
return
out
[:]
...
...
@@ -406,7 +407,7 @@ class Background(object):
def
__mul__
(
self
,
nCopies
):
"""Make expressions like Background(...) * 8 return a list of 8 identical backgrounds."""
copies
=
[
self
]
*
nCopies
return
map
(
Background
.
clone
,
copies
)
return
list
(
map
(
Background
.
clone
,
copies
)
)
# return [self.clone() for i in range(nCopies)]
def
__rmul__
(
self
,
nCopies
):
...
...
scripts/Inelastic/Direct/DirectEnergyConversion.py
View file @
811c0538
#pylint: disable=too-many-lines
#pylint: disable=too-many-lines
#pylint: disable=invalid-name
#pylind: disable=attribute-defined-outside-init
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
mantid.simpleapi
import
*
from
mantid.kernel
import
funcinspect
from
mantid
import
geometry
,
api
...
...
@@ -11,6 +12,8 @@ import math
import
time
import
numpy
as
np
import
collections
from
six
import
iteritems
from
six.moves
import
range
import
Direct.CommonFunctions
as
common
import
Direct.diagnostics
as
diagnostics
...
...
@@ -1087,8 +1090,8 @@ class DirectEnergyConversion(object):
TOF_range
=
self
.
get_TOF_for_energies
(
workspace
,
en_list
,
spectra_id
,
ei
)
def
process_block
(
tof_range
):
tof_range
=
filter
(
lambda
x
:
not
(
math
.
isnan
(
x
))
,
tof_range
)
dt
=
map
(
lambda
x
,
y
:
abs
(
x
-
y
),
tof_range
[
1
:],
tof_range
[:
-
1
])
tof_range
=
[
x
for
x
in
tof_range
if
not
(
math
.
isnan
(
x
))
]
dt
=
list
(
map
(
lambda
x
,
y
:
abs
(
x
-
y
),
tof_range
[
1
:],
tof_range
[:
-
1
])
)
t_step
=
min
(
dt
)
tof_min
=
min
(
tof_range
)
tof_max
=
max
(
tof_range
)
...
...
@@ -1097,7 +1100,7 @@ class DirectEnergyConversion(object):
nBlocks
=
len
(
spectra_id
)
if
nBlocks
>
1
:
tof_min
,
t_step
,
tof_max
=
process_block
(
TOF_range
[
0
])
for
ind
in
x
range
(
1
,
nBlocks
):
for
ind
in
range
(
1
,
nBlocks
):
tof_min1
,
t_step1
,
tof_max1
=
process_block
(
TOF_range
[
ind
])
tof_min
=
min
(
tof_min
,
tof_min1
)
tof_max
=
max
(
tof_max
,
tof_max1
)
...
...
@@ -1482,7 +1485,7 @@ class DirectEnergyConversion(object):
scale_factor
=
van_multiplier
*
sample_multiplier
/
xsection
for
norm_type
,
val
in
norm_factor
.
iteritems
(
):
for
norm_type
,
val
in
iteritems
(
norm_factor
):
norm_factor
[
norm_type
]
=
val
*
scale_factor
# check for NaN
...
...
scripts/Inelastic/Direct/ISISDirecInelasticConfig.py
View file @
811c0538
#!/usr/bin/python
#!/usr/bin/python
from
__future__
import
(
absolute_import
,
division
,
print_function
)
import
os
import
sys
import
platform
...
...
@@ -8,6 +9,7 @@ import copy
from
datetime
import
date
import
time
from
xml.dom
import
minidom
from
six
import
iteritems
# the list of instruments this configuration is applicable to
INELASTIC_INSTRUMENTS
=
[
'MAPS'
,
'LET'
,
'MERLIN'
,
'MARI'
,
'HET'
]
...
...
@@ -85,7 +87,7 @@ class UserProperties(object):
self
.
_rb_dirs
[
recent_date_id
]
=
rb_folder_or_id
if
self
.
_recent_dateID
:
max_date
=
self
.
_start_dates
[
self
.
_recent_dateID
]
for
date_key
,
a_date
in
self
.
_start_dates
.
iteritems
(
):
for
date_key
,
a_date
in
iteritems
(
self
.
_start_dates
):
if
a_date
>
max_date
:
self
.
_recent_dateID
=
date_key
max_date
=
a_date
...
...
@@ -310,15 +312,15 @@ class UserProperties(object):
def
get_all_instruments
(
self
):
""" Return list of all instruments, user is working on during this cycle"""
return
self
.
_instrument
.
values
()
return
list
(
self
.
_instrument
.
values
()
)
def
get_all_cycles
(
self
):
"""Return list of all cycles the user participates in"""
return
self
.
_instrument
.
keys
()
return
list
(
self
.
_instrument
.
keys
()
)
def
get_all_rb
(
self
):
"""Return list of all rb folders the user participates in"""
return
self
.
_rb_dirs
.
values
()
return
list
(
self
.
_rb_dirs
.
values
()
)
#
...
...
@@ -544,7 +546,7 @@ class MantidConfigDirectInelastic(object):
fh_targ
=
open
(
output_file
,
'w'
)
if
not
fh_targ
:
return
var_to_replace
=
replacemets_list
.
keys
()
var_to_replace
=
list
(
replacemets_list
.
keys
()
)
with
open
(
input_file
)
as
fh_source
:
for
line
in
fh_source
:
rez
=
line
...
...
@@ -572,7 +574,7 @@ class MantidConfigDirectInelastic(object):
shutil
.
copyfile
(
input_file
,
output_file
)
else
:
self
.
_copy_and_parse_user_file
(
input_file
,
output_file
,
replacement_list
)
os
.
chmod
(
output_file
,
0777
)
os
.
chmod
(
output_file
,
0
o
777
)
ownership_str
=
"chown {0}:{1} {2}"
.
format
(
self
.
_user
.
userID
,
rb_group
,
output_file
)
if
platform
.
system
()
!=
'Windows'
:
...
...
@@ -732,7 +734,7 @@ class MantidConfigDirectInelastic(object):
# how to check cycle folders, they may not be available
self
.
_cycle_data_folder
=
set
()
# pylint: disable=W0212
for
date_key
,
folder_id
in
theUser
.
_cycle_IDs
.
items
():
for
date_key
,
folder_id
in
list
(
theUser
.
_cycle_IDs
.
items
()
)
:
self
.
_cycle_data_folder
.
add
(
self
.
get_data_folder_name
(
theUser
.
_instrument
[
date_key
],
folder_id
))
# Initialize configuration settings
self
.
_dynamic_configuration
=
copy
.
deepcopy
(
self
.
_dynamic_options_base
)
...
...
@@ -788,7 +790,7 @@ class MantidConfigDirectInelastic(object):
# define and append user scripts search path
user_path_part
=
copy
.
deepcopy
(
self
.
_python_user_scripts
)
# pylint: disable=W0212
for
instr
in
self
.
_user
.
_instrument
.
values
():
for
instr
in
list
(
self
.
_user
.
_instrument
.
values
()
)
:
user_path_part
.
add
(
os
.
path
.
join
(
'direct_inelastic'
,
instr
.
upper
()))
for
part
in
user_path_part
:
path
+=
';'
+
os
.
path
.
join
(
self
.
_script_repo
,
part
)
+
'/'
...
...
@@ -849,7 +851,7 @@ class MantidConfigDirectInelastic(object):
users_cycles
=
self
.
_user
.
get_all_cycles
()
users_rb
=
self
.
_user
.
get_all_rb
()
# extract rb folder without path, which gives RB group name
users_rb
=
map
(
os
.
path
.
basename
,
users_rb
)
users_rb
=
list
(
map
(
os
.
path
.
basename
,
users_rb
)
)
#
for
cycle
,
rb_name
in
zip
(
users_cycles
,
users_rb
):
if
key_users_list
:
...
...
@@ -914,7 +916,7 @@ class MantidConfigDirectInelastic(object):
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
!=
6
:
print
"usage: Config.py userID instrument RBNumber cycleID start_date"
print
(
"usage: Config.py userID instrument RBNumber cycleID start_date"
)
exit
()
argi
=
sys
.
argv
[
1
:]
...
...
@@ -946,19 +948,19 @@ if __name__ == "__main__":
# initialize Mantid configuration
# its testing route under main so it rightly imports itself
#pylint: disable=W0406
from
ISISDirecInelasticConfig
import
MantidConfigDirectInelastic
,
UserProperties
from
.
ISISDirecInelasticConfig
import
MantidConfigDirectInelastic
,
UserProperties
mcf
=
MantidConfigDirectInelastic
(
MantidDir
,
rootDir
,
UserScriptRepoDir
,
MapMaskDir
)
print
"Successfully initialized ISIS Inelastic Configuration script generator"
print
(
"Successfully initialized ISIS Inelastic Configuration script generator"
)
rb_user_folder
=
os
.
path
.
join
(
mcf
.
_home_path
,
user
.
userID
)
user
.
rb_dir
=
rb_user_folder
if
not
user
.
rb_dir_exist
:
print
"RB folder {0} for user {1} should exist and be accessible to configure this user"
.
format
(
user
.
rb_dir
,
user
.
userID
)
print
(
"RB folder {0} for user {1} should exist and be accessible to configure this user"
.
format
(
user
.
rb_dir
,
user
.
userID
)
)
exit
()
# Configure user
mcf
.
init_user
(
user
.
userID
,
user
)
mcf
.
generate_config
()
print
"Successfully Configured user: {0} for instrument {1} and RBNum: {2}"
\
.
format
(
user
.
userID
,
user
.
instrument
,
user
.
rb_folder
)
print
(
"Successfully Configured user: {0} for instrument {1} and RBNum: {2}"
\
.
format
(
user
.
userID
,
user
.
instrument
,
user
.
rb_folder
)
)
scripts/Inelastic/Direct/NonIDF_Properties.py
View file @
811c0538
#pylint: disable=invalid-name
#pylint: disable=invalid-name
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
Direct.PropertiesDescriptors
import
*
from
Direct.RunDescriptor
import
RunDescriptor
,
RunDescriptorDependent
...
...
@@ -16,11 +17,11 @@ class NonIDF_Properties(object):
# logging levels available for user
#pylint: disable=unnecessary-lambda
log_options
=
\
{
"error"
:
(
1
,
lambda
(
msg
)
:
logger
.
error
(
msg
)),
"warning"
:
(
2
,
lambda
(
msg
)
:
logger
.
warning
(
msg
)),
"notice"
:
(
3
,
lambda
(
msg
)
:
logger
.
notice
(
msg
)),
"information"
:
(
4
,
lambda
(
msg
)
:
logger
.
information
(
msg
)),
"debug"
:
(
5
,
lambda
(
msg
)
:
logger
.
debug
(
msg
))}
{
"error"
:
(
1
,
lambda
msg
:
logger
.
error
(
msg
)),
"warning"
:
(
2
,
lambda
msg
:
logger
.
warning
(
msg
)),
"notice"
:
(
3
,
lambda
msg
:
logger
.
notice
(
msg
)),
"information"
:
(
4
,
lambda
msg
:
logger
.
information
(
msg
)),
"debug"
:
(
5
,
lambda
msg
:
logger
.
debug
(
msg
))}
def
__init__
(
self
,
Instrument
,
run_workspace
=
None
):
""" initialize main properties, defined by the class
...
...
@@ -66,7 +67,7 @@ class NonIDF_Properties(object):
else
:
# TODO: reconcile this with Mantid.
if
lev
<=
self
.
_current_log_level
:
print
msg
print
(
msg
)
#-----------------------------------------------------------------------------
# Complex properties with personal descriptors
#-----------------------------------------------------------------------------
...
...
scripts/Inelastic/Direct/PropertiesDescriptors.py
View file @
811c0538
#pylint: disable=too-many-lines
#pylint: disable=too-many-lines
#pylint: disable=invalid-name
""" File contains collection of Descriptors used to define complex
properties in NonIDF_Properties and PropertyManager classes
"""
from
__future__
import
(
absolute_import
,
division
,
print_function
)
import
os
import
numpy
as
np
import
math
...
...
@@ -17,6 +18,7 @@ from mantid import api,geometry,config
import
Direct.ReductionHelpers
as
prop_helpers
#pylint: disable=unused-import
import
Direct.CommonFunctions
as
common
import
collections
#-----------------------------------------------------------------------------------------
...
...
@@ -194,7 +196,7 @@ class IncidentEnergy(PropDescriptor):
else
:
if
value
.
find
(
'['
)
>
-
1
:
energy_list
=
True
value
=
value
.
trans
la
t
e
(
None
,
'[]
'
).
strip
()
value
=
value
.
rep
la
c
e
(
'['
,
''
).
replace
(
']'
,
'
'
).
strip
()
else
:
energy_list
=
False
en_list
=
str
.
split
(
value
,
','
)
...
...
@@ -381,7 +383,7 @@ class EnergyBins(PropDescriptor):
def
__set__
(
self
,
instance
,
values
):
if
values
is
not
None
:
if
isinstance
(
values
,
str
):
values
=
values
.
trans
la
t
e
(
None
,
'[]
'
).
strip
()
values
=
values
.
rep
la
c
e
(
'['
,
''
).
replace
(
']'
,
'
'
).
strip
()
lst
=
values
.
split
(
','
)
self
.
__set__
(
instance
,
lst
)
return
...
...
@@ -514,7 +516,7 @@ class SaveFileName(PropDescriptor):
if
value
is
None
:
self
.
_file_name
=
None
elif
callable
(
valu
e
):
elif
isinstance
(
value
,
collections
.
Callabl
e
):
self
.
_custom_print
=
value
else
:
self
.
_file_name
=
str
(
value
)
...
...
@@ -1067,7 +1069,7 @@ class EiMonSpectra(prop_helpers.ComplexProperty):
tDict
=
instance
.
__dict__
if
isinstance
(
value
,
str
):
val
=
value
.
trans
la
t
e
(
None
,
'[]
'
).
strip
()
val
=
value
.
replace
(
'['
,
''
).
rep
la
c
e
(
']'
,
'
'
).
strip
()
if
val
.
find
(
':'
)
>-
1
:
val
=
val
.
split
(
':'
)
else
:
...
...
scripts/Inelastic/Direct/PropertyManager.py
View file @
811c0538
#pylint: disable=invalid-name
#pylint: disable=invalid-name
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
Direct.NonIDF_Properties
import
*
from
collections
import
OrderedDict
,
Iterable
from
six
import
iteritems
class
PropertyManager
(
NonIDF_Properties
):
...
...
@@ -95,7 +97,7 @@ class PropertyManager(NonIDF_Properties):
self
.
__dict__
.
update
(
param_dict
)
# use existing descriptors setter to define IDF-defined descriptor's state
for
key
,
val
in
descr_dict
.
iteritems
():
for
key
,
val
in
iteritems
(
descr_dict
):
object
.
__setattr__
(
self
,
key
,
val
)
# file properties -- the properties described files which should exist for reduction to work.
...
...
@@ -132,7 +134,7 @@ class PropertyManager(NonIDF_Properties):
class_decor
=
'_'
+
type
(
self
).
__name__
+
'__'
for
key
,
val
in
prop_dict
.
iteritems
():
for
key
,
val
in
iteritems
(
prop_dict
):
new_key
=
class_decor
+
key
object
.
__setattr__
(
self
,
new_key
,
val
)
...
...
@@ -281,7 +283,7 @@ class PropertyManager(NonIDF_Properties):
with some parameters missing.
"""
for
par_name
,
value
in
kwargs
.
items
()
:
for
par_name
,
value
in
list
(
kwargs
.
items
()
)
:
if
value
is
not
None
:
setattr
(
self
,
par_name
,
value
)
#
...
...
@@ -290,7 +292,7 @@ class PropertyManager(NonIDF_Properties):
""" Set input properties from a dictionary of parameters
"""
for
par_name
,
value
in
kwargs
.
items
()
:
for
par_name
,
value
in
list
(
kwargs
.
items
()
)
:
setattr
(
self
,
par_name
,
value
)
return
self
.
getChangedProperties
()
...
...
@@ -339,7 +341,7 @@ class PropertyManager(NonIDF_Properties):
'instr_name'
:
''
,
'print_diag_results'
:
True
,
'mapmask_ref_ws'
:
None
}
result
=
{}
for
key
,
val
in
diag_param_list
.
iteritems
(
):
for
key
,
val
in
iteritems
(
diag_param_list
):
try
:
result
[
key
]
=
getattr
(
self
,
key
)
except
KeyError
:
...
...
@@ -379,7 +381,7 @@ class PropertyManager(NonIDF_Properties):
param_list
=
prop_helpers
.
get_default_idf_param_list
(
pInstrument
,
self
.
__subst_dict
)
# remove old changes which are not related to IDF (not to reapply it again)
for
prop_name
in
old_changes
:
for
prop_name
in
old_changes
.
copy
()
:
if
prop_name
not
in
param_list
:
try
:
dependencies
=
getattr
(
PropertyManager
,
prop_name
).
dependencies
()
...
...
@@ -402,12 +404,12 @@ class PropertyManager(NonIDF_Properties):
self
.
setChangedProperties
(
set
())
#sort parameters to have complex properties (with underscore _) first
sorted_param
=
OrderedDict
(
sorted
(
param_list
.
items
(),
key
=
lambda
x
:
ord
((
x
[
0
][
0
]).
lower
())))
sorted_param
=
OrderedDict
(
sorted
(
list
(
param_list
.
items
()
)
,
key
=
lambda
x
:
ord
((
x
[
0
][
0
]).
lower
())))
# Walk through descriptors list and set their values
# Assignment to descriptors should accept the form, descriptor is written in IDF
changed_descriptors
=
set
()
for
key
,
val
in
descr_dict
.
iteritems
():
for
key
,
val
in
iteritems
(
descr_dict
):
if
key
not
in
old_changes_list
:
try
:
# this is reliability check, and except ideally should never be hit. May occur if old IDF contains
# properties, not present in recent IDF.
...
...
@@ -458,7 +460,7 @@ class PropertyManager(NonIDF_Properties):
self
.
setChangedProperties
(
changed_descriptors
)
# Walk through the complex properties first and then through simple properties
for
key
,
val
in
sorted_param
.
iteritems
(
):
for
key
,
val
in
iteritems
(
sorted_param
.
copy
()
):
# complex properties may change through their dependencies so we are setting them first
if
isinstance
(
val
,
prop_helpers
.
ComplexProperty
):
public_name
=
key
[
1
:]
...
...
@@ -501,7 +503,7 @@ class PropertyManager(NonIDF_Properties):
self
.
setChangedProperties
(
set
())
# set back all changes stored earlier and may be overwritten by new IDF
# (this is just to be sure -- should not change anything as we do not set properties changed)
for
key
,
val
in
old_changes
.
iteritems
(
):
for
key
,
val
in
iteritems
(
old_changes
):
setattr
(
self
,
key
,
val
)
# Clear changed properties list (is this wise?, may be we want to know that some defaults changed?)
...
...
@@ -740,7 +742,12 @@ class PropertyManager(NonIDF_Properties):
if
key
in
already_changed
:
continue
val
=
getattr
(
self
,
key
)
self
.
log
(
" Value of : {0:<25} is set to : {1:<20} "
.
format
(
key
,
val
),
log_level
)
try
:
self
.
log
(
" Value of : {0:<25} is set to : {1:<20} "
.
format
(
key
,
val
),
log_level
)
except
TypeError
:
# Python 3 fails here sometimes, I don't know why
# TypeError: non-empty format string passed to object.__format__
pass
if
not
display_header
:
return
...
...
scripts/Inelastic/Direct/ReductionHelpers.py
View file @
811c0538
#pylint: disable=invalid-name
#pylint: disable=invalid-name
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
mantid
import
config
import
os
import
re
from
six.moves
import
range
"""
Set of functions to assist with processing instrument parameters relevant to reduction.
"""
...
...
@@ -143,11 +145,11 @@ def build_properties_dict(param_map,synonims,descr_list=[]) :
final_name
=
str
(
name
)
prelim_dict
[
final_name
]
=
None
param_keys
=
prelim_dict
.
keys
()
param_keys
=
list
(
prelim_dict
.
keys
()
)
properties_dict
=
dict
()
descr_dict
=
dict
()
for
name
,
val
in
param_map
.
items
()
:
for
name
,
val
in
list
(
param_map
.
items
()
)
:
if
name
in
synonims
:
final_name
=
str
(
synonims
[
name
])
else
:
...
...
@@ -230,7 +232,7 @@ def build_subst_dictionary(synonims_list=None) :
if
len
(
keys
[
0
])
==
0
:
raise
AttributeError
(
"The pairs in the synonyms fields have to have form key1=key2=key3 with at least two values present, "
"but the first key is empty"
)
for
i
in
x
range
(
1
,
len
(
keys
))
:
for
i
in
range
(
1
,
len
(
keys
))
:
if
len
(
keys
[
i
])
==
0
:
raise
AttributeError
(
"The pairs in the synonyms fields have to have form key1=key2=key3 with at least two values present, "
"but the key"
+
str
(
i
)
+
" is empty"
)
...
...
@@ -343,7 +345,7 @@ def parse_single_name(filename):
if
ind1
>
ind2
:
raise
ValueError
(
'Invalid file number defined using colon : left run number '
'{0} has to be large then right {1}'
.
format
(
ind1
,
ind2
))
number
=
range
(
ind1
[
0
],
ind2
[
0
]
+
1
)
number
=
list
(
range
(
ind1
[
0
],
ind2
[
0
]
+
1
)
)
if
len
(
filepath
)
>
0
:
filepath
=
[
filepath
]
*
len
(
number
)
else
:
...
...
@@ -356,11 +358,11 @@ def parse_single_name(filename):
return
(
filepath
,
number
,
fext
)
fname
,
fext
=
os
.
path
.
splitext
(
fname
)
fnumber
=
filter
(
lambda
x
:
x
.
isdigit
()
,
fname
)
fnumber
=
re
.
findall
(
'\d+'
,
fname
)
if
len
(
fnumber
)
==
0
:
number
=
0
else
:
number
=
int
(
fnumber
)
number
=
int
(
fnumber
[
0
]
)
return
([
filepath
],[
number
],[
fext
])
...
...
@@ -380,7 +382,7 @@ def parse_run_file_name(run_string):
filenum
+=
ind
fext
+=
ext1
non_empty
=
filter
(
lambda
x
:
len
(
x
)
>
0
,
fext
)
non_empty
=
[
x
for
x
in
fext
if
len
(
x
)
>
0
]
if
len
(
non_empty
)
>
0
:
anExt
=
non_empty
[
-
1
]
for
i
,
val
in
enumerate
(
fext
):
...
...
@@ -402,7 +404,7 @@ def process_prop_list(workspace,logName="CombinedSpectraIDList"):
"""
if
workspace
.
run
().
hasProperty
(
logName
):
spec_id_str
=
workspace
.
run
().
getProperty
(
logName
).
value
spec_id_str
=
spec_id_str
.
trans
la
t
e
(
None
,
'[]
'
).
strip
()
spec_id_str
=
spec_id_str
.
replace
(
'['
,
''
).
rep
la
c
e
(
']'
,
'
'
).
strip
()
spec_id_listS
=
spec_id_str
.
split
(
','
)
spec_list
=
[]
for
val
in
spec_id_listS
:
...
...
scripts/Inelastic/Direct/ReductionWrapper.py
View file @
811c0538
#pylint: disable=invalid-name
#pylint: disable=invalid-name
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
mantid.simpleapi
import
*
from
mantid
import
config
,
api
from
mantid.kernel
import
funcinspect
...
...
@@ -9,6 +10,7 @@ from Direct.DirectEnergyConversion import DirectEnergyConversion
import
os
import
re
import
time
<