Skip to content
Snippets Groups Projects
Commit 0ba9ae9d authored by Savici, Andrei T.'s avatar Savici, Andrei T.
Browse files

Merge pull request #489 from jcns/fix_dnspaloader

Corrections to LoadDNSLegacy and its documentation.
parents 1580f5a1 fbdea201
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,8 @@ sys.path.insert(0, os.path.dirname(__file__)) ...@@ -9,6 +9,8 @@ sys.path.insert(0, os.path.dirname(__file__))
from dnsdata import DNSdata from dnsdata import DNSdata
sys.path.pop(0) sys.path.pop(0)
POLARISATIONS = ['0', 'x', 'y', 'z', '-x', '-y', '-z']
class LoadDNSLegacy(PythonAlgorithm): class LoadDNSLegacy(PythonAlgorithm):
""" """
Load the DNS Legacy data file to the mantid workspace Load the DNS Legacy data file to the mantid workspace
...@@ -35,7 +37,9 @@ class LoadDNSLegacy(PythonAlgorithm): ...@@ -35,7 +37,9 @@ class LoadDNSLegacy(PythonAlgorithm):
self.declareProperty(WorkspaceProperty("OutputWorkspace", \ self.declareProperty(WorkspaceProperty("OutputWorkspace", \
"", direction=Direction.Output), \ "", direction=Direction.Output), \
doc="Name of the workspace to store the experimental data.") doc="Name of the workspace to store the experimental data.")
self.declareProperty("Polarisation", "0", \
StringListValidator(POLARISATIONS), \
doc="Type of polarisation. Valid values: %s" % str(POLARISATIONS))
return return
...@@ -43,6 +47,7 @@ class LoadDNSLegacy(PythonAlgorithm): ...@@ -43,6 +47,7 @@ class LoadDNSLegacy(PythonAlgorithm):
# Input # Input
filename = self.getPropertyValue("Filename") filename = self.getPropertyValue("Filename")
outws = self.getPropertyValue("OutputWorkspace") outws = self.getPropertyValue("OutputWorkspace")
pol = self.getPropertyValue("Polarisation")
# load data array from the given file # load data array from the given file
data_array = np.loadtxt(filename) data_array = np.loadtxt(filename)
...@@ -61,17 +66,28 @@ class LoadDNSLegacy(PythonAlgorithm): ...@@ -61,17 +66,28 @@ class LoadDNSLegacy(PythonAlgorithm):
run = __temporary_workspace__.mutableRun() run = __temporary_workspace__.mutableRun()
run.setStartAndEndTime(DateAndTime(metadata.start_time), \ run.setStartAndEndTime(DateAndTime(metadata.start_time), \
DateAndTime(metadata.end_time)) DateAndTime(metadata.end_time))
# add name of file as a run title
fname = os.path.splitext(os.path.split(filename)[1])[0]
run.addProperty('run_title', fname, True)
#run.addProperty('dur_secs', str(metadata.duration), True)
# rotate the detector bank to the proper position # rotate the detector bank to the proper position
api.RotateInstrumentComponent(__temporary_workspace__, \ api.RotateInstrumentComponent(__temporary_workspace__, \
"bank0", X=0, Y=1, Z=0, Angle=metadata.deterota) "bank0", X=0, Y=1, Z=0, Angle=metadata.deterota)
# add sample log Ei # add sample log Ei and wavelength
energy = get_energy(metadata.wavelength) api.AddSampleLog(__temporary_workspace__, \
'Ei', LogText=str(metadata.incident_energy), \
LogType='Number')
api.AddSampleLog(__temporary_workspace__, \ api.AddSampleLog(__temporary_workspace__, \
'Ei', LogText=str(energy), LogType='Number') 'wavelength', LogText=str(metadata.wavelength), \
LogType='Number')
# add other sample logs # add other sample logs
api.AddSampleLog(__temporary_workspace__, 'deterota', \ api.AddSampleLog(__temporary_workspace__, 'deterota', \
LogText=str(metadata.deterota), LogType='Number') LogText=str(metadata.deterota), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'mon_sum', \
LogText=str(metadata.monitor_counts), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'duration', \
LogText=str(metadata.duration), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'huber', \ api.AddSampleLog(__temporary_workspace__, 'huber', \
LogText=str(metadata.huber), LogType='Number') LogText=str(metadata.huber), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'T1', \ api.AddSampleLog(__temporary_workspace__, 'T1', \
...@@ -80,6 +96,28 @@ class LoadDNSLegacy(PythonAlgorithm): ...@@ -80,6 +96,28 @@ class LoadDNSLegacy(PythonAlgorithm):
LogText=str(metadata.t2), LogType='Number') LogText=str(metadata.t2), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'Tsp', \ api.AddSampleLog(__temporary_workspace__, 'Tsp', \
LogText=str(metadata.tsp), LogType='Number') LogText=str(metadata.tsp), LogType='Number')
# flipper
api.AddSampleLog(__temporary_workspace__, 'flipper_precession', \
LogText=str(metadata.flipper_precession_current), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'flipper_z_compensation', \
LogText=str(metadata.flipper_z_compensation_current), LogType='Number')
flipper_status = 'OFF'
if abs(metadata.flipper_precession_current) > sys.float_info.epsilon:
flipper_status = 'ON'
api.AddSampleLog(__temporary_workspace__, 'flipper', \
LogText=flipper_status, LogType='String')
# coil currents
api.AddSampleLog(__temporary_workspace__, 'C_a', \
LogText=str(metadata.a_coil_current), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'C_b', \
LogText=str(metadata.b_coil_current), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'C_c', \
LogText=str(metadata.c_coil_current), LogType='Number')
api.AddSampleLog(__temporary_workspace__, 'C_z', \
LogText=str(metadata.z_coil_current), LogType='Number')
# type of polarisation
api.AddSampleLog(__temporary_workspace__, 'polarisation', \
LogText=pol, LogType='String')
self.setProperty("OutputWorkspace", __temporary_workspace__) self.setProperty("OutputWorkspace", __temporary_workspace__)
self.log().debug('LoadDNSLegacy: OK') self.log().debug('LoadDNSLegacy: OK')
......
...@@ -15,6 +15,7 @@ class DNSdata: ...@@ -15,6 +15,7 @@ class DNSdata:
self.duration = None self.duration = None
self.deterota = 0 self.deterota = 0
self.wavelength = None # Angstrom self.wavelength = None # Angstrom
self.incident_energy = None # meV
self.ndet = 24 self.ndet = 24
self.sample_name = "" self.sample_name = ""
self.userid = "" self.userid = ""
...@@ -113,6 +114,7 @@ class DNSdata: ...@@ -113,6 +114,7 @@ class DNSdata:
line = b2splitted[2].split() line = b2splitted[2].split()
self.monochromator_angle = float(line[2]) self.monochromator_angle = float(line[2])
self.wavelength = float(line[3])*10.0 self.wavelength = float(line[3])*10.0
self.incident_energy = float(line[4])
# parse block 3 (motors position) # parse block 3 (motors position)
b3splitted = map(str.strip, blocks[3].split('#')) b3splitted = map(str.strip, blocks[3].split('#'))
......
...@@ -12,7 +12,7 @@ class LoadDNSLegacyTest(unittest.TestCase): ...@@ -12,7 +12,7 @@ class LoadDNSLegacyTest(unittest.TestCase):
outputWorkspaceName = "LoadDNSLegacyTest_Test1" outputWorkspaceName = "LoadDNSLegacyTest_Test1"
filename = "dn134011vana.d_dat" filename = "dn134011vana.d_dat"
alg_test = run_algorithm("LoadDNSLegacy", Filename = filename, \ alg_test = run_algorithm("LoadDNSLegacy", Filename = filename, \
OutputWorkspace = outputWorkspaceName) OutputWorkspace = outputWorkspaceName, Polarisation='y')
self.assertTrue(alg_test.isExecuted()) self.assertTrue(alg_test.isExecuted())
...@@ -25,14 +25,13 @@ class LoadDNSLegacyTest(unittest.TestCase): ...@@ -25,14 +25,13 @@ class LoadDNSLegacyTest(unittest.TestCase):
self.assertEqual(31461, ws.readY(1)) self.assertEqual(31461, ws.readY(1))
self.assertEqual(13340, ws.readY(23)) self.assertEqual(13340, ws.readY(23))
# sample logs # sample logs
logs = ws.getRun().getLogData() run = ws.getRun()
self.assertEqual('deterota', logs[4].name) self.assertEqual(-8.54, run.getProperty('deterota').value)
self.assertEqual(-8.54, logs[4].value) self.assertEqual(8332872, run.getProperty('mon_sum').value)
self.assertEqual('y', run.getProperty('polarisation').value)
# check whether detector bank is rotated # check whether detector bank is rotated
samplePos = ws.getInstrument().getSample().getPos()
beamDirection = V3D(0,0,1)
det = ws.getDetector(1) det = ws.getDetector(1)
self.assertAlmostEqual(8.54, det.getTwoTheta(samplePos, beamDirection)*180/pi) self.assertAlmostEqual(8.54, ws.detectorSignedTwoTheta(det)*180/pi)
run_algorithm("DeleteWorkspace", Workspace = outputWorkspaceName) run_algorithm("DeleteWorkspace", Workspace = outputWorkspaceName)
return return
......
...@@ -10,7 +10,7 @@ Description ...@@ -10,7 +10,7 @@ Description
----------- -----------
Loads a DNS legacy .d_dat data file into a :ref:`Workspace2D <Workspace2D>` with Loads a DNS legacy .d_dat data file into a :ref:`Workspace2D <Workspace2D>` with
the given name. the given name.
The loader rotates the detector bank in the position given in the data file. The loader rotates the detector bank in the position given in the data file.
...@@ -27,7 +27,7 @@ Usage ...@@ -27,7 +27,7 @@ Usage
datafile = 'dn134011vana.d_dat' datafile = 'dn134011vana.d_dat'
# Load dataset # Load dataset
ws = LoadDNSLegacy(datafile) ws = LoadDNSLegacy(datafile, Polarisation='x')
print "This workspace has", ws.getNumDims(), "dimensions and has", \ print "This workspace has", ws.getNumDims(), "dimensions and has", \
ws.getNumberHistograms(), "histograms." ws.getNumberHistograms(), "histograms."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment