def chunks_dict(chunks, mapping):
    """Get the chunks dict either from keys or values in mapping.

    Handy function to allow specifying chunks using dim names from either original
        dataset or from wavespectra.

    """
    if not mapping:
        mapping = {key: key for key in chunks.keys()}
    _chunks = {}
    for key, val in chunks.items():
        if key in mapping.keys():
            dim = key
        elif key in mapping.values():
            dim = list(mapping.keys())[list(mapping.values()).index(key)]
        else:
            raise KeyError(
                "Dim '{}' not in chunks, supported dims are {}".format(
                    key, list(mapping.keys()) + list(mapping.values())
                )
            )
        _chunks.update({dim: val})
    return _chunks