def _mem_unitconv(mem, units='MB'):
    """Convert memory from bytes to the specified unit.

    Parameters
    ----------
    mem : int
        The amount of memory in bytes.
    units : {'B', 'KB', 'MB', 'GB'}
        Specificy the units of the output ('B'=bytes, 'KB'=kilobytes,
        'MB=megabytes, 'GB'=gigabytes).

    Returns
    -------
    mem : float
        The amount of memory in the specified units.
    """
    if units.lower() == 'b':
        return mem
    elif units.lower() == 'kb':
        denom = 1024.0
    elif units.lower() == 'mb':
        denom = 1024 * 1024.0
    elif units.lower() == 'gb':
        denom = 1024 * 1024 * 1024.0
    else:
        raise ValueError(
            'units must be B, KB, MB or GB. (corresponding to bytes, kilobytes, megabytes, gigabytes)'
            )
    return mem / denom
