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

Unexpected behavior on HD-MEA simulation ? #172

Open
b-grimaud opened this issue Sep 30, 2024 · 11 comments
Open

Unexpected behavior on HD-MEA simulation ? #172

b-grimaud opened this issue Sep 30, 2024 · 11 comments

Comments

@b-grimaud
Copy link
Contributor

Hi,
I'm trying to simulate data from in vitro neuronal cultures growing on a CMOS-based HD-MEA, specifically the 3Brain Accura chips.
I understand that this might be a bit beyond what is originally the aim of this tool, but it might be easier on some other points (e.g. in terms of drift, jitter).

I first made the following custom probe with MEAutility :

dim: 64
electrode_name: '3Brain_Accura'
description: "3Brain Accura CMOS"
pitch: 60
shape: 'square'
size: 10.5
plane: 'xy'
sortlist: null
type: 'mea'

Then I used it with the generate_templates_and_recordings notebook, I only changed the n_jobs parameter to -1 during template generation to speed things up a bit.

The output is very "patchy", and quite unusual :

plot_templates(recgen, single_axes=False, ncols=4) returns something like this :
Figure 1

plot_templates(recgen, single_axes=True, cmap='rainbow') returns :
Figure 2bis

Zoomed in :
Figure 2

plot_recordings(recgen, start_time=0, end_time=1, overlay_templates=True) :
Figure 3

Ideally, I'd like to reach an output like this :
téléchargement

Taken from this HerdingSpike example notebook.

Is this reasonably achievable ? Some additional changes would involve sampling frequency and bit depth, but from what I've seen that's doable, my main concern is wether in vivo cell models can be more or less accurately adpated to this setup.

Thanks !

@samuelgarcia
Copy link
Member

@b-grimaud : spikeinterface.generation has now a full machinery to generate recording.
You should have a look.

@alejoe91
Copy link
Member

alejoe91 commented Oct 1, 2024

Hi @b-grimaud

The issue is the plane. By default, cells are oriented as in a in vivo settings, and the plane should be yz. If you use xy, then the cells will be perpendicular to the MEA, which is not what you want.

So I suggest you try again with plane='yz' in your probe and also to set the rot field in the templates_params to xrot, so that cells will be randomly rotate around the x axis (perpendicular to the probe).

Let me know if that works!

@b-grimaud
Copy link
Contributor Author

@samuelgarcia I wasn't aware of this, I'll check it out !

@alejoe91 Thanks for the advice !
I switched those parameters, things changed a bit but not as much.

Figure 4

Figure 5

From the logs during template generation, I saw that some already calculated models are being loaded from disk. Should I delete those to get the cells properly modelled again ?

@alejoe91
Copy link
Member

alejoe91 commented Oct 1, 2024

Something is really weird in the traces...can you paste you're entire code? I'll try to reproduce the issue

@b-grimaud
Copy link
Contributor Author

Here it is, almost entirely based on the example notebook :

import MEArec as mr
import MEAutility as mu
from pprint import pprint
import matplotlib.pylab as plt

%matplotlib widget
default_info, mearec_home = mr.get_default_config()
pprint(default_info)
mu.add_mea(r'./accura.yaml')

With accura.yaml as :

dim: 64
electrode_name: '3Brain_Accura'
description: "3Brain Accura CMOS"
pitch: 60
shape: 'square'
size: 10.5
plane: 'yz'
sortlist: null
type: 'mea'
# define cell_models folder
cell_folder = default_info['cell_models_folder']
template_params = mr.get_default_templates_params()
pprint(template_params)
template_params['n'] = 10
template_params['probe'] = '3Brain_Accura'
template_params['rot'] = 'xrot'
# the templates are not saved, but the intracellular simulations are saved in 'templates_folder'
tempgen = mr.gen_templates(cell_models_folder=cell_folder, params=template_params, n_jobs=-1)
# this will take a few minutes...
print('Templates shape', tempgen.templates.shape)
print('Sample locations', tempgen.locations[:3])
print('Sample rotations', tempgen.rotations[:3])
print('Sample cell types', tempgen.celltypes[:3])
# save templates in h5 format
mr.save_template_generator(tempgen, filename='data/test_templates_yz.h5')
recordings_params = mr.get_default_recordings_params()
pprint(recordings_params)
recgen = mr.gen_recordings(templates='data/test_templates_yz.h5', params=recordings_params)
print('Recordings shape', recgen.recordings.shape)
print('Selected templates shape', recgen.recordings.shape)
print('Sample template locations', recgen.template_locations[:3])
print('Number of neurons', len(recgen.spiketrains))
print('Sample spike train', recgen.spiketrains[0].times)
# save recordings in h5 format
mr.save_recording_generator(recgen, filename='data/test_recordings_yz.h5')
# plot templates
mr.plot_templates(recgen, single_axes=False, ncols=4)
# mr.plot_recordings(recgen)
mr.plot_recordings(recgen, start_time=0, end_time=1, overlay_templates=True)

@alejoe91
Copy link
Member

alejoe91 commented Oct 1, 2024

Can you try the plot_templates with the tempgen?

@b-grimaud
Copy link
Contributor Author

Here's the output for mr.plot_templates(tempgen, single_axes=False, ncols=4), I keep zooming into it but it doesn't look like there are hidden details, just those blocks.

Figure 6

For mr.plot_templates(tempgen, single_axes=True, cmap='rainbow') :

Figure 7

Figure 7bis

@alejoe91
Copy link
Member

alejoe91 commented Oct 4, 2024

@b-grimaud actually everything seems to work on my end, and the problem could be in the overlay_templates. Here's a snippet of the data loaded and plotted with spikeinterface:
image

@alejoe91
Copy link
Member

alejoe91 commented Oct 4, 2024

also the overlay templates seems to be ok..since you have so many electrodes on both axis, you need to zoom in in order to see them properly, since at each electrode location you will see the entire trace:
image

Can you make sure you can reproduce these plots? In that case, I think that it's expected behavior

@b-grimaud
Copy link
Contributor Author

Sorry for the delay, here's the output :
Figure 8

Zoomed in :
Figure 8bis

Figure 9ter

Figure 9bis

It seems that the templates are mostly matching as expected ?
Regarding the template spread and density, I guess this can be fine tuned in the parameters ?

@alejoe91
Copy link
Member

alejoe91 commented Oct 8, 2024

Ok great! Not too much fine tuning is possible, except for choosing some boundaries for the distance from the probe (x limits). In general the spread will depend on the model and it's positioning with respect to the probe.

What do you mean with density? If it's density of neurons, you can just increase the number of n_exc and n_inh in the recording generation so that you reach the desired density

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

3 participants