Python code for opacity analysis