Skip to content

Python API

passthrough.Template

The Template class manages the creation of a data product from a type template.

After instantiation, the partial label is available through the label attribute. For convenience, the document root is also exposed, together with its nsmap (the namespace prefix->uri dictionary of the partial label).

Attributes:

Name Type Description
label lxml.etree._ElementTree

The partial label represented as an lxml element tree, which allows access to its classes and attributes via the XML DOM.

root lxml.etree._Element

The partial label's root element (e.g. Product_Observational)

nsmap dict

The partial label's namespace map

__init__(self, template, source_map, context_map=None, template_source_entry=True, keep_template_comments=False, skip_structure_check=False, quiet=False) special

Instantiate a partial label from the provided type template.

Run the provided template through a series of pre-processing steps resulting in a partial label.

Parameters:

Name Type Description Default
template Union[lxml.etree._ElementTree, pds4_tools.reader.general_objects.StructureList, pds4_tools.reader.label_objects.Label, pathlib.Path, str]

LabelLike representation of the output product's type template (e.g. a string path to an XML file).

required
source_map Dict[str, Union[lxml.etree._ElementTree, pds4_tools.reader.general_objects.StructureList, pds4_tools.reader.label_objects.Label, pathlib.Path, str, Sequence[Union[lxml.etree._ElementTree, pds4_tools.reader.general_objects.StructureList, pds4_tools.reader.label_objects.Label, pathlib.Path, str]]]]

A dictionary which maps string monikers used by the pt:sources property, to LabelLike source products. A single moniker can map to a single product or a list of products, and products can be referenced by multiple monikers. For instance:

    {
        "input": "input.xml",
        "flat": "flatfield.xml",
        "processing_inputs": [
            "input.xml",
            "flatfield.xml"
        ],
    }

required
context_map Optional[dict]

If called for by the template, a dictionary of key-value pairs which can be looked up using the pt:context() XPath extension function, for instance to automatically populate history entries with the processor's ID and version using the pt:fill property.

None
template_source_entry bool

Add a "template"->template mapping to source_map. Convenience option for self-referencing templates.

True
keep_template_comments bool

If enabled, propagate XML comments from template to the exported output product.

False
skip_structure_check bool

If enabled, share a few milliseconds off the export process (and some kilobytes of memory) by not sanity-checking the structure of the partial label to that of the original template.

False
quiet int

If set to True, suppress Template log messages below logging.ERROR from propagating up the hierarchy. Alternatively, a numeric log level can be provided, which will be forwarded directly to the Template logger.

False

export(self, directory, filename=None)

Export the partial label to the filesystem.

Run the partial label through a series of post-processing steps before exporting the completed label to filename in `directory.

If filename is not provided, the product ID part of the post-processed label's logical identifier (LID) will be used. Please note that this behaviour is likely to change in an upcoming release!

Parameters:

Name Type Description Default
directory Union[pathlib.Path, str]

Path to the desired output directory.

required
filename Optional[str]

Filename override to use for the output label.

None