MRI Python code