import math


def convert_to_readable_size(size, orig_unit='B'):
    """Converts size to human readable unit"""
    units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']

    # convert original size to bytes
    try:
        i = units.index(orig_unit)
    except:
        raise RuntimeError('Invalid size unit passed: %s' % (orig_unit))
    size = size * pow(1024, i)

    unitIndex = int(math.floor(math.log(size, 1024)))
    # set size unit to PB max if size is greater than 1024 PB
    if unitIndex > 5:
        unitIndex = 5
    sizer = math.pow(1024, unitIndex)
    newsize = round(size / sizer, 2)
    return "%s %s" % (newsize, units[unitIndex])