scippnexus.Group#

class scippnexus.Group(group, definitions=None)[source]#

A group in a NeXus file.

This class is a wrapper around an h5py.Group object. It provides a dict-like interface to the children of the group, and provides access to the attributes of the group. The children are either Field or Group objects, depending on whether the child is a dataset or a group, respectively.

__init__(group, definitions=None)[source]#

Methods

__init__(group[, definitions])

create_class(name, class_name)

Create empty HDF5 group with given name and set the NX_class attribute.

create_field(key, value)

Create a child dataset with given name and value.

get(k[,d])

items()

keys()

values()

Attributes

attrs

The attributes of the group.

dims

file

name

nx_class

The value of the NX_class attribute of the group.

parent

shape

sizes

unit

__getitem__(sel)[source]#

Get a child group or child dataset, a selection of child groups, or load and return the current group.

Three cases are supported:

  • String name: The child group or child dataset of that name is returned.

  • Class such as NXdata or NXlog: A dict containing all direct children with a matching NX_class attribute are returned. Also accepts a tuple of classes. Field selects all child fields, i.e., all datasets but not groups.

  • Scipp-style index: Load the specified slice of the current group, returning a scipp.DataArray or scipp.DataGroup.

Parameters:

sel – Child name, class, or index.

Returns:

Field, group, dict of fields, or loaded data.

attrs#

The attributes of the group.

Cannot be used for writing attributes, since they are cached for performance.

create_class(name, class_name)[source]#

Create empty HDF5 group with given name and set the NX_class attribute.

Note that due to the caching mechanisms in this class, reading the group or its children may not reflect the changes made by this method.

Parameters:
  • name (str) – Group name.

  • nx_class – Nexus class, can be a valid string for the NX_class attribute, or a subclass of NXobject, such as NXdata or NXlog.

Return type:

Group

create_field(key, value)[source]#

Create a child dataset with given name and value.

Note that due to the caching mechanisms in this class, reading the group or its children may not reflect the changes made by this method.

Returns:

H5Dataset – The created dataset of the values. If errors are written to the file, their dataset is not returned.

property nx_class: type | None#

The value of the NX_class attribute of the group.

In case of the subclass NXroot this returns NXroot even if the attr is not actually set. This is to support the majority of all legacy files, which do not have this attribute.