Related to channel density (not histogram), it can be very slow with the current custom methods. To use the KDTree with a periodic boundary method, it seems https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.cKDTree.html could help.