scippneutron.io.xye.save_xye#

scippneutron.io.xye.save_xye(fname, da, *, coord=None, header=GenerateHeader)[source]#

Write a data array to an XYE file.

The input must be 1-dimensional, have variances, and at least one coordinate. It is possible to select which coordinate gets written with the coord argument.

The data are written as an ASCII table with columns X, Y, E, where

  • X: coordinate of the data array,

  • Y: data values of the data array,

  • E: standard deviations corresponding to Y.

This format is lossy, coordinates other than X, attributes, and masks are not written and the coordinate name, dimension name, and units of the input are lost. To improve the situation slightly, save_xye writes a basic header by default. All lines in the header are prefixed with #.

Parameters:
  • fname (str | Path | TextIO) – Name or file handle of the output file.

  • da (DataArray) – 1-dimensional data to write.

  • coord (Optional[str], default: None) – Coordinate name of da to write. If omitted and da has only one coordinate, that coordinate is used. If omitted and da has multiple coordinates, attempts to use a coordinate with the same name as da.dim. If that does not exist, raise an error.

  • header (str | GenerateHeaderType, default: GenerateHeader) – String to write at the beginning of the file. A simple table header gets generated automatically by default. Set header='' to prevent this.

Return type:

None

See also

scippneutron.io.xye.load_xye

Function to load XYE files.