我有两个无线电,sdr和sdr2,接收数据,我想将该日期(是复数)保存在CSV文件中。我需要同时从两个无线电中获取数据,每个无线电都运行5次扫描,因此我在代码主要部分中所做的是:
#we save the sdr and sdr2 in the same array
radios = [ sdr, sdr2]
pool = ThreadPool(4)
#create an object of class Scan
s=Scan()
#pool.map(function, array)
pool.map(s.scan, radios)
pool.close()
pool.join()
然后,扫描功能为:
class Scan:
def scan(self, object):
for i in range(0,1):
#Read iq data
samples = object.read_samples(256*1024)
#print(samples)
#get the maximum amplitude in frequency to save IQ samples if it's greater
#than -1 dB
sp = np.fft.fft(samples)
ps_real=sp.real
ps_imag=sp.imag
sq=np.power(ps_real,2)+np.power(ps_imag,2)
sqrt=np.sqrt(sq)
psd=sqrt/1024
value=[ps_real,ps_imag]
max=np.max(psd)
log=10*math.log10(max)
print(value)
current_time = time.strftime("%m.%d.%y-%H%M.csv", time.localtime())
if log > -1:
#save the IQ data in csv
with open('%s' % current_time, 'w',newline='') as f:
writer = csv.writer(f, delimiter=',')
writer.writerows(zip(ps_real,ps_imag))
但这是从一个收音机(我认为是唯一一个)的最后一次迭代中获得阵列(真实,imag对)并将其保存在唯一的CSV中...我想拥有2个不同的CSV,因此,我将时间戳记为CSV名称,并且还需要记录任何迭代中的数据。关于如何解决这个问题的任何想法?谢谢!
您将在同一天,同一小时和同一分钟打开输出文件,因此您要在两个作业中写入同一文件,只需使该函数使用id并将其作为参数传递即可:
class Scan:
def scan(self, id, object):
...
current_time = time.strftime("%m.%d.%y-%H%M", time.localtime())
if log > -1:
#save the IQ data in csv
with open('{}_{}.csv' .format(current_time, id), 'w',newline='') as f:
...
然后enumerate
在将其映射到线程池中时使用包装器将ID从中解压缩到无线电中:
#we save the sdr and sdr2 in the same array
radios = [ sdr, sdr2]
pool = ThreadPool(4)
#create an object of class Scan
s=Scan()
def scan(args_tuple):
global s
id, code = args_tuple
return s.scan(id, code)
pool.map(scan, enumerate(radios))
pool.close()
pool.join()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句