converted some scripts from matlab to python