nexus_functions¶
Various utilities for reading and writing nexus files
bytes2str(value)
¶
Convert bytes or string to string
Source code in mmg_toolbox/nexus/nexus_functions.py
get_attr_datasets(group, attr_name)
¶
Return list of datasets mentioned in group attribute
Source code in mmg_toolbox/nexus/nexus_functions.py
get_axes_signals(nxdata)
¶
Return lists of axes and signal+auxiliary_signals datasets
Source code in mmg_toolbox/nexus/nexus_functions.py
get_dataset_string(dataset)
¶
Return formatted string of value stored in dataset
Source code in mmg_toolbox/nexus/nexus_functions.py
get_dataset_value(path, group, default=None, units='')
¶
Get value from dataset in group, or return default
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
hdf path of dataset in group |
required |
group
|
Group
|
hdf group |
required |
default
|
str | float | ndarray | None
|
returned if path doesn't exist |
None
|
units
|
str
|
converts to given units if units in attrs |
''
|
Returns:
| Type | Description |
|---|---|
ndarray | None
|
value or default as ndarray, or None if default is None |
Source code in mmg_toolbox/nexus/nexus_functions.py
get_metadata(group, *name_paths_default)
¶
Return a dict with metadata available in hdf Group. All metadata formated as strings
Source code in mmg_toolbox/nexus/nexus_functions.py
nx_beam_energy(beam)
¶
Return beam energy in keV and wavelength in A
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
beam
|
Group
|
Nexus NXbeam group |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
incident_energy, incident_wavelength |
Source code in mmg_toolbox/nexus/nexus_functions.py
nx_find(parent, *field_or_class)
¶
Return default or first object to match a set of NXclass or field names
Example: with h5py.File('/path/to/file.h5', 'r') as hdf group = nx_find(hdf, 'NXentry', 'NXinstrument', 'NXdetector') # returns NXdetector group dataset = nx_find(hdf, 'NXdata', 'signal') # returns @signal dataset in @default NXdata data = dataset[()]
Accepted field_or_class arguments: - dataset name, e.g. 'data' (returns dataset) - group name, e.g. 'entry' (returns group) - NX class name, e.g. 'NX_class' (returns NXclass group) - NXclass definition, e.g. 'NXmx' (returns NXentry group) - local_name attribute name, e.g. 'eta.eta' (returns dataset) - 'axes' or 'signal' in NXdata group (returns dataset) - hdf path, e.g. 'group/dataset' (returns dataset)
Parameters:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Group
|
parent group, must be h5py.File or h5py.Group |
required |
field_or_class
|
str
|
names to search for, in hierarchical order. |
()
|
Returns:
| Type | Description |
|---|---|
Dataset | Group | None
|
matching Dataset, Group or None if no match |
Source code in mmg_toolbox/nexus/nexus_functions.py
nx_find_all(parent, *field_or_class)
¶
Return all objects that match a set of NXclass or field names
Example: with h5py.File('/path/to/file.h5', 'r') as hdf groups = nx_find_all(hdf, 'NXdetector') # returns list of NXdetector group datasets = nx_find(hdf, 'NXdata', 'signal') # returns list of @signal datasets in NXdata groups arrays = [dataset[()] for dataset in datasets]
Accepted field_or_class arguments: - dataset name, e.g. 'data' (returns dataset) - group name, e.g. 'entry' (returns group) - NX class name, e.g. 'NX_class' (returns NXclass group) - NXclass definition, e.g. 'NXmx' (returns NXentry group) - local_name attribute name, e.g. 'eta.eta' (returns dataset) - 'axes' or 'signal' in NXdata group (returns dataset)
Parameters:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Group
|
parent group, must be h5py.File or h5py.Group |
required |
field_or_class
|
str
|
names to search for, in hierarchical order. |
()
|
Returns:
| Type | Description |
|---|---|
list[Dataset | Group]
|
list of matching Datasets or Groups |
Source code in mmg_toolbox/nexus/nexus_functions.py
nx_find_data(parent, *field_or_class, default=None)
¶
Use nx_find to get dataset, return data or default
Source code in mmg_toolbox/nexus/nexus_functions.py
reorder_group_items(group)
¶
re-order the group.items list to get the put @default objects first
Source code in mmg_toolbox/nexus/nexus_functions.py
update_args(name, obj, axes, signal, *args)
¶
remove object from search arguments if it matches