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

Neuropixel data used in rastermap(gui) #27

Open
gersgers opened this issue Jan 11, 2024 · 5 comments
Open

Neuropixel data used in rastermap(gui) #27

gersgers opened this issue Jan 11, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@gersgers
Copy link

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

@jbwallace123
Copy link

Hi @gersgers, did you ever figure out a solution to this issue? I have attempted feeding in npx data as spikes binned (neuron x time -- e.g. histogram counts) and as neurons x spiketimes but did not have success. I am not using the GUI but attempting via jupyter/cli first. Any luck on your end?

@carsen-stringer
Copy link
Member

can you please post the error message? we have an example notebook here using a neuron by time matrix (binned from spike times): https://github.com/MouseLand/rastermap/blob/main/notebooks/rastermap_singleneurons.ipynb

@jbwallace123
Copy link

jbwallace123 commented Apr 25, 2024

For my use case, I have sorted with kilosort and ingested the results into a MySQL database (i.e. datajoint). I am then querying the results and attempting to get the data into the right shape for rastermap.

At the moment, I am attempting to create a dataframe with the following shape: neurons x timestep. I have downsampled this to 20Hz for now to decrease the size of my dataframe. Since, the matrix is quite sparse, I have attempted two methods: 1) keep the zeros in or 2) replace them for NaNs (in case this affects handling by rastermap). This results in a dataframe looking like the following:
image

Placing into Rastermap as a dataframe resulted into a slicing error so I changed it to a numpy array then run:

# fit rastermap
model = Rastermap(n_PCs=200, n_clusters=100, locality=0.0, time_lag_window=5, grid_upsample=0).fit(df_array)
y = model.embedding # neurons x 1
isort = model.isort

Which results in the following error:

TypeError                                 Traceback (most recent call last)
Cell In[13], [line 2](vscode-notebook-cell:?execution_count=13&line=2)
      [1](vscode-notebook-cell:?execution_count=13&line=1) # fit rastermap
----> [2](vscode-notebook-cell:?execution_count=13&line=2) model = Rastermap(n_PCs=200, n_clusters=100, locality=0.0, time_lag_window=5, grid_upsample=0).fit(df_array)
      [3](vscode-notebook-cell:?execution_count=13&line=3) y = model.embedding # neurons x 1
      [4](vscode-notebook-cell:?execution_count=13&line=4) isort = model.isort

File [c:\Users\janet\anaconda3\envs\sabatini-datajoint\lib\site-packages\rastermap\rastermap.py:247](file:///C:/Users/janet/anaconda3/envs/sabatini-datajoint/lib/site-packages/rastermap/rastermap.py:247), in Rastermap.fit(self, data, Usv, Vsv, U_nodes, itrain, compute_X_embedding)
    [244](file:///C:/Users/janet/anaconda3/envs/sabatini-datajoint/lib/site-packages/rastermap/rastermap.py:244) self.n_clusters = None if self.n_clusters==0 else self.n_clusters
    [246](file:///C:/Users/janet/anaconda3/envs/sabatini-datajoint/lib/site-packages/rastermap/rastermap.py:246) # normalize data
--> [247](file:///C:/Users/janet/anaconda3/envs/sabatini-datajoint/lib/site-packages/rastermap/rastermap.py:247) igood = ~np.isnan(data[:,0]) if data is not None else ~np.isnan(Usv[:,0])
    [248](file:///C:/Users/janet/anaconda3/envs/sabatini-datajoint/lib/site-packages/rastermap/rastermap.py:248) stdx = None
    [249](file:///C:/Users/janet/anaconda3/envs/sabatini-datajoint/lib/site-packages/rastermap/rastermap.py:249) normed = False

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I have a suspicion the type error is more to do with the way my data is formatted since I am querying, however, it would be great to know if this is the right shape of the data.
Thanks!

@carsen-stringer
Copy link
Member

Ah no, the zeros should be kept in. Those are bins where the neurons don't spike and that's useful info for making the visualization. The sparsity is fine, it should also be able to handle neurons without any spikes, but let me know if you get an error there.

Instead of downsampling, you should bin so that you retain all the spikes. If you have a list of spike times and cluster ids (st and clu), this can be done with this command here:

spks = csr_array((np.ones(len(st), "uint8"),

We will integrate this in as a data loader, I'll put an enhancement tag on it.

@carsen-stringer carsen-stringer added the enhancement New feature or request label Apr 25, 2024
@jbwallace123
Copy link

Got it! That worked! I was able to run it and successfully produce the raster.
There were some dtype issues based on querying from the database. But going from object --> float64 fixed the issue.

Thank you!

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

No branches or pull requests

3 participants