Table of Contents
Name | Direction | Type | Default | Description |
---|---|---|---|---|
InputWorkspace | Input | MatrixWorkspace | Mandatory | Name of data workspace containing sample logs to be exported. |
OutputFilename | Input | string | Mandatory | Name of the output sample environment log file name. Allowed extensions: [‘.txt’] |
SampleLogNames | Input | str list | Names of sample logs to be exported in a same file. | |
WriteHeaderFile | Input | boolean | False | Flag to generate a sample log header file. |
Header | Input | string | String in the header file. | |
TimeZone | Input | string | America/New_York | Sample logs recorded in NeXus files (in SNS) are in UTC time. TimeZone can allow the algorithm to output the log with local time. Allowed values: [‘UTC’, ‘America/New_York’, ‘Asia/Shanghai’, ‘Australia/Sydney’, ‘Europe/London’, ‘GMT+0’, ‘Europe/Paris’, ‘Europe/Copenhagen’] |
TimeTolerance | Input | number | 0.01 | If any 2 log entries with log times within the time tolerance, they will be recorded in one line. Unit is second. |
Algorithm LoadSampleLogsToCSVFile exports a specified set of sample logs , which are stored in a MatrixWorkspace, to a CSV file. The header for the sample log csv file can also be created by this algorithm in a seperate header file.
Sample logs are written to a csv file. A tab separates any two adjacent values.
Each entry of each exported sample log will be an individual entry in the output CSV file, except in the situation that two entries with time stamps within time tolerance.
The output CSV file has 2+n columns, where n is the number of sample logs to be exported.
Here is the definition for the columns.
A sample log header file can be generated optionally. It contains theree lines described as below.
The time stamps of sample logs are recorded as UTC time in SNS. Some users wants to see the exported sample log as the neutron facility’s local time. So the input property ‘TimeZone’ is for this purpose.
Property TimeZone does not support all the time zones but only those with facilities that use Mantid.
Here is the list of all time zones that are allowed by this algorithm. - UTC - GMT+0 - America/New_York - Asia/Shanghai - Australia/Sydney - Europe/London - Europe/Paris - Europe/Copenhagen
Example - Export a time series sample log to a csv file:
import os
nxsfilename = "HYS_11092_event.nxs"
wsname = "HYS_11092_event"
defaultdir = config["default.savedirectory"]
if defaultdir == "":
defaultdir = config["defaultsave.directory"]
savefile = os.path.join(defaultdir, "testphase4.txt")
Load(Filename = nxsfilename,
OutputWorkspace = wsname,
MetaDataOnly = True,
LoadLogs = True)
ExportSampleLogsToCSVFile(
InputWorkspace = wsname,
OutputFilename = savefile,
SampleLogNames = "Phase1, Phase2, Phase3, Phase4",
WriteHeaderFile = True,
Header = "Test sample log: Phase1-Phase4",
TimeZone = "America/New_York",
TimeTolerance = 0.01)
headerfilename = os.path.join(defaultdir, "testphase4_header.txt")
print "File is created = ", os.path.exists(savefile)
print "Header file is created = ", os.path.exists(headerfilename)
# Get the lines of both files
sfile = open(savefile, 'r')
slines = sfile.readlines()
sfile.close()
hfile = open(headerfilename, 'r')
hlines = hfile.readlines()
hfile.close()
print "Number of lines in File =", len(slines)
print "Number of lines in Header file =", len(hlines)
Output:
File is created = True
Header file is created = True
Number of lines in File = 36
Number of lines in Header file = 3
Categories: Algorithms | Utility | PythonAlgorithms
Python: ExportSampleLogsToCSVFile.py