Python code for PhD project