def quantity_to_hdf5(f, key, q):
    """
    Turn an Astropy Quantity object into something we can write out to
    an HDF5 file.

    Parameters
    ----------
    f : :class:`h5py.File`, :class:`h5py.Group`, :class:`h5py.DataSet`
    key : str
        The name.
    q : float, `astropy.units.Quantity`
        The quantity.

    """
    if hasattr(q, 'unit'):
        f[key] = q.value
        f[key].attrs['unit'] = str(q.unit)
    else:
        f[key] = q
        f[key].attrs['unit'] = ''
