fastoad.io.xml.translator module
Conversion from OpenMDAO variables to XPath
- class fastoad.io.xml.translator.VarXpathTranslator(*, variable_names: Sequence[str] = None, xpaths: Sequence[str] = None, source: str | IO = None)[source]
Bases:
object
Allows to convert OpenMDAO variable names from and to XPath, using a provided conversion table.
- At instantiation, user can provide (as keyword arguments only):
variable_names and xpaths (see
set()
)translation file (see
read_translation_table()
)
- set(variable_names: Sequence[str], xpaths: Sequence[str])[source]
Sets the “conversion table”, i.e. two lists where each element matches the other with same index. Provided lists must have the same length.
- Parameters:
variable_names – List of OpenMDAO variable names
xpaths – List of XML Paths
- read_translation_table(source: str | IO)[source]
Reads a file that sets how OpenMDAO variable are matched to XML Path. Provided file should have 2 comma-separated columns:
first one with OpenMDAO names
second one with their matching XPath
- Parameters:
source –
- get_xpath(var_name: str) str [source]
- Parameters:
var_name – OpenMDAO variable name
- Returns:
XPath that matches var_name
- Raises:
FastXpathTranslatorVariableError – if var_name is unknown
- get_variable_name(xpath: str) str [source]
- Parameters:
xpath – XML Path
- Returns:
OpenMDAO variable name that matches xpath
- Raises:
FastXpathTranslatorXPathError – if xpath is unknown