qens.io

Reader for ISIS Mantid ‘.nxspe’ (NeXus / HDF5) files.

Filename convention (lowercase, underscore-separated)

<sample>_<temperature_K>_<Ei_x_100>_<kind>.nxspe

Example: “benzene_290_360_inc.nxspe” >>> benzene, 290 K, Ei = 3.60 meV, incoherent measurement.

qens.io.inspect_nxspe(path)[source]

Print the HDF5 tree of a .nxspe file (debugging tool).

Return type:

None

Parameters:

path (str)

qens.io.read_nxspe(path)[source]

Load a single ‘.nxspe’ file.

Parameters:

path (str) – Path to the file.

Return type:

dict

Returns:

dict with keys – “name” : filename “sample”, “temp”, “ei”, “kind” : metadata “e_raw” : energy axis (meV) before elastic-peak alignment “e” : energy axis (meV) — initially copy of e_raw, gets shifted

by :func:’qens.preprocessing.fit_elastic_peak’

”data”, “errs” : (n_det, n_E) arrays of intensity and 1σ errors “q” : (n_det,) momentum transfer at elastic line, Å⁻¹ “good” : (n_good,) integer indices of detectors with usable data

qens.io.read_nxspe_with_overrides(path, *, sample=None, temp=None, ei=None, kind=None)[source]

Like :func:’read_nxspe’ but lets you override metadata.

Useful when filenames don’t follow the convention.

Return type:

dict

Parameters:
  • path (str)

  • sample (str | None)

  • temp (int | None)

  • ei (float | None)

  • kind (str | None)

qens.io.load_dataset(file_list, data_dir='.', critical_files=None, verbose=True)[source]

Load several .nxspe files into a dict keyed by filename.

Parameters:
  • file_list (iterable of str) – Filenames to load (relative to “data_dir”).

  • data_dir (str) – Directory containing the files.

  • critical_files (iterable of str, optional) – Files that must load — raises if any are missing/unreadable. Other failures are warnings.

  • verbose (bool) – If True, print a one-line summary per file.

Return type:

dict[str, dict]

Returns:

dict[str, dict] – Keys are filenames, values are the dicts returned by :func:’read_nxspe’.

qens.io.compute_q_from_2theta(two_theta_deg, ei_mev)[source]

Q(2θ) at the elastic line from the incident wavevector.

Parameters:
  • two_theta_deg (array) – Scattering angle in degrees.

  • ei_mev (float) – Incident energy in meV.

Return type:

ndarray

Returns:

Q in Å⁻¹.