Commit 62f92a3d authored by Jose Borreguero's avatar Jose Borreguero
Browse files

Rename algorithm SuggestTibHYSPEC



Signed-off-by: default avatarJose Borreguero <borreguero@gmail.com>
parent db4961d5
......@@ -178,7 +178,7 @@ set(PYTHON_PLUGINS
algorithms/StatisticsOfTableWorkspace.py
algorithms/StringToPng.py
algorithms/CNCSSuggestTIB.py
algorithms/SuggestTibHYSPEC.py
algorithms/HYSPECSuggestTIB.py
algorithms/Symmetrise.py
algorithms/TOFTOFCropWorkspace.py
algorithms/TOFTOFMergeRuns.py
......
......@@ -10,6 +10,7 @@
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
......@@ -53,7 +54,7 @@ class CNCSSuggestTIB(PythonAlgorithm):
return "Inelastic\\Utility"
def seeAlso(self):
return ["SuggestTibHYSPEC"]
return ["HYSPECSuggestTIB"]
def name(self):
""" Return name
......
......@@ -5,27 +5,37 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
#pylint: disable=no-init
# package imports
from mantid.api import PythonAlgorithm, AlgorithmFactory
from mantid.kernel import FloatBoundedValidator,Direction,logger
from mantid.kernel import FloatBoundedValidator, Direction, logger
from mantid.utils.deprecator import deprecated_alias
# third party imports
import numpy
class SuggestTibHYSPEC(PythonAlgorithm):
@deprecated_alias('2021-09-16')
class HYSPECSuggestTIB(PythonAlgorithm):
""" Check if certain sample logs exists on a workspace
"""
def alias(self):
r"""Alternative name to this algorithm"""
return 'SuggestTibHYSPEC'
def category(self):
""" Return category
"""
return "Inelastic\\Utility"
def seeAlso(self):
return [ "CNCSSuggestTIB" ]
return ["CNCSSuggestTIB"]
def name(self):
""" Return name
"""
return "SuggestTibHYSPEC"
return "HYSPECSuggestTIB"
def summary(self):
""" Return summary
......@@ -35,15 +45,15 @@ class SuggestTibHYSPEC(PythonAlgorithm):
def PyInit(self):
""" Declare properties
"""
val=FloatBoundedValidator()
val.setBounds(3,100) #reasonable incident nergy range for HYSPEC
self.declareProperty("IncidentEnergy",0.,val,"Incident energy (3 to 100 meV)")
self.declareProperty("TibMin",0.,Direction.Output)
self.declareProperty("TibMax",0.,Direction.Output)
val = FloatBoundedValidator()
val.setBounds(3, 100) # reasonable incident nergy range for HYSPEC
self.declareProperty("IncidentEnergy", 0., val, "Incident energy (3 to 100 meV)")
self.declareProperty("TibMin", 0., Direction.Output)
self.declareProperty("TibMax", 0., Direction.Output)
return
def e2v(self,energy):
return numpy.sqrt(energy/5.227e-6)
def e2v(self, energy):
return numpy.sqrt(energy / 5.227e-6)
def PyExec(self):
""" Main execution body
......@@ -51,26 +61,26 @@ class SuggestTibHYSPEC(PythonAlgorithm):
#get parameter
energy = self.getProperty("IncidentEnergy").value
msd=1800.0
msd = 1800.0
tail_length_us = 3000.0
dist_mm = 39000.0 + msd + 4500.0
T0_moderator = 0.0
t_focEle_us = 39000.0 / self.e2v(energy) * 1000.0 + T0_moderator
t_samp_us = (dist_mm - 4500.0) / self.e2v(energy) * 1000.0 + T0_moderator
t_det_us = dist_mm /self.e2v(energy) * 1000 + T0_moderator
frame_start_us = t_det_us - 16667/2
frame_end_us = t_det_us + 16667/2
index_under_frame = int(numpy.divide(int(t_det_us),16667))
t_det_us = dist_mm / self.e2v(energy) * 1000 + T0_moderator
frame_start_us = t_det_us - 16667 / 2
frame_end_us = t_det_us + 16667 / 2
index_under_frame = int(numpy.divide(int(t_det_us), 16667))
pre_lead_us = 16667 * index_under_frame
pre_tail_us = pre_lead_us + tail_length_us
post_lead_us = 16667 * (1+ index_under_frame)
#post_tail_us = post_lead_us + tail_length_us
#E_final_meV = -1
#E_transfer_meV = -1
post_lead_us = 16667 * (1 + index_under_frame)
# post_tail_us = post_lead_us + tail_length_us
# E_final_meV = -1
# E_transfer_meV = -1
# finding an ok TIB range
MinTIB_us = 2000.0
slop_frac = 0.2
#print t_focEle_us,pre_lead_us,frame_start_us,MinTIB_us,slop_frac
# print t_focEle_us,pre_lead_us,frame_start_us,MinTIB_us,slop_frac
if (t_focEle_us < pre_lead_us) and (t_focEle_us-frame_start_us > MinTIB_us * (slop_frac + 1.0)):
logger.debug('choosing TIB just before focus element-1')
TIB_high_us = t_focEle_us - MinTIB_us * slop_frac / 2.0
......@@ -79,19 +89,23 @@ class SuggestTibHYSPEC(PythonAlgorithm):
logger.debug('choosing TIB just before focus element-2')
TIB_high_us = t_focEle_us - MinTIB_us * slop_frac / 2.0
TIB_low_us = TIB_high_us - MinTIB_us
elif t_focEle_us-pre_tail_us > MinTIB_us * (slop_frac + 1.0) and (t_focEle_us-frame_start_us > MinTIB_us * (slop_frac + 1.0)):
elif t_focEle_us-pre_tail_us > MinTIB_us * (slop_frac + 1.0) and\
(t_focEle_us - frame_start_us > MinTIB_us * (slop_frac + 1.0)):
logger.debug('choosing TIB just before focus element-3')
TIB_high_us = t_focEle_us - MinTIB_us * slop_frac / 2.0
TIB_low_us = TIB_high_us - MinTIB_us
elif t_samp_us-pre_tail_us > MinTIB_us * (slop_frac + 1.0) and (t_samp_us-frame_start_us > MinTIB_us * (slop_frac + 1.0)):
elif t_samp_us-pre_tail_us > MinTIB_us * (slop_frac + 1.0) and\
(t_samp_us - frame_start_us > MinTIB_us * (slop_frac + 1.0)):
logger.debug('choosing TIB just before sample-1')
TIB_high_us = t_samp_us - MinTIB_us * slop_frac / 2.0
TIB_low_us = TIB_high_us - MinTIB_us
elif t_samp_us-pre_tail_us > MinTIB_us / 1.5 * (slop_frac + 1.0) and (t_samp_us-frame_start_us > MinTIB_us * (slop_frac + 1.0)):
elif t_samp_us-pre_tail_us > MinTIB_us / 1.5 * (slop_frac + 1.0) and\
(t_samp_us - frame_start_us > MinTIB_us * (slop_frac + 1.0)):
logger.debug('choosing TIB just before sample-2')
TIB_high_us = t_samp_us - MinTIB_us / 1.5 * slop_frac / 2.0
TIB_low_us = TIB_high_us - MinTIB_us / 1.5
elif t_samp_us-pre_tail_us > MinTIB_us / 2.0 * (slop_frac + 1.0) and (t_samp_us-frame_start_us > MinTIB_us * (slop_frac + 1.0)):
elif t_samp_us-pre_tail_us > MinTIB_us / 2.0 * (slop_frac + 1.0) and\
(t_samp_us - frame_start_us > MinTIB_us * (slop_frac + 1.0)):
logger.debug('choosing TIB just before sample-3')
TIB_high_us = t_samp_us - MinTIB_us / 2.0 * slop_frac / 2.0
TIB_low_us = TIB_high_us - MinTIB_us / 2.0
......@@ -125,9 +139,9 @@ class SuggestTibHYSPEC(PythonAlgorithm):
TIB_high_us = 0.0
#return the result
self.setProperty("TibMin",TIB_low_us)
self.setProperty("TibMax",TIB_high_us)
self.setProperty("TibMin", TIB_low_us)
self.setProperty("TibMax", TIB_high_us)
return
AlgorithmFactory.subscribe(SuggestTibHYSPEC)
AlgorithmFactory.subscribe(HYSPECSuggestTIB)
......@@ -111,7 +111,7 @@ set(TEST_PY_FILES
StatisticsOfTableWorkspaceTest.py
StringToPngTest.py
CNCSSuggestTIBTest.py
SuggestTibHYSPECTest.py
HYSPECSuggestTIBTest.py
SymmetriseTest.py
UpdatePeakParameterTableValueTest.py
SANSSubtractTest.py
......
......@@ -8,12 +8,12 @@ import unittest
from mantid import simpleapi
class SuggestTibHYSPECTest(unittest.TestCase):
class HYSPECSuggestTIBTest(unittest.TestCase):
def test_simple(self):
result = simpleapi.SuggestTibHYSPEC(5.)
result = simpleapi.HYSPECSuggestTIB(5.)
self.assertAlmostEqual(result[0] * .1, 3951.5, 0)
self.assertAlmostEqual(result[1] * .1, 4151.5, 0)
result = simpleapi.SuggestTibHYSPEC(40.)
result = simpleapi.HYSPECSuggestTIB(40.)
self.assertAlmostEqual(result[0] * .1, 1189.8, 0)
self.assertAlmostEqual(result[1] * .1, 1389.8, 0)
......
......@@ -17,19 +17,19 @@ Usage
**Example:**
.. testcode:: ExSuggestTibHYSPEC
.. testcode:: ExHYSPECSuggestTIB
incidentEnergy = 5
(tibMin,tibMax) = SuggestTibHYSPEC(incidentEnergy)
(tibMin,tibMax) = HYSPECSuggestTIB(incidentEnergy)
print("Incident Energy = %i, tibMin = %.2f, tibMax = %.2f" % (incidentEnergy,tibMin,tibMax))
incidentEnergy = 40
(tibMin,tibMax) = SuggestTibHYSPEC(incidentEnergy)
(tibMin,tibMax) = HYSPECSuggestTIB(incidentEnergy)
print("Incident Energy = %i, tibMin = %.2f, tibMax = %.2f" % (incidentEnergy,tibMin,tibMax))
Output:
.. testoutput:: ExSuggestTibHYSPEC
.. testoutput:: ExHYSPECSuggestTIB
Incident Energy = 5, tibMin = 39515.88, tibMax = 41515.88
Incident Energy = 40, tibMin = 11898.11, tibMax = 13898.11
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment