问题描述
下面更新!** *
我有几个 CSV 文件,我正在尝试为其生成热图图像以供分析,但我无法生成图像。我检查了 CSV 中的空行,并尝试了不同的文件。
user@host:~/Downloads/sdr-misc/rtl-sdr-misc/heatmap$ ./heatmap.py ~/Documents/StoGB1.csv image.jpg
loading
x: 7260,y: 1822,z: (-136.700000,-11.050000)
drawing
Traceback (most recent call last):
File "./heatmap.py",line 618,in <module>
img = push_pixels(args)
File "./heatmap.py",line 420,in push_pixels
pix[x,y+tape_height+1] = rgb(zs[x])
File "./heatmap.py",line 360,in rgb_inner
return palette[tone_scaled]
IndexError: list index out of range
第 618 行是:
print("drawing")
img = push_pixels(args)
第 420 行:
for x in range(len(zs)):
pix[x,y+tape_height+1] = rgb(zs[x])
第 360 行:
tone_scaled = int(tone * (len(palette)-1))
return palette[tone_scaled]
更新**** ***
问题实际上来自扫描数据中的非常低的点。
我有从 -60 跳到 -90dB 的负尖峰或凹坑,然后下降到 -136 或 -145。
这些坑是导致 IndexError 的原因。
Mossman 的 Heatmap.py 正在尝试 push_pixels 但 rgb_inner,其中 IndexError 发生在大的负尖峰上。是除以零还是什么?大的负值可能会破坏数组索引数学计算,但这是我第一次深入 Python,我很慢,感谢任何帮助!
第 621 行
img = push_pixels(args)
文件“./heatmap.py”,第 422 行,在 push_pixels 中
pix[x,y+tape_height] = rgb(zs[x])
文件“./heatmap.py”,第 362 行,在 rgb_inner 中
返回调色板[tone_scaled]
rgb_inner 定义:
def rgb_fn(palette,min_z,max_z):
"palette is a list of tuples,returns a function of z"
def rgb_inner(z):
tone = (z - min_z) / (max_z - min_z)
tone_scaled = int(tone * (len(palette)-1))
return palette[tone_scaled]
return rgb_inner
rgb_inner 正在被 rgb_fn 函数 push_pixels 调用:
def push_pixels(args):
"returns PIL img"
width = len(args.freqs)
rgb = rgb_fn(args.palette(),args.db_limit[0],args.db_limit[1])
img = Image.new("RGB",(width,tape_height + args.pix_height))
pix = img.load()
x_size = img.size[0]
average = [0.0] * width
tally = 0
old_y = None
height = len(args.times)
for t,zs in collate_row(x_size):
y = args.times.index(t)
if not args.compress:
for x in range(len(zs)):
pix[x,y+tape_height] = rgb(zs[x])
continue
# ugh
y = args.pix_height - time_compression(height - y,args.compress)
if old_y is None:
old_y = y
if old_y != y:
for x in range(len(average)):
pix[x,old_y+tape_height] = rgb(average[x]/tally)
tally = 0
average = [0.0] * width
old_y = y
for x in range(len(zs)):
average[x] += zs[x]
tally += 1
return img
解决方法
您只需要使用 In a grid layout,content must be placed within columns and only columns may be immediate children of rows.
参数设置一个较低的最小值点,如下所示:
因为“然后它下降到-136或-145”,运行:
--db
这将确保它也呈现不低于 -150 的任何内容。