我正在尝试创建电压颜色映射,如果我想这样做,我必须维护3个不同的列表,这些列表使用了3个不同的值。这三个值称为:峰值,X3和Y3(如下面的代码所示)。以前我在插入新值时更新列表时出现问题,但是通过包含try:
except:
块来解决这个问题。在包含try:
except:
块之后,代码看起来如下:
for k in range(elec_array.nb_chan):
print "electrode number", k
print "The value of act info is", act_info.nb_act[k]
try:
if (act_info.nb_act[k]) >0:
#find the maximum voltage for the set of samples of each channel
max_V.insert(k,np.max(array_data[:,k]))
#find the minimum voltage for the set of samples of each channel
min_V.insert(k,np.min(array_data[:,k]))
dif = ((((max_V[k] - min_V[k])/(4096.0))*10.0)/
elec_array.chan[k].gain) * 1000
#then compute the difference between the max and min to find the
#peak-to-peak value
peak.insert(k,dif)
X3.insert(k, elec_array.chan[k].x) #get the coordinates
Y3.insert(k, elec_array.chan[k].y)
aa=aa+1
except IndexError, ValueError:
Z2as[k] = k #Identify the broken electrode which will be painted white
print k
pass
当我打印所有k值和所有act_info.nb_act [k]值时,我可以看到act_info.nb_act [k]的所有值都有一个大于零的数字,所以它应该返回到if语句并插入数字,但它没有。这是我打印的值:
electrode number 0
The value of act info is 4
electrode number 1
The value of act info is 4
electrode number 2
The value of act info is 4
electrode number 3
The value of act info is 4
electrode number 4
The value of act info is 4
electrode number 5
The value of act info is 4
electrode number 6
The value of act info is 4
electrode number 7
The value of act info is 4
electrode number 8
The value of act info is 4
electrode number 9
The value of act info is 4
electrode number 10
The value of act info is 4
electrode number 11
The value of act info is 4
electrode number 12
The value of act info is 4
electrode number 13
The value of act info is 4
electrode number 14
The value of act info is 4
electrode number 15
The value of act info is 4
electrode number 16
The value of act info is 4
electrode number 17
The value of act info is 4
electrode number 18
The value of act info is 4
electrode number 19
The value of act info is 4
electrode number 20
The value of act info is 4
electrode number 21
The value of act info is 4
electrode number 22
The value of act info is 4
electrode number 23
The value of act info is 4
electrode number 24
The value of act info is 4
electrode number 25
The value of act info is 4
electrode number 26
The value of act info is 4
electrode number 27
The value of act info is 4
electrode number 28
The value of act info is 4
electrode number 29
The value of act info is 4
electrode number 30
The value of act info is 4
electrode number 31
The value of act info is 4
electrode number 32
The value of act info is 4
electrode number 33
The value of act info is 4
electrode number 34
The value of act info is 4
electrode number 35
The value of act info is 4
electrode number 36
The value of act info is 4
electrode number 37
The value of act info is 4
electrode number 38
The value of act info is 4
electrode number 39
The value of act info is 4
electrode number 40
The value of act info is 4
electrode number 41
The value of act info is 2
electrode number 42
The value of act info is 4
electrode number 43
The value of act info is 4
electrode number 44
The value of act info is 4
electrode number 45
The value of act info is 4
electrode number 46
The value of act info is 4
electrode number 47
The value of act info is 4
electrode number 48
The value of act info is 4
electrode number 49
The value of act info is 4
electrode number 50
The value of act info is 4
electrode number 51
The value of act info is 4
electrode number 52
The value of act info is 4
electrode number 53
The value of act info is 4
electrode number 54
The value of act info is 4
electrode number 55
The value of act info is 4
electrode number 56
The value of act info is 4
electrode number 57
The value of act info is 4
electrode number 58
The value of act info is 4
electrode number 59
The value of act info is 4
electrode number 60
The value of act info is 4
electrode number 61
The value of act info is 4
electrode number 62
The value of act info is 4
electrode number 63
The value of act info is 4
electrode number 64
The value of act info is 4
electrode number 65
The value of act info is 4
electrode number 66
The value of act info is 4
electrode number 67
The value of act info is 4
electrode number 68
The value of act info is 4
electrode number 69
The value of act info is 4
electrode number 70
The value of act info is 1
electrode number 71
The value of act info is 2
electrode number 72
The value of act info is 4
electrode number 73
The value of act info is 4
electrode number 74
The value of act info is 4
electrode number 75
The value of act info is 4
electrode number 76
The value of act info is 4
electrode number 77
The value of act info is 4
electrode number 78
The value of act info is 4
electrode number 79
The value of act info is 2
electrode number 80
The value of act info is 4
electrode number 81
The value of act info is 4
electrode number 82
The value of act info is 4
electrode number 83
The value of act info is 4
electrode number 84
The value of act info is 4
electrode number 85
The value of act info is 4
electrode number 86
The value of act info is 4
electrode number 87
The value of act info is 2
electrode number 88
The value of act info is 4
electrode number 89
The value of act info is 4
electrode number 90
The value of act info is 4
electrode number 91
The value of act info is 4
electrode number 92
The value of act info is 4
electrode number 93
The value of act info is 4
electrode number 94
The value of act info is 4
electrode number 95
The value of act info is 4
electrode number 96
The value of act info is 3
electrode number 97
The value of act info is 4
electrode number 98
The value of act info is 4
electrode number 99
The value of act info is 4
electrode number 100
The value of act info is 3
electrode number 101
The value of act info is 4
electrode number 102
The value of act info is 0
electrode number 103
The value of act info is 4
electrode number 104
The value of act info is 4
electrode number 105
The value of act info is 4
electrode number 106
The value of act info is 4
electrode number 107
The value of act info is 4
electrode number 108
The value of act info is 4
electrode number 109
The value of act info is 4
electrode number 110
The value of act info is 4
electrode number 111
The value of act info is 4
当我在异常中打印k时,这是我得到的输出:
103
104
105
106
107
108
109
110
111
意味着最后九个电极显示不起作用。
整个代码的输出是:
如果观察图片,我看到大部分电极是黑色的,9个是白色的,这表明有9个电极坏了。这不是真的,因为当我观察数据时,只有一个电极被破坏。所以我假设当值被插入到列表中时,被调用的异常显示第一个被破坏的电极,然后它似乎不包括列表的下列值,认为它们是被破坏的电极。虽然如果我有许多断电极显示我插入它们以获得一个充满颜色的地图(插补器不是问题)。我想知道如何让代码在第一个真正的断开电极之后继续输入值,因此显示一个白色电极,其余为黑色。提前谢谢。
答案 0 :(得分:0)
因此,通过在异常内部打印(如上面的问题所示),我发现值103到111显示为断开的电极(它们不应该因为它们具有值而不是)。具有零值的唯一电极(如上面的问题中所见)是电极102(其是被破坏的电极)。 所以要解决这个问题,我必须将代码改为:
for k in range(elec_array.nb_chan):
try:
if (act_info.nb_act[k]) >0:
max_V.insert(k,np.max(array_data[:,k]))#find the maximum voltage for the set of samples of each channel
min_V.insert(k,np.min(array_data[:,k])) #find the minimum voltage for the set of samples of each channel
dif = ((((max_V[k] - min_V[k])/(4096.0))*10.0)/elec_array.chan[k].gain)*1000
peak.insert(k,dif) #then compute the difference between the max and min to find the peak-to-peak value
X3.insert(k, elec_array.chan[k].x) #get the coordinates
Y3.insert(k, elec_array.chan[k].y)
else:
Z2as[k] = k #Identify the broken electrode
aa=aa+1
except IndexError, ValueError: #In here all the values of the not broken channels detected as broken receive their values.
max_V.insert(k,np.max(array_data[:,k]))#find the maximum voltage for the set of samples of each channel
min_V.insert(k,np.min(array_data[:,k])) #find the minimum voltage for the set of samples of each channe
dif = ((((max_V[k] - min_V[k])/(4096.0))*10.0)/elec_array.chan[k].gain)*1000
peak.insert(k,dif) #then compute the difference between the max and min to find the peak-to-peak value
X3.insert(k, elec_array.chan[k].x) #get the coordinates
Y3.insert(k, elec_array.chan[k].y)
pass
执行这个新代码时,我得到的输出是:
这比之前的输出更加明显。
非常感谢大家的帮助,我希望这对你们中的一些人有所帮助。