def convert_quat(q, to='xyzw'):
    """
    Converts quaternion from one convention to another.
    The convention to convert TO is specified as an optional argument.
    If to == 'xyzw', then the input is in 'wxyz' format, and vice-versa.

    Args:
        q: a 4-dim numpy array corresponding to a quaternion
        to: a string, either 'xyzw' or 'wxyz', determining
            which convention to convert to.
    """
    if to == 'xyzw':
        return q[[1, 2, 3, 0]]
    if to == 'wxyz':
        return q[[3, 0, 1, 2]]
    raise Exception('convert_quat: choose a valid `to` argument (xyzw or wxyz)'
        )
