Added python version of optimal filter code