Vector Values

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
Jahanzaib
Posts: 1
Joined: Tue Feb 25, 2020 9:28 am

Vector Values

Post by Jahanzaib »

I am working with the model. Passing different values of GNABAR, GKBAR; GL, EL into the model and plotting the results of voltage change. The problem I am having is I cannot save this voltage value to the csv format because its in the vector from

Code: Select all

%%time
t = []
v = []
i = []
for row in range(data_with_sampling.shape[0]):
    
    t_, v_, i_ = run_one_sim(data_with_sampling.iloc[row, :].values)
    t.append(t_)
    v.append(v_)
    i.append(i_)
    
The above is the code that I am using to run the model with different values and appending all the values in the list.

Code: Select all

import csv
with open('data.csv', 'w') as f:
    csv.writer(f).writerows(zip(t, v))
above Code for writing the file that I copied from neuron website.

Code: Select all

with open('data.csv') as f:
    reader = csv.reader(f)
    tnew, vnew = zip(*[[float(val) for val in row] for row in reader if row])
    
The above code is also from the neuron website. And I get the error that is
ValueError: could not convert string to float: 'Vector[3780]'
I don't understand how to fix this and what I am doing wrong. Any help will be appreciated.
vogdb
Posts: 37
Joined: Sun Aug 13, 2017 9:51 am

Re: Vector Values

Post by vogdb »

Hi! The error message clearly say that you are trying to access a string value as float (numeric type). Please post the links to the code from neuron website you are mentioning.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Vector Values

Post by ramcdougal »

I suspect if you look at t, v, etc, you would find that they're lists of Vectors (or maybe but probably not strings), whereas the code you found on the NEURON site assumes them to be lists/vectors of floats. i.e. what is returned in t_, v_, etc is likely Vectors showing the full time course of the variables rather than the ending value. What do you want them to be?

With respect to pandas, here you're iterating over a count of a thing and then slicing to get the specific item you want. You can simplify this by just looping over the rows of your data frame with iterrows, e.g.

Code: Select all

import pandas as pd

data_with_sampling = pd.DataFrame({'gkbar': [1, 1.5, 2], 'gnabar': [1, 7, 14]})

for id_, my_data in data_with_sampling.iterrows():
    print('id', id_, 'gkbar', my_data.gkbar, 'gnabar', my_data.gnabar)
Post Reply