Beispiel #1
0
def applyRasterMap(data_nt, n_X=30):
    import numpy as np
    from rastermap import Rastermap
    model = Rastermap(n_components=1, n_X=30, nPC=200, init='pca')
    model = model.fit(data_nt)
    isort_full = np.argsort(model.embedding[:, 0])
    return isort_full
Beispiel #2
0
    def ROI_selection(self, loaded=False):
        self.colormat = np.zeros((0, 10, 3), dtype=np.int64)
        lROI = len(self.Rselected)
        if lROI > 0:
            self.selected = np.array(
                [item for sublist in self.Rselected for item in sublist])
            self.colormat = np.concatenate(self.Rcolors, axis=0)
            if not loaded:
                print('yo')
                if lROI > 4:
                    self.Ur = np.zeros((lROI, self.U.shape[1]),
                                       dtype=np.float32)
                    ugood = np.zeros((lROI, )).astype(np.int32)
                    for r, rc in enumerate(self.Rselected):
                        if len(rc) > 0:
                            self.Ur[r, :] = self.U[rc, :].mean(axis=0)
                            ugood[r] = 1
                    ugood = ugood.astype(bool)
                    if ugood.sum() > 4:
                        model = Rastermap(n_components=1,
                                          n_X=20,
                                          init=np.arange(
                                              0, ugood.sum()).astype(
                                                  np.int32)[:, np.newaxis])
                        y = model.fit_transform(self.Ur[ugood, :])
                        y = y.flatten()
                        y2 = np.zeros((lROI, ))
                        y2[(ugood).nonzero()[0]] = y
                        print(y2)
                        rsort = np.argsort(y2)
                        print(rsort)
                        roiorder = []
                        for r in self.ROIorder:
                            roiorder.append((rsort == r).nonzero()[0][0])
                        self.ROIorder = roiorder
                        self.ROIs = [self.ROIs[i] for i in rsort]
                        self.Rselected = [self.Rselected[i] for i in rsort]
                        self.Rcolors = [self.Rcolors[i] for i in rsort]
                        self.selected = np.array([
                            item for sublist in self.Rselected
                            for item in sublist
                        ])
                        self.colormat = np.concatenate(self.Rcolors, axis=0)
        else:
            self.selected = np.argsort(self.embedding[:, 0])
            self.colormat = 255 * np.ones(
                (self.sp.shape[0], 10, 3), dtype=np.int32)

        self.colormat_plot = self.colormat.copy()
        self.plot_activity()
        self.plot_colorbar()
        self.win.show()
Beispiel #3
0
def getRastermapEmbeddings(PV, nX=50, nbin=50):
    """
    Parameters
    ----------
    PV : float32/float64
        population vector: Time x Number of cells matrix
    Returns
    -------
    isort : manifold embedding
    Sfilt : sorted signals from all neurons.

    """
    # raster map to find underlying embeddings
    model = Rastermap(n_components=1, n_X=nX).fit(PV.T)
    # the manifold embedding is in model.embedding
    isort = np.argsort(model.embedding[:,0])
    # sort by embedding and smooth over neurons
    Sfilt = running_average(PV.T[isort, :], nbin)
    Sfilt = zscore(Sfilt, axis=1)
    return isort, Sfilt
Beispiel #4
0
         iscell = iscell[:, 0].astype(np.bool)
     else:
         iscell = iscell.astype(np.bool)
     if iscell.size == S.shape[0]:
         S = S[iscell, :]
         print('iscell found and used to select neurons')
 print('size of rastermap matrix')
 print(S.shape)
 if len(S.shape) > 2:
     S = S.mean(axis=-1)
 S = zscore(S, axis=1)
 ops['mode'] = 'basic'
 model = Rastermap(n_components=ops['n_components'],
                   n_X=ops['n_X'],
                   nPC=ops['nPC'],
                   init=ops['init'],
                   alpha=ops['alpha'],
                   K=ops['K'],
                   constraints=ops['constraints'],
                   annealing=ops['annealing'])
 if ops['end_time'] == -1:
     ops['end_time'] = S.shape[1]
     ops['start_time'] = 0
 train_time = np.zeros((S.shape[1], )).astype(bool)
 print(train_time.shape)
 train_time[np.arange(ops['start_time'],
                      ops['end_time']).astype(int)] = 1
 model.fit(S[:, train_time])
 proc = {
     'embedding': model.embedding,
     'uv': [model.u, model.v],
     'ops': ops,
def rastermap_comp(dff_path, rastermap_save_path):
    dff = np.load(dff_path)
    model = Rastermap(n_components=1, n_X=100).fit(dff)
    np.save(rastermap_save_path, model.embedding[:, 0])
Beispiel #6
0
    parser = argparse.ArgumentParser(description='spikes')
    parser.add_argument('--S', default=[], type=str, help='spiking matrix')
    parser.add_argument('--ops', default=[], type=str, help='options file')
    parser.add_argument('--iscell', default=[], type=str, help='which cells to use')
    args = parser.parse_args()

    if len(args.S)>0:
        S = np.load(args.S)
        ops = np.load(args.ops)
        ops = ops.item()
        if len(args.iscell) > 0:
            iscell = np.load(args.iscell)
            if iscell.ndim > 1:
                iscell = iscell[:, 0].astype(np.bool)
            else:
                iscell = iscell.astype(np.bool)
            if iscell.size == S.shape[0]:
                S = S[iscell, :]
                print('iscell found and used to select neurons')
        print(S.shape)
        S = zscore(S,axis=1)
        model = Rastermap(ops['n_components'], ops['n_X'], ops['n_Y'], ops['nPC'],
                          ops['sig_Y'], ops['init'], ops['alpha'], ops['K'])
        model.fit(S)
        proc  = {'embedding': model.embedding, 'usv': [model.u, model.sv, model.v],
                 'cmap': model.cmap, 'A': model.A, 'ops': ops, 'filename': args.S}
        basename, fname = os.path.split(args.S)
        np.save(os.path.join(basename, 'embedding.npy'), proc)
    else:
        gui.run()