sierra.core.experiment.definition

Functionality for reading, writing, and manipulating experiment definitions.

Currently, experiments can be specified in:

  • XML

  • XMLExpDef: Read, write, and modify parsed XML files into experiment definitions.

class sierra.core.experiment.definition.XMLExpDef(input_fpath: Path, write_config: Optional[WriterConfig] = None)[source]

Read, write, and modify parsed XML files into experiment definitions.

Functionality includes single tag removal/addition, single attribute change/add/remove.

input_filepath

The location of the XML file to process.

writer

The configuration for how the XML data will be written.

Inheritance

Inheritance diagram of XMLExpDef
__dict__ = mappingproxy({'__module__': 'sierra.core.experiment.definition', '__doc__': 'Read, write, and modify parsed XML files into experiment definitions.\n\n    Functionality includes single tag removal/addition, single attribute\n    change/add/remove.\n\n    Attributes:\n\n        input_filepath: The location of the XML file to process.\n\n        writer: The configuration for how the XML data will be written.\n    ', '__init__': <function XMLExpDef.__init__>, 'write_config_set': <function XMLExpDef.write_config_set>, 'write': <function XMLExpDef.write>, 'attr_get': <function XMLExpDef.attr_get>, 'attr_change': <function XMLExpDef.attr_change>, 'attr_add': <function XMLExpDef.attr_add>, 'has_tag': <function XMLExpDef.has_tag>, 'has_attr': <function XMLExpDef.has_attr>, 'tag_change': <function XMLExpDef.tag_change>, 'tag_remove': <function XMLExpDef.tag_remove>, 'tag_remove_all': <function XMLExpDef.tag_remove_all>, 'tag_add': <function XMLExpDef.tag_add>, '__dict__': <attribute '__dict__' of 'XMLExpDef' objects>, '__weakref__': <attribute '__weakref__' of 'XMLExpDef' objects>, '__annotations__': {}})
__doc__ = 'Read, write, and modify parsed XML files into experiment definitions.\n\n    Functionality includes single tag removal/addition, single attribute\n    change/add/remove.\n\n    Attributes:\n\n        input_filepath: The location of the XML file to process.\n\n        writer: The configuration for how the XML data will be written.\n    '
__init__(input_fpath: Path, write_config: Optional[WriterConfig] = None) None[source]
__module__ = 'sierra.core.experiment.definition'
__weakref__

list of weak references to the object (if defined)

attr_add(path: str, attr: str, value: str, noprint: bool = False) bool[source]

Add the specified attribute to the element matching the specified path.

Only the FIRST element matching the specified path searching from the tree root is modified.

Parameters:
  • path – An XPath expression that for the element containing the attribute to add. The element must exist or an error will be raised.

  • attr – An XPath expression for the name of the attribute to change within the enclosing element.

  • value – The value to set the attribute to.

attr_change(path: str, attr: str, value: str, noprint: bool = False) bool[source]

Change the specified attribute of the element at the specified path.

Only the attribute of the FIRST element matching the specified path is changed.

Parameters:
  • path – An XPath expression that for the element containing the attribute to change. The element must exist or an error will be raised.

  • attr – An XPath expression for the name of the attribute to change within the enclosing element.

  • value – The value to set the attribute to.

attr_get(path: str, attr: str)[source]

Retrieve the specified attribute of the element at the specified path.

If it does not exist, None is returned.

has_attr(path: str, attr: str) bool[source]
has_tag(path: str) bool[source]
tag_add(path: str, tag: str, attr: Dict[str, str] = {}, allow_dup: bool = True, noprint: bool = False) bool[source]

Add tag name as a child element of enclosing parent.

tag_change(path: str, tag: str, value: str) bool[source]

Change the specified tag of the element matching the specified path.

Parameters:
  • path – An XPath expression that for the element containing the tag to change. The element must exist or an error will be raised.

  • tag – An XPath expression of the tag to change within the enclosing element.

  • value – The value to set the tag to.

tag_remove(path: str, tag: str, noprint: bool = False) bool[source]

Remove the specified child in the enclosing parent specified by the path.

If more than one tag matches, only one is removed. If the path does not exist, nothing is done.

Parameters:
  • path – An XPath expression that for the element containing the tag to remove. The element must exist or an error will be raised.

  • tag – An XPath expression of the tag to remove within the enclosing element.

tag_remove_all(path: str, tag: str, noprint: bool = False) bool[source]

Remove the specified tag(s) in the enclosing parent specified by the path.

If more than one tag matches in the parent, all matching child tags are removed.

Parameters:
  • path – An XPath expression that for the element containing the tag to remove. The element must exist or an error will be raised.

  • tag – An XPath expression for the tag to remove within the enclosing element.

write(base_opath: Path) None[source]

Write the XML stored in the object to the filesystem.

write_config_set(config: WriterConfig) None[source]

Set the write config for the object.

Provided for cases in which the configuration is dependent on whether or not certain tags are present in the input file.