Skip to main content

Unsupervised clustering algorithm for 2D data

Project description

rastermap

This algorithm computes a 2D continuous sorting of neural activity. It assumes that the spike matrix S is neurons by timepoints.

Here is what the output looks like for a segment of a mesoscope recording (2.5Hz sampling rate):

rastersorted

Here is an example using the algorithm (also see this jupyter-notebook)

from rastermap import rastermap # <-- if pip installed
import numpy as np
from scipy.ndimage import gaussian_filter1d
import matplotlib.pyplot as plt

# load data (S is neurons x time)
# these files are the outputs of suite2p
S = np.load('spks.npy')
iscell = np.load('iscell.npy')
S = S[iscell[:,0].astype(bool),:]

# run rastermap 
# (will take ~ 30s for 6000 neurons x 20000 timepts on a laptop)
# these are the default options, you can change them and input them to the function
ops = {'nclust': 30, # number of clusters
       'iPC': np.arange(0,200).astype(np.int32), # number of PCs to use for mapping algorithm
       'upsamp': 100, # upsampling factor for embedding position
       'sigUp': 1, # standard deviation for kriging upsampling
       'equal': False # whether or not clusters should be of equal size (recommended False!)
       }
# user options
isort1,isort2 = rastermap.main(S,ops)

# if you just want to use the defaults
isort1,isort2 = rastermap.main(S)

# sort neurons and smooth across neurons and zscore in time
# smoothing will take ~ 10s depending on data size
Sm = gaussian_filter1d(S[isort1,:].T, np.minimum(10,int(S.shape[0]*0.005)), axis=1)
Sm = Sm.T
Sm = zscore(Sm, axis=1)

# (optional) smooth in time
Sm = gaussian_filter1d(Sm, 1, axis=1)

# view neuron sorting :)
fs = 2.5 # sampling rate of data in Hz
sp = Sm[:,1000:3000]
plt.figure(figsize=(16,12))
ax=plt.imshow(sp,vmin=0,vmax=3,aspect='auto',extent=[0,sp.shape[1]/fs, 0,sp.shape[0]])
plt.xlabel('time (s)', fontsize=18)
plt.ylabel('neurons', fontsize=18)
plt.show()

If you don't pip install the package, you can also run it using the path to this github folder

import sys
sys.path.insert(0, '/media/carsen/DATA2/github/rastermap/rastermap/')
import rastermap

Installation

You can just download the github folder as outlined above or you can pip install the package:

pip install rastermap

Requirements

This package was written for Python 3 and relies on numpy and scipy. The Python3.x Anaconda distributions will contain all the dependencies.

Matlab

The matlab code needs to be cleaned up but the main function to call is mapTmap.m. This function is used in the example script loadFromPython.m.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rastermap-0.0.2.tar.gz (618.5 kB view details)

Uploaded Source

Built Distribution

rastermap-0.0.2-py3-none-any.whl (604.8 kB view details)

Uploaded Python 3

File details

Details for the file rastermap-0.0.2.tar.gz.

File metadata

  • Download URL: rastermap-0.0.2.tar.gz
  • Upload date:
  • Size: 618.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for rastermap-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b720794613a1f764c069ada413d9ac9b730b5be71c9c5aa9b61213e728876e5a
MD5 b8e29c4fdfa64fd2759838adf1cc8429
BLAKE2b-256 eb72fcc97a9beb92cddf5f9c1c4e92c8415b3f5d71812f325ac620fb0d3b608d

See more details on using hashes here.

File details

Details for the file rastermap-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: rastermap-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 604.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for rastermap-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8b95f01a5860a999109008ccdb1f9d85cef2a179bc78ead48e943e61086024c1
MD5 f2313559d7c897b1b7b38c798fab1aa6
BLAKE2b-256 4703d7a1be2ff83a7ef4b2f6ea9d3890f85552e5c4f025acc8de103bc6526ebd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page