def populate_datasets(categories, data_names):
    """ Populate dictionary of dataset labels with the corresponding column names.
    Creates a dictionary with keys from the list "categories". For each key, if a column
    name contains that key, the name is added to a tuple of strings stored under that
    key. This is used to access a set of data columns using the names stored under each
    dataset key. Intended to gather node history datasets, which should have columns
    names in the form u1_001, u1_002, u1_003, ... to be stored under the dataset
    label "u1"

    Args:
        categories (str, nx1 tuple): list of dataset labels used to locate corresponding
                                     column names
        data_names (str, mx1 tuple): list of column names taken from structured np array

    Returns:
        datasets (dict): dictionary containing sets of column names
    """
    datasets = {}
    for key in categories:
        datasets.update({key: tuple(name for name in data_names if key in name)})
    return datasets