Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run rastermap on binarized data #31

Closed
Pentabyteman opened this issue Jun 2, 2024 · 6 comments
Closed

run rastermap on binarized data #31

Pentabyteman opened this issue Jun 2, 2024 · 6 comments

Comments

@Pentabyteman
Copy link

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

@Lucas97223
Copy link

I am running into the same issue. Any solution arose?

@carsen-stringer
Copy link
Member

can you try the latest version of the code please and see if you still have this issue?

@alemessurier
Copy link

I'm getting the same error with the gui version (just installed today, and ran pip install rastermap[gui] --upgrade):

data matrix:
(152, 30863)
2024-10-17 16:13:37,981 [INFO] normalizing data across axis=1
2024-10-17 16:13:38,001 [INFO] binning in time with time_bin = 2
2024-10-17 16:13:38,062 [INFO] projecting out mean along axis=0
2024-10-17 16:13:38,081 [INFO] data normalized, 0.10sec
2024-10-17 16:13:38,082 [INFO] sorting activity: 150 valid samples by 30863 timepoints
2024-10-17 16:13:38,415 [INFO] n_PCs = 100 computed, 0.43sec
2024-10-17 16:13:38,482 [INFO] 30 clusters computed, time 0.50sec
2024-10-17 16:13:38,562 [INFO] clusters sorted, time 0.58sec
2024-10-17 16:13:38,585 [INFO] clusters upsampled, time 0.60sec

ERROR<<<
Traceback (most recent call last):
File "/Users/aml717/opt/anaconda3/envs/rastermap/lib/python3.9/runpy.py", line 197, in _run_module_as_main
ERROR<<<
return _run_code(code, main_globals, None,
File "/Users/aml717/opt/anaconda3/envs/rastermap/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/aml717/opt/anaconda3/envs/rastermap/lib/python3.9/site-packages/rastermap/main.py", line 62, in
model.fit(data=X, Usv=Usv, Vsv=Vsv)
File "/Users/aml717/opt/anaconda3/envs/rastermap/lib/python3.9/site-packages/rastermap/rastermap.py", line 494, in fit
ERROR<<<
self.X_embedding = zscore(bin1d(X[igood][self.isort], bin_size, axis=0), axis=1)
IndexError: index 150 is out of bounds for axis 0 with size 150
Interrupted by error (not finished)

if it's useful here is my environment:

image

@carsen-stringer
Copy link
Member

thanks everyone for catching this, this bug should be fixed now! please pip install git+https://github.com/mouseland/rastermap.git for the latest code, I will also push a new pypi release later today

@alemessurier
Copy link

works for me now! thanks!!

@carsen-stringer
Copy link
Member

hurray! created the pypi will close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants