Import data

nPDyn provides various ways to handle data.

The data importation routines are found in nPDyn.dataParsers module.

Sample data are stored in the sample.Sample class. Some useful information about the sample.Sample class and about different data importation routines can be found in the following.

Access the data values

Each imported data consists in a sample.Sample class. The class is essentially a NumPy ndarray with extra features specific to neutron scattering dataset. In addition, the class contains several methods for processing and fitting.

The specific attributes are the following:
  • filename, the name of the file used to extract the data.
  • errors, the errors associated with scattering data.
  • energies, the energy transfers associated with the data.
  • time, the experimental time.
  • wavelength, the wavelength of the incoming neutrons.
  • name, the name for the sample.
  • temperature, the temperature(s) used experimentally.
  • concentration, the concentration of the sample.
  • pressure, the pressure used experimentally.
  • buffer, a description of the buffer used experimentally.
  • q, the values for the momentum transfer q.
  • beamline, the name of the beamline used.
  • observable_name, the name of the observable variable.

These attributes might be empty or not depending on the source file.

Note

The errors metadata is special as it is updated for various operations that are performed on the data array such as indexing or for the use of universal functions. For instance, indexing of the data will be performed on errors as well if its shape is the same as for the data. Also, addition, subtraction and other universal functions will lead to automatic error propagation. Some other metadata might change as well, like q, but only for the use of methods specific of the Sample class and not for methods inherited from numpy.

Raw data

Raw dataset, as generated on IN16B at the ILL, can be imported directly. The algorithm has several options allowing for detector grouping, unmirroring, integrating and summation of the scans.

See in16b_qens_scans_reduction.IN16B_QENS or in16b_fws_scans_reduction.IN16B_FWS for example.

To import raw data, the following can be used:

from nPDyn.dataParsers import IN16B_QENS, IN16B_FWS

# we can use a path to a folder or a list of strings
# here for FWS data where we only keep elastic scans
# and we choose the observable to be the temperature
sample = IN16B_FWS(
    'myDataFolder/',
    offset=0.0,
    observable='temperature'
)

# ...and here for a range of QENS data with .xml detector grouping file
sample = IN16B_QENS(
    'myDataFolder/scan01:scan10.nxs',
    detGroup='IN16B_detGroup.xml'
)

Different methods and properties of the dataset are accessible through this list, e.g., the momentum transfers using:

>>> sample.q
array([0.19102381, 0.29274028, 0.43543718, 0.56747019, 0.69687497,
0.82305221, 0.94541753, 1.0634042 , 1.17646584, 1.28407863,
1.38574439, 1.48099215, 1.5693807 , 1.65050083, 1.72397668,
1.78946811, 1.84667172, 1.89532256])

Nexus (hdf5) files

Nexus files as generated by Mantid can be read by nPDyn using the dataParsers.mantidNexus.processNexus() method.

The file will be assumed to be a Nexus file if the extension is ‘.nxs’, hence the following:

from nPDyn.dataParsers import processNexus

sample = processNexus('mySample01.nxs', FWS=False)

will import all files using the Nexus file parser.

.inx files

Similarly to Nexus files, nPDyn can read ‘.inx’ files as generated by the software SLAW available at the MLZ in Garching, Germany. The usage is essentially the same as for Nexus files:

from nPDyn.dataParsers import inxConvert

sample = inxConvert('mySample01.nxs', FWS=False)