NXDL Manager : nxdl_manager#

source code documentation#

Python representation of an NeXus NXDL class specification.

  • The nxdl_manager calls schema_manager

  • It gets a specific file_set from cache_manager

  • It is called from validate

A file_set refers to a directory containing a complete set of the NXDL files and XML Schema files that comprise a version of the NeXus definitions standard. It is identified by a name (release name, tag name, short commit hash, or branch name).

class punx.nxdl_manager.NXDL_Manager(file_set=None)[source]#

Python access to the NXDL classes found in nxdl_dir.

Attributes

classes dict :

Dictionary of the NXDL classes found in nxdl_dir where the key is the NeXus class name and the value is an instance of the NXDL__definition() class (defined below) which describes the NXDL structure.

nxdl_file_set str :

Absolute path to a directory which contains a complete set of the NeXus definitions. This directory will have this content: * file nxdl.xsd : The XML Schema defining the NeXus NXDL language * file nxdlTypes.xsd : data and engineering units types used by nxdl.xsd * file __github_info__.json : description of the git repository for this file set * directory applications : contains NXDL files of NeXus application definitions * directory base_classes : contains NXDL files of NeXus base classes * directory contributed_definitions : contains NXDL files of NeXus contributed definitions

nxdl_defaults obj :

Instance of punx.nxdl_schema.NXDL_Summary() or None. If not None, default values for all NXDL as defined by the nxdl.xsd.

get_nxdl_defaults()[source]#

Get default values for this NXDL type from the NXDL Schema.

class punx.nxdl_manager.NXDL__attribute(nxdl_definition, nxdl_defaults=None, *args, **kwargs)[source]#

Contents of a attribute structure (XML element) in a NXDL XML file.

~parse_nxdl_xml

parse_nxdl_xml(xml_node)[source]#

parse the XML content

class punx.nxdl_manager.NXDL__base(nxdl_definition, *args, **kwargs)[source]#

Base class for each NXDL structure.

assign_defaults()[source]#

Set default values for required components now.

ensure_unique_name(obj)[source]#

Check obj.name, replace to make unique if needed.

EXAMPLE:

  • First name of item will stay item.

  • Second name of item will become item1.

  • Third name of item will become item2.

PARAMETERS

obj obj:

Instance of nxdl_manager.NXDL__base subclass.

parse_attributes(xml_node)[source]#

Parse NXDL <attribute> elements in xml_node.

PARAMETERS

xml_node obj:

Instance of XML element in NXDL file with <attribute> nodes.

Element is one of the NXDL elements: field, group, attribute, link, …

parse_fields(xml_node)[source]#

Parse NXDL <field> elements in xml_node.

PARAMETERS

xml_node obj:

Instance of XML element in NXDL file with <field> nodes.

parse_groups(xml_node)[source]#

Parse NXDL <group> elements in xml_node.

PARAMETERS

xml_node obj:

Instance of XML element in NXDL file with <group> nodes.

Parse NXDL <link> elements in xml_node.

PARAMETERS

xml_node obj:

Instance of XML element in NXDL file with <link> nodes.

parse_nxdl_xml(*args, **kwargs)[source]#

Parse the XML node and assemble NXDL structure.

parse_symbols(xml_node)[source]#

Parse NXDL <symbols> elements in xml_node.

PARAMETERS

xml_node obj:

Instance of XML element in NXDL file with <symbols> nodes.

parse_xml_attributes(defaults)[source]#

Parse the XML attributes of an NXDL element tag.

PARAMETERS

defaults obj:

Instance of nxdl_schema.NXDL_schema__element.

class punx.nxdl_manager.NXDL__definition(nxdl_manager=None, *args, **kwargs)[source]#

Contents of a definition element in a NXDL XML file.

nxdl_manager obj :

Instance of NXDL_Manager().

parse_nxdl_xml()[source]#

parse the XML content

set_file(fname)[source]#

self.category: base_classes | applications | contributed_definitions

determine the category of this NXDL

class punx.nxdl_manager.NXDL__dim(nxdl_definition, nxdl_defaults=None, *args, **kwargs)[source]#

Contents of a dim structure (XML element) in a NXDL XML file.

parse_nxdl_xml(xml_node)[source]#

parse the XML content

class punx.nxdl_manager.NXDL__dimensions(nxdl_definition, nxdl_defaults=None, *args, **kwargs)[source]#

Contents of a dimensions structure (XML element) in a NXDL XML file.

parse_nxdl_xml(xml_node)[source]#

parse the XML content

class punx.nxdl_manager.NXDL__field(nxdl_definition, nxdl_defaults=None, *args, **kwargs)[source]#

Contents of a field structure (XML element) in a NXDL XML file.

parse_nxdl_xml(xml_node)[source]#

parse the XML content

class punx.nxdl_manager.NXDL__group(nxdl_definition, nxdl_defaults=None, *args, **kwargs)[source]#

Contents of a group structure (XML element) in a NXDL XML file.

parse_nxdl_xml(xml_node)[source]#

parse the XML content

Contents of a link structure (XML element) in a NXDL XML file.

example from NXmonopd:

<link name="polar_angle" target="/NXentry/NXinstrument/NXdetector/polar_angle">
    <doc>Link to polar angle in /NXentry/NXinstrument/NXdetector</doc>
</link>
<link name="data" target="/NXentry/NXinstrument/NXdetector/data">
    <doc>Link to data in /NXentry/NXinstrument/NXdetector</doc>
</link>
parse_nxdl_xml(xml_node)[source]#

parse the XML content

class punx.nxdl_manager.NXDL__symbols(nxdl_definition, nxdl_defaults=None, *args, **kwargs)[source]#

Contents of a symbols structure (XML element) in a NXDL XML file.

example from NXcrystal:

<symbols>
  <doc>These symbols will be used below to coordinate dimensions with the same lengths.</doc>
  <symbol name="n_comp"><doc>number of different unit cells to be described</doc></symbol>
  <symbol name="i"><doc>number of wavelengths</doc></symbol>
</symbols>
parse_nxdl_xml(symbols_node)[source]#

parse the XML content

punx.nxdl_manager.get_NXDL_file_list(nxdl_dir)[source]#

Return a list of all NXDL files in the nxdl_dir.

The list is sorted by NXDL category (base_classes, applications, contributed_definitions) and then alphabetically within each category.

PARAMETERS

nxdl_dir str:

Absolute path to the directory of a file_set (defined above).

punx.nxdl_manager.validate_xml_tree(xml_tree)[source]#

Validate an NXDL XML file against its NeXus NXDL XML Schema file.

Parameters:

xml_file_name (str) – name of XML file