Input file formats
To generate the SQW file from which Horace reads S(Q,w), neutron scattering data for each individual run and needs to be provided in one of two formats: the legacy ASCII format SPE file, together with an ASCII detector parameter file (the PAR file), or their replacements the HDF5 (Hierarchical Data Format) NXSPE file. Two functions are available as part of Horace to create SQW files from these input files, namely
gen_sqw (creates a new SQW file) and
accumulate_sqw (accumulates data to an existing SQW file). The functions to generate SQW files are described in detail here.
Generally, the input data files (SPE or NXSPE format) will be created by the data reduction code for the instrument which you are using if Horace has been made available for that instrument by the scientist(s) responsible. However, if you want to use Horace to analyse data from other instruments you need to know how to create the input files from whatever format your data is saved in.
The recommended input data file is the NXSPE file, which holds both the S(w) data and errors for each detector and detector position and size information, together with crystal orientation angle
psi and the incident neutron energy Ei. The NXSPE file stores the information in a NeXus format file, which is a common data exchange format for neutron, X-ray and muon data that is built on top of the HDF5 (Hierarchical Data Format) scientific data format.
Data files in the NXSPE format are produced by the Mantid data analysis software (). They are directly produced by the data reduction algorithms within Mantid for the direct geometry spectrometers at both the ISIS spallation neutron source at the Rutherford Appleton Laboratory in the UK and the SNS spallation neutron source at Oak Ridge National Laboratory in the USA. Mantid is an open source data manipulation and analysis framework for neutron and muon data analysis. If Mantid is used to perform the data corrections for a neutron spectrometer, then the algorithm SaveNXSPE in Mantid can be used to output NXSPE files. Full details of how to use Mantid and the input/output for each algorithm are available at the Mantid web site.
More suitable for a 'quick start', if you can read corrected scattering data, associated estimated errors, and detector parameters into Matlab arrays, is to use the Horace utility function gen_nxspe to create NXSPE files.
This is a flexible to repackage and/or save S(Q,w) and detector to file. To write a single NXSPE file the syntax is as follows:
The input parameters are defined as follows:
S: Array of signal strength size [ne,nd] where ne is the number of energy bins and nd is the number of detector elements.
ERR: Array of estimated standard errors with size [ne,nd].
en: Array of energy bin boundaries. The number of elements is therefore (ne+1).
par: Array of detector parameters with size [6,nd]. Each column of the array contains information for a detector element: detector index (integer), sample-to-detector distance (m), scattering angle
- L2: Distance (m) from the sample to detector.
- phi: Scattering angle (degrees) i.e. angle between the incident beam direction and a line connecting the sample to the detector. In spherical polar coordinates where the conventional z-axis points in the direction of the incident beam, this angle is the conventional polar angle theta.
- azim: Azimuthal angle (degrees). In the spherical polar frame defined above, and with the conventional y-axis pointing vertically upwards, this angle is the conventional azimuthal angle phi.
- width: Width (m) of the detector perpendicular to the Debye-Scherrer ring.
- length: Length (m) of the detector tangential to the Debye-Scherrer ring.
The width and length of the detector are not actually used by Horace, but dummy values need to be present
SPE file and PAR file
These files may be encountered if you are using Horace to analyse older data. The ASCII format SPE file stores S(w) and associated error bars as a function of energy transfer, ħw, for each detector in turn. In addition to the set of SPE files, Horace requires an accompanying ASCII file which contains information about the location of the detectors in the spectrometer’s reference frame, the PAR file. Although these ASCII format files have largely been superseded in favour of the NXSPE format described above, such files are ubiquitous as the format in which historic data is saved, and are recognised by several other neutron visualisation and analysis programs. Some programs can also write their own output as SPE files, and consequently the SPE file is sometimes used as a transportable format data file for time-of-flight neutron spectrometers. The format of these two files is described here, however, it is not recommended to create new SPE files as this is now an obsolete format.
SPE file format
The SPE file contains the intensity and estimated standard deviation on those intensities for each detector element in turn, with header blocks that give the number of detectors and energy bins, and the scattering angle and energy transfer bin boundaries. These blocks are all separated by character strings that begin with '###'. The format in full is as follows:
|### Phi Grid|
|### Energy Grid|
On the first line, nd and ne need only to be separated by white space. In the blocks containing the signal and error the format is highly prescribed: each line must contain 8 real numbers, apart from the last line in each block, and each number must occupy a field of precisely 10 spaces. No white space is necessary. This is a frequent source of problem when writing the files. It is strongly recommended that you do not try to create your own SPE format files.
PAR file format
The PAR file contains the position information of the detectors and their sizes. The format is:
The width and length of the detector are not actually used by Horace, but dummy values need to be present in the file. The parameters need to be separated by white space, but otherwise there are no constraints on the format.