def filterOnNamespace(GOdict, namespace):
    """
    Reduces the dictionary of goTerm objects to those belonging to a specific namespace.

    Parameters
    ----------
    GOdict : dict
        A dictionary of GO objects generated by importOBO().
        Keys are of the format `GO-0000001` and map to goTerm objects.
    namespace : str
        The namespace to restrict the GO dictionary and enrichment test to. E.g. biological_process, cellular_component
        or molecular_function.

    Returns
    -------
    dict
        A filtered dictionary of GO objects all belonging to the namespace.
    """

    filteredGOdict = {GOid: GOobj for GOid, GOobj in GOdict.items() if GOobj.namespace == namespace}

    if not filteredGOdict:
        print('Namespace', namespace, 'was not found in the obo file. Using all annotations in obo file instead.\n')
        return GOdict

    print('Found', len(filteredGOdict), 'GO terms belonging to', namespace + '.\n')

    return filteredGOdict