维护地图的列表和插值

Maintaining a list and interpolation of a map

我正在尝试创建一个电压颜色图,如果我想这样做,我必须维护 3 个不同的列表,它们使用了 3 个不同的值。这 3 个值称为:peak、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个坏了。这不是真的,因为当我观察数据时,只有一个电极坏了。所以我假设当值被插入列表时,异常被调用显示第一个损坏的电极,然后它似乎不包括列表的以下值,认为它们是损坏的电极。虽然如果我有许多破碎的电极显示我对它们进行插值以获得充满颜色的地图(插值器不是问题)。我想知道如何让代码在第一个真正损坏的电极之后继续输入值,从而显示一个白色电极,其余电极为黑色。提前谢谢你。

因此,通过在异常内部打印(如上面的问题所示),我发现值 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

当执行这个新代码时,我得到的输出是:

这比之前的输出更有意义。

非常感谢大家的帮助,希望这对你们中的一些人有所帮助。