scidash / neuronunit

A package for data-driven validation of neuron and ion channel models using SciUnit
http://neuronunit.scidash.org
38 stars 24 forks source link

Given GLIF given replaced nan's with interpolated_spike_voltages. How to deal with unrealistic Membrane potentials such that GLIF membrane potential is elligible for tests? #180

Open russelljjarvis opened 6 years ago

russelljjarvis commented 6 years ago

@rgerkin @JustasB @vrhaynes

Currently in the GLIF model, to deal with nan values, I have substituted in the code below

The y-axis is (pA) and the x-axis is (seconds). From visual inspection, there might be something a bit wrong with the time scale and I am thinking through this issue now ...

self.results = self.glif.run(stim)
vm = self.results['voltage']
isv = self.results['interpolated_spike_voltage']
dt = 0.0001
voltage = list(map(lambda x: isv if np.isnan(x) else x, vm))
vms = AnalogSignal(voltage,
                            units = mV,
                            sampling_period = dt * ms)

However the returned membrane potential looks much more like the current injection value than an expected membrane potential. See the figure for of plt.plot(times,vm) below:

@vrhaynes you seem pretty savy with the GLIF models. Do you think replacing nans with self.results['interpolated_spike_voltage']'s is appropriate? Is it correct to think of glif.run(stim) as a first pass run, and results['interpolated_spike_voltage'] as a components of a second pass run?

plotting code:

        import matplotlib as mpl
        mpl.use('Agg')
        from matplotlib import pyplot as plt
        plt.plot(vms.times,vms,label=str(c['amplitude']))
        plt.savefig('unrealistic_firing.png')
        plt.legend()
russelljjarvis commented 6 years ago

Perhaps if I export to LEMs model via the file parse_glif.py I can re-simulate with a similar LEMs and verify the output?

JustasB commented 6 years ago

Could also do parse_glif, then convert the LEMS file to NEURON with jnml, and then check the output. NEURON does not support NaN values so PG had to decide how to deal with them when he converted the original models. You could also examine the NeuroML glif definition to see how he ensures all values are defined:

https://github.com/OpenSourceBrain/AllenInstituteNeuroML/blob/master/CellTypesDatabase/models/GLIF/GLIFs.xml

russelljjarvis commented 6 years ago

Thanks, Justas yes I will take the parse glif_approach for sure.

The reason, the waveform looks like it pertains to, two unrealistic spikes instead of one is because I am using the glif cells own spike counting function, instead of the alternative of just using neuronunits own spike_train function instead.

        vms = self.get_membrane_potential()
        from neuronunit.capabilities.spike_functions import get_spike_train
        return get_spike_train(vms)

code for this is now at
https://github.com/russelljjarvis/neuronunit/blob/glif/neuronunit/models/interfaces/glif.py#L62-#L65

Through trial and error I learned that the glif cells simply have different units (seconds, voltage) as opposed to (ms, mV). Using the approach above I have learned that I can get smooth membrane potential waveforms, indicative of time constants and capacitive resistance, however I also think that the default glif models, may lead to very unrealistic traces under the default parameters.

Running dir over the glif model indicates a lot of object attributes that are actually changeable model parameters. If I attach these to the genetic algorithm, I think I would start to get realistic outputs.

russelljjarvis commented 6 years ago

As discussed I have attached the GLIF cells to the BluePyOpt optimizer.

The result is more realistic waveforms, but still not realistic enough to do spike width and height tests.

rheobase

rgerkin commented 6 years ago

Right, the GLIF model is definitely not meant to capture anything about spike waveform properties, only spike timing and maybe a little bit of simple subthreshold behavior.

pgleeson commented 6 years ago

@russelljjarvis @rgerkin Glad to see you're using the GLIFs from the Allen Institute OSB repo. I haven't been following all of the discussions here, but if you do have any issue with running these, do open up issues in the https://github.com/OpenSourceBrain/AllenInstituteNeuroML repo.

BTW, as you'll probably have seen the cells are I&F (so no real spikes), but also the resting potentials of the cells are all shifted to 0mV to ease tuning/comparison between cells. This would probably mean many of the measures of whether they're like the equivalent bio cell can be expected to fail. The GLIFs could be adjusted to be more like the real ephys data, but that's a project in itself...

russelljjarvis commented 6 years ago

Yes, I was slow to remember that GLIF actually expands out to (Generalized Leaky Integrate and Fire) Neurons. It's hard to know what tests to run if any. I can imagine a case for testing the Coefficient of Variation of spike times, in a network connected GLIF cell, perhaps.