import numpy as np
import logging

from .deconvolute import Deconvolution
from .. import read_config


def run(spike_train_clear, templates, spike_index_collision):
    """Run deconvolution

    Parameters
    ----------
    spike_train
    spikes_left
    templates

    Returns
    -------
    spike_train

    Examples
    --------

    .. literalinclude:: ../examples/deconvolute.py
    """
    logger = logging.getLogger(__name__)

    CONFIG = read_config()
    deconv = Deconvolution(CONFIG, np.transpose(templates, [1, 0, 2]),
                           spike_index_collision, filename='whiten.bin')
    spike_train_deconv = deconv.fullMPMU()

    spike_train = np.concatenate((spike_train_deconv, spike_train_clear))

    idx_sort = np.argsort(spike_train[:, 0])
    spike_train = spike_train[idx_sort]

    idx_keep = np.zeros(spike_train.shape[0], 'bool')

    for k in range(templates.shape[2]):
        idx_c = np.where(spike_train[:, 1] == k)[0]
        idx_keep[idx_c[np.concatenate(([True], np.diff(spike_train[idx_c,0]) > 1))]] = 1

    spike_train = spike_train[idx_keep]

    return spike_train

@@ -645,16 +645,117 @@
 MPMU()%0A%0A
+    logger.debug('spike_train_deconv.shape: %7B%7D'%0A                 .format(spike_train_deconv.shape))%0A%0A
     spik
@@ -1185,16 +1185,85 @@
 _keep%5D%0A%0A
+    logger.debug('spike_train.shape: %7B%7D'.format(spike_train.shape))%0A%0A
     retu

debug logging in deconv