Generalized magnitude.py