nyaml notation reference¶
This page is the detailed reference for writing NeXus definitions in YAML using nyaml. It documents all building blocks and special keywords, with YAML and NXDL XML comparisons for each.
For a step-by-step introduction that teaches these concepts progressively through an example, see Tutorials > Writing a NeXus definition in YAML.
Note
The NeXus choice concept is not yet supported in nyaml.
Root section¶
The root section is the top-level block of a definition. It maps to the XML <definition> element and contains the following keys:
category:applicationfor application definitions,basefor base classestype: alwaysgroupdoc: free-text description of the definitionsymbols: named dimension constants used throughout the definition (optional)- The schema name (e.g.
NXmpes(NXobject)): the parenthesized base class indicates what this definition extends. An application definition extends eitherNXobjector another application definition.
category: application
type: group
doc: |
This is the most general application definition for multidimensional photoelectron spectroscopy.
.. _ISO 18115-1:2023: https://www.iso.org/standard/74811.html
.. _IUPAC Recommendations 2020: https://doi.org/10.1515/pac-2019-0404
symbols:
doc: |
The symbols used in the schema to specify e.g. dimensions of arrays
n_transmission_function: |
Number of data points in the transmission function.
NXmpes(NXobject):
<definition xmlns="http://definition.nexusformat.org/nxdl/3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
category="application"
type="group"
name="NXmpes"
extends="NXobject"
xsi:schemaLocation="http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd">
<doc>
This is the most general application definition for multidimensional photoelectron spectroscopy.
.. _ISO 18115-1:2023: https://www.iso.org/standard/74811.html
.. _IUPAC Recommendations 2020: https://doi.org/10.1515/pac-2019-0404
</doc>
<symbols>
<doc>
The symbols used in the schema to specify e.g. dimensions of arrays
</doc>
<symbol name="n_transmission_function">
<doc>
Number of data points in the transmission function.
</doc>
</symbol>
</symbols>
</definition>
Groups¶
NeXus groups are instances of NeXus base classes and form the compositional structure of a definition. A group is written as name(NXbaseclass): in YAML.
The nameType keyword (see below) controls whether the name is matched exactly, loosely, or as a prefix (or suffix) pattern in HDF5 files. Dynamic initialization (using nameType: any) allows multiple instances of the same group type at the same hierarchy level; for example, (NXmanipulator) (with nameType: any) can be instantiated as manipulator1 and manipulator2 during data writing.
The group annotation source_TYPE(NXsource) means the group's concept name is source_TYPE and its type is the NXsource base class. For nameType: partial, the uppercase part of the name can be replaced at instantiation time, allowing multiple distinct instances (e.g. source_electric and source_magnetic). The same uppercase rules apply to fields and attributes.
<group name="source_TYPE" type="NXsource" recommended="true" nameType="partial">
<doc>
A source used to generate a beam.
</doc>
</group>
<!-- If no nameType is specified, NXmanipulator has nameType any by default -->
<group type="NXmanipulator" optional="true" nameType="any">
<doc>
Manipulator for positioning of the sample.
</doc>
<group name="value_log" type="NXlog" optional="true"/>
</group>
Fields and attributes¶
A NeXus field is a named data entry written without an NX prefix. Its NeXus type is given in parentheses, e.g. end_time(NX_DATE_TIME). If the type is omitted the field defaults to NX_CHAR. See the full list of NeXus types.
A NeXus attribute is a metadata entry for a field or group, prefixed with \@. It must also have a NeXus type, which defaults to NX_CHAR if omitted.
Descriptive text for any concept is given in the doc child.
<group type="NXentry">
<field name="definition" type="NX_CHAR">
<attribute name="\@version"/>
<enumeration>
<item value="NXmpes"/>
</enumeration>
</field>
<field name="title"/>
<field name="start_time" type="NX_DATE_TIME">
<doc>Datetime of the start of the measurement.</doc>
</field>
<field name="end_time" type="NX_DATE_TIME" recommended="true">
<doc>Datetime of the end of the measurement.</doc>
</field>
</group>
Links¶
A NeXus link avoids data duplication by letting one concept point to another. In YAML it uses the (link) suffix; the target child gives the path to the actual data.
In the example above, reference_measurement links to the NXentry group at /entry. This ensures that the concept referencing the data points to the designated target, reducing redundancy and maintaining data integrity.
Special keywords¶
nameType¶
Controls how an instance name in an HDF5 file is matched against the concept name in the definition.
nameType |
specified |
any |
partial |
Default value |
|---|---|---|---|---|
| All upper case | ✓ | ✓ | ✓ (with warning) | specified |
| All lower case | ✓ | ✓ (with warning) | ✓ (with error) | specified |
| Mixed case | ✓ | ✓ (with warning) | ✓ | specified |
| Anonymous group name | ✓ (with error) | ✓ | ✓ (with error) | any |
<group name="source_TYPE" type="NXsource" recommended="true" nameType="partial">
<doc>
A source used to generate a beam.
</doc>
</group>
<!-- If no nameType is specified, NXmanipulator has nameType any by default -->
<group type="NXmanipulator" optional="true" nameType="any">
<doc>
Manipulator for positioning of the sample.
</doc>
<group name="value_log" type="NXlog" optional="true"/>
</group>
exists¶
Controls whether an instance of a concept is present in a conforming NeXus file. By default, all concepts in a base class are optional, and all concepts in an application definition are required.
Accepted values:
required: must be present; validation fails if absentrecommended: advised but not mandatory; validation warns if absentoptional: may be absent without any validation error[min, <number>, max, <number> or infty]: specifies a multiplicity range
In the example above, transmission_correction is optional, while calibrationDATA must appear at least three times.
unit¶
Specifies the NeXus unit category for a field. Use one of the existing unit categories (e.g. NX_VOLTAGE, NX_LENGTH, NX_WAVELENGTH) rather than raw unit strings like "m". The unit category declares the physical dimension; the actual unit written to the HDF5 file (e.g. V, mV) is stored as a sibling attribute fieldname/@units.
dimensions¶
Describes the shape of a multidimensional data array. Using the "dimensions" keyword constraints the instance data of a field to an array with at least one dimension. The rank key gives the number of dimensions. Each dimension is specified with dim using either the full array-of-arrays form or the shorter tuple form. Use symbolic names from the root symbols block rather than hardcoded integers.
The optional dim_parameters key allows adding documentation or references to individual dimensions; each entry must have the same length as rank.
enumeration¶
A list of predefined allowed values for a field or attribute. Individual items may include a doc child. Set open_enum: true to allow values beyond the listed ones.
xref¶
The xref keyword (only valid inside doc) links a concept to an entry in an external ontology or standard such as ISO. It is YAML-only: nyaml converts it to the corresponding textual representation inside the XML <doc> element.