Python 2:使用带有neo.Spike2IO的pd.read()键入错误“只能将整数标量数组转换为标量索引”

时间:2017-02-16 20:01:35

标签: python-2.7 jupyter-notebook

我有代码加载Spike2 .smr文件并在Jupyter中读取它们。我的代码在2天前工作正常,现在,对于加载的文件或加载它的代码完全没有变化,它无法正常工作。问题代码如下......

单元格1输入(显示我的包的版本):

import sys
print("Python version: {}\n\nPackages versions: ".format(sys.version))

# which package versions are installed?
import pip
all_packages = pip.get_installed_distributions()
used_packages = ["matplotlib", "neo", "numpy", "OpenElectrophy", "os", "pandas", 
             "pylab", "scipy"]
for entry in used_packages:
    for p in all_packages:
        if entry in str(p):
            print(str(p))

单元格1输出:

Python version: 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

Packages versions: 
matplotlib 1.4.3
matplotlib-venn 0.11.3
neo 0.3.3
numpy 1.12.0
pycosat 0.6.1
nose 1.3.7
backports.ssl-match-hostname 3.5.0.1
pandas 0.19.2
scipy 0.15.1

Cell 2 Input(在我的模块中加载):

import pylab
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats as st
import os
import tables
import neo
import scipy.signal as sg
from scipy import interpolate as inter
import h5py as h
import quantities as q

plt.style.use('ggplot')
pd.options.display.max_rows = 999

%matplotlib inline

现在,我用:

加载Spike2 .smr文件
r = neo.Spike2IO("Rawdata/143-16/nerve.smr").read()[0]    

并获得以下类型错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-3-f81fd520a4c5> in <module>()
----> 1 r = neo.Spike2IO("Rawdata/143-16/nerve.smr").read()[0]

/home/wolverine/anaconda/lib/python2.7/site-packages/neo/io/baseio.pyc in read(self, lazy, cascade, **kargs)
    107             if not cascade:
    108                 return bl
--> 109             seg = self.read_segment(lazy=lazy, cascade=cascade,  **kargs)
    110             bl.segments.append(seg)
    111             create_many_to_one_relationship(bl)

/home/wolverine/anaconda/lib/python2.7/site-packages/neo/io/spike2io.pyc in read_segment(self, take_ideal_sampling_rate, lazy, cascade)
    120             if channelHeader.kind in [1, 9]:
    121                 #~ print 'analogChanel'
--> 122                 anaSigs = self.readOneChannelContinuous( fid, i, header, take_ideal_sampling_rate, lazy = lazy)
    123                 #~ print 'nb sigs', len(anaSigs) , ' sizes : ',
    124                 for anaSig in anaSigs :

/home/wolverine/anaconda/lib/python2.7/site-packages/neo/io/spike2io.pyc in readOneChannelContinuous(self, fid, channel_num, header, take_ideal_sampling_rate, lazy)
    240 
    241         anaSigs = [ ]
--> 242         if channelHeader.unit in unit_convert:
    243             unit = pq.Quantity(1, unit_convert[channelHeader.unit] )
    244         else:

/home/wolverine/anaconda/lib/python2.7/site-packages/neo/io/spike2io.pyc in __getattr__(self, name)
    444                 else:
    445                     l = np.fromstring(self.array[name][0], 'u1')
--> 446                 return self.array[name][1:l+1]
    447             else:
    448                 return self.array[name]

TypeError: only integer scalar arrays can be converted to a scalar index    

“neo.Spike2IO(”filename.smr“)工作正常,但只要我添加”read()[0]“部分,就是我得到TypeError。我读到了这个类型的错误我看到的唯一答案是文件可能已损坏。我删除了我的本地文件并重新下载了它,并且还下载了另一个类似的文件以防万一另一个文件的主文件损坏。我在这两个上重试了我的代码新文件并收到两者的类型错误代码。如前所述,代码在两天前完美运行,现在它不会加载任何.smr文件。我经历并更新了我的所有模块和pip和anaconda,所有这一切都无济于事。

Here is a link到我为共享目的而剪切的简短示例.smr文件(仅3.1 MB)。它还给出了类型错误。有任何想法吗?谢谢。

1 个答案:

答案 0 :(得分:1)

我通过进一步更新我的模块和Anaconda本身(及其所有相应的模块)解决了这个问题。某些东西必须恢复到旧版本。

更新Anaconda中每个包的代码是:

conda update --all    

可以在Conda主页上找到here的进一步帮助。关闭,然后重新启动计算机也可以帮助确保实现所有这些更新。