calculate min and max of curves avoiding 0 values