transparently handle Rotation/Orientation objects

slow but very convenient
This commit is contained in:
Martin Diehl 2021-03-08 16:37:07 +01:00
parent 15517c4d4f
commit 1f383ddeff
1 changed files with 9 additions and 2 deletions

View File

@ -5,6 +5,9 @@ import abc
import numpy as np
import yaml
from . import Rotation
from . import Orientation
class NiceDumper(yaml.SafeDumper):
"""Make YAML readable for humans."""
@ -19,8 +22,12 @@ class NiceDumper(yaml.SafeDumper):
def represent_data(self, data):
"""Cast Config objects and its subclasses to dict."""
return self.represent_data(dict(data)) if isinstance(data, dict) and type(data) != dict else \
super().represent_data(data)
if isinstance(data, dict) and type(data) != dict:
return self.represent_data(dict(data))
if isinstance(data, (Rotation, Orientation)):
return self.represent_data(data.as_quaternion())
else:
return super().represent_data(data)
def ignore_aliases(self, data):
"""No references."""