scippnexus.load#

scippnexus.load(filename, *, root=None, select=(), definitions=DefaultDefinitions)[source]#

Load a NeXus file.

This function is a shorthand for opening a file manually. That is

loaded = snx.load('path/to/nexus_file.nxs')

is equivalent to

with snx.File('path/to/nexus_file.nxs') as f:
    loaded = f[()]

The additional arguments of load are used as:

loaded = snx.load(
    'path/to/nexus_file.nxs'
    root='entry/instrument',
    select={'x': slice(None, 100)},
    definitions=my_definitions,
)

which corresponds to

with snx.File('path/to/nexus_file.nxs', definitions=my_definitions) as f:
    loaded = f['entry/instrument']['x', :100]
Parameters:
  • filename (str | PathLike[str] | BytesIO | Group | Group) –

    One of:

  • root (Optional[str], default: None) –

    The root group in the NeXus file to load. If not provided

    • Everything is loaded under the given group if filename is a group.

    • Or the entire file is loaded otherwise.

  • select (EllipsisType | int | tuple | slice | tuple[str, int | slice] | dict[str, int | slice], default: ()) – Selects a subset of the data to load. Corresponds to the argument passed in brackets when using file objects: loaded = group[select]. See Loading groups and datasets. Defaults to () which selects the entire data.

  • definitions (Mapping[str, type] | DefaultDefinitionsType, default: DefaultDefinitions) – NeXus application definitions. Defaults to the ScippNexus base definitions.

Returns:

DataGroup | DataArray | Dataset – The loaded data.