fastoad.io.xml.variable_io_standard module¶
Defines how OpenMDAO variables are serialized to XML
- class fastoad.io.xml.variable_io_standard.VariableXmlStandardFormatter[source]¶
Bases:
fastoad.io.xml.variable_io_base.VariableXmlBaseFormatter
Standard XML formatter for variables
Assuming self.path_separator is defined as
:
(default), a variable named likefoo:bar
with unitsm/s
will be read and written as:<aircraft> <foo> <bar units="m/s" >`42.0</bar> </foo> <aircraft>
When writing outputs of a model, OpenMDAO component hierarchy may be used by defining
self.path_separator = '.' # Discouraged for reading ! self.use_promoted_names = False
This way, a variable like
componentA.subcomponent2.my_var
will be written as:<aircraft> <componentA> <subcomponent2> <my_var units="m/s" >72.0</my_var> </subcomponent2> <componentA> <aircraft>
- property path_separator¶
The separator that will be used in OpenMDAO variable names to match XML path. Warning: The dot “.” can be used when writing, but not when reading.
- read_variables(data_source: Union[str, IO]) → fastoad.openmdao.variables.VariableList[source]¶
Reads variables from provided data source file.
- Parameters
data_source –
- Returns
a list of Variable instance
- write_variables(data_source: Union[str, IO], variables: fastoad.openmdao.variables.VariableList)[source]¶
Writes variables to defined data source file.
- Parameters
data_source –
variables –
- class fastoad.io.xml.variable_io_standard.BasicVarXpathTranslator(path_separator)[source]¶
Bases:
fastoad.io.xml.translator.VarXpathTranslator
Dedicated VarXpathTranslator that builds variable names by simply converting the ‘/’ separator of XPaths into the desired separator.
- get_variable_name(xpath: str) → str[source]¶
- Parameters
xpath – XML Path
- Returns
OpenMDAO variable name that matches xpath
- Raises
FastXpathTranslatorXPathError – if xpath is unknown
- 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