Digital Grain Size algorithm in Python