def split_quantities(data, units='units', magnitude='magnitude',
                     list_of_dicts=False):
    """ split pint.Quantity objects into <unit,magnitude> pairs

    Parameters
    ----------
    data : dict
    units : str
        name for units key
    magnitude : str
        name for magnitude key
    list_of_dicts: bool
        treat list of dicts as additional branches

    Examples
    --------
    >>> from pprint import pprint

    >>> from pint import UnitRegistry
    >>> ureg = UnitRegistry()
    >>> Q = ureg.Quantity

    >>> qdata = {'energy': Q(1.602e-22, 'kilojoule'),
    ...          'meta': None,
    ...          'other': {'y': Q([4,5,6], 'nanometer')},
    ...          'x': Q([1,2,3], 'nanometer'),
    ...          'y': Q([8,9,10], 'meter')}
    ...
    >>> split_data = split_quantities(qdata)
    >>> pprint(split_data)
    {'energy': {'magnitude': 1.602e-22, 'units': 'kilojoule'},
     'meta': None,
     'other': {'y': {'magnitude': array([4, 5, 6]), 'units': 'nanometer'}},
     'x': {'magnitude': array([1, 2, 3]), 'units': 'nanometer'},
     'y': {'magnitude': array([ 8,  9, 10]), 'units': 'meter'}}

    """
    try:
        from pint.quantity import _Quantity
    except ImportError:
        raise ImportError('please install pint to use this module')
    list_of_dicts = '__list__' if list_of_dicts else None
    data_flatten = flatten(data, list_of_dicts=list_of_dicts)
    for key, val in data_flatten.items():
        if isinstance(val, _Quantity):
            data_flatten[key] = {units: str(val.units),
                                 magnitude: val.magnitude}
    return unflatten(data_flatten, list_of_dicts=list_of_dicts)