writing my own threshold_matrix.py