# Path: pytim/utilities.py
# def lap(show=False):
# def correlate(a1, a2=None, _normalize=True):
# def extract_positions(inp):
# def get_box(universe, normal=2):
# def get_pos(group, normal=2):
# def get_coord(coord, group, normal=2):
# def get_x(group, normal=2):
# def get_y(group, normal=2):
# def get_z(group, normal=2):
# def centerbox(universe,
#               x=None,
#               y=None,
#               z=None,
#               vector=None,
#               center_direction=2,
#               halfbox_shift=True):
# def guess_normal(universe, group):
# def density_map(pos, grid, sigma, box):
# def _NN_query(kdtree, position, qrange):
# def consecutive_filename(universe, basename, extension):
# def generate_cube_vertices(box, delta=0.0, jitter=False, dim=3):


import numpy as np
from pytim import utilities
from MDAnalysis.core.groups import Atom, AtomGroup, Residue, ResidueGroup
    def _survival_intermittent(self, ms):
        corr = np.sum(utilities.correlate(ms, _normalize=False), axis=1)
        return corr / np.sum(np.cumsum(self.timeseries, axis=0), axis=1)[::-1]

    @staticmethod
    def _find_edges(mask):
        return np.where(mask[:-1] != mask[1:])[0]

    def _survival_continuous(self, ms):
        n_part = len(ms[0])
        corr = np.zeros((self.nseries, n_part))
        counting = (1. + np.arange(len(self.timeseries)))

        for part in range(n_part):
            edges = self._find_edges(ms[::, part])
            deltat = edges[1::2] - edges[0::2]
            # for each of the disconnected segments:
            for n, dt in enumerate(deltat):
                # no need to compute the correlation, we know what it is
                corr[0:dt, part] += counting[:dt][::-1]

        corr = np.sum(corr, axis=1)
        return corr / np.sum(np.cumsum(self.timeseries, axis=0), axis=1)[::-1]

    def _autocorrelation_intermittent(self, ts, ms):

        dim = self.dim

        corr = ts.copy()
        for xyz in range(dim):

# Path: pytim/utilities.py
# def lap(show=False):
# def correlate(a1, a2=None, _normalize=True):
# def extract_positions(inp):
# def get_box(universe, normal=2):
# def get_pos(group, normal=2):
# def get_coord(coord, group, normal=2):
# def get_x(group, normal=2):
# def get_y(group, normal=2):
# def get_z(group, normal=2):
# def centerbox(universe,
#               x=None,
#               y=None,
#               z=None,
#               vector=None,
#               center_direction=2,
#               halfbox_shift=True):
# def guess_normal(universe, group):
# def density_map(pos, grid, sigma, box):
# def _NN_query(kdtree, position, qrange):
# def consecutive_filename(universe, basename, extension):
# def generate_cube_vertices(box, delta=0.0, jitter=False, dim=3):


# Path: pytim/observables/correlator.py
import numpy as np
from pytim import utilities
from MDAnalysis.core.groups import Atom, AtomGroup, Residue, ResidueGroup

    def _survival_intermittent(self, ms):
        corr = np.sum(utilities.correlate(ms, _normalize=False), axis=1)
        return corr / np.sum(np.cumsum(self.timeseries, axis=0), axis=1)[::-1]

    @staticmethod
    def _find_edges(mask):
        return np.where(mask[:-1] != mask[1:])[0]

    def _survival_continuous(self, ms):
        n_part = len(ms[0])
        corr = np.zeros((self.nseries, n_part))
        counting = (1. + np.arange(len(self.timeseries)))

        for part in range(n_part):
            edges = self._find_edges(ms[::, part])
            deltat = edges[1::2] - edges[0::2]
            # for each of the disconnected segments:
            for n, dt in enumerate(deltat):
                # no need to compute the correlation, we know what it is
                corr[0:dt, part] += counting[:dt][::-1]

        corr = np.sum(corr, axis=1)
        return corr / np.sum(np.cumsum(self.timeseries, axis=0), axis=1)[::-1]

    def _autocorrelation_intermittent(self, ts, ms):

        dim = self.dim

        corr = ts.copy()
        for xyz in range(dim):

            corr[:, xyz::dim] = utilities.correlate(