From fbdea2016691b596ad51e7d0f9424d8687a9777d Mon Sep 17 00:00:00 2001 From: Marina Ganeva <m.ganeva@fz-juelich.de> Date: Mon, 30 Mar 2015 15:52:13 +0200 Subject: [PATCH] Corrections to LoadDNSLegacy and its documentation. --- .../plugins/algorithms/LoadDNSLegacy.py | 46 +++++++++++++++++-- .../plugins/algorithms/dnsdata.py | 2 + .../plugins/algorithms/LoadDNSLegacyTest.py | 13 +++--- .../source/algorithms/LoadDNSLegacy-v1.rst | 4 +- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/LoadDNSLegacy.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/LoadDNSLegacy.py index 62b8cc71d14..110ffd12c23 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/LoadDNSLegacy.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/LoadDNSLegacy.py @@ -9,6 +9,8 @@ sys.path.insert(0, os.path.dirname(__file__)) from dnsdata import DNSdata sys.path.pop(0) +POLARISATIONS = ['0', 'x', 'y', 'z', '-x', '-y', '-z'] + class LoadDNSLegacy(PythonAlgorithm): """ Load the DNS Legacy data file to the mantid workspace @@ -35,7 +37,9 @@ class LoadDNSLegacy(PythonAlgorithm): self.declareProperty(WorkspaceProperty("OutputWorkspace", \ "", direction=Direction.Output), \ 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 @@ -43,6 +47,7 @@ class LoadDNSLegacy(PythonAlgorithm): # Input filename = self.getPropertyValue("Filename") outws = self.getPropertyValue("OutputWorkspace") + pol = self.getPropertyValue("Polarisation") # load data array from the given file data_array = np.loadtxt(filename) @@ -61,17 +66,28 @@ class LoadDNSLegacy(PythonAlgorithm): run = __temporary_workspace__.mutableRun() run.setStartAndEndTime(DateAndTime(metadata.start_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 api.RotateInstrumentComponent(__temporary_workspace__, \ "bank0", X=0, Y=1, Z=0, Angle=metadata.deterota) - # add sample log Ei - energy = get_energy(metadata.wavelength) + # add sample log Ei and wavelength + api.AddSampleLog(__temporary_workspace__, \ + 'Ei', LogText=str(metadata.incident_energy), \ + LogType='Number') api.AddSampleLog(__temporary_workspace__, \ - 'Ei', LogText=str(energy), LogType='Number') + 'wavelength', LogText=str(metadata.wavelength), \ + LogType='Number') # add other sample logs api.AddSampleLog(__temporary_workspace__, 'deterota', \ 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', \ LogText=str(metadata.huber), LogType='Number') api.AddSampleLog(__temporary_workspace__, 'T1', \ @@ -80,6 +96,28 @@ class LoadDNSLegacy(PythonAlgorithm): LogText=str(metadata.t2), LogType='Number') api.AddSampleLog(__temporary_workspace__, 'Tsp', \ 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.log().debug('LoadDNSLegacy: OK') diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/dnsdata.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/dnsdata.py index 97f14ac5e68..755c4925c6b 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/dnsdata.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/dnsdata.py @@ -15,6 +15,7 @@ class DNSdata: self.duration = None self.deterota = 0 self.wavelength = None # Angstrom + self.incident_energy = None # meV self.ndet = 24 self.sample_name = "" self.userid = "" @@ -113,6 +114,7 @@ class DNSdata: line = b2splitted[2].split() self.monochromator_angle = float(line[2]) self.wavelength = float(line[3])*10.0 + self.incident_energy = float(line[4]) # parse block 3 (motors position) b3splitted = map(str.strip, blocks[3].split('#')) diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/LoadDNSLegacyTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/LoadDNSLegacyTest.py index bf8977363dc..d9c5c6df681 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/LoadDNSLegacyTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/LoadDNSLegacyTest.py @@ -12,7 +12,7 @@ class LoadDNSLegacyTest(unittest.TestCase): outputWorkspaceName = "LoadDNSLegacyTest_Test1" filename = "dn134011vana.d_dat" alg_test = run_algorithm("LoadDNSLegacy", Filename = filename, \ - OutputWorkspace = outputWorkspaceName) + OutputWorkspace = outputWorkspaceName, Polarisation='y') self.assertTrue(alg_test.isExecuted()) @@ -25,14 +25,13 @@ class LoadDNSLegacyTest(unittest.TestCase): self.assertEqual(31461, ws.readY(1)) self.assertEqual(13340, ws.readY(23)) # sample logs - logs = ws.getRun().getLogData() - self.assertEqual('deterota', logs[4].name) - self.assertEqual(-8.54, logs[4].value) + run = ws.getRun() + self.assertEqual(-8.54, run.getProperty('deterota').value) + self.assertEqual(8332872, run.getProperty('mon_sum').value) + self.assertEqual('y', run.getProperty('polarisation').value) # check whether detector bank is rotated - samplePos = ws.getInstrument().getSample().getPos() - beamDirection = V3D(0,0,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) return diff --git a/Code/Mantid/docs/source/algorithms/LoadDNSLegacy-v1.rst b/Code/Mantid/docs/source/algorithms/LoadDNSLegacy-v1.rst index 369b381acf6..ed825958bf1 100644 --- a/Code/Mantid/docs/source/algorithms/LoadDNSLegacy-v1.rst +++ b/Code/Mantid/docs/source/algorithms/LoadDNSLegacy-v1.rst @@ -10,7 +10,7 @@ Description ----------- 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. @@ -27,7 +27,7 @@ Usage datafile = 'dn134011vana.d_dat' # Load dataset - ws = LoadDNSLegacy(datafile) + ws = LoadDNSLegacy(datafile, Polarisation='x') print "This workspace has", ws.getNumDims(), "dimensions and has", \ ws.getNumberHistograms(), "histograms." -- GitLab