in mujoco_worldgen/parser/normalize.py [0:0]
def normalize(xml_dict):
'''
The starting point is a dictionary of the form returned by xmltodict.
See that module's documentation here:
https://github.com/martinblech/xmltodict
Normalize a mujoco model XML:
- some nodes have OrderDict value (mostly top-lever such as worldbody)
some nodes have list values (mostly lower level). Check const.py
for more information.
- parameters ('@name', etc) never have list or OrderedDict values
- "true" and "false" are converted to bool()
- numbers are converted to floats
- vectors are converted to np.ndarray()
Note: stringify() is the opposite of this, and converts everything back
into strings in preparation for unparse_dict().
'''
# As a legacy, previously many of our XMLs had an unused model name.
# This removes it (as part of annotate) and can be phased out eventually.
if '@model' in xml_dict:
del xml_dict['@model']
for key, value in xml_dict.items():
if isinstance(value, OrderedDict):
# There is one exception.
# <default> symbol occurs twice.
# Once as OrderDict (top-level), once as list (lower-level).
if key == "default":
if "@class" in value:
xml_dict[key] = [value]
elif key in list_types:
xml_dict[key] = [value]
normalize(value)
continue
if isinstance(value, list):
for child in value:
normalize(child)
continue
if isinstance(value, str):
xml_dict[key] = normalize_value(value)
# sometimes data is stored as int when it's float.
# We make a conversion here.
if key in float_arg_types:
if isinstance(xml_dict[key], int):
xml_dict[key] = float(xml_dict[key])
elif isinstance(xml_dict[key], np.ndarray):
xml_dict[key] = xml_dict[key].astype(np.float64)