Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
b4955e58
Commit
b4955e58
authored
Sep 16, 2021
by
Jose Borreguero
Browse files
Rename algorithm SuggestTibCNCS
Signed-off-by:
Jose Borreguero
<
borreguero@gmail.com
>
parent
4cbd7fc0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Framework/PythonInterface/plugins/CMakeLists.txt
View file @
b4955e58
...
...
@@ -177,7 +177,7 @@ set(PYTHON_PLUGINS
algorithms/SortDetectors.py
algorithms/StatisticsOfTableWorkspace.py
algorithms/StringToPng.py
algorithms/SuggestT
ibCNCS
.py
algorithms/
CNCS
SuggestT
IB
.py
algorithms/SuggestTibHYSPEC.py
algorithms/Symmetrise.py
algorithms/TOFTOFCropWorkspace.py
...
...
Framework/PythonInterface/plugins/algorithms/SuggestT
ibCNCS
.py
→
Framework/PythonInterface/plugins/algorithms/
CNCS
SuggestT
IB
.py
View file @
b4955e58
...
...
@@ -5,8 +5,12 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
#pylint: disable=no-init,invalid-name
# package imports
from
mantid.api
import
PythonAlgorithm
,
AlgorithmFactory
from
mantid.kernel
import
FloatBoundedValidator
,
Direction
from
mantid.utils.deprecator
import
deprecated_alias
# third party imports
import
numpy
as
np
#pylint: disable=too-few-public-methods
...
...
@@ -16,36 +20,45 @@ class Interval(object):
"""Simple class that provides check for overlapping intervals
"""
def
__init__
(
self
,
minv
,
maxv
):
self
.
min
=
minv
self
.
max
=
maxv
def
__init__
(
self
,
minv
,
maxv
):
self
.
min
=
minv
self
.
max
=
maxv
def
overlap
(
self
,
other
):
if
other
.
max
>
self
.
min
and
other
.
max
<
self
.
max
:
if
other
.
max
>
self
.
min
and
other
.
max
<
self
.
max
:
return
True
if
other
.
min
>
self
.
min
and
other
.
min
<
self
.
max
:
if
other
.
min
>
self
.
min
and
other
.
min
<
self
.
max
:
return
True
if
other
.
min
<
self
.
min
and
other
.
max
>
self
.
max
:
if
other
.
min
<
self
.
min
and
other
.
max
>
self
.
max
:
return
True
return
False
class
SuggestTibCNCS
(
PythonAlgorithm
):
@
deprecated_alias
(
'2021-09-16'
)
class
CNCSSuggestTIB
(
PythonAlgorithm
):
""" Check if certain sample logs exists on a workspace
"""
@
staticmethod
def
e2v
(
energy
):
return
np
.
sqrt
(
energy
/
5.227e-6
)
def
alias
(
self
):
r
"""Alternative name to this algorithm"""
return
'SuggestTibCNCS'
def
category
(
self
):
""" Return category
"""
return
"Inelastic
\\
Utility"
def
seeAlso
(
self
):
return
[
"SuggestTibHYSPEC"
]
return
[
"SuggestTibHYSPEC"
]
def
name
(
self
):
""" Return name
"""
return
"SuggestT
ibCNCS
"
return
"
CNCS
SuggestT
IB
"
def
summary
(
self
):
""" Return summary
...
...
@@ -55,98 +68,95 @@ class SuggestTibCNCS(PythonAlgorithm):
def
PyInit
(
self
):
""" Declare properties
"""
val
=
FloatBoundedValidator
()
val
.
setBounds
(
0.5
,
50
)
#
reasonable incident nergy range for CNCS
self
.
declareProperty
(
"IncidentEnergy"
,
0.
,
val
,
"Incident energy (0.5 to 50 meV)"
)
self
.
declareProperty
(
"TibMin"
,
0.
,
Direction
.
Output
)
self
.
declareProperty
(
"TibMax"
,
0.
,
Direction
.
Output
)
val
=
FloatBoundedValidator
()
val
.
setBounds
(
0.5
,
50
)
#
reasonable incident
e
nergy range for CNCS
self
.
declareProperty
(
"IncidentEnergy"
,
0.
,
val
,
"Incident energy (0.5 to 50 meV)"
)
self
.
declareProperty
(
"TibMin"
,
0.
,
Direction
.
Output
)
self
.
declareProperty
(
"TibMax"
,
0.
,
Direction
.
Output
)
return
def
e2v
(
self
,
energy
):
return
np
.
sqrt
(
energy
/
5.227e-6
)
#pylint: disable=too-many-branches
# pylint: disable=too-many-branches
def
PyExec
(
self
):
""" Main execution body
"""
#get parameter
#
get parameter
energy
=
self
.
getProperty
(
"IncidentEnergy"
).
value
frame
=
1e6
/
60.
#calculate tel, tmin, tmax, tinf, tpulse
tel
=
1e6
*
(
3.5
+
36.262
)
/
self
.
e2v
(
energy
)
tmin
=
tel
-
frame
*
0.5
if
tmin
<
0
:
tmin
=
0.
tmax
=
tmin
+
frame
tinf
=
1e6
*
(
36.262
)
/
self
.
e2v
(
energy
)
if
tinf
<
tmin
:
tinf
+=
frame
tpulse
=
frame
*
np
.
floor
(
tmax
/
frame
)
#check for TIB
dtib
=
3500.
# default length of TIB range
dtibreduced
=
2500
#
reduced range
dtinfminus
=
500
dtinfplus
=
1500
dtpulseminus
=
50
dtpulseplus
=
1500
#Create intervals that cannot be used for TIB. For ease,
#move everything to times lower than t_inf, make sure
#one doesn't overlap with the frame edge, then if the TIB
#interval is in the previous frame, jut move it up
intervalList
=
[]
intervalList
.
append
(
Interval
(
tinf
-
dtinfminus
,
tinf
))
#interval close to t_inf, on the lower side
#intervaldenoting frame edge. This will make sure that one cannot get an interval overlapping t_min
intervalList
.
append
(
Interval
(
tmin
,
tmin
))
#interval close to t_inf, on the upper side, but moved one frame down
intervalList
.
append
(
Interval
(
tinf
-
frame
,
tinf
-
frame
+
dtinfplus
))
if
tpulse
+
dtpulseplus
<
tmax
:
itpulse
=
Interval
(
tpulse
-
dtpulseminus
,
tpulse
+
dtpulseplus
)
frame
=
1e6
/
60.
#
calculate tel, tmin, tmax, tinf, tpulse
tel
=
1e6
*
(
3.5
+
36.262
)
/
self
.
e2v
(
energy
)
tmin
=
tel
-
frame
*
0.5
if
tmin
<
0
:
tmin
=
0.
tmax
=
tmin
+
frame
tinf
=
1e6
*
(
36.262
)
/
self
.
e2v
(
energy
)
if
tinf
<
tmin
:
tinf
+=
frame
tpulse
=
frame
*
np
.
floor
(
tmax
/
frame
)
#
check for TIB
dtib
=
3500.
# default length of TIB range
dtibreduced
=
2500
#
reduced range
dtinfminus
=
500
dtinfplus
=
1500
dtpulseminus
=
50
dtpulseplus
=
1500
#
Create intervals that cannot be used for TIB. For ease,
#
move everything to times lower than t_inf, make sure
#
one doesn't overlap with the frame edge, then if the TIB
#
interval is in the previous frame, jut move it up
intervalList
=
[]
intervalList
.
append
(
Interval
(
tinf
-
dtinfminus
,
tinf
))
#
interval close to t_inf, on the lower side
#
interval
denoting frame edge. This will make sure that one cannot get an interval overlapping t_min
intervalList
.
append
(
Interval
(
tmin
,
tmin
))
#
interval close to t_inf, on the upper side, but moved one frame down
intervalList
.
append
(
Interval
(
tinf
-
frame
,
tinf
-
frame
+
dtinfplus
))
if
tpulse
+
dtpulseplus
<
tmax
:
itpulse
=
Interval
(
tpulse
-
dtpulseminus
,
tpulse
+
dtpulseplus
)
else
:
itpulse
=
Interval
(
tpulse
-
dtpulseminus
-
frame
,
tpulse
+
dtpulseplus
-
frame
)
itpulse
=
Interval
(
tpulse
-
dtpulseminus
-
frame
,
tpulse
+
dtpulseplus
-
frame
)
if
itpulse
.
overlap
(
Interval
(
tinf
,
tinf
)):
#if the prompt pulse overlaps with t_inf move the upper part one frame down
intervalList
.
append
(
Interval
(
itpulse
.
min
,
tinf
))
intervalList
.
append
(
Interval
(
tinf
-
frame
,
itpulse
.
max
-
frame
))
if
itpulse
.
overlap
(
Interval
(
tinf
,
tinf
)):
#
if the prompt pulse overlaps with t_inf move the upper part one frame down
intervalList
.
append
(
Interval
(
itpulse
.
min
,
tinf
))
intervalList
.
append
(
Interval
(
tinf
-
frame
,
itpulse
.
max
-
frame
))
else
:
if
tinf
<
itpulse
.
min
:
itpulse
=
Interval
(
itpulse
.
min
-
frame
,
itpulse
.
max
-
frame
)
if
tinf
<
itpulse
.
min
:
itpulse
=
Interval
(
itpulse
.
min
-
frame
,
itpulse
.
max
-
frame
)
intervalList
.
append
(
itpulse
)
#create the list of times to checked. These are the lower parts of the intervals
timestocheck
=
[]
#
create the list of times to checked. These are the lower parts of the intervals
timestocheck
=
[]
for
i
in
intervalList
:
if
i
.
min
>
tinf
-
frame
:
if
i
.
min
>
tinf
-
frame
:
timestocheck
.
append
(
i
.
min
)
timestocheck
.
sort
()
timestocheck
.
reverse
()
for
t
in
timestocheck
:
tInterval
=
Interval
(
t
-
dtib
,
t
)
if
all
(
not
inter
.
overlap
(
tInterval
)
for
inter
in
intervalList
):
tibmin
=
tInterval
.
min
tibmax
=
tInterval
.
max
tInterval
=
Interval
(
t
-
dtib
,
t
)
if
all
(
not
inter
.
overlap
(
tInterval
)
for
inter
in
intervalList
):
tibmin
=
tInterval
.
min
tibmax
=
tInterval
.
max
break
tInterval
=
Interval
(
t
-
dtibreduced
,
t
)
if
all
(
not
inter
.
overlap
(
tInterval
)
for
inter
in
intervalList
):
tibmin
=
tInterval
.
min
tibmax
=
tInterval
.
max
tInterval
=
Interval
(
t
-
dtibreduced
,
t
)
if
all
(
not
inter
.
overlap
(
tInterval
)
for
inter
in
intervalList
):
tibmin
=
tInterval
.
min
tibmax
=
tInterval
.
max
break
#move to the data frame
if
tibmin
<
tmin
:
tibmin
+=
frame
tibmax
+=
frame
#
move to the data frame
if
tibmin
<
tmin
:
tibmin
+=
frame
tibmax
+=
frame
#return the result
self
.
setProperty
(
"TibMin"
,
tibmin
+
50
)
self
.
setProperty
(
"TibMax"
,
tibmax
-
50
)
#
return the result
self
.
setProperty
(
"TibMin"
,
tibmin
+
50
)
self
.
setProperty
(
"TibMax"
,
tibmax
-
50
)
return
AlgorithmFactory
.
subscribe
(
SuggestT
ibCNCS
)
AlgorithmFactory
.
subscribe
(
CNCS
SuggestT
IB
)
Framework/PythonInterface/plugins/algorithms/SuggestTibHYSPEC.py
View file @
b4955e58
...
...
@@ -20,7 +20,7 @@ class SuggestTibHYSPEC(PythonAlgorithm):
return
"Inelastic
\\
Utility"
def
seeAlso
(
self
):
return
[
"SuggestT
ibCNCS
"
]
return
[
"
CNCS
SuggestT
IB
"
]
def
name
(
self
):
""" Return name
...
...
Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt
View file @
b4955e58
...
...
@@ -110,7 +110,7 @@ set(TEST_PY_FILES
SortDetectorsTest.py
StatisticsOfTableWorkspaceTest.py
StringToPngTest.py
SuggestT
ibCNCS
Test.py
CNCS
SuggestT
IB
Test.py
SuggestTibHYSPECTest.py
SymmetriseTest.py
UpdatePeakParameterTableValueTest.py
...
...
Framework/PythonInterface/test/python/plugins/algorithms/SuggestT
ibCNCS
Test.py
→
Framework/PythonInterface/test/python/plugins/algorithms/
CNCS
SuggestT
IB
Test.py
View file @
b4955e58
...
...
@@ -9,21 +9,21 @@ from mantid import simpleapi
import
numpy
class
SuggestT
ibCNCS
Test
(
unittest
.
TestCase
):
class
CNCS
SuggestT
IB
Test
(
unittest
.
TestCase
):
def
test_simple
(
self
):
result
=
simpleapi
.
SuggestT
ibCNCS
(
3.
)
result
=
simpleapi
.
CNCS
SuggestT
IB
(
3.
)
self
.
assertAlmostEqual
(
result
[
0
]
*
0.1
,
4491.5
,
0
)
self
.
assertAlmostEqual
(
result
[
1
]
*
0.1
,
4731.5
,
0
)
result
=
simpleapi
.
SuggestT
ibCNCS
(
1.
)
result
=
simpleapi
.
CNCS
SuggestT
IB
(
1.
)
self
.
assertAlmostEqual
(
result
[
0
]
*
0.1
,
9562.1
,
0
)
self
.
assertAlmostEqual
(
result
[
1
]
*
0.1
,
9902.1
,
0
)
result
=
simpleapi
.
SuggestT
ibCNCS
(
6.
)
result
=
simpleapi
.
CNCS
SuggestT
IB
(
6.
)
self
.
assertAlmostEqual
(
result
[
0
]
*
0.1
,
2983.3
,
0
)
self
.
assertAlmostEqual
(
result
[
1
]
*
0.1
,
3323.3
,
0
)
def
test_someresult
(
self
):
for
en
in
numpy
.
arange
(
1.
,
30.
,
0.1
):
result
=
simpleapi
.
SuggestT
ibCNCS
(
en
)
result
=
simpleapi
.
CNCS
SuggestT
IB
(
en
)
self
.
assertTrue
(
result
[
1
]
-
result
[
0
]
>
1000.
)
...
...
Testing/SystemTests/tests/framework/CNCSReductionTest.py
View file @
b4955e58
...
...
@@ -47,7 +47,7 @@ class CNCSReductionTest(systemtesting.MantidSystemTest):
Load
(
Filename
=
'CNCS_23936-23937'
,
OutputWorkspace
=
'sum'
)
GenerateGroupingPowder
(
InputWorkspace
=
"sum"
,
AngleStep
=
0.5
,
GroupingFilename
=
self
.
groupingFile
)
Ei
=
mtd
[
'sum'
].
getRun
()[
'EnergyRequest'
].
firstValue
()
tib
=
SuggestT
ibCNCS
(
Ei
)
tib
=
CNCS
SuggestT
IB
(
Ei
)
DgsReduction
(
SampleInputWorkspace
=
"sum"
,
OutputWorkspace
=
"reduced"
,
...
...
docs/source/algorithms/SuggestT
ibCNCS
-v1.rst
→
docs/source/algorithms/
CNCS
SuggestT
IB
-v1.rst
View file @
b4955e58
...
...
@@ -21,19 +21,19 @@ Usage
**Example:**
.. testcode:: ExSuggestT
ibCNCS
.. testcode:: Ex
CNCS
SuggestT
IB
incidentEnergy = 3
(tibMin,tibMax) = SuggestT
ibCNCS
(incidentEnergy)
(tibMin,tibMax) =
CNCS
SuggestT
IB
(incidentEnergy)
print("Incident Energy = %i, tibMin = %.2f, tibMax = %.2f" % (incidentEnergy,tibMin,tibMax))
incidentEnergy = 1
(tibMin,tibMax) = SuggestT
ibCNCS
(incidentEnergy)
(tibMin,tibMax) =
CNCS
SuggestT
IB
(incidentEnergy)
print("Incident Energy = %i, tibMin = %.2f, tibMax = %.2f" % (incidentEnergy,tibMin,tibMax))
Output:
.. testoutput:: ExSuggestT
ibCNCS
.. testoutput:: Ex
CNCS
SuggestT
IB
Incident Energy = 3, tibMin = 44914.92, tibMax = 47314.92
Incident Energy = 1, tibMin = 95621.15, tibMax = 99021.15
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment