Giter Site home page Giter Site logo

mouseland / rastermap Goto Github PK

View Code? Open in Web Editor NEW
172.0 172.0 42.0 72.12 MB

a visualization method for neural data

License: GNU General Public License v3.0

Python 72.68% Jupyter Notebook 27.32%
neuroscience neuroscience-methods unsupervised-clustering

rastermap's People

Contributors

atika-syeda avatar carsen-stringer avatar dufengtong avatar marius10p avatar neurojak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rastermap's Issues

Possible Bug

Hi,

Thanks for some great tools. I just wanted to report that when I have both FaceMap an rastermap on the matlabpath at the same time, I receive the following error (using the mapTmap function):

Error using reshape
To RESHAPE the number of elements must not change.

Error in my_conv2 (line 47)
S1 = reshape(S1, dsnew);

Error in activityMap (line 57)
V = my_conv2(V, sig(t), 2);

Error in mapTmap (line 16)
[~, isort2, ~] = activityMap(S', ops);

Error loading data: can only convert an array of size 1 to a Python scalar

Hi,
I'm testing the latest version of rastermap (version 0.9.3 installed with pip install rastermap[gui] in a new environment).
When loading a spks.npy generated by Suite2P, from the rastermap GUI's menu, I'm getting this error:

Traceback (most recent call last):
  File "C:\Users\pseud\anaconda3\envs\rastermap\lib\site-packages\rastermap\gui\menus.py", line 20, in <lambda>
    loadMat.triggered.connect(lambda: io.load_mat(parent, name=None))
  File "C:\Users\pseud\anaconda3\envs\rastermap\lib\site-packages\rastermap\gui\io.py", line 71, in load_mat
    X, Usv, Vsv, xy = load_activity(parent.fname)
  File "C:\Users\pseud\anaconda3\envs\rastermap\lib\site-packages\rastermap\io.py", line 111, in load_activity
    if isinstance(X.item(), dict):
ValueError: can only convert an array of size 1 to a Python scalar

Is it an issue of backward compatibility with an Suite2P version? Or something else?
Thanks

discretizing rastermap clusters with kmeans etc?

Hi,

Is there an easy way that you know of, or could suggest, to discretize Rastermap groups with kmeans or random forest or something like this, and to optimize cluster #, in a way that a human would generally agree with the splits into groups of cells with similar activity patterns? Have you tried this before?

Just knowing exactly where in the existing code might be best to implement this would be useful.

Thanks,

Evan

Data with a standard deviation of 0 prevents rastermap from running

When running rastermap with default settings and alpha of 1.43 on a dataset with 2 time series that have a standard deviation of 0, the resulting error occurs.

size of rastermap matrix
(892, 1200)
(1200,)
nmin 200
0.0049860477447509766
>>>ERROR<<<
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\runpy.py", line 193, in _run_module_as_main
>>>ERROR<<<
    "__main__", mod_spec)
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\site-packages\rastermap\__main__.py", line 47, in <module>
    model.fit(S[:, train_time])
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\site-packages\rastermap\mapping.py", line 675, in fit
    model = PCA(n_components=nmin).fit(X0)
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\site-packages\sklearn\decomposition\pca.py", line 341, in fit
    self._fit(X)
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\site-packages\sklearn\decomposition\pca.py", line 382, in _fit
    copy=self.copy)
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\site-packages\sklearn\utils\validation.py", line 542, in check_array
>>>ERROR<<<
    allow_nan=force_all_finite == 'allow-nan')
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\site-packages\sklearn\utils\validation.py", line 56, in _assert_all_finite
    raise ValueError(msg_err.format(type_err, X.dtype))
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
Interrupted by error (not finished)

Not sure it's that important as it's the responsibility of the user to use clean data

Preferred citation?

HI Carsen,

I've used rastermap in a supplemental figure and I'd like to appropriately credit it. Is there a preferred citation for it? I saw the other issue about a COSYNE abstract, but I wasn't sure whether there is one specifically on rastermap.

Would something like this be appropriate?

Stringer, C., Pachitariu, M. Rastermap: A multi-dimensional embedding algorithm (2018). GitHub repository. https://github.com/MouseLand/rastermap

Thanks so much for your work on this!
Dan

install and run fail on Windows

Hi,

I installed the github version of rastermap on Windows 10. I was able to create and activate the rastermap environment, but when I tried to run it I got the following error:

"

(rastermap) C:\Users\McCormick Lab\Documents\GitHub\rastermap>python -m rastermap
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\rastermap\lib\runpy.py", line 193, in _run_module_as_main
return run_code(code, main_globals, None,
File "C:\ProgramData\Anaconda3\envs\rastermap\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\McCormick Lab\Documents\GitHub\rastermap\rastermap_main
.py", line 2, in
from rastermap import gui
File "C:\Users\McCormick Lab\Documents\GitHub\rastermap\rastermap\gui.py", line 7, in
import pyqtgraph as pg
File "C:\ProgramData\Anaconda3\envs\rastermap\lib\site-packages\pyqtgraph_init
.py", line 204, in
from .graphicsItems.VTickGroup import *
File "C:\ProgramData\Anaconda3\envs\rastermap\lib\site-packages\pyqtgraph\graphicsItems\VTickGroup.py", line 7, in
from .. import functions as fn
File "C:\ProgramData\Anaconda3\envs\rastermap\lib\site-packages\pyqtgraph\functions.py", line 17, in
from . import debug
File "C:\ProgramData\Anaconda3\envs\rastermap\lib\site-packages\pyqtgraph\debug.py", line 11, in
from . import ptime
File "C:\ProgramData\Anaconda3\envs\rastermap\lib\site-packages\pyqtgraph\ptime.py", line 24, in
cstart = systime.clock() ### Required to start the clock in windows
AttributeError: module 'time' has no attribute 'clock'
"

Can you help?

Thanks,

Evan

error on launching, please see the error below:

Traceback (most recent call last):
File "/home/idl/anaconda3/envs/rastermap/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/idl/anaconda3/envs/rastermap/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/idl/anaconda3/envs/rastermap/lib/python3.9/site-packages/rastermap/main.py", line 2, in
from rastermap import gui
File "/home/idl/anaconda3/envs/rastermap/lib/python3.9/site-packages/rastermap/gui.py", line 12, in
import rastermap.run
File "/home/idl/anaconda3/envs/rastermap/lib/python3.9/site-packages/rastermap/run.py", line 6, in
class RunWindow(QtGui.QDialog):
AttributeError: module 'PyQt5.QtGui' has no attribute 'QDialog'

what is the format of the behavioral labels file

Hi,

I am trying to import behavioral traces to rastermap. I managed to upload a behavioral matrix, however I dont understand which format the behavioral labels file should be in so that I can upload it to rastermap.

Could you provide an example file or help me with an description?

Thanks
Carmen

n_components>2 bug

I was trying to fit a system which I designed to have a 3 dimensional latent space and got this error,
trying to use n_components=3

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/var/folders/kx/xq42kw197c5_qw6kxgnr4nkr0000gq/T/ipykernel_27590/822647098.py in <module>
      3 model = Rastermap(n_components=3, n_X=30, nPC=200, init='pca')
      4 
----> 5 embedding=model.fit_transform(Wtotal)

/opt/anaconda3/envs/caveclient/lib/python3.9/site-packages/rastermap/mapping.py in fit_transform(self, X, u)
    588             Embedding of the training data in low-dimensional space.
    589         """
--> 590         self.fit(X, u)
    591         return self.embedding
    592 

/opt/anaconda3/envs/caveclient/lib/python3.9/site-packages/rastermap/mapping.py in fit(self, X, u, v, s)
    768         # now sort in X
    769         print(time.time() - t0)
--> 770         isort1, iclustup = self._map(self.u, self.n_components, self.n_X, xid, s)
    771         self.isort = isort1
    772         self.embedding = iclustup

/opt/anaconda3/envs/caveclient/lib/python3.9/site-packages/rastermap/mapping.py in _map(self, X, dims, nclust, xid, SALL)
    880                 self.embedding0 = iclustup
    881             else:
--> 882                 iclustup, cmax = upsample(np.sqrt(cmap), dims, nclust, 10)
    883             isort = np.argsort(iclustup[:,0])
    884             self.cmap = cmap

/opt/anaconda3/envs/caveclient/lib/python3.9/site-packages/rastermap/mapping.py in upsample(cmap, dims, nclust, upsamp)
    285     cmax = np.amax(upC, axis=1) + mu
    286     dxs = M1[:, xid]
--> 287     xs = (iclust + dxs[1::-1, :])/nclust
    288     #xs = xs%1.
    289     xs = xs.T

ValueError: operands could not be broadcast together with shapes (3,200) (2,200) 

Rastermap in Suite2p GUI are different from results in matlab and python rastermap code

Thanks for developing rastermap function! What I want is to output the neuron sort number of the rastermap in Suite2p. I tried 2 ways, matlab and python code, buy both get results different from that from Suite2p GUI, while I set them the same parameters. I looked for the Suite2p python code for the parameters and I set it the same when I direct run python or matlab code, but the results are different as the 3 attached pictures (left to right: suite2p, python, matlab).
def compute_map(self):
ops = {'n_components': 1, 'n_X': 100, 'alpha': 1., 'K': 1.,
'nPC': 200, 'constraints': 2, 'annealing': True, 'init': 'pca',
'start_time': 0, 'end_time': -1}
And I also tried run mapping_new, mapping_old, mapping_inc, none of them can get the same result of suite2p GUI. So I want to ask what might be the reason? hope to hear advice. Thanks!
image
image
image

envirnoment.yml

I had to change line 12 from:
- pyqtgraph=0.11.0rc0
to:
- pyqtgraph==0.11.0rc0
in order to make it work.

associated paper

Hey Marius and Carsen,

Thanks for the cool talk.

I can't seem to find a paper outlining the exact steps you follow to compute the rastermap or comparison with other methods. I'm probably not looking well enough - would you mind posting the link when you have a moment?

Looking forward to better understanding it/testing it out, :)

Thanks,
Ginny

run rastermap on binarized data

Dear Team.

I was wondering whether it would be possible to run rastermap on already binarized data (meaning 0 = no spike; 1 = spike) and whether it would make more sense supplying just the peak, or setting the entire width at half maximum to 1 for the algorithms behind rastermap?

I tried to run the rastermap_singleneurons.ipnyb notebook with my own binarized matrix of 752 cells by 612 timepoints as this seemed the most applicable, however when I try to set n_clusters = None a ValueError gets raised in lines 363-364 of rastermap.py.

When I set n_clusters to some integer < 200, the following error occurs:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[7], line 1
----> 1 model = Rastermap(n_clusters=10, # None turns off clustering and sorts single neurons 
      2                   n_PCs=64, # use fewer PCs than neurons
      3                   locality=0.15, # some locality in sorting (this is a value from 0-1)
      4                   time_lag_window=15, # use future timepoints to compute correlation
      5                   normalize = None,
      6                   grid_upsample=0, # 0 turns off upsampling since we're using single neurons
      7                 ).fit(spks)
      8 y = model.embedding # neurons x 1
      9 isort = model.isort

File ~/miniconda3/envs/rastermap/lib/python3.8/site-packages/rastermap/rastermap.py:494, in Rastermap.fit(self, data, Usv, Vsv, U_nodes, itrain, compute_X_embedding, BBt)
    491     if (bin_size==0 or n_samples < bin_size or 
    492         (bin_size == 50 and n_samples < 1000)):
    493         bin_size = max(1, n_samples // 500)
--> 494     self.X_embedding = zscore(bin1d(X[igood][self.isort], bin_size, axis=0), axis=1)
    496 rmap_logger.info(f"rastermap complete, time {time.time() - t0:0.2f}sec")
    498 self.runtime = time.time() - t0

IndexError: index 751 is out of bounds for axis 0 with size 592

This happens both when explicitly setting bin_size = 0 or bin_size = 1

start the rastermap with extracted ROI excel file

Hello!

I wonder can I start the rastermap with the time series data on an Excel file? I already extract the ROI with caiman package with the traces. But it won't have the 'position' and other features like suite2p on your demo data.
Or it should be fine if I calculate the necessary SVD value and add to the Excel?

So my goal is to sort the trace only without predicting the behavior.

Thank you for your guidance!

Problem open suite2p file in rastermap

Hello! I have some problems with opening the npy file from the result of suite2p in rastermap, I have tried F.npy and spk.npy, and I have tried load data matrix and load processed data, they all show this 'ValueError: can only convert an array of size 1 to a Python scalar' I also check the libraries, seems all the libraries require are already installed in my conda environment.

Here is the detail of the ValueError:
Loading C:/Users/Zi/Downloads/test_outputs/test_outputs/1plane1chan1500/suite2p/plane0/F.npy Traceback (most recent call last): File "C:\Users\Zi\.conda\envs\rastermap\lib\site-packages\rastermap\gui\menus.py", line 20, in <lambda> loadMat.triggered.connect(lambda: io.load_mat(parent, name=None)) File "C:\Users\Zi\.conda\envs\rastermap\lib\site-packages\rastermap\gui\io.py", line 71, in load_mat X, Usv, Vsv, xy = load_activity(parent.fname) File "C:\Users\Zi\.conda\envs\rastermap\lib\site-packages\rastermap\io.py", line 111, in load_activity if isinstance(X.item(), dict): ValueError: can only convert an array of size 1 to a Python scalar

Torch not compiled with CUDA enabled

Hi, when I tried to run the tutorial locally, I have some issues with Torch and CUDA.
https://colab.research.google.com/github/MouseLand/rastermap/blob/main/notebooks/tutorial.ipynb

"Predicting with a 1D convolution layer"

from neuropop import nn_prediction
import torch

ideally we have a GPU we can use ("cuda" option)

device = torch.device("cuda")

declare the model

pred_model = nn_prediction.PredictionNetwork(n_in=beh.shape[-1], n_kp=22, identity=False,
n_filt=10, n_latents=0,
n_out=Vsv.shape[-1], n_core_layers=1,
relu_wavelets=False, relu_latents=False)

put model on the GPU

pred_model.to(device);

print(pred_model)

AssertionError Traceback (most recent call last)
Cell In[20], line 13
8 pred_model = nn_prediction.PredictionNetwork(n_in=beh.shape[-1], n_kp=22, identity=False,
9 n_filt=10, n_latents=0,
10 n_out=Vsv.shape[-1], n_core_layers=1,
11 relu_wavelets=False, relu_latents=False)
12 # put model on the GPU
---> 13 pred_model.to(device);
15 print(pred_model)

File ~\miniconda3\envs\rastermap\lib\site-packages\torch\nn\modules\module.py:1152, in Module.to(self, *args, **kwargs)
1148 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None,
1149 non_blocking, memory_format=convert_to_format)
1150 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
-> 1152 return self._apply(convert)

File ~\miniconda3\envs\rastermap\lib\site-packages\torch\nn\modules\module.py:802, in Module._apply(self, fn, recurse)
800 if recurse:
801 for module in self.children():
--> 802 module._apply(fn)
804 def compute_should_use_set_data(tensor, tensor_applied):
805 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
806 # If the new tensor has compatible tensor type as the existing tensor,
807 # the current behavior is to change the tensor in-place using .data =,
(...)
812 # global flag to let the user control whether they want the future
813 # behavior of overwriting the existing tensor or not.

File ~\miniconda3\envs\rastermap\lib\site-packages\torch\nn\modules\module.py:802, in Module._apply(self, fn, recurse)
800 if recurse:
801 for module in self.children():
--> 802 module._apply(fn)
804 def compute_should_use_set_data(tensor, tensor_applied):
805 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
806 # If the new tensor has compatible tensor type as the existing tensor,
807 # the current behavior is to change the tensor in-place using .data =,
(...)
812 # global flag to let the user control whether they want the future
813 # behavior of overwriting the existing tensor or not.

[... skipping similar frames: Module._apply at line 802 (1 times)]

File ~\miniconda3\envs\rastermap\lib\site-packages\torch\nn\modules\module.py:802, in Module._apply(self, fn, recurse)
800 if recurse:
801 for module in self.children():
--> 802 module._apply(fn)
804 def compute_should_use_set_data(tensor, tensor_applied):
805 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
806 # If the new tensor has compatible tensor type as the existing tensor,
807 # the current behavior is to change the tensor in-place using .data =,
(...)
812 # global flag to let the user control whether they want the future
813 # behavior of overwriting the existing tensor or not.

File ~\miniconda3\envs\rastermap\lib\site-packages\torch\nn\modules\module.py:825, in Module._apply(self, fn, recurse)
821 # Tensors stored in modules are graph leaves, and we don't want to
822 # track autograd history of param_applied, so we have to use
823 # with torch.no_grad():
824 with torch.no_grad():
--> 825 param_applied = fn(param)
826 should_use_set_data = compute_should_use_set_data(param, param_applied)
827 if should_use_set_data:

File ~\miniconda3\envs\rastermap\lib\site-packages\torch\nn\modules\module.py:1150, in Module.to..convert(t)
1147 if convert_to_format is not None and t.dim() in (4, 5):
1148 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None,
1149 non_blocking, memory_format=convert_to_format)
-> 1150 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)

File ~\miniconda3\envs\rastermap\lib\site-packages\torch\cuda_init_.py:293, in _lazy_init()
288 raise RuntimeError(
289 "Cannot re-initialize CUDA in forked subprocess. To use CUDA with "
290 "multiprocessing, you must use the 'spawn' start method"
291 )
292 if not hasattr(torch._C, "_cuda_getDeviceCount"):
--> 293 raise AssertionError("Torch not compiled with CUDA enabled")
294 if _cudart is None:
295 raise AssertionError(
296 "libcudart functions unavailable. It looks like you have a broken build?"
297 )

AssertionError: Torch not compiled with CUDA enabled

D:\repos\Rastermap>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:32:27_Pacific_Daylight_Time_2019
Cuda compilation tools, release 10.2, V10.2.89

conda list and CUDA version.txt

Many thanks. Looking forward to hearing from you!

ModuleNotFoundError: No module named 'rastermap.mapping'

Installation of Suite2p goes through but I cannot run Suite2p with 'python -m suite2p'. It reports an error 'ModuleNotFoundError: No module named 'rastermap.mapping''. I also independently installed Rastermap dependency but it still fails to launch suite2p. Is this due to the recent update on the package?

Could you please provide me with any leads to fix this? Thank you!

Neuropixel data used in rastermap(gui)

I would like to use rastermap on neuropixel data. The data are detected and sorted using Kilosort 2.5 and Phy. I further analyze the data with Matlab.
I have seen in your publications that rastermap can be applied to such data. However, the pipeline and necessary data layout is not clear to me.
Can you provide me with information on this?
Best,
Stefan

Loading new data sometimes crashes rastermap

When loading a new dataset using "Load Data Matrix" while a dataset is already loaded results in the following error

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\mouseland\lib\site-packages\rastermap\gui.py", line 629, in mouse_moved_embedding
    dists = (self.embedding[self.selected,0] - x)**2 + (self.embedding[self.selected,1] - y)**2
IndexError: index 1 is out of bounds for axis 1 with size 1

GUI version for linux or windows?

Hi,

When do you plan on releasing a version with the GUI that runs on Windows or Linux? This would be very helpful for us, as we don't currently use Apple products in our labs.

Thanks,

Evan

ModuleNotFoundError: No module named 'rastermap.mapping'

Hello,

When running python -m suite2p, I run into the ModuleNotFoundError: No module named 'rastermap.mapping' error, corresponding to the line from rastermap.mapping import Rastermap in suite2p/gui/visualize.py", line 13. Perhaps this has something to do with the recent Rastermap update. rastermap.mapping module might be renamed to rastermap.

I'd appreciate any help. Thank you!

Risha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.