def prepare_reference(group):
    """Prepare reference cube and remove from the group."""
    ref_name = group[0]['reference_dataset']
    reference_candidates = [ds for ds in group if ds['dataset'] == ref_name]
    assert len(reference_candidates) == 1
    reference = reference_candidates[0]
    group.remove(reference)
    return reference