Brain Observatory笔记本错误 - 'DataFrame'对象没有属性'orientation'

时间:2017-04-13 16:58:07

标签: python jupyter-notebook allen-sdk

我正在使用Allen Brain Observatory的笔记本:http://alleninstitute.github.io/AllenSDK/_static/examples/nb/brain_observatory.html

当我运行单元格16和17时,在运行单元格17后,我收到此错误:

AttributeError:'DataFrame'对象没有属性'orientation'

以下是两个单元格的代码:

from allensdk.brain_observatory.drifting_gratings import DriftingGratings

# example loading drifing grating data
#data_set = boc.get_ophys_experiment_data(512326618)
dg = DriftingGratings(data_set)
print("done analyzing drifting gratings")

import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline

# filter for visually responding, selective cells
vis_cells = (dg.peak.ptest_dg < 0.05) &  (dg.peak.peak_dff_dg > 3)
osi_cells = vis_cells & (dg.peak.osi_dg > 0.5) & (dg.peak.osi_dg <= 1.5)
dsi_cells = vis_cells & (dg.peak.dsi_dg > 0.5) & (dg.peak.dsi_dg <= 1.5)

# 2-d tf vs. ori histogram
# tfval = 0 is used for the blank sweep, so we are ignoring it here
os = np.zeros((len(dg.orivals), len(dg.tfvals)-1))
ds = np.zeros((len(dg.orivals), len(dg.tfvals)-1))

for i,trial in dg.peak[osi_cells].iterrows():
    os[trial.ori_dg, trial.tf_dg-1] += 1

for i,trial in dg.peak[dsi_cells].iterrows():
    ds[trial.ori_dg, trial.tf_dg-1] += 1

max_count = max(os.max(), ds.max())

fig, (ax1, ax2) = plt.subplots(1,2)

# plot direction selectivity
im = ax1.imshow(ds, clim=[0,max_count], cmap='hot', interpolation='nearest')
ax1.set_xlabel('temporal frequency')
ax1.set_ylabel('direction')
ax1.set_xticks(np.arange(len(dg.tfvals)-1))
ax1.set_xticklabels(dg.tfvals[1:])
ax1.set_yticks(np.arange(len(dg.orivals)))
ax1.set_yticklabels(dg.orivals)
ax1.set_title('direction selective cells')

# plot orientation selectivity
im = ax2.imshow(os, clim=[0,max_count], cmap='hot', interpolation='nearest')
ax2.set_xlabel('temporal frequency')
ax2.set_ylabel('orientation')
ax2.set_xticks(np.arange(len(dg.tfvals)-1))
ax2.set_xticklabels(dg.tfvals[1:])
ax2.set_yticks(np.arange(len(dg.orivals)))
ax2.set_yticklabels(dg.orivals)
ax2.set_title('orientation selective cells')

# plot a colorbar
fig.subplots_adjust(right=0.9)
cbar_ax = fig.add_axes([0.95, 0.05, 0.05, 0.85])
cbar = fig.colorbar(im, cax=cbar_ax)
cbar.set_ticks(np.arange(0, max_count, 2)+0.5)
cbar.set_ticklabels(np.arange(0, max_count, 2, dtype=int))

plt.show()

Traceback中指向的行是:

vis_cells = (dg.peak.ptest_dg < 0.05) &  (dg.peak.peak_dff_dg > 3)

感谢任何帮助。我想使用'allensdk'标签,但我没有1500声望。

1 个答案:

答案 0 :(得分:0)

您能否确认您使用的是python3?我们正在尝试解决与py3相关的一些问题(主要是h5py和PyTables) - 事实上我昨天碰到了这个问题。

问题在于,刺激表列名称是从NWB文件中读出的,其中包含python 3中的字节(&#39; b&#39;)字符串,这些字符串与pandas列索引不兼容。

修复方法是修补此行:

Resulting image

将字符串解码为utf-8。它看起来像这样:

features = [ f.decode('UTF-8') for f in features ]

如果你愿意,我可以把它推到主分支。否则将在6月份发布另一个包含此修复的点。我认为我们当时还没有完整的python3支持,但我们正在努力。