Well documented code! Good job! Can this function be splitted in sub-functions? I see mostly the same construction in SingleLens.py.